[content] DaySentence: Candidates held to every rule; library:verify for the author
This commit is contained in:
@@ -5,14 +5,21 @@
|
||||
* 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.
|
||||
*
|
||||
* It also holds the candidates in content/candidates/ to every rule but
|
||||
* verification (day-sentence.md P8), and the app's build runs it first, so what
|
||||
* ships is what passed (P5). ROSEA_LIBRARY_DIR swaps the library folder, for the
|
||||
* e2e build only; the app's Vite config reads the same variable.
|
||||
*/
|
||||
import { readFileSync, readdirSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
||||
import { join, relative, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { validateCandidates } from '@rosea/content/candidates';
|
||||
import { validateEntry, validateLibrary, type Rule } from '@rosea/content/validate';
|
||||
|
||||
const root = fileURLToPath(new URL('..', import.meta.url));
|
||||
const libraryDir = join(root, 'content', 'library');
|
||||
const libraryDir = resolve(root, process.env['ROSEA_LIBRARY_DIR'] ?? join('content', 'library'));
|
||||
const candidatesDir = join(root, 'content', 'candidates');
|
||||
const fixturesDir = join(root, 'content', 'fixtures');
|
||||
|
||||
const jsonIn = (dir: string): string[] =>
|
||||
@@ -27,7 +34,7 @@ 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`);
|
||||
console.error(`${relative(root, libraryDir)}/${file}: must be an array of entries`);
|
||||
failed = true;
|
||||
continue;
|
||||
}
|
||||
@@ -44,9 +51,27 @@ const sunset = entries.filter(
|
||||
).length;
|
||||
|
||||
console.log(
|
||||
`library: ${entries.length} entr${entries.length === 1 ? 'y' : 'ies'} in ${jsonIn(libraryDir).length} files, ${sunset} sunset (release needs 365)`
|
||||
`library (${relative(root, libraryDir).replaceAll('\\', '/')}): ${entries.length} entr${entries.length === 1 ? 'y' : 'ies'} in ${jsonIn(libraryDir).length} files, ${sunset} sunset (release needs 365)`
|
||||
);
|
||||
|
||||
// ── the candidates: proposed, not verified ─────────────────────────────────
|
||||
const candidates: unknown[] = [];
|
||||
const candidateFiles = existsSync(candidatesDir) ? jsonIn(candidatesDir) : [];
|
||||
for (const file of candidateFiles) {
|
||||
const data: unknown = JSON.parse(readFileSync(join(candidatesDir, file), 'utf8'));
|
||||
if (!Array.isArray(data)) {
|
||||
console.error(`content/candidates/${file}: must be an array of candidates`);
|
||||
failed = true;
|
||||
continue;
|
||||
}
|
||||
candidates.push(...data);
|
||||
}
|
||||
for (const p of validateCandidates(candidates, entries)) {
|
||||
console.error(`candidate ${p.id} [${p.rule}] ${p.message}`);
|
||||
failed = true;
|
||||
}
|
||||
console.log(`candidates: ${candidates.length} in ${candidateFiles.length} files, waiting for a person to verify them`);
|
||||
|
||||
// ── the fixtures: each must FAIL, with its named rule ───────────────────────
|
||||
interface Fixture {
|
||||
expect: Rule;
|
||||
|
||||
Reference in New Issue
Block a user