Files
TREK/shared/src/assistant/assistant-scope.schema.spec.ts
T
Maurice 2508fd8624 feat(assistant): a journey's chat request names the page it is asked from
The journey's assistant lives in TREK Studio today, and the journal page is
about to get one of its own over the same threads. The chat and decision
bodies take an optional surface, studio or journal, and the journey scope
carries it to the service; left out it reads as the Studio, so today's
client is unchanged. The scope key ignores it, so both pages keep one
thread list per journey.
2026-10-24 22:54:42 +02:00

62 lines
3.3 KiB
TypeScript

import {
ASSISTANT_JOURNEY_SURFACES,
assistantScopeKey,
assistantScopeSchema,
HOME_ASSISTANT_SCOPE,
} from './assistant-scope.schema';
import { assistantFocusSchema } from './assistant.schema';
import { describe, expect, it } from 'vitest';
describe('assistantScopeSchema', () => {
it('ASTSCOPE-001: is a trip or a journey, each by its own positive id', () => {
expect(assistantScopeSchema.parse({ kind: 'trip', tripId: 5 })).toEqual({ kind: 'trip', tripId: 5 });
expect(assistantScopeSchema.parse({ kind: 'journey', journeyId: 12 })).toEqual({ kind: 'journey', journeyId: 12 });
expect(assistantScopeSchema.safeParse({ kind: 'trip', tripId: 0 }).success).toBe(false);
expect(assistantScopeSchema.safeParse({ kind: 'journey', tripId: 5 }).success).toBe(false);
});
it('ASTSCOPE-002: is never both and never anything else', () => {
expect(assistantScopeSchema.safeParse({ kind: 'trip', tripId: 5, journeyId: 12 }).success).toBe(false);
expect(assistantScopeSchema.safeParse({ kind: 'collection', collectionId: 3 }).success).toBe(false);
expect(assistantScopeSchema.safeParse({}).success).toBe(false);
});
it('ASTSCOPE-003: keys a trip and a journey with the same id apart', () => {
expect(assistantScopeKey({ kind: 'trip', tripId: 7 })).toBe('trip:7');
expect(assistantScopeKey({ kind: 'journey', journeyId: 7 })).toBe('journey:7');
});
it('ASTSCOPE-007: a journey names the page it is asked from, which never changes its key', () => {
const journal = { kind: 'journey', journeyId: 7, surface: 'journal' } as const;
expect(assistantScopeSchema.parse(journal)).toEqual(journal);
expect(assistantScopeSchema.safeParse({ ...journal, surface: 'planner' }).success).toBe(false);
expect(assistantScopeSchema.safeParse({ kind: 'trip', tripId: 7, surface: 'journal' }).success).toBe(false);
expect(assistantScopeKey(journal)).toBe(assistantScopeKey({ kind: 'journey', journeyId: 7, surface: 'studio' }));
expect(ASSISTANT_JOURNEY_SURFACES).toEqual(['studio', 'journal']);
});
it('ASTSCOPE-006: has a home scope that names no trip and no journey', () => {
expect(assistantScopeSchema.parse({ kind: 'home' })).toEqual(HOME_ASSISTANT_SCOPE);
expect(assistantScopeSchema.safeParse({ kind: 'home', tripId: 5 }).success).toBe(false);
expect(assistantScopeSchema.safeParse({ kind: 'home', journeyId: 12 }).success).toBe(false);
expect(assistantScopeKey(HOME_ASSISTANT_SCOPE)).toBe('home');
});
});
describe('assistantFocusSchema in the Studio', () => {
it('ASTSCOPE-004: carries the page on screen and up to 30 selected elements, by their document ids', () => {
const focus = { spreadId: 'sp-ab12', elementIds: ['p-1', 'p-2'] };
expect(assistantFocusSchema.parse(focus)).toEqual(focus);
expect(assistantFocusSchema.safeParse({ spreadId: 'sp ab' }).success).toBe(false);
expect(assistantFocusSchema.safeParse({ spreadId: 'x'.repeat(41) }).success).toBe(false);
const many = Array.from({ length: 31 }, (_, i) => `p-${i}`);
expect(assistantFocusSchema.safeParse({ elementIds: many }).success).toBe(false);
});
it('ASTSCOPE-005: leaves the planner focus as it was', () => {
expect(assistantFocusSchema.parse({ dayId: 4, placeIds: [1] })).toEqual({ dayId: 4, placeIds: [1] });
expect(assistantFocusSchema.safeParse({ dayId: 4, page: 2 }).success).toBe(false);
});
});