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
80 lines
2.9 KiB
TypeScript
80 lines
2.9 KiB
TypeScript
/**
|
|
* `pnpm validate:library` — every hope sentence in content/library/, and every
|
|
* negative fixture in content/fixtures/ (CLAUDE.md §5.5).
|
|
*
|
|
* Passes when the library has no problems AND every fixture fails with the rule
|
|
* it names. A fixture that passes means a rule has stopped firing: that fails
|
|
* the run, the same as a bad sentence.
|
|
*/
|
|
import { readFileSync, readdirSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { validateEntry, validateLibrary, type Rule } from '@rosea/content/validate';
|
|
|
|
const root = fileURLToPath(new URL('..', import.meta.url));
|
|
const libraryDir = join(root, 'content', 'library');
|
|
const fixturesDir = join(root, 'content', 'fixtures');
|
|
|
|
const jsonIn = (dir: string): string[] =>
|
|
readdirSync(dir)
|
|
.filter((f) => f.endsWith('.json'))
|
|
.sort();
|
|
|
|
let failed = false;
|
|
|
|
// ── the library ────────────────────────────────────────────────────────────
|
|
const entries: unknown[] = [];
|
|
for (const file of jsonIn(libraryDir)) {
|
|
const data: unknown = JSON.parse(readFileSync(join(libraryDir, file), 'utf8'));
|
|
if (!Array.isArray(data)) {
|
|
console.error(`content/library/${file}: must be an array of entries`);
|
|
failed = true;
|
|
continue;
|
|
}
|
|
entries.push(...data);
|
|
}
|
|
|
|
for (const p of validateLibrary(entries)) {
|
|
console.error(`library ${p.id} [${p.rule}] ${p.message}`);
|
|
failed = true;
|
|
}
|
|
|
|
const sunset = entries.filter(
|
|
(e) => typeof e === 'object' && e !== null && Array.isArray((e as { use?: unknown }).use) && (e as { use: unknown[] }).use.includes('sunset')
|
|
).length;
|
|
|
|
console.log(
|
|
`library: ${entries.length} entr${entries.length === 1 ? 'y' : 'ies'} in ${jsonIn(libraryDir).length} files, ${sunset} sunset (release needs 365)`
|
|
);
|
|
|
|
// ── the fixtures: each must FAIL, with its named rule ───────────────────────
|
|
interface Fixture {
|
|
expect: Rule;
|
|
entry?: unknown;
|
|
entries?: unknown[];
|
|
}
|
|
|
|
const fixtureFiles = jsonIn(fixturesDir);
|
|
let fixtureOk = 0;
|
|
for (const file of fixtureFiles) {
|
|
const fixture = JSON.parse(readFileSync(join(fixturesDir, file), 'utf8')) as Fixture;
|
|
const problems = fixture.entries !== undefined ? validateLibrary(fixture.entries) : validateEntry(fixture.entry);
|
|
if (problems.some((p) => p.rule === fixture.expect)) {
|
|
fixtureOk += 1;
|
|
} else {
|
|
console.error(
|
|
`fixture ${file} expected [${fixture.expect}], got ${problems.length === 0 ? 'a PASS' : problems.map((p) => `[${p.rule}]`).join(' ')}`
|
|
);
|
|
failed = true;
|
|
}
|
|
}
|
|
|
|
console.log(`fixtures: ${fixtureOk} of ${fixtureFiles.length} rejected as expected`);
|
|
|
|
if (fixtureFiles.length === 0) {
|
|
console.error('fixtures: none found. The negative fixtures ARE the validator (CLAUDE.md §5.5).');
|
|
failed = true;
|
|
}
|
|
|
|
process.exit(failed ? 1 : 0);
|