REFERENCE.md was 751 lines long and said the kit had 27 models, 15,425
triangles and eleven material slots. It had 35, 31,404 and thirteen, and the
document named none of the last six models at all. A reference nobody can trust
the numbers in is worse than no reference, because a reader has no way to tell
which parts are still true.
This is the third time the same failure has happened here. It is why
`catalog-table.ts` exists — the reference once said "four items" when the kit
had twenty-three — but regenerating the TABLE never touched the prose around
it, and the prose kept its own copies of every number.
So the counts are now checked the way the geometry is: against the models
themselves, by a script that fails. `check-docs.ts` reads the built kit and
requires each of the three documents to state the right model count and
triangle total, to list every model that exists, to name none that does not,
and to get the slot count right where it is written as a word.
Mutation-tested, as everything else here is — a wrong total, a dropped model
row and a stale slot word each fail it. And that test cost me the very fix it
was testing: `git checkout REFERENCE.md` to undo a mutation threw away the
uncommitted repairs along with it. Mutation-test after committing, not before.
Two things it caught immediately:
- The root README never stated a triangle total at all, so the number a
reader most wants for judging whether a kit is affordable was in two of
the three documents and absent from the front door.
- My own first version of the slot check. It looked for any word before
"slots", matched the ordinary phrase "material slots" several paragraphs
earlier, found that "material" is not a number, and silently checked
nothing — reporting nothing rather than failing. A check that passes by
not running is worse than no check, because it reads as evidence.
`bun run check:docs`, and it is in the README's verify list with the others.
112 lines
4.7 KiB
TypeScript
112 lines
4.7 KiB
TypeScript
/**
|
|
* Checks that the documentation still describes the kit that actually exists.
|
|
*
|
|
* This is here because the same thing went wrong three times. `REFERENCE.md`
|
|
* said "four items" when there were twenty-three, which is what `catalog-table`
|
|
* was written to fix — but that only regenerates the TABLE, and the prose
|
|
* around it kept its own copies of the numbers. On the day the oak was added
|
|
* the reference still claimed 27 models, 15,425 triangles and eleven material
|
|
* slots, all three of them wrong, in a document 751 lines long whose whole
|
|
* value is that a reader can trust it.
|
|
*
|
|
* A document with confident wrong numbers in it is worse than no document, so
|
|
* the numbers are checked the way the geometry is: against the models
|
|
* themselves, in CI, where being wrong fails rather than waits to be noticed.
|
|
*
|
|
* bun scripts/check-docs.ts
|
|
*/
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
import { Mesh } from 'three/webgpu'
|
|
|
|
import { MODEL_META } from '../my-registry/meta.ts'
|
|
import { CATALOG } from '@/catalog.ts'
|
|
|
|
const failures: string[] = []
|
|
|
|
function expect(label: string, ok: boolean, detail = ''): void {
|
|
if (ok) {
|
|
console.log(` PASS ${label}`)
|
|
} else {
|
|
console.log(` FAIL ${label}${detail ? ` — ${detail}` : ''}`)
|
|
failures.push(label)
|
|
}
|
|
}
|
|
|
|
// --- what the kit actually is ------------------------------------------------
|
|
const ids = Object.keys(CATALOG).filter((id) => MODEL_META[id] !== undefined && id !== 'pressure-gauge')
|
|
const slots = new Set<string>()
|
|
let triangles = 0
|
|
for (const id of ids) {
|
|
const built = CATALOG[id]!.build()
|
|
built.root.traverse((object) => {
|
|
if (!(object instanceof Mesh)) return
|
|
const index = object.geometry.getIndex()
|
|
triangles += (index ? index.count : object.geometry.getAttribute('position').count) / 3
|
|
})
|
|
built.dispose()
|
|
for (const slot of MODEL_META[id]!.materialSlots) slots.add(slot)
|
|
}
|
|
|
|
const models = ids.length
|
|
console.log(`kit: ${models} models · ${triangles} triangles · ${slots.size} material slots\n`)
|
|
|
|
/** Digits, however the document happens to group them: 31404, 31,404, 31 404. */
|
|
function hasNumber(text: string, value: number): boolean {
|
|
const digits = String(value)
|
|
const spaced = digits.replace(/\B(?=(\d{3})+(?!\d))/g, '[ , ]?')
|
|
return new RegExp(spaced).test(text)
|
|
}
|
|
|
|
const WORDS = [
|
|
'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine',
|
|
'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen',
|
|
'seventeen', 'eighteen', 'nineteen', 'twenty',
|
|
]
|
|
|
|
for (const file of ['README.md', 'REFERENCE.md', 'my-registry/README.md']) {
|
|
const text = readFileSync(file, 'utf8')
|
|
console.log(file)
|
|
|
|
expect(`${file}: model count`, hasNumber(text, models), `expected ${models}`)
|
|
expect(`${file}: triangle total`, hasNumber(text, triangles), `expected ${triangles}`)
|
|
|
|
// Every model has to appear by id, or the document is describing a smaller
|
|
// kit than the one it ships with. The registry README and the reference each
|
|
// carry a generated table; the root README does not, so it is exempt.
|
|
if (file !== 'README.md') {
|
|
const missing = ids.filter((id) => !text.includes(`\`${id}\``))
|
|
expect(`${file}: every model listed`, missing.length === 0, missing.join(', '))
|
|
}
|
|
|
|
// A slot count written as a word ("thirteen slots") is the one number in
|
|
// these documents that cannot be grepped as a digit, and it was wrong.
|
|
//
|
|
// Looked up as a NUMBER WORD rather than as any word. The first version took
|
|
// whatever word preceded "slots", matched the ordinary phrase "material
|
|
// slots" several paragraphs earlier, found that "material" is not a number,
|
|
// and quietly checked nothing at all — a check that passes by not running is
|
|
// worse than no check, because it reads as evidence.
|
|
const written = text.match(new RegExp(`\\b(${WORDS.join('|')}) (?:material )?slots\\b`, 'i'))
|
|
expect(
|
|
`${file}: slot count in words`,
|
|
written === null || WORDS.indexOf(written[1]!.toLowerCase()) === slots.size,
|
|
written ? `says "${written[1]}", kit has ${slots.size}` : '',
|
|
)
|
|
|
|
// Any model named in prose but not in the kit at all: a rename that got
|
|
// half-applied leaves exactly this trace.
|
|
const named = [...text.matchAll(/`([a-z]+-[a-z-]+)`/g)].map((m) => m[1]!)
|
|
const ghosts = [...new Set(named)].filter(
|
|
(name) => /^(wooden|iron|oak|straw|hay|linen|log|pitch|leather|glass|coin|cart|bronze|tavern|trestle|wicker|round|forge|stone|post|hand)-/.test(name)
|
|
&& !ids.includes(name),
|
|
)
|
|
expect(`${file}: no models that do not exist`, ghosts.length === 0, ghosts.join(', '))
|
|
console.log('')
|
|
}
|
|
|
|
if (failures.length > 0) {
|
|
console.log(`${failures.length} documentation check(s) FAILED.`)
|
|
process.exit(1)
|
|
}
|
|
console.log('Documentation matches the kit.')
|