calendar-event-store-unit.test.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | /** |
| 2 | * Tier 1 — UNIT: calendar event store helpers. |
| 3 | */ |
| 4 | import { describe, it, beforeEach, afterEach } from 'node:test'; |
| 5 | import assert from 'node:assert/strict'; |
| 6 | import fs from 'node:fs'; |
| 7 | import path from 'node:path'; |
| 8 | import { fileURLToPath } from 'node:url'; |
| 9 | import { |
| 10 | buildEventId, |
| 11 | importIcsIntoVault, |
| 12 | queryStoredEvents, |
| 13 | listSourceCalendars, |
| 14 | getCalendarStorePath, |
| 15 | } from '../lib/calendar/event-store.mjs'; |
| 16 | import { SOURCE_CALENDAR_DEFAULTS } from '../lib/calendar/source-calendar-defaults.mjs'; |
| 17 | |
| 18 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 19 | const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-calendar-store'); |
| 20 | |
| 21 | describe('buildEventId', () => { |
| 22 | it('is stable for the same source calendar + external uid', () => { |
| 23 | const a = buildEventId('cal_a', 'uid@x'); |
| 24 | const b = buildEventId('cal_a', 'uid@x'); |
| 25 | assert.equal(a, b); |
| 26 | assert.match(a, /^evt_[0-9a-f]{24}$/); |
| 27 | }); |
| 28 | }); |
| 29 | |
| 30 | describe('importIcsIntoVault', () => { |
| 31 | const dataDir = path.join(tmpRoot, 'data'); |
| 32 | const vaultId = 'default'; |
| 33 | |
| 34 | beforeEach(() => { |
| 35 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 36 | fs.mkdirSync(dataDir, { recursive: true }); |
| 37 | }); |
| 38 | |
| 39 | afterEach(() => { |
| 40 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 41 | }); |
| 42 | |
| 43 | const ics = `BEGIN:VCALENDAR |
| 44 | BEGIN:VEVENT |
| 45 | UID:evt@test |
| 46 | DTSTART:20260618T170000Z |
| 47 | DTEND:20260618T173000Z |
| 48 | SUMMARY:Team standup |
| 49 | END:VEVENT |
| 50 | END:VCALENDAR`; |
| 51 | |
| 52 | it('creates a source calendar with v0 defaults and stores events', () => { |
| 53 | const result = importIcsIntoVault(dataDir, vaultId, { icsText: ics, displayName: 'Work' }); |
| 54 | assert.equal(result.imported, 1); |
| 55 | assert.equal(result.updated, 0); |
| 56 | assert.ok(result.source_calendar_id.startsWith('cal_')); |
| 57 | |
| 58 | const calendars = listSourceCalendars(dataDir, vaultId); |
| 59 | assert.equal(calendars.length, 1); |
| 60 | assert.equal(calendars[0].display_name, 'Work'); |
| 61 | assert.equal(calendars[0].enabled_for_display, SOURCE_CALENDAR_DEFAULTS.enabled_for_display); |
| 62 | assert.equal(calendars[0].enabled_for_agents, SOURCE_CALENDAR_DEFAULTS.enabled_for_agents); |
| 63 | |
| 64 | const events = queryStoredEvents(dataDir, vaultId, { |
| 65 | fromIso: '2026-06-01T00:00:00.000Z', |
| 66 | toIso: '2026-06-30T23:59:59.999Z', |
| 67 | displayOnly: true, |
| 68 | }); |
| 69 | assert.equal(events.length, 1); |
| 70 | assert.equal(events[0].summary, 'Team standup'); |
| 71 | assert.ok(fs.existsSync(getCalendarStorePath(dataDir))); |
| 72 | }); |
| 73 | |
| 74 | it('upserts into an existing source calendar on re-import', () => { |
| 75 | const first = importIcsIntoVault(dataDir, vaultId, { icsText: ics }); |
| 76 | const second = importIcsIntoVault(dataDir, vaultId, { |
| 77 | icsText: ics, |
| 78 | sourceCalendarId: first.source_calendar_id, |
| 79 | }); |
| 80 | assert.equal(second.imported, 0); |
| 81 | assert.equal(second.updated, 1); |
| 82 | }); |
| 83 | }); |
File History
1 commit
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠
1 day ago