Files
mnovak 49c8def037 [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
2026-11-01 00:27:33 +01:00

86 lines
2.9 KiB
TypeScript

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([]);
});
});