calendar-ics-normalizer-e2e.test.mjs
55 lines 2.1 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 1 day ago
1 /**
2 * Tier 3 — E2E: full VCALENDAR walkthrough mirroring a user export → normalized store-ready rows.
3 * No network; simulates the 1B ingest boundary.
4 */
5 import { describe, it } from 'node:test';
6 import assert from 'node:assert/strict';
7 import fs from 'node:fs';
8 import path from 'node:path';
9 import { fileURLToPath } from 'node:url';
10 import { parseIcsToEvents } from '../lib/calendar/ics-normalizer.mjs';
11 import { SOURCE_CALENDAR_DEFAULTS } from '../lib/calendar/source-calendar-defaults.mjs';
12
13 const __dirname = path.dirname(fileURLToPath(import.meta.url));
14 const fixtureDir = path.join(__dirname, 'fixtures', 'calendar');
15
16 /**
17 * Simulates the 1B store layer assigning ids — not part of the normalizer itself.
18 *
19 * @param {import('../lib/calendar/ics-normalizer.mjs').NormalizedCalendarEvent[]} events
20 * @param {string} sourceCalendarId
21 * @returns {object[]}
22 */
23 function attachStoreIds(events, sourceCalendarId) {
24 return events.map((e) => ({
25 event_id: `evt_${sourceCalendarId}_${e.external_uid}`,
26 source_calendar_id: sourceCalendarId,
27 ...e,
28 linked_note_paths: null,
29 deleted_at: e.status === 'cancelled' ? e.start : null,
30 }));
31 }
32
33 describe('E2E — user ICS export to store-ready records', () => {
34 it('produces dedup-friendly rows with stable external_uid', () => {
35 const ics = fs.readFileSync(path.join(fixtureDir, 'multi-event.ics'), 'utf8');
36 const normalized = parseIcsToEvents(ics, { defaultTimezone: 'America/Los_Angeles' });
37 const stored = attachStoreIds(normalized, 'cal_work');
38
39 assert.equal(stored.length, 2);
40 for (const row of stored) {
41 assert.match(row.event_id, /^evt_cal_work_/);
42 assert.equal(row.source_calendar_id, 'cal_work');
43 assert.ok(row.start.endsWith('Z'));
44 assert.ok(row.end.endsWith('Z'));
45 assert.ok(typeof row.busy === 'boolean');
46 }
47 });
48
49 it('applies v0 SourceCalendar defaults at connect time', () => {
50 const toggles = { ...SOURCE_CALENDAR_DEFAULTS };
51 assert.equal(toggles.enabled_for_display, true);
52 assert.equal(toggles.enabled_for_agents, false);
53 assert.equal(toggles.agent_context_tier_max, 0);
54 });
55 });
File History 1 commit
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor 1 day ago