import { describe, expect, it } from 'vitest'; import { InMemoryMemoryStore, Persona } from '../src'; describe('Persona schedules and availability', () => { it('creates tomorrow as a ten-minute daily schedule and persists it in memory', async () => { const memory = new InMemoryMemoryStore(); const persona = new Persona('Mina', 'Mina works weekdays and studies at night.', { memory, now: '2026-05-01T10:00:00.000Z' }); const space = await persona.ready(); const entries = await persona.createDailySchedule('2026-05-01T10:00:00.000Z', 'Keep a normal work day.'); expect(entries).toHaveLength(144); expect(entries[0]).toMatchObject({ spaceId: space.id, startAt: '2026-05-02T00:00:00.000Z', endAt: '2026-05-02T00:10:00.000Z', granularity: 'ten-minute', }); expect(entries.at(-1)?.endAt).toBe('2026-05-03T00:00:00.000Z'); await expect(memory.listScheduleEntries(space.id, '2026-05-02T00:00:00.000Z', '2026-05-03T00:00:00.000Z')).resolves.toHaveLength(144); }); it('derives online, do-not-disturb, and offline availability from the in-memory schedule window', async () => { const memory = new InMemoryMemoryStore(); const persona = new Persona('Mina', 'Mina works weekdays and studies at night.', { memory, now: '2026-05-01T10:00:00.000Z' }); await persona.ready(); await persona.createDailySchedule('2026-05-01T10:00:00.000Z', 'Keep a normal work day.'); const availability = await persona.getTodayScheduledAvailability('2026-05-01T12:00:00.000Z'); expect(availability.windowStartAt).toBe('2026-05-01T00:00:00.000Z'); expect(availability.windowEndAt).toBe('2026-05-03T00:00:00.000Z'); expect(new Set(availability.ranges.map((range) => range.mode))).toEqual(new Set(['offline', 'online', 'do-not-disturb'])); expect(availability.ranges.find((range) => range.mode === 'offline')?.startAt).toBe('2026-05-02T00:00:00.000Z'); }); it('prunes schedule entries before a caller-provided cutoff', async () => { const memory = new InMemoryMemoryStore(); const persona = new Persona('Mina', 'Mina works weekdays.', { memory, now: '2026-05-01T10:00:00.000Z' }); const space = await persona.ready(); await persona.createDailySchedule('2026-05-01T10:00:00.000Z', 'Keep a normal work day.'); const deleted = await persona.deleteSchedulesBefore('2026-05-02T12:00:00.000Z'); expect(deleted).toBe(72); await expect(memory.listScheduleEntries(space.id, '2026-05-02T00:00:00.000Z', '2026-05-03T00:00:00.000Z')).resolves.toHaveLength(72); const deletionFacts = await memory.findFacts(space.id, ['persona.schedule.deleted']); expect(deletionFacts[0]?.metadata?.['deleted']).toBe(72); }); });