* chore: rebuild ADR index as a generated artifact and enforce lifecycle invariants
The ADR index in docs/adr/README.md was hand-maintained with nothing checking
it, and had drifted to 40 of 65 ADRs. The absent rows included the entire
capability family (857/894/959/1016/1143/1213/1244) and ADR-1239 (EoS) itself,
so the decisions a reader most needed were the ones they could not find.
Make the index a derived artifact, matching the repo's existing generated-file
idiom (lint:generated-sync), and enforce the corpus' lifecycle invariants:
- scripts/gen-adr-index.cjs generates the index between markers and validates
the status vocabulary (Accepted/Proposed/Superseded/Legacy/Retired),
successor links, id/filename agreement, and supersession symmetry.
- Wire --check into lint:generated-sync so drift fails CI.
Correct the lifecycle metadata the gate surfaced, without flipping any status:
- ADR-1239 (EoS) declared it subsumed ADR-1016/58/3660/894; none recorded it.
Add reciprocal "Subsumed by" pointers + dated amendments. Subsumption keeps
the target Accepted -- these are live adapters, not dead decisions.
- ADR-857/894 carry dated status caveats: they read Proposed while the
capability system shipped and epic #857 is closed. Ratification is a
maintainer act and is deliberately left open.
- Link ADR-0005/0007/0012/3524 -> ADR-0174 and ADR-0010 -> ADR-0009; record
the reciprocal Supersedes on ADR-0009.
- ADR-218 declared itself "ADR-0175" -- an unfinished rename.
- The 0011 PRD moves from the non-canonical "Draft" to "Legacy".
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* test: capture stderr via spawnSync; record ADR-0010 draft supersession
Two fixes surfaced by the first gsd-test run and by regenerating the index:
- tests/adr-index-gate.test.cjs used execFileSync, which only surfaces stderr
through the thrown error on non-zero exit. The `--write` path exits 0 while
reporting outstanding violations on stderr, so the helper always saw ''.
spawnSync captures both streams on both outcomes.
- The hand-maintained index recorded 0010-skill-surface-budget-module.md as
"earlier draft superseded by ADR-0011" while the file itself still said
Proposed. Deriving the index from the files would have dropped that
assertion and resurrected a superseded draft as a live decision, so it is
recorded at its source, with the reciprocal Supersedes on ADR-0011.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix: drop the dead sdk/ model-catalog candidate retired by ADR-0174
src/model-catalog.cts resolved model-catalog.json through three candidates, the
second being sdk/shared/model-catalog.json three levels up. That was the legacy
source-repo fallback kept by the #3288 fix ("check the co-located path FIRST,
before the legacy source-repo path").
ADR-0174 then retired the @opengsd/gsd-sdk package boundary and deleted the sdk/
tree (11918dcc3), so the candidate can no longer resolve in any layout: a source
repo has no sdk/, and an install layout points it at ~/.claude/sdk/shared/, which
the installer never writes -- the original #3288 bug. It was dead weight implying
a package boundary this repo no longer has.
No test depends on it: the #3288 regression tests in tests/install.test.cjs write
their own synthetic old-path fixture and assert it throws.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* docs: ratify nine shipped ADRs; record why ten others stay Proposed
The corpus carried 19 Proposed ADRs, most describing architecture that had
already shipped. A Proposed label on live architecture tells contributors and
agents the decision is an unbuilt idea -- the capability system and EoS were
both being misread that way.
Audited all 19 against the shipped tree and GitHub. Each candidate flip then had
to survive two independent reviewers instructed to refute it.
Ratified Proposed -> Accepted, each with a dated Ratification section carrying
the verified evidence (file:line, symbols, tests, issue state):
857 capability system 894 declaration format 1244 capability ecosystem
1577 injection boundary 1610 size-budget ratchet 1990 existing-code onboarding
15 cross-AI convergence 22 plan-drift guard 0011 default reviewers
Held ten, each now carrying a "Why this is still Proposed" section naming the
blocker and its unblock condition, so the audit is not repeated:
2264 its own headline acceptance criterion is unmet in the tree
230 live branch protection contradicts the decided spec (1 approval, not 2)
660 the namesake release/<version> re-cut is manual, not automated
959 issue #2346 is approved and plans its graduation as its own ADR
1213 the shipped writer's return shape differs from the decided interface
443 the orchestrator override path has no live caller
1143 / 1606 each states its own bar for acceptance; neither is met
612 / 1671 legitimately open
Shipped code proved necessary but not sufficient: eight ADRs had every named
module, symbol, and test present with their epics closed, and still failed the
bar. That lesson is written into README.md's ratification procedure.
Also corrected ADR-857's "Supersedes (generalizes)" to "Subsumes": taken
literally it would have marked two live seams dead -- ADR-0011 (surface.cts:348)
and ADR-58 (runtime-artifact-install-plan.cts:82). Both keep Accepted status and
gain Subsumed-by pointers.
Index: Active 39->48, Proposed 19->10, Superseded/Legacy 7. 65 total.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix: harden gen-adr-index against hostile titles and non-ADR filenames (#2356)
Three findings from the pre-PR orthogonal security review, all confirmed:
- An ADR title containing the literal ADR-INDEX:END marker was emitted verbatim
into its table cell, relocating the splice boundary so the NEXT --write
spliced against the wrong marker and truncated README.md. Titles now render
through cellText(), which escapes pipes and angle brackets -- making an HTML
comment (and any other HTML) unformable from ADR-authored text.
- A docs/adr/*.md without a numeric prefix crashed on match(...)[1] of null.
Such a file is also invisible to the index -- the very failure this gate
exists to prevent -- so it is now reported as a naming-convention violation
naming the file and the fix.
- Tests leaked their mkdtemp dirs. They now use helpers.createTempDir/cleanup
via t.after(); helpers.cleanup carries the Windows-EBUSY retry budget that a
raw fs.rmSync lacks (caught by local/no-raw-rmsync-in-tests).
Adds five regression tests: marker hijack, HTML injection, pipe cell-break,
non-conforming filename, and splice stability across repeated writes.
Refs #2356
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix: close two gate false-passes; read ## Supersedes sections (#2356)
Second round of confirmed findings from the pre-PR orthogonal code review. Both
false-passes matter more than a false-fail: a gate that silently misses a
violation is worse than no gate, because it is trusted.
- A relation field mixing a link with a bare id silently dropped the bare claim:
the check tested `rel.links.length` (does this field have ANY link?) instead
of whether THAT id was linked. `Supersedes: [ADR-0001](...), ADR-0011` passed
clean -- accepting exactly the ambiguous bare reference the rule forbids. Now
each bare id is checked against the ids actually linked in the same field, so
a repeat in trailing prose stays quiet while an unlinked claim is flagged.
- The ratification guard (`statusToken !== 'Accepted'`) skipped BOTH relation
directions, which killed the IN check entirely: `supersedes.in` is only ever
populated on an ADR whose status IS `Superseded`, so a dangling `Superseded by
X` where X never claims it always passed. The guard now applies to OUT only --
a prospective claim must not obligate its target, but an ADR's statement about
ITSELF is always owed a reciprocal.
- Fixing that surfaced a parser gap: ADR-0174 declares its supersessions in a
`## Supersedes` table SECTION, not a header field, and headerBlock() stops at
the first `##`. The repo's best-documented supersession was invisible. Section
form is now parsed for both relations.
- Replaced a vacuous test: the em-dash negation case passed whether or not
NEGATED_RELATION_RE matched (a mutation to /$^/ survived). It now carries a
link that would create a failing asymmetric relation if negation did not fire.
Also removes docs/adr/9401-test-target.md -- a synthetic fixture a reviewer
created in the worktree while reproducing a finding, swept in by `git add -A`.
Adds regression tests for each: mixed link+bare, linked-and-repeated-in-prose,
dangling superseded-by from a non-Accepted ADR, and the ADR-0174 section shape.
Refs #2356
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix: escape backslashes before pipes in the ADR index cell renderer (#2356)
CodeQL js/incomplete-sanitization (high) on scripts/gen-adr-index.cjs: cellText()
escaped `|` -> `\|` without first escaping the backslash. Markdown's escape
character is the backslash, so the input `\|` became `\\|`, which renders as a
literal backslash followed by an UNESCAPED pipe -- re-opening the cell break the
pipe escape exists to prevent. Order is load-bearing: escape the escape
character first, then everything that emits one.
Same class as the index-marker hijack fixed earlier: ADR-authored text breaking
out of the cell it is rendered into.
Adds a regression test asserting a `\|`-bearing title leaves exactly the row's
own 5 unescaped delimiters and cannot forge a Status cell. Uses split(/\r?\n/)
per local/no-crlf-fragile-split -- a literal "\n" split is CRLF-fragile on the
Windows CI leg.
Refs #2356
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
439 lines
21 KiB
JavaScript
439 lines
21 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Behavioral tests for scripts/gen-adr-index.cjs — the ADR index generator and
|
|
* lifecycle gate (#2340).
|
|
*
|
|
* These drive the real CLI as a subprocess against synthetic ADR corpora in a
|
|
* temp dir, asserting on exit code and emitted text. No source-grepping: the
|
|
* runtime behavior is the contract.
|
|
*/
|
|
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { spawnSync } = require('node:child_process');
|
|
|
|
const { createTempDir, cleanup } = require('./helpers.cjs');
|
|
|
|
const REPO_ROOT = path.resolve(__dirname, '..');
|
|
const SCRIPT_REL = path.join('scripts', 'gen-adr-index.cjs');
|
|
|
|
const START = '<!-- ADR-INDEX:START — generated by scripts/gen-adr-index.cjs; do not edit by hand -->';
|
|
const END = '<!-- ADR-INDEX:END -->';
|
|
|
|
/**
|
|
* Build a throwaway repo whose docs/adr/ contains exactly `files`, and whose
|
|
* scripts/ holds a copy of the generator + its cli-exit dependency. A unique
|
|
* mkdtemp per call keeps parallel tests from colliding, and the dir is removed
|
|
* via `t.after()` so a failing assertion cannot leak it.
|
|
*/
|
|
function makeRepo(t, files) {
|
|
// helpers.cleanup (not raw fs.rmSync) carries the Windows-EBUSY retry budget.
|
|
const root = createTempDir('gsd-adr-index-');
|
|
t.after(() => cleanup(root));
|
|
fs.mkdirSync(path.join(root, 'docs', 'adr'), { recursive: true });
|
|
fs.mkdirSync(path.join(root, 'scripts', 'lib'), { recursive: true });
|
|
|
|
fs.copyFileSync(path.join(REPO_ROOT, SCRIPT_REL), path.join(root, SCRIPT_REL));
|
|
fs.copyFileSync(
|
|
path.join(REPO_ROOT, 'scripts', 'lib', 'cli-exit.cjs'),
|
|
path.join(root, 'scripts', 'lib', 'cli-exit.cjs'),
|
|
);
|
|
|
|
for (const [name, body] of Object.entries(files)) {
|
|
fs.writeFileSync(path.join(root, 'docs', 'adr', name), body);
|
|
}
|
|
fs.writeFileSync(
|
|
path.join(root, 'docs', 'adr', 'README.md'),
|
|
`# ADRs\n\n## Index\n\n${START}\n${END}\n`,
|
|
);
|
|
return root;
|
|
}
|
|
|
|
/**
|
|
* Run the generator in `root`; never throws — returns {status, stdout, stderr}.
|
|
*
|
|
* spawnSync (not execFileSync) because BOTH streams matter on BOTH outcomes:
|
|
* `--write` exits 0 while reporting outstanding violations on stderr, and
|
|
* execFileSync only surfaces stderr via the thrown error on non-zero exit.
|
|
*/
|
|
function run(root, args = []) {
|
|
const res = spawnSync(process.execPath, [path.join(root, SCRIPT_REL), ...args], {
|
|
cwd: root,
|
|
encoding: 'utf8',
|
|
timeout: 30_000,
|
|
});
|
|
if (res.error) throw res.error;
|
|
return { status: res.status, stdout: res.stdout || '', stderr: res.stderr || '' };
|
|
}
|
|
|
|
const adr = (title, fields) => `# ${title}\n\n${fields.map((f) => `- ${f}`).join('\n')}\n\n## Context\n\nBody.\n`;
|
|
|
|
test('a clean corpus generates an index and --check passes', (t) => {
|
|
const root = makeRepo(t, {
|
|
'0001-alpha.md': adr('Alpha module', ['**Status:** Accepted', '**Date:** 2026-01-01']),
|
|
'900-beta.md': adr('ADR-900: Beta module', ['**Status:** Proposed', '**Date:** 2026-01-02']),
|
|
});
|
|
|
|
const write = run(root, ['--write']);
|
|
assert.equal(write.status, 0, `--write failed: ${write.stderr}`);
|
|
|
|
const check = run(root, ['--check']);
|
|
assert.equal(check.status, 0, `--check failed: ${check.stderr}`);
|
|
|
|
const readme = fs.readFileSync(path.join(root, 'docs', 'adr', 'README.md'), 'utf8');
|
|
assert.match(readme, /\[ADR-0001\]\(0001-alpha\.md\)/, 'zero-padded id must render as written, not ADR-1');
|
|
assert.match(readme, /\[ADR-900\]\(900-beta\.md\)/);
|
|
assert.match(readme, /Active decisions \(1\)/);
|
|
assert.match(readme, /Proposed \(1\)/);
|
|
});
|
|
|
|
test('--check fails when an ADR is added but the index is not regenerated', (t) => {
|
|
const root = makeRepo(t, { '0001-alpha.md': adr('Alpha', ['**Status:** Accepted']) });
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
|
|
// A new ADR lands without re-running --write. This is the exact drift that let
|
|
// the hand-maintained index reach 40/65.
|
|
fs.writeFileSync(path.join(root, 'docs', 'adr', '901-gamma.md'), adr('Gamma', ['**Status:** Accepted']));
|
|
|
|
const check = run(root, ['--check']);
|
|
assert.equal(check.status, 1, 'a missing index row must fail CI');
|
|
assert.match(check.stderr, /stale/i);
|
|
});
|
|
|
|
test('a status outside the vocabulary is rejected and names the offender', (t) => {
|
|
const root = makeRepo(t, { '0001-alpha.md': adr('Alpha', ['**Status:** Draft']) });
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /0001-alpha\.md/);
|
|
assert.match(res.stderr, /"Draft" is not one of/);
|
|
});
|
|
|
|
test('an ADR with no status field at all is rejected', (t) => {
|
|
const root = makeRepo(t, { '0001-alpha.md': '# Alpha\n\nNo header fields.\n\n## Context\n\nBody.\n' });
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /no `- \*\*Status:\*\* <Token>` field/);
|
|
});
|
|
|
|
test('the table header form is parsed as legitimately as the bullet form', (t) => {
|
|
// ADR-2008 uses a markdown table for its header. Treating that as "missing a
|
|
// status" would flag a correct ADR.
|
|
const root = makeRepo(t, {
|
|
'0001-alpha.md': '# Alpha\n\n| | |\n|---|---|\n| **Status** | Accepted |\n| **Date** | 2026-01-01 |\n\n## Context\n\nBody.\n',
|
|
});
|
|
const res = run(root, ['--write']);
|
|
assert.equal(res.status, 0, `table-form header must parse: ${res.stderr}`);
|
|
assert.match(fs.readFileSync(path.join(root, 'docs', 'adr', 'README.md'), 'utf8'), /Active decisions \(1\)/);
|
|
});
|
|
|
|
test('Superseded must name its successor as a file link, not a bare id', (t) => {
|
|
const root = makeRepo(t, {
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Superseded by ADR-900 (2026-02-01)']),
|
|
'900-beta.md': adr('Beta', ['**Status:** Accepted', '**Supersedes:** [ADR-0001](0001-alpha.md)']),
|
|
});
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /not as a markdown link/);
|
|
});
|
|
|
|
test('Superseded with no successor at all is rejected', (t) => {
|
|
const root = makeRepo(t, { '0001-alpha.md': adr('Alpha', ['**Status:** Superseded']) });
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /names no successor/);
|
|
});
|
|
|
|
test('a one-way supersession is rejected and the message names the fix', (t) => {
|
|
const root = makeRepo(t, {
|
|
// Beta claims Alpha; Alpha says nothing back.
|
|
'900-beta.md': adr('Beta', ['**Status:** Accepted', '**Supersedes:** [ADR-0001](0001-alpha.md)']),
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Accepted']),
|
|
});
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /0001-alpha\.md/);
|
|
assert.match(res.stderr, /does not record it/);
|
|
assert.match(res.stderr, /\*\*Superseded by:\*\* \[ADR-900\]\(900-beta\.md\)/);
|
|
});
|
|
|
|
test('a symmetric supersession pair passes', (t) => {
|
|
const root = makeRepo(t, {
|
|
'900-beta.md': adr('Beta', ['**Status:** Accepted', '**Supersedes:** [ADR-0001](0001-alpha.md)']),
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Superseded by [ADR-900](900-beta.md) (2026-02-01)']),
|
|
});
|
|
assert.equal(run(root, ['--check']).status, 1, 'index not yet written');
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
assert.equal(run(root, ['--check']).status, 0, 'a symmetric pair must pass');
|
|
});
|
|
|
|
test('subsumption is symmetry-checked but does NOT mark the target superseded', (t) => {
|
|
// The EoS case: ADR-1239 subsumes ADR-1016 as an adapter. ADR-1016 stays
|
|
// Accepted — collapsing this into supersession would kill a live decision.
|
|
const root = makeRepo(t, {
|
|
'900-eos.md': adr('EoS', ['**Status:** Accepted', '**Subsumes as adapters:** [ADR-0001](0001-alpha.md)']),
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Accepted', '**Subsumed by:** [ADR-900](900-eos.md)']),
|
|
});
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
const readme = fs.readFileSync(path.join(root, 'docs', 'adr', 'README.md'), 'utf8');
|
|
assert.match(readme, /Active decisions \(2\)/, 'a subsumed ADR stays Active');
|
|
// The subsumer is surfaced in the "Read first" column so EoS is discoverable
|
|
// from the component ADR.
|
|
assert.match(readme, /\| \[ADR-0001\]\(0001-alpha\.md\) \|[^|]*\| Accepted \| \[ADR-900\]\(900-eos\.md\) \|/);
|
|
});
|
|
|
|
test('a missing subsumption back-link is rejected', (t) => {
|
|
const root = makeRepo(t, {
|
|
'900-eos.md': adr('EoS', ['**Status:** Accepted', '**Subsumes:** [ADR-0001](0001-alpha.md)']),
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Accepted']),
|
|
});
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /\*\*Subsumed by:\*\* \[ADR-900\]\(900-eos\.md\)/);
|
|
});
|
|
|
|
test("a Proposed ADR's supersession claim is prospective — no back-link demanded", (t) => {
|
|
// ADR-857 is Proposed and claims to generalize live ADRs. Demanding the
|
|
// back-link would stamp an Accepted decision as superseded by an unratified one.
|
|
const root = makeRepo(t, {
|
|
'900-beta.md': adr('Beta', ['**Status:** Proposed', '**Supersedes:** [ADR-0001](0001-alpha.md)']),
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Accepted']),
|
|
});
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
const check = run(root, ['--check']);
|
|
assert.equal(check.status, 0, `a Proposed claimant must not force a back-link: ${check.stderr}`);
|
|
});
|
|
|
|
test('ratifying that Proposed ADR to Accepted then demands the back-link', (t) => {
|
|
const root = makeRepo(t, {
|
|
'900-beta.md': adr('Beta', ['**Status:** Accepted', '**Supersedes:** [ADR-0001](0001-alpha.md)']),
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Accepted']),
|
|
});
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1, 'on ratification the back-link becomes required');
|
|
assert.match(res.stderr, /does not record it/);
|
|
});
|
|
|
|
test('"Supersedes: nothing" asserts no relation even when it name-drops an ADR', (t) => {
|
|
// ADR-2264 says "Supersedes: nothing; amends the ADR-1239 harness". Reading that
|
|
// as a supersession claim invents a link the author never made.
|
|
const root = makeRepo(t, {
|
|
'900-beta.md': adr('Beta', ['**Status:** Accepted', '**Supersedes:** nothing; amends the [ADR-0001](0001-alpha.md) harness']),
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Accepted']),
|
|
});
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
const check = run(root, ['--check']);
|
|
assert.equal(check.status, 0, `a negated relation field must assert nothing: ${check.stderr}`);
|
|
});
|
|
|
|
test('an em-dash relation value asserts no relation', (t) => {
|
|
// Vacuous unless the negated field also carries a LINK: with a bare em-dash
|
|
// there is nothing to mis-parse, so the test passes whether or not negation
|
|
// works. Linking an ADR after the em-dash makes it discriminating — if the
|
|
// field were read as a real claim, symmetry would demand 0001 record it.
|
|
const root = makeRepo(t, {
|
|
'900-beta.md': '# Beta\n\n| | |\n|---|---|\n| **Status** | Accepted |\n| **Supersedes** | — see [ADR-0001](0001-alpha.md) for context |\n\n## Context\n\nBody.\n',
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Accepted']),
|
|
});
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
const check = run(root, ['--check']);
|
|
assert.equal(check.status, 0, `an em-dash field must assert nothing: ${check.stderr}`);
|
|
assert.doesNotMatch(check.stderr, /does not record it/);
|
|
});
|
|
|
|
test('a mixed field with one link and one bare id still flags the bare id', (t) => {
|
|
// Regression: testing `rel.links.length` instead of the specific id meant a
|
|
// field carrying ANY link silently dropped every bare claim beside it.
|
|
const root = makeRepo(t, {
|
|
'900-beta.md': adr('Beta', ['**Status:** Accepted', '**Supersedes:** [ADR-0001](0001-alpha.md), ADR-0002']),
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Superseded by [ADR-900](900-beta.md)']),
|
|
'0002-gamma.md': adr('Gamma', ['**Status:** Accepted']),
|
|
});
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /names ADR-2 without a file link/);
|
|
});
|
|
|
|
test('a bare id repeated in prose beside its own link is not flagged', (t) => {
|
|
// The corpus legitimately writes "…([ADR-0001](0001-alpha.md)) — see ADR-0001
|
|
// below". That repeat must not be noise.
|
|
const root = makeRepo(t, {
|
|
'900-beta.md': adr('Beta', ['**Status:** Accepted', '**Supersedes:** Alpha ([ADR-0001](0001-alpha.md)) — see the ADR-0001 note below']),
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Superseded by [ADR-900](900-beta.md)']),
|
|
});
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
const check = run(root, ['--check']);
|
|
assert.equal(check.status, 0, `a linked-and-repeated id must not be flagged: ${check.stderr}`);
|
|
});
|
|
|
|
test('a dangling "Superseded by" is caught even though the ADR is not Accepted', (t) => {
|
|
// Regression: the ratification guard skipped every non-Accepted ADR, which
|
|
// killed the IN direction entirely — a Superseded ADR pointing at a successor
|
|
// that never claims it went unchecked.
|
|
const root = makeRepo(t, {
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Superseded by [ADR-900](900-beta.md)']),
|
|
'900-beta.md': adr('Beta', ['**Status:** Accepted']),
|
|
});
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1, 'a one-way superseded-by must fail');
|
|
assert.match(res.stderr, /does not claim it|does not record it/);
|
|
});
|
|
|
|
test('a `## Supersedes` table section counts as the claim (ADR-0174 shape)', (t) => {
|
|
// The richest form in the corpus declares supersession as a section+table, not
|
|
// a header field. Reading only the header block reported the repo's
|
|
// best-documented supersession as missing.
|
|
const root = makeRepo(t, {
|
|
'900-beta.md': '# Beta\n\n- **Status:** Accepted\n\n## Supersedes\n\n| ADR | What it said | Why superseded |\n|---|---|---|\n| [ADR-0001](0001-alpha.md) | a thing | a reason |\n\n## Context\n\nBody.\n',
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Superseded by [ADR-900](900-beta.md)']),
|
|
});
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
const check = run(root, ['--check']);
|
|
assert.equal(check.status, 0, `a ## Supersedes table must satisfy symmetry: ${check.stderr}`);
|
|
});
|
|
|
|
test('a title id that disagrees with the filename is rejected', (t) => {
|
|
// The real ADR-218 case: renamed to the issue# convention, title left behind.
|
|
const root = makeRepo(t, { '218-release.md': adr('ADR-0175: Harden release validation', ['**Status:** Accepted']) });
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /H1 declares ADR-175 but the filename says 218/);
|
|
});
|
|
|
|
test('a relation link to a nonexistent ADR is rejected', (t) => {
|
|
const root = makeRepo(t, {
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Accepted', '**Supersedes:** [ADR-404](404-ghost.md)']),
|
|
});
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /does not exist in docs\/adr\//);
|
|
});
|
|
|
|
test('a bare id naming a nonexistent ADR is steered toward issue syntax', (t) => {
|
|
// ADR-1610 says "superseding the #597 tier-max ratchet" — #597 is an ISSUE.
|
|
// Written as "ADR-597" it would be an unresolvable reference.
|
|
const root = makeRepo(t, {
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Accepted', '**Supersedes:** ADR-597 tier-max ratchet']),
|
|
});
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /If it is an ISSUE number, write "#597"/);
|
|
});
|
|
|
|
test('an ambiguous bare id reports every file it could mean', (t) => {
|
|
const root = makeRepo(t, {
|
|
'0011-one.md': adr('One', ['**Status:** Accepted']),
|
|
'0011-two.md': adr('Two', ['**Status:** Accepted']),
|
|
'900-beta.md': adr('Beta', ['**Status:** Accepted', '**Supersedes:** ADR-0011']),
|
|
});
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /ambiguous — resolves to 2 files/);
|
|
assert.match(res.stderr, /0011-one\.md/);
|
|
assert.match(res.stderr, /0011-two\.md/);
|
|
});
|
|
|
|
test('--check fails loudly when the README markers are missing', (t) => {
|
|
const root = makeRepo(t, { '0001-alpha.md': adr('Alpha', ['**Status:** Accepted']) });
|
|
fs.writeFileSync(path.join(root, 'docs', 'adr', 'README.md'), '# ADRs\n\nNo markers here.\n');
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /missing the index markers/);
|
|
});
|
|
|
|
test('--write still emits the index while reporting outstanding violations', (t) => {
|
|
// --write must remain usable as a repair tool on a corpus that is not yet clean,
|
|
// but must not pretend the corpus is healthy.
|
|
const root = makeRepo(t, {
|
|
'900-beta.md': adr('Beta', ['**Status:** Accepted', '**Supersedes:** [ADR-0001](0001-alpha.md)']),
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Accepted']),
|
|
});
|
|
const res = run(root, ['--write']);
|
|
assert.equal(res.status, 0, '--write proceeds');
|
|
assert.match(res.stderr, /lifecycle violation\(s\) remain/);
|
|
assert.match(fs.readFileSync(path.join(root, 'docs', 'adr', 'README.md'), 'utf8'), /Active decisions \(2\)/);
|
|
});
|
|
|
|
test('an ADR title cannot hijack the README splice with an index marker', (t) => {
|
|
// Review finding: a title carrying the literal END marker was emitted verbatim
|
|
// into the table cell, relocating the boundary so the NEXT --write spliced
|
|
// against the wrong marker and ate the rest of README.md.
|
|
const root = makeRepo(t, {
|
|
'0001-alpha.md': adr(`Evil ${END} title`, ['**Status:** Accepted']),
|
|
});
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
|
|
const readme = fs.readFileSync(path.join(root, 'docs', 'adr', 'README.md'), 'utf8');
|
|
const endCount = readme.split(END).length - 1;
|
|
assert.equal(endCount, 1, 'exactly one END marker must survive — the title must not forge another');
|
|
|
|
// The splice must remain stable across repeated writes.
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
const again = fs.readFileSync(path.join(root, 'docs', 'adr', 'README.md'), 'utf8');
|
|
assert.equal(again.split(END).length - 1, 1);
|
|
assert.equal(run(root, ['--check']).status, 0, 'a hostile title must not leave the index permanently stale');
|
|
});
|
|
|
|
test('a title cannot inject raw HTML into the generated index', (t) => {
|
|
const root = makeRepo(t, {
|
|
'0001-alpha.md': adr('Alpha <script>x</script> module', ['**Status:** Accepted']),
|
|
});
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
const readme = fs.readFileSync(path.join(root, 'docs', 'adr', 'README.md'), 'utf8');
|
|
assert.ok(!readme.includes('<script>'), 'angle brackets must be escaped, not emitted raw');
|
|
assert.match(readme, /<script>/);
|
|
});
|
|
|
|
test('a backslash-pipe in a title cannot break out of its table cell', (t) => {
|
|
// CodeQL js/incomplete-sanitization: escaping `|` -> `\|` without escaping the
|
|
// backslash FIRST turns the input `\|` into `\\|`, which markdown reads as a
|
|
// literal backslash plus an UNESCAPED pipe — re-opening the very cell break the
|
|
// pipe escape exists to prevent.
|
|
const root = makeRepo(t, {
|
|
'0001-alpha.md': adr('Alpha \\| Accepted \\| forged', ['**Status:** Proposed']),
|
|
});
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
const readme = fs.readFileSync(path.join(root, 'docs', 'adr', 'README.md'), 'utf8');
|
|
|
|
const row = readme.split(/\r?\n/).find((l) => l.includes('0001-alpha.md'));
|
|
assert.ok(row, 'the ADR must still have a row');
|
|
// 4 pipes = the row's own delimiters (| id | title | status | read-first |) = 5.
|
|
// Any unescaped pipe from the title would add a 6th boundary and shift the cells.
|
|
const unescaped = [...row.matchAll(/(?<!\\)\|/g)].length;
|
|
assert.equal(unescaped, 5, `title pipes must stay escaped; row was: ${row}`);
|
|
assert.match(readme, /Proposed \(1\)/, 'the forged cell must not land the ADR in Active');
|
|
});
|
|
|
|
test('a pipe in a title cannot break out of its table cell', (t) => {
|
|
const root = makeRepo(t, {
|
|
'0001-alpha.md': adr('Alpha | Accepted | fake', ['**Status:** Proposed']),
|
|
});
|
|
assert.equal(run(root, ['--write']).status, 0);
|
|
const readme = fs.readFileSync(path.join(root, 'docs', 'adr', 'README.md'), 'utf8');
|
|
assert.match(readme, /Alpha \\\| Accepted \\\| fake/, 'pipes must be escaped');
|
|
assert.match(readme, /Proposed \(1\)/, 'the forged cell must not land the ADR in Active');
|
|
});
|
|
|
|
test('a file that does not match the naming convention is reported, not crashed on', (t) => {
|
|
// Review finding: `notes.md` hit `file.match(/^([0-9]+)-/)[1]` → TypeError on
|
|
// null. An unparseable name is also invisible to the index — the exact failure
|
|
// this gate exists to prevent — so it must surface as a violation.
|
|
const root = makeRepo(t, {
|
|
'0001-alpha.md': adr('Alpha', ['**Status:** Accepted']),
|
|
'notes.md': '# Scratch notes\n\nNot an ADR.\n',
|
|
});
|
|
const res = run(root, ['--check']);
|
|
assert.equal(res.status, 1);
|
|
assert.match(res.stderr, /notes\.md/);
|
|
assert.match(res.stderr, /does not match the .*convention/);
|
|
assert.doesNotMatch(res.stderr, /TypeError|Cannot read propert/, 'must be a gate violation, not a crash');
|
|
});
|
|
|
|
test('the real repo corpus is clean and its index is current', () => {
|
|
// The gate must hold against docs/adr/ as committed, not only fixtures.
|
|
const res = run(REPO_ROOT, ['--check']);
|
|
assert.equal(res.status, 0, `docs/adr/ must satisfy its own gate:\n${res.stderr}`);
|
|
});
|