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.
45 lines
1.9 KiB
TypeScript
45 lines
1.9 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { existsSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { describe, it } from 'node:test';
|
|
import { exampleFiles, unmappedExamples } from './docs-examples.ts';
|
|
import { REPO_ROOT } from './public-packages.ts';
|
|
|
|
describe('exampleFiles', () => {
|
|
it('reads every example from the filesystem, project-relative and sorted', () => {
|
|
const files = exampleFiles();
|
|
assert.ok(files.length > 0, 'expected at least one example under docs/examples');
|
|
for (const file of files) {
|
|
assert.ok(file.startsWith('docs/examples/'), `not an example path: ${file}`);
|
|
assert.ok(file.endsWith('.ts'), `not a .ts file: ${file}`);
|
|
assert.ok(existsSync(join(REPO_ROOT, file)), `example does not exist: ${file}`);
|
|
}
|
|
assert.deepEqual(files, [...files].toSorted());
|
|
});
|
|
|
|
it('names the example files the docs and skill show, so the check has files to cover', () => {
|
|
const files = exampleFiles();
|
|
// Regression: these are the files a page shows; the map in
|
|
// check-docs-examples.ts must cover them.
|
|
assert.ok(files.includes('docs/examples/web/browser-provider.ts'), files.join(', '));
|
|
assert.ok(files.includes('docs/examples/skill/e2e.setup.config.ts'), files.join(', '));
|
|
});
|
|
});
|
|
|
|
describe('unmappedExamples', () => {
|
|
it('reports every example a page map does not carry', () => {
|
|
// A map that covers nothing: every example is unmapped.
|
|
assert.deepEqual(unmappedExamples([]), exampleFiles());
|
|
});
|
|
|
|
it('is empty when the map covers every example', () => {
|
|
assert.deepEqual(unmappedExamples(exampleFiles()), []);
|
|
});
|
|
|
|
it('reports a new example the map was not updated for', () => {
|
|
// The failure the hand-kept map let slip: an example added without a page.
|
|
const map = exampleFiles().filter((file) => file !== 'docs/examples/web/browser-provider.ts');
|
|
assert.deepEqual(unmappedExamples(map), ['docs/examples/web/browser-provider.ts']);
|
|
});
|
|
});
|