From 23dc17d1102ba80cf2be67959bb414abb1b42a7c Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 3 Nov 2026 15:09:32 +0000 Subject: [PATCH] ci: check code-citation drift at release, not on every merge Any PR that moves lines in a cited file drifts other PRs' citations, so failing the merge queue on drift turned main red for documentation alone (#3496). Maintainer ruling, 2026-11-03: drift is a pre-release check. - experiments/decision-citations.test.ts now holds the tree-wide drift checks: every citation anchored or excepted, exceptions exact, and the convention's own example. The experiment tier runs it, and `bun run release` refuses to publish without that tier's receipt for the exact tree. - tests/decision-citations.test.ts keeps the checker's rules on in-memory trees and the one tree-wide rule that cannot drift with code: no citation into a private repository (#303). - AGENTS.md, docs/decisions/README.md and the release skill say so. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/release/SKILL.md | 6 ++- AGENTS.md | 10 +++-- docs/decisions/README.md | 16 ++++++-- experiments/decision-citations.test.ts | 55 ++++++++++++++++++++++++++ tests/decision-citations.test.ts | 52 +++++++++--------------- 5 files changed, 97 insertions(+), 42 deletions(-) create mode 100644 experiments/decision-citations.test.ts diff --git a/.agents/skills/release/SKILL.md b/.agents/skills/release/SKILL.md index c8622e9bd6..7747d24875 100644 --- a/.agents/skills/release/SKILL.md +++ b/.agents/skills/release/SKILL.md @@ -163,7 +163,11 @@ bun run check:pr --all ## The experiment tier Tests that exercise only measurement and eval harnesses live under -`experiments/`, outside `bun run test`, `check:pr` and hosted CI. Release +`experiments/`, outside `bun run test`, `check:pr` and hosted CI. So does the +release check that every code citation under `docs/` still starts on its +anchor (`experiments/decision-citations.test.ts`): merges do not fail on +citation drift, so run `bun scripts/check-citations.ts` before versioning and +fix everything it reports in the release PR. Release preparation runs every one of them, on the post-version candidate: ```sh diff --git a/AGENTS.md b/AGENTS.md index d7988a37cb..201828f9ff 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -122,10 +122,12 @@ on, links to or describes them. `brain module lint` before submitting one. - Cite code from docs and source comments as an anchor followed by its range: (`enforcementHook`, `packages/ui-backend-claude/src/permission-hooks.ts:200-229`), - starting on the anchor's line. **A PR that moves lines under a citation owns - that citation**, wherever it is recorded; find them with - `git grep -n '.ts:' -- docs packages`. `tests/decision-citations.test.ts` - enforces this throughout `docs/`; the rules are in + starting on the anchor's line. A PR that moves lines under a citation should + fix it when it can (`git grep -n '.ts:' -- docs packages`), but drift + never blocks a merge or turns main red: it is a **release check**. + `experiments/decision-citations.test.ts` fails the experiment tier, and so + the publish, until every citation under `docs/` holds; repair drift with + `bun scripts/check-citations.ts`. The rules are in [docs/decisions/README.md](docs/decisions/README.md#citing-code). ## Testing expectations diff --git a/docs/decisions/README.md b/docs/decisions/README.md index f809b351c5..e809b0e50a 100644 --- a/docs/decisions/README.md +++ b/docs/decisions/README.md @@ -209,10 +209,18 @@ Before merging a change to a file, look for what cites it: git grep -n 'permission-hooks.ts:' -- docs packages ``` -`tests/decision-citations.test.ts` fails when a citation anywhere under `docs/` no -longer starts on its anchor, names no anchor, or names a file it cannot find. -`bun scripts/check-citations.ts` prints the same report on its own, including -where each drifted anchor now is. What it does **not** check: +**Citations are checked at release, not at merge** (maintainer ruling, +2026-11-03). Any PR that moves lines in a cited file drifts other PRs' +citations, so failing every merge on drift turned main red for documentation +alone. `experiments/decision-citations.test.ts` fails when a citation anywhere +under `docs/` no longer starts on its anchor, names no anchor, or names a file +it cannot find. It runs in the experiment tier, which `bun run release` +requires on the exact tree it publishes, so no release ships a drifted record. +`tests/decision-citations.test.ts` still runs on every merge, but only for the +checker's own rules and the one tree-wide rule that cannot drift: no citation +into a private repository. `bun scripts/check-citations.ts` prints the full +report on its own, including where each drifted anchor now is; run it before +versioning and fix what it reports. What it does **not** check: - **The end of a range.** A range that grows or shrinks around its first line still passes. diff --git a/experiments/decision-citations.test.ts b/experiments/decision-citations.test.ts new file mode 100644 index 0000000000..204faedbc1 --- /dev/null +++ b/experiments/decision-citations.test.ts @@ -0,0 +1,55 @@ +// Release check: every `file:line` citation under docs/ holds or is explained. +// +// A line number does not fail loudly when code moves under it; it comes to +// name the neighbouring code. `voice-permission.md` was written with 36 exact +// citations and eleven days later 16 had drifted. One PR that inserted a log +// block above `case "tool_denial"` turned a citation of the denial arm into one +// of the approval arm, the opposite of the claim. +// +// Merges do not fail on drift (maintainer ruling, 2026-11-03): any PR that moves +// lines in a cited file drifts some other PR's citations, and failing the +// merge queue on it turned main red for documentation alone. The experiment +// tier runs this file before every publish, so a release never ships a drifted +// record. Repair drift with the report: `bun scripts/check-citations.ts`. The +// checker's own rules are tested in tests/decision-citations.test.ts. + +import { describe, expect, test } from "bun:test"; +import { readFileSync } from "fs"; +import { join } from "path"; +import { + checkRecords, + describe as describeReport, + exceptionMismatches, + failing, + ROOT, +} from "../scripts/check-citations.ts"; + +describe("all documentation at release", () => { + const reports = checkRecords(); + + test("every citation names its anchor, or is a listed exception", () => { + expect(reports.filter(failing).map(describeReport)).toEqual([]); + }); + + test("every listed exception covers exactly the citations it declares", () => { + // Stale (the citation was anchored or reworded) or borrowed (a second + // identical citation inherits a reason written for the first) both fail. + expect(exceptionMismatches(reports)).toEqual([]); + }); + + test("the convention's own example is a citation that holds", () => { + // The example was written right and went stale within a day, when #230 + // inserted a line above `enforcementHook`. It is checked like any other. + for (const file of ["AGENTS.md", "docs/decisions/README.md", "scripts/check-citations.ts"]) { + const text = readFileSync(join(ROOT, file), "utf8"); + const example = text.match(/\(`enforcementHook`, `[^`]+`\)/)?.[0]; + expect({ file, found: Boolean(example) }).toEqual({ file, found: true }); + const [report] = checkRecords([{ doc: file, body: example! }], undefined, {}); + expect({ file, verdict: report.verdict.kind }).toEqual({ file, verdict: "anchored" }); + } + }); + + test("the check reads the records at all", () => { + expect(reports.filter((report) => report.verdict.kind === "anchored").length).toBeGreaterThan(100); + }); +}); diff --git a/tests/decision-citations.test.ts b/tests/decision-citations.test.ts index e5daf673b7..eb076f11a9 100644 --- a/tests/decision-citations.test.ts +++ b/tests/decision-citations.test.ts @@ -1,16 +1,15 @@ -// Every document under docs/ has `file:line` citations that hold or are explained. +// The rules of the citation checker, `scripts/check-citations.ts`, on in-memory +// trees, plus the one tree-wide rule that cannot drift with code: no citation +// into a private repository (#303). // -// A line number does not fail loudly when code moves under it — it comes to -// name the neighbouring code. `voice-permission.md` was written with 36 exact -// citations and eleven days later 16 had drifted; a single PR that inserted a -// log block above `case "tool_denial"` turned a citation of the denial arm into -// one of the approval arm, the opposite of the claim. This test is what makes -// that a red build instead of a confidently wrong record. The convention it -// enforces is in `docs/decisions/README.md`; the checker is -// `scripts/check-citations.ts`, which also runs on its own as a report. +// Whether every real citation still starts on its anchor is a release check, +// not a merge check (maintainer ruling, 2026-11-03): any PR that moves lines in +// a cited file drifts some other PR's citations, so failing every merge on it +// turned main red for documentation alone. That check is +// `experiments/decision-citations.test.ts`, which the experiment tier runs +// before every publish. The convention is in `docs/decisions/README.md`. import { describe, expect, test } from "bun:test"; -import { readFileSync } from "fs"; import { join } from "path"; import { checkRecords, @@ -42,35 +41,22 @@ function check(record: string, files: Record = { "src/hooks.ts": } describe("all documentation", () => { + // Drift (a citation whose anchor moved, a stale exception, the convention's + // own example) is a release check, not a merge check: it lives in + // experiments/decision-citations.test.ts and runs in the experiment tier + // before every publish (docs/decisions/README.md#citing-code). What stays + // here cannot drift with code: a citation into a private repository. const reports = checkRecords(); - test("every citation names its anchor, or is a listed exception", () => { - const failing = reports - .filter(failsCheck) + test("no citation points into a private repository (#303)", () => { + const privateCitations = reports + .filter((report) => report.verdict.kind === "private") .map(describeReport); - expect(failing).toEqual([]); - }); - - test("every listed exception covers exactly the citations it declares", () => { - // Stale (the citation was anchored or reworded) or borrowed (a second - // identical citation inherits a reason written for the first) both fail. - expect(exceptionMismatches(reports)).toEqual([]); - }); - - test("the convention's own example is a citation that holds", () => { - // The example was written right and went stale within a day, when #230 - // inserted a line above `enforcementHook`. It is checked like any other. - for (const file of ["AGENTS.md", "docs/decisions/README.md", "scripts/check-citations.ts"]) { - const text = readFileSync(join(ROOT, file), "utf8"); - const example = text.match(/\(`enforcementHook`, `[^`]+`\)/)?.[0]; - expect({ file, found: Boolean(example) }).toEqual({ file, found: true }); - const [report] = checkRecords([{ doc: file, body: example! }], undefined, {}); - expect({ file, verdict: report.verdict.kind }).toEqual({ file, verdict: "anchored" }); - } + expect(privateCitations).toEqual([]); }); test("the check reads the records at all", () => { - // A parser that found nothing would pass the first test trivially. + // A parser that found nothing would pass the test above trivially. expect(reports.filter((report) => report.verdict.kind === "anchored").length).toBeGreaterThan( 100, );