Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .agents/skills/release/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<file>.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 '<file>.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
Expand Down
16 changes: 12 additions & 4 deletions docs/decisions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
55 changes: 55 additions & 0 deletions experiments/decision-citations.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
52 changes: 19 additions & 33 deletions tests/decision-citations.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -42,35 +41,22 @@ function check(record: string, files: Record<string, string> = { "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,
);
Expand Down
Loading