@feigi/fleet-ctl 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/.claude-plugin/plugin.json +9 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +18 -0
  4. package/agents/fleet-finisher.agent.md +7 -0
  5. package/agents/fleet-implementer-alt.agent.md +210 -0
  6. package/agents/fleet-implementer.agent.md +210 -0
  7. package/agents/fleet-merge-bot.agent.md +7 -0
  8. package/agents/fleet-review-comments.agent.md +40 -0
  9. package/agents/fleet-review-correctness.agent.md +43 -0
  10. package/agents/fleet-review-runner.agent.md +73 -0
  11. package/agents/fleet-review-silent-failure.agent.md +49 -0
  12. package/agents/fleet-review-simplify.agent.md +46 -0
  13. package/agents/fleet-review-snapshot.agent.md +24 -0
  14. package/agents/fleet-review-tests.agent.md +46 -0
  15. package/agents/fleet-review-types.agent.md +41 -0
  16. package/agents/fleet-review-verifier.agent.md +29 -0
  17. package/commands/review-and-fix.md +98 -0
  18. package/commands/run-merge-bot.md +357 -0
  19. package/commands/run-team-help.md +17 -0
  20. package/package.json +23 -0
  21. package/scripts/agent-test-dir-prose.test.mjs +59 -0
  22. package/scripts/agent-test.test.mjs +1636 -0
  23. package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
  24. package/scripts/ambient-git-vars-prose.test.mjs +192 -0
  25. package/scripts/ancestry-check-position-prose.test.mjs +175 -0
  26. package/scripts/apply-ruleset.test.mjs +420 -0
  27. package/scripts/arg-header-probes-prose.test.mjs +393 -0
  28. package/scripts/arg.mjs +600 -0
  29. package/scripts/arg.test.mjs +1354 -0
  30. package/scripts/board-cli.test.mjs +694 -0
  31. package/scripts/board-identity.test.mjs +429 -0
  32. package/scripts/board-liveness-banner.test.mjs +119 -0
  33. package/scripts/board-prev-shape.test.mjs +229 -0
  34. package/scripts/board-tryparse-null.test.mjs +119 -0
  35. package/scripts/board.html +471 -0
  36. package/scripts/board.mjs +2037 -0
  37. package/scripts/board.test.mjs +3086 -0
  38. package/scripts/brief-after-cut-prose.test.mjs +53 -0
  39. package/scripts/candidates-exit3-prose.test.mjs +302 -0
  40. package/scripts/candidates.mjs +674 -0
  41. package/scripts/candidates.test.mjs +2101 -0
  42. package/scripts/caveat-unification-prose.test.mjs +98 -0
  43. package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
  44. package/scripts/ci-completes-premise-prose.test.mjs +257 -0
  45. package/scripts/ci-state-prose.test.mjs +113 -0
  46. package/scripts/ci-state.mjs +761 -0
  47. package/scripts/ci-state.test.mjs +1640 -0
  48. package/scripts/ci-vacuous-green.test.mjs +368 -0
  49. package/scripts/citation-sweep-prose.test.mjs +1572 -0
  50. package/scripts/claim-lifecycle.test.mjs +185 -0
  51. package/scripts/claim-ticket.sh +417 -0
  52. package/scripts/claim-ticket.test.mjs +1121 -0
  53. package/scripts/closing-keyword-prose.test.mjs +193 -0
  54. package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
  55. package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
  56. package/scripts/compute-board.mjs +579 -0
  57. package/scripts/compute-board.test.mjs +1060 -0
  58. package/scripts/compute-spend.mjs +329 -0
  59. package/scripts/compute-spend.test.mjs +451 -0
  60. package/scripts/cross-repo-citation-prose.test.mjs +156 -0
  61. package/scripts/cwd-isolation-pins.mjs +83 -0
  62. package/scripts/dedupe-guard-prose.test.mjs +243 -0
  63. package/scripts/derive-testcmd.sh +239 -0
  64. package/scripts/derive-testcmd.test.mjs +380 -0
  65. package/scripts/diff-stats.mjs +231 -0
  66. package/scripts/diff-stats.test.mjs +408 -0
  67. package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
  68. package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
  69. package/scripts/drop-merged-label.sh +173 -0
  70. package/scripts/drop-merged-label.test.mjs +480 -0
  71. package/scripts/expected-jobs-prose.test.mjs +80 -0
  72. package/scripts/filing-bar-seat-prose.test.mjs +242 -0
  73. package/scripts/filing-claim-bar-prose.test.mjs +166 -0
  74. package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
  75. package/scripts/finisher-halt-prose.test.mjs +106 -0
  76. package/scripts/finisher-name-prose.test.mjs +134 -0
  77. package/scripts/finisher-own-tree-prose.test.mjs +285 -0
  78. package/scripts/finisher-pin-race-prose.test.mjs +339 -0
  79. package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
  80. package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
  81. package/scripts/fleet-bootstrap +155 -0
  82. package/scripts/fleet-heartbeat.mjs +272 -0
  83. package/scripts/fleet-heartbeat.test.mjs +450 -0
  84. package/scripts/fleet-provenance +207 -0
  85. package/scripts/fleet-provenance.test.mjs +64 -0
  86. package/scripts/fleet-run +148 -0
  87. package/scripts/fleet-run.test.mjs +90 -0
  88. package/scripts/fleet-state.mjs +400 -0
  89. package/scripts/fleet-state.test.mjs +373 -0
  90. package/scripts/fleet-tick-prose.test.mjs +299 -0
  91. package/scripts/fleet-tick.mjs +832 -0
  92. package/scripts/fleet-tick.test.mjs +1332 -0
  93. package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
  94. package/scripts/frontmatter-allowlist.json +64 -0
  95. package/scripts/frontmatter-check.mjs +256 -0
  96. package/scripts/frontmatter-check.test.mjs +436 -0
  97. package/scripts/git-env.mjs +124 -0
  98. package/scripts/git-env.test.mjs +149 -0
  99. package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
  100. package/scripts/gone-walk.test.mjs +213 -0
  101. package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
  102. package/scripts/head-moved-after-label-prose.test.mjs +233 -0
  103. package/scripts/immutable-body-claim-prose.test.mjs +413 -0
  104. package/scripts/implementer-model-tier.test.mjs +643 -0
  105. package/scripts/inflight-citation-prose.test.mjs +144 -0
  106. package/scripts/inflight-exit2-prose.test.mjs +81 -0
  107. package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
  108. package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
  109. package/scripts/inflight.sh +1106 -0
  110. package/scripts/inflight.test.mjs +2984 -0
  111. package/scripts/injection-control-prose.test.mjs +404 -0
  112. package/scripts/install-root-audit.test.mjs +464 -0
  113. package/scripts/instrument-check-prose.test.mjs +235 -0
  114. package/scripts/instruments.sh +394 -0
  115. package/scripts/instruments.test.mjs +787 -0
  116. package/scripts/issue-tracker-prose.test.mjs +71 -0
  117. package/scripts/json.sh +248 -0
  118. package/scripts/json.test.mjs +364 -0
  119. package/scripts/ledger-dispatch.test.mjs +516 -0
  120. package/scripts/ledger-grammar.mjs +85 -0
  121. package/scripts/ledger-grammar.test.mjs +142 -0
  122. package/scripts/ledger-read-require-file.test.mjs +197 -0
  123. package/scripts/ledger.mjs +1753 -0
  124. package/scripts/ledger.test.mjs +3554 -0
  125. package/scripts/line-distance-prose.test.mjs +245 -0
  126. package/scripts/liveness-rationale-prose.test.mjs +83 -0
  127. package/scripts/locale-pin-prose.test.mjs +189 -0
  128. package/scripts/member-outcome-prose.test.mjs +167 -0
  129. package/scripts/member-outcomes-header.test.mjs +148 -0
  130. package/scripts/member-outcomes-prose.test.mjs +63 -0
  131. package/scripts/member-outcomes.mjs +231 -0
  132. package/scripts/member-outcomes.test.mjs +507 -0
  133. package/scripts/member-prompt-prose.test.mjs +161 -0
  134. package/scripts/member-record.mjs +605 -0
  135. package/scripts/member-record.test.mjs +516 -0
  136. package/scripts/member-write-guard.mjs +279 -0
  137. package/scripts/member-write-guard.test.mjs +211 -0
  138. package/scripts/merge-commit-probe-prose.test.mjs +122 -0
  139. package/scripts/merge-gate.mjs +262 -0
  140. package/scripts/merge-gate.test.mjs +613 -0
  141. package/scripts/muted-git-guard-sweep.test.mjs +493 -0
  142. package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
  143. package/scripts/net-watchdog-prose.test.mjs +79 -0
  144. package/scripts/net.sh +409 -0
  145. package/scripts/net.test.mjs +211 -0
  146. package/scripts/no-ci-gate-prose.test.mjs +108 -0
  147. package/scripts/no-undo-audit.sh +1134 -0
  148. package/scripts/no-undo-audit.test.mjs +3965 -0
  149. package/scripts/no-wave.test.mjs +138 -0
  150. package/scripts/node-floor-sweep.test.mjs +611 -0
  151. package/scripts/pointer-target-prose.test.mjs +186 -0
  152. package/scripts/pr-overlap.mjs +417 -0
  153. package/scripts/pr-overlap.test.mjs +695 -0
  154. package/scripts/printf-die-sweep.test.mjs +384 -0
  155. package/scripts/prompt-renderer.mjs +39 -0
  156. package/scripts/prompt-renderer.test.mjs +68 -0
  157. package/scripts/prose-pin.mjs +808 -0
  158. package/scripts/prose-pin.test.mjs +1034 -0
  159. package/scripts/prove-merge.sh +228 -0
  160. package/scripts/prove-merge.test.mjs +995 -0
  161. package/scripts/pull-table-relabel-prose.test.mjs +60 -0
  162. package/scripts/quiet-payload-prose.test.mjs +222 -0
  163. package/scripts/reap.sh +1768 -0
  164. package/scripts/reap.test.mjs +4395 -0
  165. package/scripts/reaping-prose.test.mjs +159 -0
  166. package/scripts/refuter-scratch-prose.test.mjs +135 -0
  167. package/scripts/release-label-required-prose.test.mjs +71 -0
  168. package/scripts/release-label-split-prose.test.mjs +169 -0
  169. package/scripts/release-ticket.sh +1716 -0
  170. package/scripts/release-ticket.test.mjs +5106 -0
  171. package/scripts/renovate-release-contract.test.mjs +379 -0
  172. package/scripts/repo-root.mjs +544 -0
  173. package/scripts/repo-root.test.mjs +873 -0
  174. package/scripts/reporter-output-rule-prose.test.mjs +208 -0
  175. package/scripts/review-agent-report-only.test.mjs +49 -0
  176. package/scripts/review-core-cwd-isolation.test.mjs +374 -0
  177. package/scripts/review-core-reads.test.mjs +478 -0
  178. package/scripts/review-core-refuter-scratch.test.mjs +148 -0
  179. package/scripts/review-core-snapshot-path.test.mjs +777 -0
  180. package/scripts/review-core-specialist-scratch.test.mjs +189 -0
  181. package/scripts/review-core-testcmd.test.mjs +288 -0
  182. package/scripts/review-core-unrun.test.mjs +530 -0
  183. package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
  184. package/scripts/review-core.mjs +1028 -0
  185. package/scripts/review-eval-resolver-path.test.mjs +55 -0
  186. package/scripts/review-eval.mjs +197 -0
  187. package/scripts/review-host-fixture.mjs +73 -0
  188. package/scripts/review-in-run-retry.test.mjs +187 -0
  189. package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
  190. package/scripts/review-path-default.test.mjs +796 -0
  191. package/scripts/review-runner-spawns.test.mjs +93 -0
  192. package/scripts/review-runner.test.mjs +155 -0
  193. package/scripts/review-tier-audit.test.mjs +140 -0
  194. package/scripts/run-artifact-pr-prose.test.mjs +341 -0
  195. package/scripts/run-merge-bot-prose.test.mjs +1391 -0
  196. package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
  197. package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
  198. package/scripts/section-between-guard-prose.test.mjs +378 -0
  199. package/scripts/select-dimensions.test.mjs +674 -0
  200. package/scripts/shared-refusal.test.mjs +388 -0
  201. package/scripts/shell-traps-prose.test.mjs +507 -0
  202. package/scripts/shortlist.mjs +355 -0
  203. package/scripts/shortlist.test.mjs +366 -0
  204. package/scripts/slow-transport.mjs +72 -0
  205. package/scripts/snapshot-repo.test.mjs +772 -0
  206. package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
  207. package/scripts/spend-view.test.mjs +312 -0
  208. package/scripts/staleness-qualifier-prose.test.mjs +251 -0
  209. package/scripts/staleness-verdict-prose.test.mjs +142 -0
  210. package/scripts/staleness.mjs +414 -0
  211. package/scripts/staleness.test.mjs +893 -0
  212. package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
  213. package/scripts/stash-prohibition-prose.test.mjs +313 -0
  214. package/scripts/strip-comments.mjs +44 -0
  215. package/scripts/tier-check.mjs +468 -0
  216. package/scripts/tier-check.test.mjs +726 -0
  217. package/scripts/tier-guard-gate-prose.test.mjs +216 -0
  218. package/scripts/tier-outcomes-header.test.mjs +586 -0
  219. package/scripts/tier-outcomes.mjs +441 -0
  220. package/scripts/tier-outcomes.test.mjs +342 -0
  221. package/scripts/tier-roles.mjs +250 -0
  222. package/scripts/tier-roles.test.mjs +316 -0
  223. package/scripts/tracker-block-copy-prose.test.mjs +288 -0
  224. package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
  225. package/scripts/unattended-git-sweep.test.mjs +142 -0
  226. package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
  227. package/scripts/verify-sha.sh +117 -0
  228. package/scripts/verify-sha.test.mjs +693 -0
  229. package/scripts/watcher-degraded-block.test.mjs +372 -0
  230. package/scripts/watcher-key-prose.test.mjs +106 -0
  231. package/scripts/within-run-pair-prose.test.mjs +208 -0
  232. package/scripts/worktree-audit.sh +482 -0
  233. package/scripts/worktree-audit.test.mjs +1407 -0
  234. package/scripts/worktree-head-prose.test.mjs +276 -0
  235. package/scripts/worktree-listing-sweep.test.mjs +217 -0
  236. package/scripts/worktree-model-prose.test.mjs +216 -0
  237. package/scripts/worktree.sh +470 -0
  238. package/skills/next-ticket/SKILL.md +138 -0
  239. package/skills/run-team/SKILL.md +3603 -0
  240. package/skills/run-team/references/ci-and-staleness.md +75 -0
  241. package/skills/run-team/references/correction-tickets.md +37 -0
  242. package/skills/run-team/references/isolation.md +23 -0
  243. package/skills/run-team/references/member-lifecycle.md +73 -0
  244. package/skills/run-team/references/reaping.md +73 -0
  245. package/skills/sizing-a-ticket/SKILL.md +39 -0
@@ -0,0 +1,695 @@
1
+ // Regression gate for #169: a flag given with no value must die, by name,
2
+ // rather than being read as absent or silently consumed as the following
3
+ // flag's own value.
4
+ //
5
+ // `--a`/`--b` given trailing were already caught by pr-overlap.mjs's own
6
+ // `if (!a || !b) die(...)` guard — `undefined` is falsy — so it was never a
7
+ // silent-widening site the way ci-state.mjs's `--base`/`--workflow` were (see
8
+ // feigi's PR #167 review comment). What was NOT caught: `--a` given `--b` as
9
+ // its "value" (`pr-overlap.mjs --a --b 5`) — `a` becomes the string "--b",
10
+ // passes the falsy check, and only failed later as a confusing `gh pr diff
11
+ // --b` error instead of a clear refusal naming the flag.
12
+ import { test } from "node:test";
13
+ import assert from "node:assert/strict";
14
+ import { spawnSync, execFileSync } from "node:child_process";
15
+ import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, chmodSync, rmSync } from "node:fs";
16
+ import { tmpdir } from "node:os";
17
+ import { join, dirname } from "node:path";
18
+ import { fileURLToPath } from "node:url";
19
+
20
+ const SCRIPT = fileURLToPath(new URL("./pr-overlap.mjs", import.meta.url));
21
+
22
+ test("CLI: trailing --a (no value) dies (exit 2) naming the flag", () => {
23
+ const r = spawnSync(process.execPath, [SCRIPT, "--a"], { encoding: "utf8" });
24
+ assert.equal(r.status, 2);
25
+ assert.match(r.stderr, /--a needs a value/);
26
+ });
27
+
28
+ test("CLI: --a followed by --b is rejected by name, not run through gh as a PR ref", () => {
29
+ const r = spawnSync(process.execPath, [SCRIPT, "--a", "--b", "5"], { encoding: "utf8" });
30
+ assert.equal(r.status, 2);
31
+ assert.match(r.stderr, /--a needs a value/);
32
+ });
33
+
34
+ test("CLI: --a=5 form dies by name, not silently read as absent", () => {
35
+ const r = spawnSync(process.execPath, [SCRIPT, "--a=5", "--b", "6"], { encoding: "utf8" });
36
+ assert.equal(r.status, 2);
37
+ assert.match(r.stderr, /--a needs a space-separated value/);
38
+ });
39
+
40
+ // `value.trim() === ""` was the one clause of the guard no test reached in any
41
+ // of the five scripts that then carried their own copy of it — board,
42
+ // candidates, ci-state, diff-stats, pr-overlap — so it could be deleted from
43
+ // all five at once, green. #367 has since folded those copies into arg.mjs's
44
+ // single one, which every one of the five still routes through.
45
+ test("CLI: --a given a whitespace-only value dies naming the flag", () => {
46
+ const r = spawnSync(process.execPath, [SCRIPT, "--a", " ", "--b", "6"], { encoding: "utf8" });
47
+ assert.equal(r.status, 2);
48
+ assert.match(r.stderr, /--a needs a value/);
49
+ });
50
+
51
+ // The other half of arg()'s guard: every case above is a value it must
52
+ // REFUSE. Nothing above ever hands the script a well-formed pair, so #367's
53
+ // shared arg() could return `undefined` for every accepted input and this
54
+ // file would stay green. `--a 1 --b 2` must reach gh and report a verdict.
55
+ test("CLI: well-formed --a/--b values are accepted and the CLI reports a verdict", () => {
56
+ const bin = mkdtempSync(join(tmpdir(), "pr-overlap-bin-"));
57
+ const gh = join(bin, "gh");
58
+ const log = join(bin, "calls");
59
+ // `$3` is the PR number pr-overlap.mjs passes as `gh pr diff <pr> --name-only`.
60
+ writeFileSync(
61
+ gh,
62
+ `#!/bin/sh\nprintf '%s\\n' "$*" >> ${log}\ncase "$3" in\n 1) echo src/shared.ts ;;\n 2) echo src/shared.ts ;;\nesac\n`,
63
+ );
64
+ chmodSync(gh, 0o755);
65
+ const r = spawnSync(process.execPath, [SCRIPT, "--a", "1", "--b", "2"], {
66
+ encoding: "utf8",
67
+ env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
68
+ });
69
+ const calls = readFileSync(log, "utf8").trim().split("\n");
70
+ rmSync(bin, { recursive: true, force: true });
71
+ assert.equal(r.status, 0, r.stdout + r.stderr);
72
+ const payload = JSON.parse(r.stdout);
73
+ assert.deepEqual(payload, {
74
+ a: 1,
75
+ b: 2,
76
+ files: ["src/shared.ts"],
77
+ modules: ["shared"],
78
+ dirs: ["src"],
79
+ prose: [],
80
+ proseUnrun: null,
81
+ signal: "files",
82
+ });
83
+ // #705's signal costs nothing on a pair with no data file on either side,
84
+ // which is nearly every pair. An unconditional full-diff read would double
85
+ // this tool's `gh` traffic and hand its ENOBUFS cliff to every caller, so
86
+ // the two `--name-only` calls are the whole bill here.
87
+ assert.deepEqual(calls, ["pr diff 1 --name-only", "pr diff 2 --name-only"]);
88
+ });
89
+
90
+ // ---------------------------------------------------------------------------
91
+ // #705: the prose-citation signal.
92
+ //
93
+ // A fixture is one throwaway directory holding a fake `gh` on PATH, a
94
+ // `<pr>.names` and `<pr>.diff` per PR, and a real git repo the script runs
95
+ // inside — the last one because the basename-ambiguity guard counts with
96
+ // `git ls-files`, so a test that cannot control the tree cannot reach the
97
+ // branch where a basename is dropped. An ABSENT `<pr>.diff` makes the fake
98
+ // `gh` exit non-zero, which is how the degradation case below is driven.
99
+ function fixture({ prs, tracked = [] }) {
100
+ const root = mkdtempSync(join(tmpdir(), "pr-overlap-prose-"));
101
+ const bin = join(root, "bin");
102
+ const data = join(root, "data");
103
+ const repo = join(root, "repo");
104
+ for (const d of [bin, data, repo]) mkdirSync(d);
105
+ for (const [pr, { names, diff }] of Object.entries(prs)) {
106
+ writeFileSync(join(data, `${pr}.names`), `${names.join("\n")}\n`);
107
+ if (diff !== undefined) writeFileSync(join(data, `${pr}.diff`), diff);
108
+ }
109
+ const gh = join(bin, "gh");
110
+ writeFileSync(
111
+ gh,
112
+ "#!/bin/sh\n" +
113
+ `case "$4" in\n` +
114
+ ` --name-only) cat ${data}/"$3".names ;;\n` +
115
+ ` *) cat ${data}/"$3".diff ;;\n` +
116
+ "esac\n",
117
+ );
118
+ chmodSync(gh, 0o755);
119
+ execFileSync("git", ["init", "-q"], { cwd: repo });
120
+ for (const f of tracked) {
121
+ mkdirSync(join(repo, dirname(f)), { recursive: true });
122
+ writeFileSync(join(repo, f), "x\n");
123
+ }
124
+ if (tracked.length) execFileSync("git", ["add", "--", ...tracked], { cwd: repo });
125
+ return { root, bin, repo };
126
+ }
127
+
128
+ function run({ prs, tracked }, a, b) {
129
+ const fx = fixture({ prs, tracked });
130
+ const r = spawnSync(process.execPath, [SCRIPT, "--a", String(a), "--b", String(b)], {
131
+ encoding: "utf8",
132
+ cwd: fx.repo,
133
+ env: { ...process.env, PATH: `${fx.bin}:${process.env.PATH}` },
134
+ });
135
+ rmSync(fx.root, { recursive: true, force: true });
136
+ return r;
137
+ }
138
+
139
+ // A unified diff body for one file. Only hunk lines matter to the scan; the
140
+ // `+++`/`---` headers are present because they are what the parser has to
141
+ // skip — they carry the path itself, so a parser that reads them finds every
142
+ // data file "cited" by the PR that changed it.
143
+ const hunk = (file, lines) =>
144
+ `diff --git a/${file} b/${file}\nindex 1111111..2222222 100644\n--- a/${file}\n+++ b/${file}\n@@ -1,3 +1,3 @@\n${lines.map((l) => l + "\n").join("")}`;
145
+
146
+ const TSV = "docs/metrics/tier-outcomes.tsv";
147
+
148
+ // The defect itself. #704 appended rows to the TSV, #703 held the prose that
149
+ // reads it, and the two share no path, no module and no directory — so the
150
+ // three original signals answered `none`, which is the strongest clear this
151
+ // tool has and the one that licenses a merge.
152
+ test("prose: a data file named in the other PR's diff fires signal=prose", () => {
153
+ const r = run(
154
+ {
155
+ prs: {
156
+ 1: { names: [TSV], diff: hunk(TSV, ["+1490\timpl-1490\tclass=routine"]) },
157
+ 2: {
158
+ names: ["plugin/skills/run-team/SKILL.md"],
159
+ diff: hunk("plugin/skills/run-team/SKILL.md", [
160
+ " **Recount before citing any of this.**",
161
+ `+grep -vc '^#' ${TSV}`,
162
+ ]),
163
+ },
164
+ },
165
+ },
166
+ 1,
167
+ 2,
168
+ );
169
+ assert.equal(r.status, 0, r.stdout + r.stderr);
170
+ const payload = JSON.parse(r.stdout);
171
+ assert.equal(payload.signal, "prose");
172
+ assert.deepEqual(payload.files, []);
173
+ assert.deepEqual(payload.dirs, []);
174
+ assert.equal(payload.proseUnrun, null);
175
+ assert.deepEqual(payload.prose, [
176
+ { data: TSV, citedBy: "plugin/skills/run-team/SKILL.md", token: TSV, line: `+grep -vc '^#' ${TSV}` },
177
+ ]);
178
+ // The witness is the whole value of a weak signal: one read disproves it.
179
+ assert.match(r.stderr, /cited by plugin\/skills\/run-team\/SKILL\.md/);
180
+ });
181
+
182
+ // Every citing file gets its own witness, and each one gets its OWN most
183
+ // specific token. A loop that stopped at the first token matching ANYWHERE
184
+ // reports one file and drops the rest — and the set of citing files is
185
+ // exactly what the caller has to go read to disprove the hold.
186
+ test("prose: each citing file reports its own witness, path token preferred", () => {
187
+ const r = run(
188
+ {
189
+ prs: {
190
+ 1: { names: [TSV], diff: hunk(TSV, ["+1490\timpl-1490"]) },
191
+ 2: {
192
+ names: ["plugin/skills/run-team/SKILL.md", "plugin/commands/run-merge-bot.md"],
193
+ diff:
194
+ hunk("plugin/skills/run-team/SKILL.md", [`+recount off ${TSV} and also tier-outcomes.tsv`]) +
195
+ hunk("plugin/commands/run-merge-bot.md", ["+the append lands in tier-outcomes.tsv"]),
196
+ },
197
+ },
198
+ },
199
+ 1,
200
+ 2,
201
+ );
202
+ assert.equal(r.status, 0, r.stdout + r.stderr);
203
+ const payload = JSON.parse(r.stdout);
204
+ assert.deepEqual(
205
+ payload.prose.map((h) => [h.citedBy, h.token]),
206
+ [
207
+ // Names it both ways -> reported once, by path.
208
+ ["plugin/commands/run-merge-bot.md", "tier-outcomes.tsv"],
209
+ ["plugin/skills/run-team/SKILL.md", TSV],
210
+ ],
211
+ );
212
+ });
213
+
214
+ // The citer side is an explicit extension list, and the stderr note prints it
215
+ // as the scan's scope — so it is an advertised bound and has to hold. Here a
216
+ // DATA file's own hunks name another data file: `member-outcomes.tsv`'s header
217
+ // really does cite `tier-outcomes.tsv` in this repo, and a run-artifact PR
218
+ // really does edit both. Widen the citer side to every changed file and this
219
+ // fires on every such pair.
220
+ //
221
+ // Nothing is lost by refusing it, which is what makes the bound defensible
222
+ // rather than merely narrow: both files live under `docs/metrics/`, so `dirs`
223
+ // already reports that pair — at exactly the weak strength it deserves. The
224
+ // assertion below is that the case is covered THERE, not that it is ignored.
225
+ test("prose: a data file's own hunks are not a citation site, and dirs still covers the pair", () => {
226
+ const OTHER = "docs/metrics/member-outcomes.tsv";
227
+ const cite = `+# verdicts live in ${TSV}, joined on pr`;
228
+ const r = run(
229
+ {
230
+ prs: {
231
+ 1: { names: [TSV], diff: hunk(TSV, ["+1490\timpl-1490"]) },
232
+ 2: { names: [OTHER], diff: hunk(OTHER, [cite]) },
233
+ },
234
+ },
235
+ 1,
236
+ 2,
237
+ );
238
+ assert.equal(r.status, 0, r.stdout + r.stderr);
239
+ const payload = JSON.parse(r.stdout);
240
+ assert.deepEqual(payload.prose, []);
241
+ assert.deepEqual(payload.dirs, ["docs/metrics"]);
242
+ assert.equal(payload.signal, "dirs");
243
+
244
+ // Positive control on the identical citation: move it into a `.md` and the
245
+ // signal fires. Without this, a partition that dropped the data file from
246
+ // the TARGET side too would pass above for the wrong reason.
247
+ const inProse = {
248
+ prs: {
249
+ 1: { names: [TSV], diff: hunk(TSV, ["+1490\timpl-1490"]) },
250
+ 2: { names: ["docs/metrics/README.md"], diff: hunk("docs/metrics/README.md", [cite]) },
251
+ },
252
+ };
253
+ const second = JSON.parse(run(inProse, 1, 2).stdout);
254
+ assert.deepEqual(second.prose.map((h) => h.citedBy), ["docs/metrics/README.md"]);
255
+ });
256
+
257
+ // Which PR holds the rows and which holds the prose is not knowable from the
258
+ // flags, so both directions are scanned. A one-directional wiring passes the
259
+ // test above and misses half the pairs.
260
+ test("prose: fires when the data file is on --b and the prose on --a", () => {
261
+ const r = run(
262
+ {
263
+ prs: {
264
+ 1: {
265
+ names: ["plugin/commands/run-merge-bot.md"],
266
+ diff: hunk("plugin/commands/run-merge-bot.md", [`+read ${TSV} before ruling`]),
267
+ },
268
+ 2: { names: [TSV], diff: hunk(TSV, ["+1490\timpl-1490"]) },
269
+ },
270
+ },
271
+ 1,
272
+ 2,
273
+ );
274
+ assert.equal(r.status, 0, r.stdout + r.stderr);
275
+ const payload = JSON.parse(r.stdout);
276
+ assert.equal(payload.signal, "prose");
277
+ assert.deepEqual(payload.prose.map((h) => h.citedBy), ["plugin/commands/run-merge-bot.md"]);
278
+ });
279
+
280
+ // A diff's `+++`/`--- ` lines carry the path and begin with the same
281
+ // characters a hunk line does, so a scan that reads them attributes a
282
+ // citation to the patch's own plumbing. Reachable whenever a text file's path
283
+ // CONTAINS a data file's — `docs/x.json.md` documenting `a/x.json` is the
284
+ // ordinary spelling of that — and the witness it produces is a diff header,
285
+ // which is the confident nonsense `moduleOf` above refuses to emit.
286
+ test("prose: a diff's own file headers are not read as citations", () => {
287
+ const r = run(
288
+ {
289
+ prs: {
290
+ 1: { names: ["a/x.json"], diff: hunk("a/x.json", ['+{"x":1}']) },
291
+ 2: {
292
+ names: ["docs/x.json.md"],
293
+ diff: hunk("docs/x.json.md", ["+unrelated prose that names no file"]),
294
+ },
295
+ },
296
+ tracked: ["a/x.json", "docs/x.json.md"],
297
+ },
298
+ 1,
299
+ 2,
300
+ );
301
+ assert.equal(r.status, 0, r.stdout + r.stderr);
302
+ const payload = JSON.parse(r.stdout);
303
+ assert.deepEqual(payload.prose, []);
304
+ assert.equal(payload.signal, "none");
305
+ });
306
+
307
+ // The other half, and the one that decides whether this signal is usable:
308
+ // #703 DID touch `run-team/SKILL.md`, the very file whose tier-guard
309
+ // paragraph reads the TSV, and was still correctly unrelated — its hunks
310
+ // never reach that paragraph. A whole-FILE read fires here, permanently,
311
+ // because SKILL.md names the TSV in nine places; reading the DIFF is what
312
+ // reproduces merge-bot-9's hand-run clearing grep. Re-measured live on
313
+ // #703 vs #704: `signal=none prose=0`, `proseUnrun: null`.
314
+ test("prose: a citing file edited AWAY from its citation does not fire", () => {
315
+ const r = run(
316
+ {
317
+ prs: {
318
+ 1: { names: [TSV], diff: hunk(TSV, ["+1490\timpl-1490"]) },
319
+ 2: {
320
+ names: ["plugin/skills/run-team/SKILL.md"],
321
+ diff: hunk("plugin/skills/run-team/SKILL.md", [
322
+ " Its four duties are a checklist — audit the worktree,",
323
+ "+report, and the merge gate downstream still catches it.",
324
+ ]),
325
+ },
326
+ },
327
+ },
328
+ 1,
329
+ 2,
330
+ );
331
+ assert.equal(r.status, 0, r.stdout + r.stderr);
332
+ const payload = JSON.parse(r.stdout);
333
+ assert.equal(payload.signal, "none");
334
+ assert.deepEqual(payload.prose, []);
335
+ // An empty result is only a clear when the scan actually covered the diff.
336
+ assert.equal(payload.proseUnrun, null);
337
+ });
338
+
339
+ // A bare stem with no extension is a word, not a reference. Every one of
340
+ // run-team/SKILL.md's nine references to this file is written with the
341
+ // extension — `docs/metrics/tier-outcomes.tsv` ×7, `tier-outcomes.tsv` ×2
342
+ // (measured) — so matching the stem buys no coverage and is where the false
343
+ // positives the ticket warned about would come from.
344
+ test("prose: a bare stem with no extension is never matched", () => {
345
+ const r = run(
346
+ {
347
+ prs: {
348
+ 1: { names: [TSV], diff: hunk(TSV, ["+1490\timpl-1490"]) },
349
+ 2: {
350
+ names: ["docs/notes.md"],
351
+ diff: hunk("docs/notes.md", ["+the tier-outcomes corpus is confounded with calendar date"]),
352
+ },
353
+ },
354
+ },
355
+ 1,
356
+ 2,
357
+ );
358
+ assert.equal(r.status, 0, r.stdout + r.stderr);
359
+ assert.deepEqual(JSON.parse(r.stdout).prose, []);
360
+ });
361
+
362
+ // `moduleOf`'s measurement, one file type over: a shared basename is not a
363
+ // shared file. Two `config.json` in unrelated subtrees, and the citing PR
364
+ // names the OTHER one — the full paths differ, so the only thing that could
365
+ // fire is the basename, and the tree says that basename is ambiguous.
366
+ // Derived from `git ls-files` rather than a deny-list, so it needs no
367
+ // upkeep; delete the count and this reds.
368
+ test("prose: an ambiguous basename is dropped, and the full path still decides", () => {
369
+ const tracked = ["a/config.json", "b/config.json"];
370
+ const base = {
371
+ prs: {
372
+ 1: { names: ["a/config.json"], diff: hunk("a/config.json", ['+{"x":1}']) },
373
+ 2: { names: ["docs/notes.md"], diff: hunk("docs/notes.md", ["+see b/config.json for the other one"]) },
374
+ },
375
+ tracked,
376
+ };
377
+ assert.deepEqual(JSON.parse(run(base, 1, 2).stdout).prose, []);
378
+
379
+ // Positive control for the same tree: the ambiguity guard drops basenames,
380
+ // never paths, so naming the changed file BY PATH still fires. Without
381
+ // this, a guard that dropped the data file entirely would pass above.
382
+ const byPath = {
383
+ ...base,
384
+ prs: {
385
+ ...base.prs,
386
+ 2: { names: ["docs/notes.md"], diff: hunk("docs/notes.md", ["+see a/config.json for the one that moved"]) },
387
+ },
388
+ };
389
+ const payload = JSON.parse(run(byPath, 1, 2).stdout);
390
+ assert.equal(payload.signal, "prose");
391
+ assert.deepEqual(payload.prose.map((h) => h.token), ["a/config.json"]);
392
+ });
393
+
394
+ // Ranked below `dirs` so it can only ever turn a `none` into something. A
395
+ // ladder that put it first would relabel every existing verdict, and the
396
+ // count on the summary line is what keeps the evidence visible underneath a
397
+ // stronger one.
398
+ test("prose: a prose hit never masks a stronger signal, and is still reported", () => {
399
+ const r = run(
400
+ {
401
+ prs: {
402
+ 1: { names: [TSV, "docs/notes.md"], diff: hunk(TSV, ["+1490\timpl-1490"]) },
403
+ 2: { names: ["docs/notes.md"], diff: hunk("docs/notes.md", [`+cites ${TSV} here`]) },
404
+ },
405
+ },
406
+ 1,
407
+ 2,
408
+ );
409
+ assert.equal(r.status, 0, r.stdout + r.stderr);
410
+ const payload = JSON.parse(r.stdout);
411
+ assert.equal(payload.signal, "files");
412
+ assert.deepEqual(payload.files, ["docs/notes.md"]);
413
+ assert.equal(payload.prose.length, 1);
414
+ assert.match(r.stderr, /prose=1/);
415
+ // The caveat block is keyed on the COUNT, not on `signal`: under a `files`
416
+ // verdict the ladder hides the stronger evidence, and the witness is what
417
+ // the caller disproves the pair with. Key it on `signal` and this reds.
418
+ assert.match(r.stderr, /prose citation/);
419
+ assert.match(r.stderr, new RegExp(`${TSV} cited by docs/notes\\.md`));
420
+ });
421
+
422
+ // Context lines are searched along with added and removed ones, deliberately:
423
+ // the hazard is prose being rewritten NEXT TO a citation, not only a citation
424
+ // being typed, and merge-bot-9's own clearing grep on #703 counted context
425
+ // too. A scan narrowed to `+`/`-` lines misses the whole rewrite-in-place
426
+ // case, which is the shape #705 describes — a paragraph edited underneath
427
+ // rows landing beneath it.
428
+ test("prose: a citation on a context line counts", () => {
429
+ const r = run(
430
+ {
431
+ prs: {
432
+ 1: { names: [TSV], diff: hunk(TSV, ["+1490\timpl-1490"]) },
433
+ 2: {
434
+ names: ["plugin/skills/run-team/SKILL.md"],
435
+ diff: hunk("plugin/skills/run-team/SKILL.md", [
436
+ ` grep -vc '^#' ${TSV}`,
437
+ "+recount before citing any of this",
438
+ ]),
439
+ },
440
+ },
441
+ },
442
+ 1,
443
+ 2,
444
+ );
445
+ assert.equal(r.status, 0, r.stdout + r.stderr);
446
+ const payload = JSON.parse(r.stdout);
447
+ assert.equal(payload.signal, "prose");
448
+ assert.deepEqual(payload.prose.map((h) => h.token), [TSV]);
449
+ });
450
+
451
+ // The degradation, and the reason it is a field rather than a `die()`. A
452
+ // run-artifact PR appends thousands of rows, so the full-patch read is the
453
+ // one call here with a real ENOBUFS cliff — and this signal is ranked last,
454
+ // so it must never be the reason the three above become unavailable. An
455
+ // empty `prose[]` with no reason beside it would be byte-identical to a
456
+ // clean scan, which is #705's own failure mode one level in.
457
+ test("prose: a full-diff read that fails names itself and leaves the other three answerable", () => {
458
+ const r = run(
459
+ {
460
+ prs: {
461
+ 1: { names: [TSV], diff: hunk(TSV, ["+1490\timpl-1490"]) },
462
+ 2: { names: ["plugin/skills/run-team/SKILL.md"] }, // no .diff: the fake gh exits non-zero
463
+ },
464
+ },
465
+ 1,
466
+ 2,
467
+ );
468
+ assert.equal(r.status, 0, r.stdout + r.stderr);
469
+ const payload = JSON.parse(r.stdout);
470
+ assert.deepEqual(payload.prose, []);
471
+ assert.match(payload.proseUnrun, /gh pr diff 2 failed/);
472
+ assert.equal(payload.signal, "none");
473
+ assert.match(r.stderr, /prose scan INCOMPLETE/);
474
+ assert.match(r.stderr, /does not clear the same-section case/);
475
+ });
476
+
477
+ // #878: `--a 0`/`--b 0` is the row the `=== null` absence check exists for,
478
+ // and the one a later "simplification" back to `!a || !b` silently breaks:
479
+ // numArg() returns a NUMBER, so `!a` is true for a zero the caller plainly
480
+ // GAVE, and the usage die above would then answer it as though `--a` were
481
+ // never given at all. Companion to arg.test.mjs's identical row for
482
+ // diff-stats.mjs and ci-state.test.mjs's own for `--pr` — #878's own comment
483
+ // names all three callers as sharing this contract, and only diff-stats.mjs
484
+ // had this row before.
485
+ //
486
+ // `strictEqual` on both fields, same reason as the well-formed test above: a
487
+ // payload reading `a`/`b` back as the string "0" would satisfy a loose check
488
+ // while breaking every consumer that keys on a number.
489
+ test("#878: --a 0/--b 0 reach gh rather than drawing the usage line for an absent flag", () => {
490
+ const bin = mkdtempSync(join(tmpdir(), "pr-overlap-bin-"));
491
+ const gh = join(bin, "gh");
492
+ writeFileSync(gh, '#!/bin/sh\ncase "$3" in\n 0) echo src/shared.ts ;;\nesac\n');
493
+ chmodSync(gh, 0o755);
494
+ const r = spawnSync(process.execPath, [SCRIPT, "--a", "0", "--b", "0"], {
495
+ encoding: "utf8",
496
+ env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
497
+ });
498
+ rmSync(bin, { recursive: true, force: true });
499
+ assert.equal(r.status, 0, r.stdout + r.stderr);
500
+ assert.doesNotMatch(r.stderr, /usage:/, `--a 0/--b 0 was answered as an absent flag: ${r.stderr}`);
501
+ const payload = JSON.parse(r.stdout);
502
+ assert.strictEqual(payload.a, 0, `a zero --a must survive to the payload as 0: ${r.stdout}`);
503
+ assert.strictEqual(payload.b, 0, `a zero --b must survive to the payload as 0: ${r.stdout}`);
504
+ });
505
+
506
+ // A `-`/`+` diff marker followed by CONTENT that itself starts with a dash
507
+ // or plus (a removed `--pin ...` line, an added `++retry ...` line) composes
508
+ // to `---`/`+++` — the same three characters a real file-header line begins
509
+ // with. Gating capture on the `@@` hunk boundary rather than on those three
510
+ // characters is what tells the two apart; testing the header text alone
511
+ // mistakes the hunk-body line for its own file header and drops it.
512
+ test("prose: a hunk-body line beginning with -- or ++ is still read as a citation, not mistaken for a diff header", () => {
513
+ const REMOVED_CITER = "docs/removed-hazard.md";
514
+ const ADDED_CITER = "docs/added-hazard.md";
515
+ const r = run(
516
+ {
517
+ prs: {
518
+ 1: { names: [TSV], diff: hunk(TSV, ["+1490\timpl-1490"]) },
519
+ 2: {
520
+ names: [REMOVED_CITER, ADDED_CITER],
521
+ diff:
522
+ hunk(REMOVED_CITER, [`---pin ${TSV} (stale, drop it)`]) +
523
+ hunk(ADDED_CITER, [`+++retry ${TSV} (kept)`]),
524
+ },
525
+ },
526
+ },
527
+ 1,
528
+ 2,
529
+ );
530
+ assert.equal(r.status, 0, r.stdout + r.stderr);
531
+ const payload = JSON.parse(r.stdout);
532
+ assert.equal(payload.signal, "prose");
533
+ assert.deepEqual(
534
+ payload.prose.map((h) => h.citedBy).sort(),
535
+ [ADDED_CITER, REMOVED_CITER],
536
+ );
537
+ });
538
+
539
+ // `trackedBasenameCounts()`'s own `git ls-files` failure must name its cause
540
+ // the same way `changedFiles()` and `diffOf()` do — a bare `null` collapsing
541
+ // into a fixed string is indistinguishable from every OTHER git failure, and
542
+ // disables the ambiguity guard (full paths only) with no diagnostic to act
543
+ // on. Shadows `git` on PATH so `git ls-files -z` fails; the full-path
544
+ // citation below still fires because the guard narrowing to full-paths-only
545
+ // is exactly what a failed count means, not a disabled scan.
546
+ test("prose: a git ls-files failure names its cause instead of vanishing into a fixed string", () => {
547
+ const fx = fixture({
548
+ prs: {
549
+ 1: { names: [TSV], diff: hunk(TSV, ["+1490\timpl-1490"]) },
550
+ 2: { names: ["docs/notes.md"], diff: hunk("docs/notes.md", [`+cites ${TSV} here`]) },
551
+ },
552
+ });
553
+ const git = join(fx.bin, "git");
554
+ writeFileSync(git, "#!/bin/sh\nexit 1\n");
555
+ chmodSync(git, 0o755);
556
+ const r = spawnSync(process.execPath, [SCRIPT, "--a", "1", "--b", "2"], {
557
+ encoding: "utf8",
558
+ cwd: fx.repo,
559
+ env: { ...process.env, PATH: `${fx.bin}:${process.env.PATH}` },
560
+ });
561
+ rmSync(fx.root, { recursive: true, force: true });
562
+ assert.equal(r.status, 0, r.stdout + r.stderr);
563
+ const payload = JSON.parse(r.stdout);
564
+ assert.equal(payload.signal, "prose");
565
+ assert.match(payload.proseUnrun, /git ls-files failed: exit 1/);
566
+ assert.match(r.stderr, /git ls-files failed: exit 1/);
567
+ });
568
+
569
+ // The guard counted only the PRE-PR index: a data file the PR itself ADDS is
570
+ // untracked at this checkout, so subtracting nothing from an existing
571
+ // OTHER tracked file's count left the added file wrongly "unique" — the two
572
+ // files share a basename post-PR and neither should be citable by it alone.
573
+ test("prose: a data file the PR itself adds is still checked against existing tracked basenames", () => {
574
+ const EXISTING = "other/dir/config.json";
575
+ const ADDED = "new/config.json";
576
+ const CITER = "docs/notes.md";
577
+ const r = run(
578
+ {
579
+ prs: {
580
+ 1: { names: [ADDED], diff: hunk(ADDED, ['+{"x":1}']) },
581
+ 2: { names: [CITER], diff: hunk(CITER, ["+see config.json for the format"]) },
582
+ },
583
+ tracked: [EXISTING],
584
+ },
585
+ 1,
586
+ 2,
587
+ );
588
+ assert.equal(r.status, 0, r.stdout + r.stderr);
589
+ const payload = JSON.parse(r.stdout);
590
+ assert.equal(payload.signal, "none");
591
+ assert.deepEqual(payload.prose, []);
592
+ });
593
+
594
+ // The guard's other branch: a data file the PR only MODIFIES (already
595
+ // tracked, exactly once) must still be matched by its bare basename. Only
596
+ // the ambiguous case (count 2+) and the freshly-added case (count 0) were
597
+ // covered before this — a mutation that narrows the "unique" boundary
598
+ // silently drops this branch, and no test caught it.
599
+ test("prose: a uniquely-tracked data file is still matched by its bare basename", () => {
600
+ const UNIQUE = "data/only-owner.json";
601
+ const CITER = "docs/notes.md";
602
+ const r = run(
603
+ {
604
+ prs: {
605
+ 1: { names: [UNIQUE], diff: hunk(UNIQUE, ['+{"x":1}']) },
606
+ 2: { names: [CITER], diff: hunk(CITER, ["+see only-owner.json for the schema"]) },
607
+ },
608
+ tracked: [UNIQUE],
609
+ },
610
+ 1,
611
+ 2,
612
+ );
613
+ assert.equal(r.status, 0, r.stdout + r.stderr);
614
+ const payload = JSON.parse(r.stdout);
615
+ assert.equal(payload.signal, "prose");
616
+ assert.deepEqual(payload.prose.map((h) => h.token), ["only-owner.json"]);
617
+ });
618
+
619
+ // #1599: trackedBasenameCounts() passed no env at all before this fix, and
620
+ // #1020's own census could not see it — its scan is `.sh`-only. Measured
621
+ // directly: an ambient GIT_DIR (a git hook, `rebase --exec`, `bisect run`)
622
+ // makes `git ls-files -z` answer for a DIFFERENT repository regardless of
623
+ // `cwd`, silently, at exit 0 — so the count this guard bases its verdict on
624
+ // comes from whichever repository the ambient variable names, not the one
625
+ // the caller is actually running the tool against.
626
+ //
627
+ // The fixture pairs a real repository where the data file's basename is
628
+ // UNIQUE (`only-owner.json`, tracked once — the exact positive shape the
629
+ // test above pins) with an ambient GIT_DIR naming an unrelated repository
630
+ // where that basename is tracked TWICE. Unscrubbed, the guard reads the
631
+ // ambient repository's count (2) instead of the real one (1), the bare
632
+ // basename is wrongly judged ambiguous and dropped, and the citation below
633
+ // goes unreported — `signal` stays "none" instead of "prose".
634
+ test("prose: an inherited GIT_DIR must not substitute another repository's basename count for this repository's own", () => {
635
+ const UNIQUE = "data/only-owner.json";
636
+ const CITER = "docs/notes.md";
637
+
638
+ const otherRepo = mkdtempSync(join(tmpdir(), "pr-overlap-other-"));
639
+ execFileSync("git", ["init", "-q"], { cwd: otherRepo });
640
+ mkdirSync(join(otherRepo, "a"), { recursive: true });
641
+ mkdirSync(join(otherRepo, "b"), { recursive: true });
642
+ writeFileSync(join(otherRepo, "a", "only-owner.json"), "x\n");
643
+ writeFileSync(join(otherRepo, "b", "only-owner.json"), "x\n");
644
+ execFileSync("git", ["add", "-A"], { cwd: otherRepo });
645
+
646
+ const fx = fixture({
647
+ prs: {
648
+ 1: { names: [UNIQUE], diff: hunk(UNIQUE, ['+{"x":1}']) },
649
+ 2: { names: [CITER], diff: hunk(CITER, ["+see only-owner.json for the schema"]) },
650
+ },
651
+ tracked: [UNIQUE],
652
+ });
653
+ let r;
654
+ try {
655
+ r = spawnSync(process.execPath, [SCRIPT, "--a", "1", "--b", "2"], {
656
+ encoding: "utf8",
657
+ cwd: fx.repo,
658
+ env: { ...process.env, PATH: `${fx.bin}:${process.env.PATH}`, GIT_DIR: join(otherRepo, ".git") },
659
+ });
660
+ } finally {
661
+ rmSync(fx.root, { recursive: true, force: true });
662
+ rmSync(otherRepo, { recursive: true, force: true });
663
+ }
664
+ assert.equal(r.status, 0, r.stdout + r.stderr);
665
+ const payload = JSON.parse(r.stdout);
666
+ assert.equal(payload.signal, "prose",
667
+ "an ambient GIT_DIR must not substitute the OTHER repository's (ambiguous) basename count for this repository's own (unique) one");
668
+ assert.deepEqual(payload.prose.map((h) => h.token), ["only-owner.json"]);
669
+ });
670
+
671
+ // The other ranking pair: `dirs` sits ABOVE `prose` in the ladder, and no
672
+ // test drove a PR pair where both fire simultaneously. A swap of that
673
+ // ordering (`prose` checked before `dirs`) would pass the whole suite
674
+ // untouched without this.
675
+ test("prose: dirs outranks prose when both fire, and the prose hit is still reported", () => {
676
+ const r = run(
677
+ {
678
+ prs: {
679
+ 1: { names: [TSV, "docs/metrics/other.md"], diff: hunk(TSV, ["+1490\timpl-1490"]) },
680
+ 2: {
681
+ names: ["docs/metrics/notes.md"],
682
+ diff: hunk("docs/metrics/notes.md", [`+cites ${TSV} here`]),
683
+ },
684
+ },
685
+ },
686
+ 1,
687
+ 2,
688
+ );
689
+ assert.equal(r.status, 0, r.stdout + r.stderr);
690
+ const payload = JSON.parse(r.stdout);
691
+ assert.equal(payload.signal, "dirs");
692
+ assert.deepEqual(payload.dirs, ["docs/metrics"]);
693
+ assert.equal(payload.prose.length, 1);
694
+ assert.match(r.stderr, /prose citation/);
695
+ });