[repo] Workspace: Scaffold Phase 0 with schema, engine, content, ui and the PWA shell

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
This commit is contained in:
2026-11-01 00:27:33 +01:00
parent 1e4c5a06b6
commit 49c8def037
78 changed files with 9015 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
import { describe, expect, it } from 'vitest';
import { lintCopy, stripComments } from '../src/copy-lint.js';
describe('lint:copy core', () => {
it('reports a forbidden word in a string, with its line', () => {
const problems = lintCopy("export const a = 'ok';\nexport const b = 'A gentle therapy';\n");
expect(problems).toHaveLength(1);
expect(problems[0]?.line).toBe(2);
expect(problems[0]?.message).toContain('therapy');
});
it('reports a forbidden word in Svelte markup', () => {
expect(lintCopy('<p>For the lonely.</p>')).toHaveLength(1);
});
it('ignores comments, where rules are explained', () => {
expect(lintCopy('// never say therapy\n/* nor lonely */\n<!-- nor Gandalf -->\nconst ok = 1;')).toEqual([]);
});
it('keeps line numbers when it strips a multi-line comment', () => {
const problems = lintCopy("/*\n\n*/\nconst s = 'cure';");
expect(problems[0]?.line).toBe(4);
});
it('does not mistake a URL for a comment', () => {
expect(stripComments("'https://example.invalid/cure'")).toContain('cure');
});
it("reports 'Domi' standing alone", () => {
expect(lintCopy("const title = 'Domi';")).toHaveLength(1);
expect(lintCopy("const title = 'Welcome to Domi';")).toHaveLength(1);
});
it("accepts 'Domi' after its first word", () => {
expect(lintCopy("'Rosea Domi', 'Panda Domi', 'Amicitia Domi'")).toEqual([]);
});
it('accepts clean shell copy', () => {
expect(lintCopy("preparing: 'The garden is being prepared.'")).toEqual([]);
});
});
+44
View File
@@ -0,0 +1,44 @@
import { describe, expect, it } from 'vitest';
import { FORBIDDEN, findForbidden } from '../src/forbidden.js';
const terms = (text: string): string[] => findForbidden(text).map((h) => h.term);
describe('forbidden words — what is caught', () => {
it('catches every listed term on its own', () => {
const missed = FORBIDDEN.filter(({ term }) => !terms(`before ${term} after`).includes(term)).map((t) => t.term);
expect(missed).toEqual([]);
});
it.each([
['A soft THERAPY for the soul', 'therapy'],
['self-healing petals', 'healing'],
["the rose's lonely planet", 'lonely'],
['Loneliness.', 'loneliness'],
['a treat for the fox', 'treat'],
['be patient with yourself', 'patient'],
['Middle-earth', 'Middle-earth'],
['Middle earth', 'Middle-earth'],
['Malý princ', 'Malý princ'],
['Saint-Exupéry wrote', 'Saint-Exupéry']
])('"%s" contains %s', (text, term) => {
expect(terms(text)).toContain(term);
});
it('reports hits in reading order', () => {
expect(terms('cure first, then therapy')).toEqual(['cure', 'therapy']);
});
});
describe('forbidden words — what is NOT caught', () => {
it.each([
'a treaty between two roses',
'a healthy rose',
'patience, and patiently waiting',
'the lamplighter on his planet',
'the king, the vain man, the businessman',
'a fox among the berries',
'Rosea Domi'
])('"%s" is clean', (text) => {
expect(terms(text)).toEqual([]);
});
});
+85
View File
@@ -0,0 +1,85 @@
import { readFileSync, readdirSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, it } from 'vitest';
import { LENGTH_CAP, validateEntry, validateLibrary, type Rule } from '../src/validator.js';
const fixturesDir = fileURLToPath(new URL('../../../content/fixtures', import.meta.url));
interface Fixture {
readonly expect: Rule;
readonly why: string;
readonly entry?: unknown;
readonly entries?: readonly unknown[];
}
const fixtures = readdirSync(fixturesDir)
.filter((f) => f.endsWith('.json'))
.sort()
.map((file) => ({ file, fixture: JSON.parse(readFileSync(join(fixturesDir, file), 'utf8')) as Fixture }));
const valid = {
id: 'valid-entry',
text: { en: 'Fixture text, not a real sentence.', cs: 'Testovací text.' },
source: {
work: 'Fixture',
author: null,
tradition: 'biblical',
translation: 'KJV',
publicDomain: true,
verifiedBy: 'Fixture',
verifiedAt: '2026-11-01'
},
use: ['sunset', 'comfort'],
tone: 'gentle',
promisesOutcome: false
};
describe('library validator — negative fixtures', () => {
it('finds the fixtures', () => {
// A glob matching nothing would pass every case below.
expect(fixtures.length).toBeGreaterThanOrEqual(13);
});
it.each(fixtures)('$file fails with its named rule', ({ fixture }) => {
const problems = fixture.entries !== undefined ? validateLibrary(fixture.entries) : validateEntry(fixture.entry);
expect(problems.map((p) => p.rule), fixture.why).toContain(fixture.expect);
for (const p of problems) expect(p.message.length, 'each problem says what is wrong').toBeGreaterThan(10);
});
it('every rule the validator has is proved by at least one fixture', () => {
const proved = new Set(fixtures.map(({ fixture }) => fixture.expect));
const RULES: readonly Rule[] = [
'schema',
'no-source',
'not-public-domain',
'translation-under-copyright',
'too-long',
'promises-outcome',
'forbidden-word',
'no-tradition',
'duplicate-id'
];
expect(RULES.filter((r) => !proved.has(r))).toEqual([]);
});
});
describe('library validator — what passes', () => {
it('accepts a sourced, public-domain, short, gentle entry', () => {
expect(validateEntry(valid)).toEqual([]);
});
it('accepts a line the author wrote for Rosea, though it is not public domain', () => {
const own = { ...valid, source: { ...valid.source, tradition: 'rosea', translation: null, publicDomain: false } };
expect(validateEntry(own)).toEqual([]);
});
it('accepts text exactly at the length cap, counting characters and not UTF-16 units', () => {
const atCap = { ...valid, text: { en: 'ř'.repeat(LENGTH_CAP) } };
expect(validateEntry(atCap)).toEqual([]);
});
it('accepts an empty library, and says nothing about it', () => {
expect(validateLibrary([])).toEqual([]);
});
});