calendar-agent-retrieval-performance.test.mjs
66 lines 2.2 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 3 days ago
1 /**
2 * Tier 6 — PERFORMANCE: agent retrieval throughput smoke (no network).
3 *
4 * @see lib/calendar/agent-retrieval.mjs
5 */
6 import { describe, it, beforeEach, afterEach } from 'node:test';
7 import assert from 'node:assert/strict';
8 import fs from 'node:fs';
9 import path from 'node:path';
10 import { fileURLToPath } from 'node:url';
11 import { importIcsIntoVault } from '../lib/calendar/event-store.mjs';
12 import { patchSourceCalendar } from '../lib/calendar/source-calendar-patch.mjs';
13 import { retrieveAgentCalendarContext } from '../lib/calendar/agent-retrieval.mjs';
14
15 const __dirname = path.dirname(fileURLToPath(import.meta.url));
16 const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-calendar-agent-perf');
17
18 const EVENT_COUNT = 500;
19
20 function buildBulkIcs(count) {
21 const chunks = ['BEGIN:VCALENDAR', 'VERSION:2.0'];
22 for (let i = 0; i < count; i += 1) {
23 const day = String((i % 27) + 1).padStart(2, '0');
24 chunks.push(
25 'BEGIN:VEVENT',
26 `UID:perf-${i}@perf.test`,
27 `DTSTART:202606${day}T120000Z`,
28 `DTEND:202606${day}T123000Z`,
29 `SUMMARY:Perf event ${i}`,
30 'END:VEVENT',
31 );
32 }
33 chunks.push('END:VCALENDAR');
34 return chunks.join('\n');
35 }
36
37 describe('Performance — agent retrieval over 500 events', () => {
38 const dataDir = path.join(tmpRoot, 'data');
39 const vaultId = 'default';
40
41 beforeEach(() => {
42 fs.rmSync(tmpRoot, { recursive: true, force: true });
43 fs.mkdirSync(dataDir, { recursive: true });
44 const id = importIcsIntoVault(dataDir, vaultId, {
45 icsText: buildBulkIcs(EVENT_COUNT),
46 displayName: 'Perf',
47 }).source_calendar_id;
48 patchSourceCalendar(dataDir, vaultId, id, { enabled_for_agents: true, agent_context_tier_max: 2 });
49 });
50
51 afterEach(() => {
52 fs.rmSync(tmpRoot, { recursive: true, force: true });
53 });
54
55 it('completes a tier-2 retrieval in under 750ms', () => {
56 const start = performance.now();
57 const result = retrieveAgentCalendarContext(dataDir, vaultId, {
58 from: '2026-06-01',
59 to: '2026-06-30',
60 agentContextTier: 2,
61 });
62 const elapsed = performance.now() - start;
63 assert.equal(result.items.length, EVENT_COUNT);
64 assert.ok(elapsed < 750, `retrieval took ${elapsed.toFixed(1)}ms`);
65 });
66 });
File History 1 commit
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor 3 days ago