/** * The card reference must not drift from the cards. * * `docs/rules/card-reference.md` spent several releases describing the v0.4.5 deck — twelve numbered * trains, "3 / 4 Mail-Express, 3 coaches" — while `content.ts` had train 3 as the Express with two * freight cars and a per-location freight rule. Worse, `content.ts` named that file as "the place * that now carries what the cards say", so the code sent readers to a table its own banner told them * not to trust. Nothing failed, because nothing checked. * * `docs/rules/as-built.md` is emitted from the same exported catalogues the engine instantiates * from, and this re-runs the generator and compares. Change a card face without regenerating and * this goes red — which is the whole point: a document nothing verifies is a document that will be * wrong, and this project's own history is the evidence. */ import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { execFileSync } from 'node:child_process'; import { readFileSync } from 'node:fs'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const root = join(dirname(fileURLToPath(import.meta.url)), '..'); const doc = join(root, 'docs/rules/as-built.md'); describe('docs/rules/as-built.md is generated, and current', () => { it('matches what the generator emits from content.ts today', () => { const before = readFileSync(doc, 'utf8'); execFileSync(process.execPath, [join(root, 'scripts/build-card-reference.ts')], { cwd: root }); const after = readFileSync(doc, 'utf8'); assert.equal( after, before, 'the checked-in card reference is stale — run `npm run build:cards` and commit the result', ); }); it('carries the current train catalogue, not the v0.4.5 deck', () => { // The specific drift that went unnoticed for several releases, asserted by name so a future // regeneration against an old content.ts cannot quietly reintroduce it. const md = readFileSync(doc, 'utf8'); assert.match(md, /Crack Limited/); assert.match(md, /\| 3 \| Express \|/); assert.ok(!/Mail-Express/.test(md), 'the superseded v0.4.5 train names are back'); assert.ok(!/Manifest Freight/.test(md), 'the superseded v0.4.5 train names are back'); }); it('says it is generated, so nobody edits it by hand', () => { const md = readFileSync(doc, 'utf8'); assert.match(md, /Generated from `src\/engine\/content\.ts`/); assert.match(md, /Do not edit by/); }); });