49c8def037
pnpm + turbo workspace with the commands from CLAUDE.md §3. The contracts from §6 as JSON Schemas with generated types; localDay as the one place a day is computed; the forbidden-word list shared by lint:copy and the library validator, with 13 negative fixtures; a Svelte 5 PWA shell built under /Rosea/ with a meta CSP. E2E and offline suites run against the built bundle; the offline one closes the server rather than emulating. Analysis: .agents/features/phase0-workspace.md
113 lines
3.2 KiB
TypeScript
113 lines
3.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { validateCareEvent, validateHopeSentence, validateTrace } from '../src/validate.js';
|
|
|
|
const KEY_A = 'A'.repeat(43);
|
|
const KEY_B = 'b_-'.repeat(15);
|
|
|
|
const careEvent = {
|
|
kind: 'care',
|
|
ts: 1761500000000,
|
|
localDay: '2026-10-24',
|
|
from: KEY_A,
|
|
to: KEY_B,
|
|
act: 'water',
|
|
trace: 'petal:pale-pink',
|
|
messageId: 'ps-23-4',
|
|
clientVersion: '0.1.0'
|
|
};
|
|
|
|
const sentence = {
|
|
id: 'ps-23-4',
|
|
text: { en: 'Placeholder text for a schema test.' },
|
|
source: {
|
|
work: 'Psalms 23:4',
|
|
author: null,
|
|
tradition: 'biblical',
|
|
translation: 'KJV',
|
|
publicDomain: true,
|
|
verifiedBy: 'Test',
|
|
verifiedAt: '2026-11-01'
|
|
},
|
|
use: ['sunset'],
|
|
tone: 'gentle',
|
|
promisesOutcome: false
|
|
};
|
|
|
|
const trace = {
|
|
traceId: 'r'.repeat(22),
|
|
geocell: 'u2fkb',
|
|
dayBucket: '2026-10-24',
|
|
gesture: 'petal',
|
|
sig: 's'.repeat(64)
|
|
};
|
|
|
|
describe('hope sentence', () => {
|
|
it('accepts a complete entry', () => {
|
|
expect(validateHopeSentence(sentence)).toMatchObject({ ok: true });
|
|
});
|
|
|
|
it('rejects an entry with no source', () => {
|
|
const { source: _source, ...rest } = sentence;
|
|
const result = validateHopeSentence(rest);
|
|
expect(result.ok).toBe(false);
|
|
expect(!result.ok && result.errors.join('\n')).toContain("'source'");
|
|
});
|
|
|
|
it('rejects an id with a space, because an id is what travels between players', () => {
|
|
expect(validateHopeSentence({ ...sentence, id: 'you are seen' }).ok).toBe(false);
|
|
});
|
|
|
|
it('rejects an unknown use', () => {
|
|
expect(validateHopeSentence({ ...sentence, use: ['push-notification'] }).ok).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('care event', () => {
|
|
it('accepts every act the rose has', () => {
|
|
for (const act of ['water', 'shade', 'weed', 'petals']) {
|
|
expect(validateCareEvent({ ...careEvent, act }), act).toMatchObject({ ok: true });
|
|
}
|
|
});
|
|
|
|
it('rejects the acts §6.2 used to list by mistake', () => {
|
|
for (const act of ['wind', 'light']) {
|
|
expect(validateCareEvent({ ...careEvent, act }).ok, act).toBe(false);
|
|
}
|
|
});
|
|
|
|
it('accepts a null messageId', () => {
|
|
expect(validateCareEvent({ ...careEvent, messageId: null })).toMatchObject({ ok: true });
|
|
});
|
|
|
|
it('rejects free text in messageId (CLAUDE.md §5.6 rule 1)', () => {
|
|
expect(validateCareEvent({ ...careEvent, messageId: 'meet me at the station' }).ok).toBe(false);
|
|
});
|
|
|
|
it('rejects a missing localDay', () => {
|
|
const { localDay: _day, ...rest } = careEvent;
|
|
expect(validateCareEvent(rest).ok).toBe(false);
|
|
});
|
|
|
|
it('rejects any extra field, so nothing rides along unseen', () => {
|
|
expect(validateCareEvent({ ...careEvent, note: 'hello' }).ok).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('trace', () => {
|
|
it('accepts a day-bucketed trace', () => {
|
|
expect(validateTrace(trace)).toMatchObject({ ok: true });
|
|
});
|
|
|
|
it('rejects a day bucket finer than a day', () => {
|
|
expect(validateTrace({ ...trace, dayBucket: '2026-10-24T18:42' }).ok).toBe(false);
|
|
});
|
|
|
|
it('rejects a timestamp field', () => {
|
|
expect(validateTrace({ ...trace, ts: 1761500000000 }).ok).toBe(false);
|
|
});
|
|
|
|
it('rejects a precise coordinate in place of a cell', () => {
|
|
expect(validateTrace({ ...trace, geocell: '50.0755,14.4378' }).ok).toBe(false);
|
|
});
|
|
});
|