[schema] DaySentence: The sentence-opened event, an id and never text

This commit is contained in:
2026-11-02 08:55:04 +01:00
parent 9c7f67a1f0
commit ad41c58730
3 changed files with 63 additions and 2 deletions
@@ -0,0 +1,39 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://rosea.invalid/schema/sentence-opened.json",
"title": "SentenceOpened",
"description": "The rose's folded petal was opened (CLAUDE.md §6.2, .agents/features/day-sentence.md). Append-only, never edited. The first one of a local day is that day's petal.",
"type": "object",
"additionalProperties": false,
"required": ["kind", "ts", "localDay", "from", "messageId", "clientVersion"],
"properties": {
"kind": {
"const": "sentence-opened"
},
"ts": {
"description": "Epoch milliseconds. Stays on the device.",
"type": "integer",
"minimum": 0
},
"localDay": {
"description": "The player's local day, from engine/src/time/localDay.ts and nowhere else.",
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$"
},
"from": {
"description": "The key of the rose whose petal it was.",
"type": "string",
"pattern": "^[A-Za-z0-9_-]{32,128}$"
},
"messageId": {
"description": "The hope-library id that was in the petal. Never text: the pattern admits no space (CLAUDE.md §5.6 rule 1).",
"type": "string",
"pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
"maxLength": 64
},
"clientVersion": {
"type": "string",
"pattern": "^\\d+\\.\\d+\\.\\d+$"
}
}
}
+3 -1
View File
@@ -10,8 +10,9 @@
import { Ajv, type ErrorObject, type ValidateFunction } from 'ajv';
import careEvent from '../schemas/care-event.schema.json' with { type: 'json' };
import hopeSentence from '../schemas/hope-sentence.schema.json' with { type: 'json' };
import sentenceOpened from '../schemas/sentence-opened.schema.json' with { type: 'json' };
import trace from '../schemas/trace.schema.json' with { type: 'json' };
import type { CareEvent, HopeSentence, Trace } from './generated/index.js';
import type { CareEvent, HopeSentence, SentenceOpened, Trace } from './generated/index.js';
export type SchemaResult<T> =
| { readonly ok: true; readonly value: T }
@@ -38,4 +39,5 @@ function describe(error: ErrorObject): string {
export const validateHopeSentence = wrap<HopeSentence>(ajv.compile(hopeSentence));
export const validateCareEvent = wrap<CareEvent>(ajv.compile(careEvent));
export const validateSentenceOpened = wrap<SentenceOpened>(ajv.compile(sentenceOpened));
export const validateTrace = wrap<Trace>(ajv.compile(trace));
+21 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { validateCareEvent, validateHopeSentence, validateTrace } from '../src/validate.js';
import { validateCareEvent, validateHopeSentence, validateSentenceOpened, validateTrace } from '../src/validate.js';
const KEY_A = 'A'.repeat(43);
const KEY_B = 'b_-'.repeat(15);
@@ -103,6 +103,26 @@ describe('care event', () => {
});
});
describe('sentence opened (day-sentence.md P6)', () => {
const opened = { kind: 'sentence-opened', ts: 1761500000000, localDay: '2026-10-24', from: KEY_A, messageId: 'ps-23-4', clientVersion: '0.1.0' };
it('accepts an opened petal', () => {
expect(validateSentenceOpened(opened)).toMatchObject({ ok: true });
});
it('rejects text in place of an id, so no words can ride in the log', () => {
expect(validateSentenceOpened({ ...opened, messageId: 'The LORD is my shepherd' }).ok).toBe(false);
expect(validateSentenceOpened({ ...opened, messageId: null }).ok).toBe(false);
});
it('rejects a missing day, an extra field, or another kind', () => {
const { localDay: _, ...noDay } = opened;
expect(validateSentenceOpened(noDay).ok).toBe(false);
expect(validateSentenceOpened({ ...opened, atSunset: true }).ok).toBe(false);
expect(validateSentenceOpened({ ...opened, kind: 'care' }).ok).toBe(false);
});
});
describe('trace', () => {
it('accepts a day-bucketed trace', () => {
expect(validateTrace(trace)).toMatchObject({ ok: true });