mirror of
https://github.com/tester-army/e2e.git
synced 2026-11-27 02:36:21 +08:00
`check-docs-examples.ts` asserted that every code block a page shows from
`docs/examples/` matches the file it came from, but it iterated a hand-kept
page map. A new example that no page showed was never read, so the check
passed while `AGENTS.md`'s invariant ("`docs/examples/` is shown verbatim on
docs pages and in `skills/e2e/`") silently broke. The map also names which
page owns each example, and the docs and skill are its only readers, so
nothing else could catch a forgotten file.
Read the file list from the filesystem instead, the way `error-codes.ts`
reads the published packages' source roots rather than trusting a literal
list, and report every example the map does not carry. The map stays as the
declaration of *which* page shows an example; the filesystem decides whether
one exists at all.
Verified: `node scripts/check-docs-examples.ts` exits 1 on an example added
with no page and 0 on the current tree; `node --test scripts/**/*.test.ts`
passes (5 new cases); `tsc -p scripts`, `oxlint`, and `fallow dead-code`
are clean. No changeset: `scripts/` is not a published package.
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
/**
|
|
* The example files under `docs/examples/`, and the ones a page map has
|
|
* forgotten.
|
|
*
|
|
* `check-docs-examples.ts` asserts that every code block a docs page or the
|
|
* consumer skill shows from `docs/examples/` matches the file it came from,
|
|
* but its page map was hand-kept: a new example that no page showed was never
|
|
* read, so the check passed while the invariant ("`docs/examples/` is shown
|
|
* verbatim on docs pages and in `skills/e2e/`", `AGENTS.md`) silently broke.
|
|
* Deriving the file list from the filesystem, rather than trusting the map to
|
|
* remember itself, is what `error-codes.ts` does for the source roots the
|
|
* error reference is checked against.
|
|
*/
|
|
|
|
import { readdirSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { REPO_ROOT } from './public-packages.ts';
|
|
|
|
/** The directory every example lives under, project-relative with `/` separators. */
|
|
const EXAMPLES_DIR = 'docs/examples';
|
|
|
|
/**
|
|
* Every example file, project-relative with `/` separators, sorted: the
|
|
* `.ts` files under `docs/examples/`, nested folders included. The
|
|
* `tsconfig.json` beside them is not an example.
|
|
*/
|
|
export function exampleFiles(): string[] {
|
|
const files: string[] = [];
|
|
const walk = (dir: string): void => {
|
|
for (const entry of readdirSync(join(REPO_ROOT, dir), { withFileTypes: true })) {
|
|
const path = `${dir}/${entry.name}`;
|
|
if (entry.isDirectory()) walk(path);
|
|
else if (entry.name.endsWith('.ts')) files.push(path);
|
|
}
|
|
};
|
|
walk(EXAMPLES_DIR);
|
|
return files.toSorted();
|
|
}
|
|
|
|
/**
|
|
* The examples `mapped` does not carry, by path: what the check would
|
|
* otherwise never read. Empty when every example is a key of the page map.
|
|
*/
|
|
export function unmappedExamples(mapped: Iterable<string>): string[] {
|
|
const known = new Set(mapped);
|
|
return exampleFiles().filter((file) => !known.has(file));
|
|
}
|