From 8290dbec93df2b834e501b3607e50b770a7f3925 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 2 Oct 2026 18:56:22 +0200 Subject: [PATCH 1/4] =?UTF-8?q?test:=20reproduce=20#255=20=E2=80=94=20docs?= =?UTF-8?q?/=20holds=20a=20doc=20neither=20end-user=20list=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs-audience.test.ts | 143 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/docs-audience.test.ts diff --git a/src/docs-audience.test.ts b/src/docs-audience.test.ts new file mode 100644 index 000000000..f72d836b5 --- /dev/null +++ b/src/docs-audience.test.ts @@ -0,0 +1,143 @@ +import { execFileSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import { basename, dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +import { describe, expect, it } from "vitest"; + +const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), ".."); + +/** Every tracked path, from the git index, so no doc escapes by sitting in a directory the test did not name. */ +const trackedFiles = execFileSync("git", ["ls-files", "-z"], { + cwd: REPO_ROOT, + encoding: "utf8", + maxBuffer: 32 * 1024 * 1024, +}) + .split("\0") + .filter((name) => name.length > 0); + +/** `README.md` and every markdown file under `docs/` that is not under `docs/internal/`. */ +const endUserDocs = trackedFiles.filter( + (name) => + name === "README.md" || + (name.startsWith("docs/") && !name.startsWith("docs/internal/") && name.endsWith(".md")), +); + +/** + * File names that exist only under `docs/internal/`. `EVENTS.md` and `README.md` are left out: + * an end-user doc of the same name exists, so the bare name says nothing about the audience. + */ +const internalOnlyNames = [ + ...new Set( + trackedFiles + .filter((name) => name.startsWith("docs/internal/") && name.endsWith(".md")) + .map((name) => basename(name)), + ), +].filter((name) => !endUserDocs.some((doc) => basename(doc) === name)); + +const escape = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + +/** What documentation rule 2 forbids an end-user doc from naming. */ +const FORBIDDEN: RegExp[] = [ + /docs\/internal\b/, + /\]\((?:\.\/)?internal\//, + /\bADRs?\b/, + /\badr\//, + ...internalOnlyNames.map((name) => new RegExp(`(? { + it("were enumerated from the git index", () => { + // Without this, an empty enumeration would leave the scan below with nothing to read and + // the suite would pass while checking no doc at all. + expect(endUserDocs).toEqual( + expect.arrayContaining([ + "README.md", + "docs/ABOUT.md", + "docs/CLI.md", + "docs/CLIENT.md", + "docs/CONFIGURATION.md", + "docs/EVENTS.md", + "docs/HTTP-API.md", + ]), + ); + expect(internalOnlyNames).toEqual( + expect.arrayContaining(["ARCHITECTURE.md", "KNOWN-PITFALLS.md", "testing.md"]), + ); + }); + + it("name no path under docs/internal/, no internal-only doc by file name, and no ADR", () => { + const offenders = endUserDocs.flatMap((doc) => + readFileSync(join(REPO_ROOT, doc), "utf8") + .split("\n") + .flatMap((text, index) => + FORBIDDEN.flatMap((pattern) => { + const match = pattern.exec(text); + return match === null ? [] : [`${doc}:${index + 1}: ${match[0]}`]; + }), + ), + ); + + expect(offenders).toEqual([]); + }); +}); + +/** The text of `markdown` from the first line starting with `from` up to the next starting with `to`. */ +function section(markdown: string, from: string, to: string): string { + const lines = markdown.split("\n"); + const start = lines.findIndex((line) => line.startsWith(from)); + const end = lines.findIndex((line, index) => index > start && line.startsWith(to)); + return start === -1 || end === -1 ? "" : lines.slice(start, end).join("\n"); +} + +/** + * Documentation rule 1: `docs/` is the end-user directory, and a doc for maintainers or agents + * goes under `docs/internal/`. The two places that name the end-user docs -- AGENTS.md's list + * and rule 2's list -- are what a file directly in `docs/` has to be one of. + */ +describe("the files directly in docs/", () => { + const inDocsDir = trackedFiles + .filter((name) => /^docs\/[^/]+\.md$/.test(name)) + .toSorted((a, b) => a.localeCompare(b)); + + const listedInAgents = [ + ...section( + readFileSync(join(REPO_ROOT, "AGENTS.md"), "utf8"), + "End-user docs live directly under", + "Maintainer/agent docs live under", + ).matchAll(/\]\((docs\/[^/)]+\.md)\)/g), + ] + .map((match) => match[1] ?? "") + .toSorted((a, b) => a.localeCompare(b)); + + const listedInRule2 = [ + ...section( + readFileSync(join(REPO_ROOT, "docs/internal/agent-rules/documentation.md"), "utf8"), + "2. **", + "3. **", + ).matchAll(/`(docs\/[^/`]+\.md)`/g), + ] + .map((match) => match[1] ?? "") + .toSorted((a, b) => a.localeCompare(b)); + + it("were read, along with both lists of end-user docs", () => { + // Without this, a heading reworded in AGENTS.md or documentation.md would empty a list + // and the comparison below would fail for the wrong reason -- or, with docs/ also + // empty, pass while checking nothing. + for (const list of [inDocsDir, listedInAgents, listedInRule2]) { + expect(list).toEqual(expect.arrayContaining(["docs/CLI.md", "docs/HTTP-API.md"])); + } + }); + + it("are exactly the end-user docs AGENTS.md and documentation rule 2 list", () => { + expect({ listedInAgents: inDocsDir, listedInRule2: inDocsDir }).toEqual({ + listedInAgents, + listedInRule2, + }); + }); +}); From 4d16dc64383b95c86f3777981f9b9fe98f37f430 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 2 Oct 2026 19:03:52 +0200 Subject: [PATCH 2/4] fix(docs): move loop.md under docs/internal/ and drop HTTP-API.md's internal-doc pointer (#255) docs/loop.md is a maintainer doc in the end-user directory; it moves to docs/internal/LOOP.md and joins AGENTS.md's maintainer list. docs/HTTP-API.md loses the parenthesis that carried 0.3.0 history and pointed at docs/internal/KNOWN-PITFALLS.md (#254). src/docs-audience.test.ts guards documentation rules 1 and 2. Closes #255 --- AGENTS.md | 1 + docs/HTTP-API.md | 6 +----- docs/{loop.md => internal/LOOP.md} | 0 3 files changed, 2 insertions(+), 5 deletions(-) rename docs/{loop.md => internal/LOOP.md} (100%) diff --git a/AGENTS.md b/AGENTS.md index b0b157f29..039f1da8e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -65,4 +65,5 @@ Maintainer/agent docs live under [docs/internal/](docs/internal/): - [EVENTS.md](docs/internal/EVENTS.md) — the same catalog with rationale and ADR references - [IDEAS.md](docs/internal/IDEAS.md) — post-v1 ideas; don't implement these unless asked - [KNOWN-PITFALLS.md](docs/internal/KNOWN-PITFALLS.md) — accepted gaps and their planned fixes +- [LOOP.md](docs/internal/LOOP.md) — historical instructions for implementing a stage - [adr/](docs/internal/adr/) — architecture decision records and their status diff --git a/docs/HTTP-API.md b/docs/HTTP-API.md index 339faad88..5f12614bb 100644 --- a/docs/HTTP-API.md +++ b/docs/HTTP-API.md @@ -493,11 +493,7 @@ not distinguish them. (`lease.renew`, `lease.release`, `device.exec`) directly, so another requester's own, still-live lease answers `403 FORBIDDEN` from them — the same answer the socket transport gives, via the same operation's `ownsLease` -authorize hook. (0.3.0 briefly had every lease route answering `404` here; -that overcorrected the lease-*request* routes' old `403` and is why renew -and release were moved off the `lease.list`-filtered lookup — see -`docs/internal/KNOWN-PITFALLS.md`. `exec` arrives on the dispatching side of that -split, with renew and release.) +authorize hook. This is different again from the lease-*request* routes below (`/v1/lease-requests/{id}` and friends), which answer `403 FORBIDDEN` for a diff --git a/docs/loop.md b/docs/internal/LOOP.md similarity index 100% rename from docs/loop.md rename to docs/internal/LOOP.md From 1b144e4988c1d5e423341785a45c1829accb418c Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 2 Oct 2026 19:12:55 +0200 Subject: [PATCH 3/4] test(docs): catch every link form into internal/, any-case names and ADRs, and docs/ subdirectories Also mark docs/internal/LOOP.md as superseded by DELIVERY.md, since AGENTS.md now lists it for agents. --- AGENTS.md | 3 ++- docs/internal/LOOP.md | 3 +++ src/docs-audience.test.ts | 44 ++++++++++++++++++++++++++------------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 039f1da8e..526f1fdd4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -65,5 +65,6 @@ Maintainer/agent docs live under [docs/internal/](docs/internal/): - [EVENTS.md](docs/internal/EVENTS.md) — the same catalog with rationale and ADR references - [IDEAS.md](docs/internal/IDEAS.md) — post-v1 ideas; don't implement these unless asked - [KNOWN-PITFALLS.md](docs/internal/KNOWN-PITFALLS.md) — accepted gaps and their planned fixes -- [LOOP.md](docs/internal/LOOP.md) — historical instructions for implementing a stage +- [LOOP.md](docs/internal/LOOP.md) — the old stage-implementation loop, kept as + history; DELIVERY.md replaces it - [adr/](docs/internal/adr/) — architecture decision records and their status diff --git a/docs/internal/LOOP.md b/docs/internal/LOOP.md index e58bc57c5..df99f58c4 100644 --- a/docs/internal/LOOP.md +++ b/docs/internal/LOOP.md @@ -3,6 +3,9 @@ Historical instructions for implementing a Simlock stage. Completed stage specifications have been removed from `docs/stages/`. +Do not follow this loop for new work. [DELIVERY.md](DELIVERY.md) and the +delivery rules in `docs/internal/agent-rules/delivery.md` replace it. + ## Phase 0 — Orient 1. Read `AGENTS.md`, all of `docs/internal/agent-rules/`, and `docs/internal/ARCHITECTURE.md`. diff --git a/src/docs-audience.test.ts b/src/docs-audience.test.ts index f72d836b5..f19865cdb 100644 --- a/src/docs-audience.test.ts +++ b/src/docs-audience.test.ts @@ -1,5 +1,5 @@ import { execFileSync } from "node:child_process"; -import { readFileSync } from "node:fs"; +import { readFileSync, statSync } from "node:fs"; import { basename, dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; @@ -14,7 +14,16 @@ const trackedFiles = execFileSync("git", ["ls-files", "-z"], { maxBuffer: 32 * 1024 * 1024, }) .split("\0") - .filter((name) => name.length > 0); + .filter((name) => name.length > 0) + // A path deleted from the working tree is still listed by `git ls-files`; only regular files + // can be read. + .filter((name) => { + try { + return statSync(join(REPO_ROOT, name)).isFile(); + } catch { + return false; + } + }); /** `README.md` and every markdown file under `docs/` that is not under `docs/internal/`. */ const endUserDocs = trackedFiles.filter( @@ -24,8 +33,9 @@ const endUserDocs = trackedFiles.filter( ); /** - * File names that exist only under `docs/internal/`. `EVENTS.md` and `README.md` are left out: - * an end-user doc of the same name exists, so the bare name says nothing about the audience. + * File names that exist only under `docs/internal/`, compared ignoring case. `EVENTS.md`, + * `events.md` and `README.md` are left out: an end-user doc of the same name exists, so the + * bare name says nothing about the audience. */ const internalOnlyNames = [ ...new Set( @@ -33,26 +43,28 @@ const internalOnlyNames = [ .filter((name) => name.startsWith("docs/internal/") && name.endsWith(".md")) .map((name) => basename(name)), ), -].filter((name) => !endUserDocs.some((doc) => basename(doc) === name)); +].filter((name) => !endUserDocs.some((doc) => basename(doc).toLowerCase() === name.toLowerCase())); const escape = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); /** What documentation rule 2 forbids an end-user doc from naming. */ const FORBIDDEN: RegExp[] = [ /docs\/internal\b/, - /\]\((?:\.\/)?internal\//, - /\bADRs?\b/, - /\badr\//, - ...internalOnlyNames.map((name) => new RegExp(`(? new RegExp(`(? { - it("were enumerated from the git index", () => { + it("include the known end-user docs, beside a list of internal-only names", () => { // Without this, an empty enumeration would leave the scan below with nothing to read and // the suite would pass while checking no doc at all. expect(endUserDocs).toEqual( @@ -98,11 +110,13 @@ function section(markdown: string, from: string, to: string): string { /** * Documentation rule 1: `docs/` is the end-user directory, and a doc for maintainers or agents * goes under `docs/internal/`. The two places that name the end-user docs -- AGENTS.md's list - * and rule 2's list -- are what a file directly in `docs/` has to be one of. + * and rule 2's list -- are what a markdown file under `docs/` and outside `docs/internal/` has + * to be one of. Both lists name files directly in `docs/`, so a doc in any other subdirectory + * of `docs/` fails. */ -describe("the files directly in docs/", () => { - const inDocsDir = trackedFiles - .filter((name) => /^docs\/[^/]+\.md$/.test(name)) +describe("the markdown files under docs/ outside docs/internal/", () => { + const inDocsDir = endUserDocs + .filter((name) => name !== "README.md") .toSorted((a, b) => a.localeCompare(b)); const listedInAgents = [ From 92c467ea631de47ff0d1a2ac2948fb3eb21c1105 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 2 Oct 2026 19:41:18 +0200 Subject: [PATCH 4/4] test(docs): keep events.md an internal-only name, and scan .markdown and .MD docs --- src/docs-audience.test.ts | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/docs-audience.test.ts b/src/docs-audience.test.ts index f19865cdb..12c961e11 100644 --- a/src/docs-audience.test.ts +++ b/src/docs-audience.test.ts @@ -25,28 +25,42 @@ const trackedFiles = execFileSync("git", ["ls-files", "-z"], { } }); +/** A markdown file by extension, in any case: `.md` or `.markdown`. */ +const isMarkdown = (name: string) => /\.(?:md|markdown)$/i.test(name); + /** `README.md` and every markdown file under `docs/` that is not under `docs/internal/`. */ const endUserDocs = trackedFiles.filter( (name) => name === "README.md" || - (name.startsWith("docs/") && !name.startsWith("docs/internal/") && name.endsWith(".md")), + (name.startsWith("docs/") && !name.startsWith("docs/internal/") && isMarkdown(name)), ); +const endUserNames = endUserDocs.map((doc) => basename(doc)); + /** - * File names that exist only under `docs/internal/`, compared ignoring case. `EVENTS.md`, - * `events.md` and `README.md` are left out: an end-user doc of the same name exists, so the - * bare name says nothing about the audience. + * File names that exist only under `docs/internal/`. `EVENTS.md` and `README.md` are left out: + * an end-user doc of the same name exists, so the bare name says nothing about the audience. */ const internalOnlyNames = [ ...new Set( trackedFiles - .filter((name) => name.startsWith("docs/internal/") && name.endsWith(".md")) + .filter((name) => name.startsWith("docs/internal/") && isMarkdown(name)) .map((name) => basename(name)), ), -].filter((name) => !endUserDocs.some((doc) => basename(doc).toLowerCase() === name.toLowerCase())); +].filter((name) => !endUserNames.includes(name)); const escape = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); +/** + * An internal-only name, matched in any case unless that would also match an end-user doc's + * name: `events.md` is matched exactly, since ignoring case it is `EVENTS.md`. + */ +const internalName = (name: string) => + new RegExp( + `(? doc.toLowerCase() === name.toLowerCase()) ? "" : "i", + ); + /** What documentation rule 2 forbids an end-user doc from naming. */ const FORBIDDEN: RegExp[] = [ /docs\/internal\b/, @@ -55,7 +69,7 @@ const FORBIDDEN: RegExp[] = [ /(? new RegExp(`(? { ]), ); expect(internalOnlyNames).toEqual( - expect.arrayContaining(["ARCHITECTURE.md", "KNOWN-PITFALLS.md", "testing.md"]), + expect.arrayContaining(["ARCHITECTURE.md", "KNOWN-PITFALLS.md", "events.md", "testing.md"]), ); }); @@ -95,7 +109,8 @@ describe("end-user docs", () => { ), ); - expect(offenders).toEqual([]); + // `ARCHITECTURE.md` and `architecture.md` both match either spelling; report a hit once. + expect([...new Set(offenders)]).toEqual([]); }); });