A PR whose diff is entirely under docs/ runs zero tests, so a guard whose INPUT
is shipped prose cannot protect the PR lane of the diffs it exists to check. Its
only firing opportunity is after merge, on the shared branch -- which is how next
went red on dacae9273 while the PR that caused it (#3746) was green on every
check.
The docs-lint job in .github/workflows/docs-required.yml -- an ALREADY-REQUIRED
context -- now selects and runs the docs guards that read the specific docs files
the PR changed.
scripts/docs-guard-registry.cjs test file -> the docs paths it reads (63)
scripts/select-docs-guards.cjs pure (changedPaths, registry) -> test files
scripts/lint-docs-guard-registration.cjs drift guard, wired into lint:ci
scripts/ci-test-scope.cjs is NOT touched -- `git diff origin/next --` on it is
empty -- so #764's saving stands and its 21 pinning tests are untouched.
Selection: exact path; trailing-slash directory prefix (boundary-checked --
docs/adrenaline.md does NOT match docs/adr/, which a naive startsWith gets
wrong); and '*' for the 6 entries that walk docs/ generally or read a computed
path. Unknown maps to '*' -- guessing narrow is how a guard silently stops
running. Measured: a typo fix selects 6 of 63; docs/AGENTS.md selects 12;
docs/COMMANDS.md selects 18.
Four things this got wrong first, each found by an independent reviewer or by
probe, and each having been asserted safe in a comment:
1. The registry started as a RULE in ci-test-scope.cjs's RULES, on the theory
that classify()'s !codeChanged normalization made it inert. True for
docs-ONLY diffs; false for MIXED docs+code diffs, where codeChanged is true
and the normalization never runs:
node scripts/ci-test-scope.cjs --files "docs/a.md src/semver.cts"
with the RULE: 25 targeted_tests
origin/next: 3 targeted_tests
Category error: RULES is the scoped lane's input; a docs-guard registry is a
lane manifest for a consumer that never calls classify(). Extracted; pinned
by value.
2. The second attempt was a dedicated workflow with paths: [docs/**]. Such a
workflow never reports on a non-docs PR, so it can never be a required
context without hanging every non-docs PR -- and a non-required check does not
block a merge, so the guard would have been advisory and #3753 unfixed.
docs-required.yml already has no paths: filter, already supplies the required
docs-lint context, already computes docs_changed, and already ran one docs
guard gated on it. Generalizing that step needs no ruleset edit at all.
3. The registry and the drift lint were built from ONE path-segment heuristic, so
both were blind identically -- and blind at the guard that motivated the issue.
The reader-call regex required a character BEFORE its keyword, so a callee
named exactly read( / load( / parse( / doc( / file( / content( could never
match; and only an INLINE path.join(ROOT,'docs','X.md') argument was caught,
missing the two-step-via-variable form -- the MAJORITY spelling -- plus
template literals and concatenation. Detector 1 fired on 14 of ~450 files, so
35 genuine guards sat unregistered while the lint reported 0 violations,
including cursor-reviewer (reads docs/COMMANDS.md, asserts
.includes('--cursor')) and inventory-headings-countfree. The "accepted blind
spot" this shipped with was the common case, not a fringe.
4. With detection fixed the true population is 115 files: 63 genuine guards, 52
incidental. Running all 63 in a REQUIRED check on a one-line typo fix is the
cost #764 exists to avoid -- install.test.cjs is 7840 lines and reads exactly
one docs file, docs/AGENTS.md, for its frontmatter. Dropping it reproduces the
bug; running it for a typo elsewhere is waste. Hence the map.
Then a second review round found six more, all fixed here:
- fragment-single-edit-propagation.install.test.cjs was EXEMPTED as
"overlay fixture only". False: it reads the real docs/registries/eos.json and
asserts on a registry entry name, and reads the real ADR-0001 and asserts its
H1. A docs-only PR touching either would have gone green and red next -- #3753
shipping again, from inside the fix for it. Now registered against both paths,
and all 52 remaining exemptions were re-audited one by one.
- The SUITES-collision guard compared RAW registry keys, but run-tests.cjs strips
a leading `tests/` BEFORE its suite check. So it caught 'all' and missed
'tests/all' -- the only spelling that can actually occur, since every key
carries the prefix. One typo would have run all 824 test files inside the
required job. Now normalized the same way run-tests.cjs normalizes.
- The lint failed OPEN on an unreadable tests dir or candidate file: 0 violations,
ok:true. A guard that cannot read its input must never report success.
- The exemption ratchet gated identity only, so a baselined file that later
STARTED asserting on shipped docs stayed exempt silently -- 52 permanently blind
files. The baseline now fingerprints the docs paths each exempted file
references and fails when that set changes, naming what changed.
- The exemption marker was still honored inside a multi-line template literal in
the header window. The scanner now tracks template-literal and block-comment
state.
- `git diff --name-only | grep '^docs/'` silently dropped C-quoted non-ASCII docs
paths, making docs_changed=false a green zero-guard check. Both call sites now
pass -c core.quotepath=false.
- The run step was gated on hashFiles(), which a force-committed
.docs-guard-tests.txt would satisfy. The step now rm -f's both scratch files
first and gates on an output it sets itself.
Three empty states, deliberately distinct, because conflating them rebuilds
#3753: an empty or malformed registry HARD-FAILS; docs changed with no guard
covering them logs and skips; no docs change is already gated. The middle state
must never be expressed as an empty --files-from, which prints `no tests in suite
"all"` and exits 0 -- a green check that guarded nothing. With the current
registry that state is unreachable, because the six '*' entries always match;
the branch is kept as defensive handling for a future registry and says so.
timeout-minutes: 15 bounds the required job against a hanging fork-supplied test;
it had none. npm ci was added because the job never installed dependencies -- the
previous single-file step got away without it, the registry does not.
docs/contributing/docs-guard-registration.md documents the rule, following its
sibling cross-platform-portability-rules.md, and CONTRIBUTING.md's CI Test
Quality Checks table links to it. It is also load-bearing: without a docs/ file
in the diff this PR would not have triggered its own lane, shipping an
unexercised change to a required check.
One unrelated fix, included because this PR surfaced it and CLAUDE.md forbids
deferring a defect found while working. On this branch's first CI run,
`full test (windows-latest, 24, shard 3/3)` was CANCELLED at exactly 30 minutes;
tests were still passing 0.8s before the cancel, so it is a wall-clock timeout,
not a hang, and a cancelled job reddens `Required tests`.
The cause is not this PR's test file, which costs ~60ms. Shard composition is
unstable: adding ONE file to the unit suite reshuffled 115 of 268 files between
shards, and shard 3 drew a heavier mix. Underneath that is a real pre-existing
defect. tests/ci-test-job-timeout-budget.test.cjs requires every lane's budget to
be >= 1.5x its MEASURED cost -- "a lane that got slower must be re-budgeted, not
excused" -- and its test-full entry recorded 19m from a windows-22 shard. That is
stale. Measured on `next` with none of this PR's changes present: 26m18s (run
32614439702, windows-latest/24 shard 3/3), 23m36s and 23m17s on shard 2/3. So the
lane costs ~26m and the 30-minute cap carried 1.14x headroom, not 1.5x. The gate
had been out of compliance with its own rule; this PR was merely the file
addition that reshuffled shard 3 past the cliff.
Fixed as that file prescribes: measuredMinutes 19 -> 27 with fresh evidence, and
test-full timeout-minutes 30 -> 45. The rule's minimum for 27m is 41; 45 is
deliberately above it because the reshuffle means per-shard worst case moves run
to run, and a budget pinned to the exact minimum would be re-breached by the next
test file anyone adds. Only that one job's timeout changed; test.yml's scope,
matrix and steps are untouched, so #764's saving is unaffected.
Raising that cap let the Windows shard finish (28m45s, inside 45) and uncovered
a real failure the 30-minute cancel had been masking:
`new quick-task branch branches off origin/main (#2916)` died with
`outcome=timed_out exitCode=null`, SIGTERM, at the 15000ms bound.
tests/quick-branching.test.cjs:149 `runStep` runs a `#!/usr/bin/env bash` script
executing MULTIPLE git commands, but was bound to GIT_TIMEOUT_MS (15000) -- the
norm for a SINGLE git plumbing call. tests/helpers/timeouts.cjs already documents
this exact failure and exists to fix it: HOOK_FANOUT_TIMEOUT_MS was created after
PR #3285 recorded "outcome=timed_out exitCode=null at exactly the 15000ms probe
bound while every other lane passed the same commit", and calls that "a bound
sized for the wrong class, not a slow machine". Our failure is that case
verbatim, so both sites move to the class norm rather than to a bigger number.
The same class also failed on `next` itself 21 hours earlier -- run 32608945654,
windows-latest/24 shard 1/3, `plan touching only src/ in a submodule project
keeps worktree isolation ENABLED` -- where tests/worktree-safety.test.cjs:5845
`runGate` fans out to `git config --file .gitmodules` under a hardcoded 30000.
Fixed too, since it is a defect in the tree regardless of which branch surfaced
it.
A survey of the whole tests/ tree found the same class-mismatch at further
bash fan-out sites bound under 60000ms, and the maintainer approved sweeping
them rather than leaving them latent to surface the same way one at a time. 16
fan-out sites across 16 files now use the class norm.
The sweep is class-correctness, not raising numbers until things pass. Sites
were moved ONLY where the bash body demonstrably spawns something (git, node,
npm, a CLI); self-contained shell snippets were left where they are, and are
listed as deliberately unchanged: pure if/printf bodies (copilot-install), pure
array/case builtins (code-review-pipeline-regression:638), a documented
pure-shell gsd_run stub (host-integration), single-process hook calls
(workflow-guard:222/271/302), and a deliberately tight 5000ms fast-check hook
(gsd-write-guard.property). Nothing was lowered. process-seam.test.cjs:513
(literal 300) is untouched on purpose -- it tests timeout BEHAVIOR, so raising
it would destroy what it asserts.
Shared file-level constants were the trap here, and were handled per file rather
than by redefinition: GIT_TIMEOUT_MS has ~15 users in git-base-branch and only 1
is a fan-out; WORKTREE_TIMEOUT_MS has 16 users in worktree.test.cjs and 3 are;
PROBE_TIMEOUT_MS has several in three more files. In each the CALL SITE was
changed and the constant left alone, so no single-plumbing-call site silently
inherited a 60s bound. The one exception is hooks-opt-in.test.cjs, where
HOOK_TIMEOUT_MS has exactly one consumer -- spawnHook, the fan-out itself -- so
redefining it is identical in effect and reads better.
Only two of these sites have actually been observed failing. The rest cite that
shared class and those two run ids rather than inventing evidence of their own.
Co-authored-by: sim <sim@local>
435 lines
20 KiB
JavaScript
435 lines
20 KiB
JavaScript
'use strict';
|
|
|
|
// docs-guard-exempt: allPathsAreTestsOrDocs(['tests/a.cjs', 'docs/b.md']) below
|
|
// spot-checks a pure path-classifier predicate with string literals — no real
|
|
// docs/ file is ever read or asserted on for content.
|
|
|
|
/**
|
|
* Tests for scripts/require-issue-link-policy.cjs (#3211, preserving #1389).
|
|
*
|
|
* All assertions are on the typed ISSUE_LINK_REASON enum, never on free
|
|
* text — see CLAUDE.md "Mutation Score" / test conventions.
|
|
*/
|
|
|
|
const { describe, test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const yaml = require('js-yaml');
|
|
|
|
const {
|
|
ISSUE_LINK_REASON,
|
|
hasClosingKeyword,
|
|
hasFollowUpReference,
|
|
allPathsAreTestsOrDocs,
|
|
evaluateIssueLink,
|
|
EXEMPT_PATH_PREFIXES,
|
|
EXCLUDED_ROOT_DOCS,
|
|
} = require('../scripts/require-issue-link-policy.cjs');
|
|
|
|
const { fileListIsComplete } = require('../scripts/pr-changed-files.cjs');
|
|
|
|
function forkPr(overrides = {}) {
|
|
return {
|
|
prBody: '',
|
|
headRef: 'fix/123-something',
|
|
sameRepo: false,
|
|
changedFiles: ['src/init.cts'],
|
|
changedFilesTotal: 1,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function testPaths(n) {
|
|
return Array.from({ length: n }, (_, i) => `tests/generated-${i}.test.cjs`);
|
|
}
|
|
|
|
describe('evaluateIssueLink', () => {
|
|
// 1. Real-world vector: a fork PR that adds regression coverage for an
|
|
// issue without closing it.
|
|
test('fork PR referencing an issue with a tests-only diff is OK_FOLLOWUP_REFERENCE', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #2269 — regression coverage.',
|
|
changedFiles: ['tests/commit-files-pathspec.test.cjs'],
|
|
changedFilesTotal: 1,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.OK_FOLLOWUP_REFERENCE);
|
|
assert.strictEqual(result.ok, true);
|
|
});
|
|
|
|
// 2. Every accepted reference form, including a lowercase variant.
|
|
test('every accepted follow-up reference form passes with a tests-only diff', () => {
|
|
const forms = [
|
|
'Refs #1', 'Ref #1', 'References #1', 'Relates to #1',
|
|
'Related to #1', 'Follow-up to #1', 'Follow up to #1', 'refs #1',
|
|
];
|
|
for (const body of forms) {
|
|
const result = evaluateIssueLink(forkPr({ prBody: body, changedFiles: ['tests/a.test.cjs'], changedFilesTotal: 1 }));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.OK_FOLLOWUP_REFERENCE, `form: ${body}`);
|
|
}
|
|
});
|
|
|
|
// 3. Docs-only and mixed tests+docs diffs are both allowed.
|
|
test('docs-only and mixed tests+docs diffs pass', () => {
|
|
const docsOnly = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #1', changedFiles: ['docs/CONFIGURATION.md'], changedFilesTotal: 1,
|
|
}));
|
|
assert.strictEqual(docsOnly.reason, ISSUE_LINK_REASON.OK_FOLLOWUP_REFERENCE);
|
|
|
|
const mixed = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #1', changedFiles: ['tests/a.test.cjs', 'docs/guide.md'], changedFilesTotal: 2,
|
|
}));
|
|
assert.strictEqual(mixed.reason, ISSUE_LINK_REASON.OK_FOLLOWUP_REFERENCE);
|
|
});
|
|
|
|
// 4. Windows-style backslash path is normalized before the prefix check.
|
|
test('backslash path is normalized and recognized as tests/', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #1', changedFiles: ['tests\\windows\\a.test.cjs'], changedFilesTotal: 1,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.OK_FOLLOWUP_REFERENCE);
|
|
});
|
|
|
|
// 5. CRLF vs LF bodies must produce the same reason.
|
|
test('CRLF and LF bodies with the same reference produce the same reason', () => {
|
|
const lf = evaluateIssueLink(forkPr({ prBody: 'Refs #1\n\nMore prose.', changedFiles: ['tests/a.test.cjs'], changedFilesTotal: 1 }));
|
|
const crlf = evaluateIssueLink(forkPr({ prBody: 'Refs #1\r\n\r\nMore prose.', changedFiles: ['tests/a.test.cjs'], changedFilesTotal: 1 }));
|
|
assert.strictEqual(lf.reason, ISSUE_LINK_REASON.OK_FOLLOWUP_REFERENCE);
|
|
assert.strictEqual(crlf.reason, ISSUE_LINK_REASON.OK_FOLLOWUP_REFERENCE);
|
|
});
|
|
|
|
// 6. No reference at all, even with a docs-only diff, fails.
|
|
test('no reference at all fails even with a docs-only diff', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Just a description, no issue mentioned.', changedFiles: ['docs/guide.md'], changedFilesTotal: 1,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_NO_ISSUE_REFERENCE);
|
|
});
|
|
|
|
// 7 & 8. A reference (not a closing keyword) touching source files needs
|
|
// an actual closing keyword instead.
|
|
test('reference-only PR touching a source file fails needs-closing', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #2269', changedFiles: ['src/init.cts'], changedFilesTotal: 1,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_REFERENCE_NEEDS_CLOSING);
|
|
});
|
|
|
|
test('reference-only PR with a mixed tests+source diff fails needs-closing', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #2269',
|
|
changedFiles: ['tests/a.test.cjs', 'tests/b.test.cjs', 'src/b.cts'],
|
|
changedFilesTotal: 3,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_REFERENCE_NEEDS_CLOSING);
|
|
});
|
|
|
|
// 9. Bodies that must NOT be recognized as any kind of issue reference.
|
|
test('non-reference bodies fail with FAIL_NO_ISSUE_REFERENCE', () => {
|
|
const bodies = ['see #123', '#123', 'unlike #123', 'issue 123', 'a #123 b'];
|
|
for (const body of bodies) {
|
|
const result = evaluateIssueLink(forkPr({ prBody: body, changedFiles: ['tests/a.test.cjs'], changedFilesTotal: 1 }));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_NO_ISSUE_REFERENCE, `body: ${JSON.stringify(body)}`);
|
|
}
|
|
});
|
|
|
|
// 10. Lookalike words that embed "ref"/"reference" inside a longer word
|
|
// must not be treated as a reference.
|
|
test('lookalike embedded-word bodies fail with FAIL_NO_ISSUE_REFERENCE', () => {
|
|
const bodies = ['prefs #1', 'unreferenced #1', 'xref#1', 'preferences #1'];
|
|
for (const body of bodies) {
|
|
const result = evaluateIssueLink(forkPr({ prBody: body, changedFiles: ['tests/a.test.cjs'], changedFilesTotal: 1 }));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_NO_ISSUE_REFERENCE, `body: ${JSON.stringify(body)}`);
|
|
}
|
|
});
|
|
|
|
// 11. Directory-lookalike paths (tests-e2e/, src/tests/, testsuite/,
|
|
// docsite/) must NOT be treated as tests/ or docs/.
|
|
test('directory-lookalike paths are rejected, forcing needs-closing', () => {
|
|
const paths = ['tests-e2e/src/a.ts', 'src/tests/x.ts', 'testsuite/y.cjs', 'docsite/z.md'];
|
|
for (const p of paths) {
|
|
const result = evaluateIssueLink(forkPr({ prBody: 'Refs #1', changedFiles: [p], changedFilesTotal: 1 }));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_REFERENCE_NEEDS_CLOSING, `path: ${p}`);
|
|
}
|
|
});
|
|
|
|
// 12. A closing keyword on a source diff passes outright.
|
|
test('Closes #123 with a source diff is OK_CLOSING_KEYWORD', () => {
|
|
const result = evaluateIssueLink(forkPr({ prBody: 'Closes #123', changedFiles: ['src/init.cts'], changedFilesTotal: 1 }));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.OK_CLOSING_KEYWORD);
|
|
});
|
|
|
|
// 13. Closing keyword case/whitespace variants.
|
|
test('closing keyword variants (case, whitespace) all pass', () => {
|
|
const bodies = ['closes #1', 'FIXES #1', 'Resolves #1', 'resolves\t#1'];
|
|
for (const body of bodies) {
|
|
const result = evaluateIssueLink(forkPr({ prBody: body, changedFiles: ['src/init.cts'], changedFilesTotal: 1 }));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.OK_CLOSING_KEYWORD, `body: ${JSON.stringify(body)}`);
|
|
}
|
|
});
|
|
|
|
// 14 & 15. #1389 anti-forgery property: the backmerge exemption requires
|
|
// BOTH the branch prefix AND sameRepo === true.
|
|
test('backmerge branch + sameRepo true is exempt with no reference at all', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: '', headRef: 'chore/backmerge-main-to-next-20260101', sameRepo: true,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.OK_BACKMERGE_EXEMPT);
|
|
});
|
|
|
|
test('#1389 anti-forgery: backmerge branch name from a FORK (sameRepo false) is NOT exempt', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: '', headRef: 'chore/backmerge-main-to-next-20260101', sameRepo: false,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_NO_ISSUE_REFERENCE);
|
|
});
|
|
|
|
// 16. hasClosingKeyword corpus parity — expected values come from the
|
|
// shipped shell grep this regex replaces:
|
|
// grep -qiE '(closes|fixes|resolves)\s+#[0-9]+'
|
|
test('hasClosingKeyword corpus parity with the replaced shell grep', () => {
|
|
const cases = [
|
|
['Closes #2269', true],
|
|
['closes #1', true],
|
|
['Fixes #12', true],
|
|
['Resolves #3', true],
|
|
['fixes #4', true],
|
|
['Closes #123 and more prose', true],
|
|
['Refs #2269', false],
|
|
['Follow-up to #2269', false],
|
|
['no reference at all', false],
|
|
['Closes #', false],
|
|
['Closes123', false],
|
|
['closes issue 5', false],
|
|
];
|
|
for (const [body, expected] of cases) {
|
|
assert.strictEqual(hasClosingKeyword(body), expected, `body: ${JSON.stringify(body)}`);
|
|
}
|
|
});
|
|
|
|
// 17-18. BOUNDARY: exactly at and just below the page cap, with a total
|
|
// that matches, must pass.
|
|
test('BOUNDARY 99 tests-only paths, total 99 passes', () => {
|
|
const paths = testPaths(99);
|
|
const result = evaluateIssueLink(forkPr({ prBody: 'Refs #1', changedFiles: paths, changedFilesTotal: 99 }));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.OK_FOLLOWUP_REFERENCE);
|
|
});
|
|
|
|
test('BOUNDARY 100 tests-only paths, total 100 passes', () => {
|
|
const paths = testPaths(100);
|
|
const result = evaluateIssueLink(forkPr({ prBody: 'Refs #1', changedFiles: paths, changedFilesTotal: 100 }));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.OK_FOLLOWUP_REFERENCE);
|
|
});
|
|
|
|
// 19. Real vector: PR #3202 — gh returns 100 of 118 changed files.
|
|
test('BOUNDARY 100 tests-only paths, total 118 fails FAIL_FILE_LIST_INCOMPLETE (PR #3202 vector)', () => {
|
|
const paths = testPaths(100);
|
|
const result = evaluateIssueLink(forkPr({ prBody: 'Refs #1', changedFiles: paths, changedFilesTotal: 118 }));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_FILE_LIST_INCOMPLETE);
|
|
});
|
|
|
|
test('100 tests-only paths, total undefined fails FAIL_FILE_LIST_INCOMPLETE', () => {
|
|
const paths = testPaths(100);
|
|
const result = evaluateIssueLink(forkPr({ prBody: 'Refs #1', changedFiles: paths, changedFilesTotal: undefined }));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_FILE_LIST_INCOMPLETE);
|
|
});
|
|
|
|
// Reviewed BLOCKER: the old fileListIsComplete only consulted the total
|
|
// when length >= FILE_LIST_PAGE_LIMIT, so ANY mechanism that shortens the
|
|
// list below 100 went undetected. A $GITHUB_OUTPUT heredoc terminated
|
|
// early by a file named after the delimiter is exactly such a mechanism —
|
|
// it truncates the list well below the page cap, with the true total
|
|
// still available from the separate, non-paginated `changedFiles` field.
|
|
test('a list shorter than its authoritative total fails closed', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #1', changedFiles: ['CONTRIBUTING.md'], changedFilesTotal: 3,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_FILE_LIST_INCOMPLETE);
|
|
});
|
|
|
|
// A path containing a literal newline can inflate the parsed list past the
|
|
// true total (e.g. a filename that itself looks like another path once
|
|
// split on newlines) — the total is the authority in both directions.
|
|
test('a list longer than its authoritative total fails closed', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #1',
|
|
changedFiles: ['tests/a.test.cjs', 'tests/b.test.cjs', 'tests/c.test.cjs'],
|
|
changedFilesTotal: 2,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_FILE_LIST_INCOMPLETE);
|
|
});
|
|
|
|
// 21. An empty changedFiles list cannot confirm anything.
|
|
test('empty changedFiles fails FAIL_FILE_LIST_INCOMPLETE', () => {
|
|
const result = evaluateIssueLink(forkPr({ prBody: 'Refs #1', changedFiles: [], changedFilesTotal: 0 }));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_FILE_LIST_INCOMPLETE);
|
|
});
|
|
});
|
|
|
|
describe('fileListIsComplete', () => {
|
|
// 22. Direct table of (changedFiles, changedFilesTotal) -> expected.
|
|
test('boundary table', () => {
|
|
const cases = [
|
|
[['a', 'b', 'c'], 3, true],
|
|
[['a', 'b', 'c'], undefined, true],
|
|
[testPaths(100), 100, true],
|
|
[testPaths(100), 101, false],
|
|
[testPaths(100), undefined, false],
|
|
[[], 0, false],
|
|
[undefined, 0, false],
|
|
[testPaths(3), 5, false],
|
|
[testPaths(5), 3, false],
|
|
[testPaths(3), 3, true],
|
|
[testPaths(3), undefined, true],
|
|
];
|
|
for (const [changedFiles, changedFilesTotal, expected] of cases) {
|
|
assert.strictEqual(
|
|
fileListIsComplete(changedFiles, changedFilesTotal),
|
|
expected,
|
|
`changedFiles.length=${Array.isArray(changedFiles) ? changedFiles.length : changedFiles}, total=${changedFilesTotal}`,
|
|
);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('hasFollowUpReference', () => {
|
|
// 23. Direct spot checks on the raw predicate.
|
|
test('rejects a closing keyword, accepts a reference', () => {
|
|
assert.strictEqual(hasFollowUpReference('Closes #1'), false);
|
|
assert.strictEqual(hasFollowUpReference('Refs #1'), true);
|
|
});
|
|
});
|
|
|
|
describe('allPathsAreTestsOrDocs', () => {
|
|
// 24. Direct spot checks on the raw predicate.
|
|
test('true for tests/docs mix, false for a non-exempt path, false for empty', () => {
|
|
assert.strictEqual(allPathsAreTestsOrDocs(['tests/a.cjs', 'docs/b.md']), true);
|
|
assert.strictEqual(allPathsAreTestsOrDocs(['tests/a.cjs', '.github/workflows/x.yml']), false);
|
|
assert.strictEqual(allPathsAreTestsOrDocs([]), false);
|
|
});
|
|
|
|
// 25. Root-level markdown is a third accepted shape; CHANGELOG.md is
|
|
// excluded from it even though it is root-level markdown.
|
|
test('root-level markdown is accepted, CHANGELOG.md and subdirectory markdown are not', () => {
|
|
assert.strictEqual(allPathsAreTestsOrDocs(['CONTRIBUTING.md']), true);
|
|
assert.strictEqual(allPathsAreTestsOrDocs(['CHANGELOG.md']), false);
|
|
assert.strictEqual(allPathsAreTestsOrDocs(['agents/x.md']), false);
|
|
assert.strictEqual(allPathsAreTestsOrDocs(['package.json']), false);
|
|
});
|
|
|
|
// The exclusion of CHANGELOG.md must not be defeatable by casing — the
|
|
// extension test (`/\.md$/i`) is already case-insensitive, so the
|
|
// exclusion lookup must match it rather than silently letting a
|
|
// differently-cased CHANGELOG.md ride in on the docs carve-out.
|
|
test('CHANGELOG.md exclusion is case-insensitive', () => {
|
|
assert.strictEqual(allPathsAreTestsOrDocs(['changelog.md']), false);
|
|
assert.strictEqual(allPathsAreTestsOrDocs(['CHANGELOG.MD']), false);
|
|
});
|
|
});
|
|
|
|
describe('require-issue-link policy — root-level documentation (#2290 shape)', () => {
|
|
// #2290 is the motivating PR the follow-up-reference exemption failed to
|
|
// cover: its diff is CONTRIBUTING.md (root-level markdown) plus a tests/
|
|
// file, and the old EXEMPT_PATH_PREFIXES-only predicate rejected it because
|
|
// CONTRIBUTING.md is neither tests/ nor docs/-prefixed.
|
|
test('the motivating PR #2290 shape qualifies', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #2269',
|
|
changedFiles: ['CONTRIBUTING.md', 'tests/commit-files-pathspec.test.cjs'],
|
|
changedFilesTotal: 2,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.OK_FOLLOWUP_REFERENCE);
|
|
});
|
|
|
|
test('a root-level README change qualifies', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #2269', changedFiles: ['README.md'], changedFilesTotal: 1,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.OK_FOLLOWUP_REFERENCE);
|
|
});
|
|
|
|
// scripts/changeset/lint.cjs classes a direct CHANGELOG.md edit as
|
|
// user-facing specifically to close a bypass — the docs carve-out here
|
|
// must not undo that by treating CHANGELOG.md as ordinary documentation.
|
|
test('a direct CHANGELOG.md edit does NOT qualify', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #2269', changedFiles: ['CHANGELOG.md'], changedFilesTotal: 1,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_REFERENCE_NEEDS_CLOSING);
|
|
});
|
|
|
|
test('CHANGELOG.md alongside real docs still disqualifies', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #2269', changedFiles: ['docs/a.md', 'CHANGELOG.md'], changedFilesTotal: 2,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_REFERENCE_NEEDS_CLOSING);
|
|
});
|
|
|
|
// These are runtime-loaded text, deliberately gated by the same root-only
|
|
// anchor pre-pr-gate.sh uses — a subdirectory .md file is not root-level.
|
|
test('subdirectory markdown is not root-level documentation', () => {
|
|
const paths = ['gsd-core/workflows/next.md', 'agents/reviewer.md', 'commands/gsd/plan.md', 'src/notes.md'];
|
|
for (const p of paths) {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #2269', changedFiles: [p], changedFilesTotal: 1,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_REFERENCE_NEEDS_CLOSING, `path: ${p}`);
|
|
}
|
|
});
|
|
|
|
test('a root-level non-markdown file does not qualify', () => {
|
|
const result = evaluateIssueLink(forkPr({
|
|
prBody: 'Refs #2269', changedFiles: ['package.json'], changedFilesTotal: 1,
|
|
}));
|
|
assert.strictEqual(result.reason, ISSUE_LINK_REASON.FAIL_REFERENCE_NEEDS_CLOSING);
|
|
});
|
|
});
|
|
|
|
describe('require-issue-link policy — the workflow guidance matches the rule', () => {
|
|
// Parity assertion (CLAUDE.md "Generative Fix Divergence"): the sticky
|
|
// comment's guidance text is generated separately from the predicate it
|
|
// describes, and the two have already drifted once (the predicate widened
|
|
// to accept root-level markdown while the guidance kept saying "nothing
|
|
// outside tests/ and docs/"). Every expectation below is derived from the
|
|
// module's actual exports, never hardcoded, so a future widening of the
|
|
// predicate without a guidance update fails this test.
|
|
const workflowPath = path.join(__dirname, '..', '.github', 'workflows', 'require-issue-link.yml');
|
|
const workflowDoc = yaml.load(fs.readFileSync(workflowPath, 'utf8'));
|
|
const job = workflowDoc.jobs['check-issue-link'];
|
|
const steps = job.steps;
|
|
const lastStep = steps[steps.length - 1];
|
|
const script = lastStep.with.script;
|
|
|
|
// Non-vacuous guards: if these fail, the assertions below would otherwise
|
|
// silently pass against zero-length input.
|
|
test('the resolved script text and export lists are non-empty (guard)', () => {
|
|
assert.strictEqual(typeof script, 'string');
|
|
assert.ok(script.length > 200, `expected script.length > 200, got ${script.length}`);
|
|
assert.ok(EXEMPT_PATH_PREFIXES.length > 0, 'EXEMPT_PATH_PREFIXES must be non-empty');
|
|
assert.ok(EXCLUDED_ROOT_DOCS instanceof Set, 'EXCLUDED_ROOT_DOCS must be a Set');
|
|
assert.ok(EXCLUDED_ROOT_DOCS.size > 0, 'EXCLUDED_ROOT_DOCS must be non-empty');
|
|
});
|
|
|
|
test('guidance names every EXEMPT_PATH_PREFIXES entry verbatim', () => {
|
|
for (const prefix of EXEMPT_PATH_PREFIXES) {
|
|
assert.ok(script.includes(prefix), `guidance script missing prefix: ${prefix}`);
|
|
}
|
|
});
|
|
|
|
// isRootLevelDoc accepts root-level *.md — the guidance must say so; this
|
|
// is the exact shape that drifted before.
|
|
test('guidance mentions root-level markdown', () => {
|
|
assert.ok(script.includes('root-level'), 'guidance script missing "root-level"');
|
|
});
|
|
|
|
test('guidance names every EXCLUDED_ROOT_DOCS entry verbatim', () => {
|
|
for (const doc of EXCLUDED_ROOT_DOCS) {
|
|
assert.ok(script.includes(doc), `guidance script missing excluded doc: ${doc}`);
|
|
}
|
|
});
|
|
|
|
test('guidance mentions an accepted non-closing reference marker', () => {
|
|
assert.ok(script.includes('Refs #'), 'guidance script missing "Refs #"');
|
|
});
|
|
});
|