calendar-agent-retrieval-integration.test.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | /** |
| 2 | * Tier 2 — INTEGRATION: agent retrieval against the local event store. |
| 3 | * |
| 4 | * Imports ICS, toggles agent access, and asserts that retrieveAgentCalendarContext |
| 5 | * enforces enabled_for_agents and per-calendar tier caps server-side. |
| 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-integration'); |
| 19 | const ics = fs.readFileSync(path.join(__dirname, 'fixtures', 'calendar', 'simple-utc.ics'), 'utf8'); |
| 20 | |
| 21 | const RANGE = { from: '2026-06-01', to: '2026-06-30' }; |
| 22 | |
| 23 | describe('retrieveAgentCalendarContext — store integration', () => { |
| 24 | const dataDir = path.join(tmpRoot, 'data'); |
| 25 | const vaultId = 'default'; |
| 26 | /** @type {string} */ |
| 27 | let calendarId; |
| 28 | |
| 29 | beforeEach(() => { |
| 30 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 31 | fs.mkdirSync(dataDir, { recursive: true }); |
| 32 | delete process.env.KNOWTATION_CALENDAR_AGENT_TIER_MAX_CAP; |
| 33 | calendarId = importIcsIntoVault(dataDir, vaultId, { icsText: ics, displayName: 'Work' }).source_calendar_id; |
| 34 | }); |
| 35 | |
| 36 | afterEach(() => { |
| 37 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 38 | delete process.env.KNOWTATION_CALENDAR_AGENT_TIER_MAX_CAP; |
| 39 | }); |
| 40 | |
| 41 | it('returns no events for a calendar with agents disabled (v0 default)', () => { |
| 42 | const result = retrieveAgentCalendarContext(dataDir, vaultId, { ...RANGE, agentContextTier: 2 }); |
| 43 | assert.equal(result.schema, 'knowtation.calendar_agent_context/v0'); |
| 44 | assert.equal(result.items.length, 0); |
| 45 | assert.equal(result.source_calendars.length, 0); |
| 46 | }); |
| 47 | |
| 48 | it('tier 2 returns summary and calendar label once agents are enabled', () => { |
| 49 | patchSourceCalendar(dataDir, vaultId, calendarId, { enabled_for_agents: true, agent_context_tier_max: 2 }); |
| 50 | const result = retrieveAgentCalendarContext(dataDir, vaultId, { ...RANGE, agentContextTier: 2 }); |
| 51 | assert.equal(result.items.length, 1); |
| 52 | const [item] = result.items; |
| 53 | assert.equal(item.summary, 'Team standup'); |
| 54 | assert.equal(item.calendar_label, 'Work'); |
| 55 | assert.equal(item.agent_tier, 2); |
| 56 | assert.equal(item.busy, true); |
| 57 | assert.equal(result.source_calendars[0].event_count, 1); |
| 58 | }); |
| 59 | |
| 60 | it('tier 1 redacts the title but keeps busy blocks', () => { |
| 61 | patchSourceCalendar(dataDir, vaultId, calendarId, { enabled_for_agents: true, agent_context_tier_max: 2 }); |
| 62 | const result = retrieveAgentCalendarContext(dataDir, vaultId, { ...RANGE, agentContextTier: 1 }); |
| 63 | assert.equal(result.items.length, 1); |
| 64 | const [item] = result.items; |
| 65 | assert.equal(item.agent_tier, 1); |
| 66 | assert.ok(!('summary' in item), 'tier 1 must not include summary'); |
| 67 | assert.ok(!('calendar_label' in item), 'tier 1 must not include calendar_label'); |
| 68 | assert.equal(typeof item.start, 'string'); |
| 69 | assert.equal(item.busy, true); |
| 70 | }); |
| 71 | |
| 72 | it('requested tier 0 returns no events even with agents enabled', () => { |
| 73 | patchSourceCalendar(dataDir, vaultId, calendarId, { enabled_for_agents: true, agent_context_tier_max: 2 }); |
| 74 | const result = retrieveAgentCalendarContext(dataDir, vaultId, { ...RANGE, agentContextTier: 0 }); |
| 75 | assert.equal(result.items.length, 0); |
| 76 | assert.equal(result.source_calendars[0].effective_tier, 0); |
| 77 | }); |
| 78 | |
| 79 | it('per-calendar cap clamps a tier-2 request down to tier 1', () => { |
| 80 | patchSourceCalendar(dataDir, vaultId, calendarId, { enabled_for_agents: true, agent_context_tier_max: 1 }); |
| 81 | const result = retrieveAgentCalendarContext(dataDir, vaultId, { ...RANGE, agentContextTier: 2 }); |
| 82 | assert.equal(result.items.length, 1); |
| 83 | assert.equal(result.items[0].agent_tier, 1); |
| 84 | assert.ok(!('summary' in result.items[0])); |
| 85 | }); |
| 86 | }); |
File History
1 commit
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠
1 day ago