calendar-agent-retrieval-stress.test.mjs
87 lines 2.9 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 1 day ago
1 /**
2 * Tier 4 — STRESS: large event volumes and repeated agent retrievals.
3 *
4 * Confirms enforcement and counts stay correct under load and repetition.
5 * @see lib/calendar/agent-retrieval.mjs
6 */
7 import { describe, it, beforeEach, afterEach } from 'node:test';
8 import assert from 'node:assert/strict';
9 import fs from 'node:fs';
10 import path from 'node:path';
11 import { fileURLToPath } from 'node:url';
12 import { importIcsIntoVault } from '../lib/calendar/event-store.mjs';
13 import { patchSourceCalendar } from '../lib/calendar/source-calendar-patch.mjs';
14 import { retrieveAgentCalendarContext } from '../lib/calendar/agent-retrieval.mjs';
15
16 const __dirname = path.dirname(fileURLToPath(import.meta.url));
17 const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-calendar-agent-stress');
18
19 const EVENT_COUNT = 600;
20
21 function buildBulkIcs(count) {
22 const chunks = ['BEGIN:VCALENDAR', 'VERSION:2.0'];
23 for (let i = 0; i < count; i += 1) {
24 const day = String((i % 27) + 1).padStart(2, '0');
25 chunks.push(
26 'BEGIN:VEVENT',
27 `UID:bulk-${i}@stress.test`,
28 `DTSTART:202606${day}T090000Z`,
29 `DTEND:202606${day}T093000Z`,
30 `SUMMARY:Bulk event ${i}`,
31 'STATUS:CONFIRMED',
32 'END:VEVENT',
33 );
34 }
35 chunks.push('END:VCALENDAR');
36 return chunks.join('\n');
37 }
38
39 describe('Stress — bulk agent retrieval', () => {
40 const dataDir = path.join(tmpRoot, 'data');
41 const vaultId = 'default';
42 /** @type {string} */
43 let calendarId;
44
45 beforeEach(() => {
46 fs.rmSync(tmpRoot, { recursive: true, force: true });
47 fs.mkdirSync(dataDir, { recursive: true });
48 calendarId = importIcsIntoVault(dataDir, vaultId, {
49 icsText: buildBulkIcs(EVENT_COUNT),
50 displayName: 'Bulk',
51 }).source_calendar_id;
52 patchSourceCalendar(dataDir, vaultId, calendarId, { enabled_for_agents: true, agent_context_tier_max: 2 });
53 });
54
55 afterEach(() => {
56 fs.rmSync(tmpRoot, { recursive: true, force: true });
57 });
58
59 it('returns every in-range event exactly once at tier 2', () => {
60 const result = retrieveAgentCalendarContext(dataDir, vaultId, {
61 from: '2026-06-01',
62 to: '2026-06-30',
63 agentContextTier: 2,
64 });
65 assert.equal(result.items.length, EVENT_COUNT);
66 const uids = new Set(result.items.map((i) => i.external_uid));
67 assert.equal(uids.size, EVENT_COUNT);
68 assert.equal(result.source_calendars[0].event_count, EVENT_COUNT);
69 });
70
71 it('produces identical output across 50 repeated retrievals', () => {
72 let previous = null;
73 for (let i = 0; i < 50; i += 1) {
74 const result = retrieveAgentCalendarContext(dataDir, vaultId, {
75 from: '2026-06-01',
76 to: '2026-06-30',
77 agentContextTier: 1,
78 });
79 assert.equal(result.items.length, EVENT_COUNT);
80 const signature = result.items.map((i) => `${i.external_uid}:${i.agent_tier}`).join('|');
81 if (previous !== null) {
82 assert.equal(signature, previous);
83 }
84 previous = signature;
85 }
86 });
87 });
File History 1 commit
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor 1 day ago