calendar-agent-retrieval-e2e.test.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | /** |
| 2 | * Tier 3 — E2E: multi-calendar agent context walkthrough. |
| 3 | * |
| 4 | * Simulates a user with several connected calendars at mixed agent settings and |
| 5 | * asserts an agent only ever sees the calendars/fields it is entitled to. |
| 6 | * @see lib/calendar/agent-retrieval.mjs |
| 7 | */ |
| 8 | import { describe, it, beforeEach, afterEach } from 'node:test'; |
| 9 | import assert from 'node:assert/strict'; |
| 10 | import fs from 'node:fs'; |
| 11 | import path from 'node:path'; |
| 12 | import { fileURLToPath } from 'node:url'; |
| 13 | import { importIcsIntoVault } from '../lib/calendar/event-store.mjs'; |
| 14 | import { patchSourceCalendar } from '../lib/calendar/source-calendar-patch.mjs'; |
| 15 | import { retrieveAgentCalendarContext } from '../lib/calendar/agent-retrieval.mjs'; |
| 16 | |
| 17 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 18 | const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-calendar-agent-e2e'); |
| 19 | const fixtureDir = path.join(__dirname, 'fixtures', 'calendar'); |
| 20 | const simpleIcs = fs.readFileSync(path.join(fixtureDir, 'simple-utc.ics'), 'utf8'); |
| 21 | const multiIcs = fs.readFileSync(path.join(fixtureDir, 'multi-event.ics'), 'utf8'); |
| 22 | |
| 23 | const RANGE = { from: '2026-06-01', to: '2026-06-30' }; |
| 24 | |
| 25 | describe('E2E — agent context across mixed calendars', () => { |
| 26 | const dataDir = path.join(tmpRoot, 'data'); |
| 27 | const vaultId = 'default'; |
| 28 | /** @type {string} */ |
| 29 | let workId; |
| 30 | /** @type {string} */ |
| 31 | let personalId; |
| 32 | |
| 33 | beforeEach(() => { |
| 34 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 35 | fs.mkdirSync(dataDir, { recursive: true }); |
| 36 | delete process.env.KNOWTATION_CALENDAR_AGENT_TIER_MAX_CAP; |
| 37 | workId = importIcsIntoVault(dataDir, vaultId, { icsText: simpleIcs, displayName: 'Work' }).source_calendar_id; |
| 38 | personalId = importIcsIntoVault(dataDir, vaultId, { icsText: multiIcs, displayName: 'Personal' }).source_calendar_id; |
| 39 | }); |
| 40 | |
| 41 | afterEach(() => { |
| 42 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 43 | delete process.env.KNOWTATION_CALENDAR_AGENT_TIER_MAX_CAP; |
| 44 | }); |
| 45 | |
| 46 | it('only includes the agent-enabled calendar, leaves the other invisible', () => { |
| 47 | patchSourceCalendar(dataDir, vaultId, workId, { enabled_for_agents: true, agent_context_tier_max: 2 }); |
| 48 | // personal stays at the v0 default (agents off) |
| 49 | |
| 50 | const result = retrieveAgentCalendarContext(dataDir, vaultId, { ...RANGE, agentContextTier: 2 }); |
| 51 | assert.equal(result.source_calendars.length, 1); |
| 52 | assert.equal(result.source_calendars[0].source_calendar_id, workId); |
| 53 | assert.ok(result.items.every((i) => i.source_calendar_id === workId)); |
| 54 | assert.ok(result.items.some((i) => i.summary === 'Team standup')); |
| 55 | }); |
| 56 | |
| 57 | it('applies the lower tier per calendar in a single request', () => { |
| 58 | patchSourceCalendar(dataDir, vaultId, workId, { enabled_for_agents: true, agent_context_tier_max: 2 }); |
| 59 | patchSourceCalendar(dataDir, vaultId, personalId, { enabled_for_agents: true, agent_context_tier_max: 1 }); |
| 60 | |
| 61 | const result = retrieveAgentCalendarContext(dataDir, vaultId, { ...RANGE, agentContextTier: 2 }); |
| 62 | const work = result.items.filter((i) => i.source_calendar_id === workId); |
| 63 | const personal = result.items.filter((i) => i.source_calendar_id === personalId); |
| 64 | |
| 65 | assert.ok(work.every((i) => i.agent_tier === 2 && typeof i.summary === 'string')); |
| 66 | assert.ok(personal.length > 0); |
| 67 | assert.ok(personal.every((i) => i.agent_tier === 1 && !('summary' in i))); |
| 68 | }); |
| 69 | |
| 70 | it('restricts scope when source_calendar_ids is supplied', () => { |
| 71 | patchSourceCalendar(dataDir, vaultId, workId, { enabled_for_agents: true, agent_context_tier_max: 2 }); |
| 72 | patchSourceCalendar(dataDir, vaultId, personalId, { enabled_for_agents: true, agent_context_tier_max: 2 }); |
| 73 | |
| 74 | const result = retrieveAgentCalendarContext(dataDir, vaultId, { |
| 75 | ...RANGE, |
| 76 | agentContextTier: 2, |
| 77 | sourceCalendarIds: personalId, |
| 78 | }); |
| 79 | assert.equal(result.source_calendars.length, 1); |
| 80 | assert.ok(result.items.every((i) => i.source_calendar_id === personalId)); |
| 81 | }); |
| 82 | }); |
File History
1 commit
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠
1 day ago