@feigi/fleet-ctl 3.23.36 → 3.23.38

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 (205) hide show
  1. package/package.json +1 -1
  2. package/scripts/cell-readout.mjs +38 -11
  3. package/scripts/main-checkout.mjs +1 -1
  4. package/scripts/member-write-guard.mjs +1 -1
  5. package/scripts/repo-root.mjs +1 -1
  6. package/skills/run-team/references/reaping.md +1 -1
  7. package/scripts/agent-test-dir-prose.test.mjs +0 -59
  8. package/scripts/agent-test.test.mjs +0 -1640
  9. package/scripts/ambient-git-vars-mjs-prose.test.mjs +0 -397
  10. package/scripts/ambient-git-vars-prose.test.mjs +0 -192
  11. package/scripts/ancestry-check-position-prose.test.mjs +0 -175
  12. package/scripts/apply-ruleset.test.mjs +0 -421
  13. package/scripts/arg-header-probes-prose.test.mjs +0 -394
  14. package/scripts/arg.test.mjs +0 -1354
  15. package/scripts/board-cli.test.mjs +0 -710
  16. package/scripts/board-identity.test.mjs +0 -429
  17. package/scripts/board-liveness-banner.test.mjs +0 -119
  18. package/scripts/board-prev-shape.test.mjs +0 -228
  19. package/scripts/board-tryparse-null.test.mjs +0 -119
  20. package/scripts/board.test.mjs +0 -3121
  21. package/scripts/brief-after-cut-prose.test.mjs +0 -53
  22. package/scripts/candidates-exit3-prose.test.mjs +0 -302
  23. package/scripts/candidates.test.mjs +0 -2312
  24. package/scripts/caveat-unification-prose.test.mjs +0 -98
  25. package/scripts/cell-readout.test.mjs +0 -615
  26. package/scripts/ci-comment-rot-prose.test.mjs +0 -2025
  27. package/scripts/ci-completes-premise-prose.test.mjs +0 -257
  28. package/scripts/ci-state-prose.test.mjs +0 -113
  29. package/scripts/ci-state.test.mjs +0 -1933
  30. package/scripts/ci-vacuous-green.test.mjs +0 -368
  31. package/scripts/citation-sweep-prose.test.mjs +0 -1712
  32. package/scripts/claim-lifecycle.test.mjs +0 -187
  33. package/scripts/claim-ticket.test.mjs +0 -1122
  34. package/scripts/closing-keyword-prose.test.mjs +0 -193
  35. package/scripts/cockpit-launch-idempotent-prose.test.mjs +0 -165
  36. package/scripts/cockpit-tick-nonblocking.test.mjs +0 -210
  37. package/scripts/compute-board.test.mjs +0 -1214
  38. package/scripts/compute-spend.test.mjs +0 -517
  39. package/scripts/consumer-technology-prose.test.mjs +0 -126
  40. package/scripts/cross-repo-citation-prose.test.mjs +0 -155
  41. package/scripts/cwd-isolation-pins.mjs +0 -83
  42. package/scripts/dedupe-guard-prose.test.mjs +0 -243
  43. package/scripts/delete-merged-branch.test.mjs +0 -576
  44. package/scripts/derive-testcmd.test.mjs +0 -595
  45. package/scripts/diff-stats.test.mjs +0 -404
  46. package/scripts/dispatch-block-golden-prose.test.mjs +0 -1130
  47. package/scripts/dispatch-block-pins-prose.test.mjs +0 -615
  48. package/scripts/dispositions-check.test.mjs +0 -936
  49. package/scripts/dispositions-gate-prose.test.mjs +0 -129
  50. package/scripts/drop-merged-label.test.mjs +0 -479
  51. package/scripts/exec-stub.mjs +0 -93
  52. package/scripts/exec-stub.test.mjs +0 -69
  53. package/scripts/expected-jobs-prose.test.mjs +0 -80
  54. package/scripts/fan-out-authorization-prose.test.mjs +0 -80
  55. package/scripts/filing-bar-seat-prose.test.mjs +0 -242
  56. package/scripts/filing-claim-bar-prose.test.mjs +0 -166
  57. package/scripts/finisher-died-prose.test.mjs +0 -31
  58. package/scripts/finisher-dispatch-premise-prose.test.mjs +0 -312
  59. package/scripts/finisher-halt-prose.test.mjs +0 -106
  60. package/scripts/finisher-name-prose.test.mjs +0 -134
  61. package/scripts/finisher-own-tree-prose.test.mjs +0 -299
  62. package/scripts/finisher-pin-race-prose.test.mjs +0 -339
  63. package/scripts/finisher-test-verdict-prose.test.mjs +0 -102
  64. package/scripts/fix-applier-correction-rules-prose.test.mjs +0 -202
  65. package/scripts/fix-applier-result-file-prose.test.mjs +0 -149
  66. package/scripts/fleet-bootstrap.test.mjs +0 -75
  67. package/scripts/fleet-heartbeat.test.mjs +0 -450
  68. package/scripts/fleet-provenance.test.mjs +0 -138
  69. package/scripts/fleet-run.test.mjs +0 -90
  70. package/scripts/fleet-state.test.mjs +0 -460
  71. package/scripts/fleet-tick-prose.test.mjs +0 -300
  72. package/scripts/fleet-tick.test.mjs +0 -2444
  73. package/scripts/force-with-lease-reason-prose.test.mjs +0 -184
  74. package/scripts/frontmatter-check.test.mjs +0 -436
  75. package/scripts/git-env.test.mjs +0 -149
  76. package/scripts/git-status-untracked-mode-sweep.test.mjs +0 -216
  77. package/scripts/gone-walk.test.mjs +0 -213
  78. package/scripts/gp-sep-invariant-prose.test.mjs +0 -188
  79. package/scripts/head-moved-after-label-prose.test.mjs +0 -233
  80. package/scripts/immutable-body-claim-prose.test.mjs +0 -204
  81. package/scripts/implementer-model-tier.test.mjs +0 -235
  82. package/scripts/inflight-citation-prose.test.mjs +0 -144
  83. package/scripts/inflight-exit2-prose.test.mjs +0 -81
  84. package/scripts/inflight-probe-guard-prose.test.mjs +0 -109
  85. package/scripts/inflight-scan-scope-prose.test.mjs +0 -57
  86. package/scripts/inflight.test.mjs +0 -2882
  87. package/scripts/injection-control-prose.test.mjs +0 -404
  88. package/scripts/install-root-audit.test.mjs +0 -464
  89. package/scripts/instrument-check-prose.test.mjs +0 -235
  90. package/scripts/instruments.test.mjs +0 -787
  91. package/scripts/is-cli.test.mjs +0 -99
  92. package/scripts/issue-tracker-prose.test.mjs +0 -71
  93. package/scripts/json.test.mjs +0 -364
  94. package/scripts/ledger-dispatch.test.mjs +0 -927
  95. package/scripts/ledger-grammar.test.mjs +0 -227
  96. package/scripts/ledger-read-require-file.test.mjs +0 -197
  97. package/scripts/ledger-rotate.test.mjs +0 -142
  98. package/scripts/ledger.test.mjs +0 -3436
  99. package/scripts/line-distance-prose.test.mjs +0 -245
  100. package/scripts/liveness-rationale-prose.test.mjs +0 -83
  101. package/scripts/locale-pin-prose.test.mjs +0 -189
  102. package/scripts/main-checkout.test.mjs +0 -332
  103. package/scripts/member-outcome-prose.test.mjs +0 -167
  104. package/scripts/member-outcomes-header.test.mjs +0 -129
  105. package/scripts/member-outcomes-prose.test.mjs +0 -63
  106. package/scripts/member-outcomes.test.mjs +0 -638
  107. package/scripts/member-prompt-prose.test.mjs +0 -165
  108. package/scripts/member-record.test.mjs +0 -541
  109. package/scripts/member-write-guard.test.mjs +0 -214
  110. package/scripts/merge-commit-probe-prose.test.mjs +0 -122
  111. package/scripts/merge-gate.test.mjs +0 -613
  112. package/scripts/muted-git-guard-sweep.test.mjs +0 -493
  113. package/scripts/net-ssh-precedence-prose.test.mjs +0 -91
  114. package/scripts/net-watchdog-prose.test.mjs +0 -79
  115. package/scripts/net.test.mjs +0 -211
  116. package/scripts/no-ci-gate-prose.test.mjs +0 -108
  117. package/scripts/no-undo-audit.test.mjs +0 -3961
  118. package/scripts/no-wave.test.mjs +0 -138
  119. package/scripts/node-floor-sweep.test.mjs +0 -611
  120. package/scripts/pointer-target-prose.test.mjs +0 -186
  121. package/scripts/pr-cost.test.mjs +0 -521
  122. package/scripts/pr-overlap.test.mjs +0 -692
  123. package/scripts/printf-die-sweep.test.mjs +0 -384
  124. package/scripts/prompt-renderer.mjs +0 -40
  125. package/scripts/prompt-renderer.test.mjs +0 -68
  126. package/scripts/prose-pin.mjs +0 -807
  127. package/scripts/prose-pin.test.mjs +0 -1034
  128. package/scripts/prove-merge.test.mjs +0 -995
  129. package/scripts/pull-table-relabel-prose.test.mjs +0 -60
  130. package/scripts/quiet-payload-prose.test.mjs +0 -222
  131. package/scripts/reap-cherry-check-prose.test.mjs +0 -80
  132. package/scripts/reap.test.mjs +0 -4432
  133. package/scripts/reaping-prose.test.mjs +0 -239
  134. package/scripts/reaping-reap-authorizers-prose.test.mjs +0 -112
  135. package/scripts/reaping-release-authorizers-prose.test.mjs +0 -85
  136. package/scripts/recipe-derivation-prose.test.mjs +0 -112
  137. package/scripts/recipe-prove.test.mjs +0 -1042
  138. package/scripts/refuter-scratch-prose.test.mjs +0 -135
  139. package/scripts/release-label-required-prose.test.mjs +0 -71
  140. package/scripts/release-label-split-prose.test.mjs +0 -184
  141. package/scripts/release-ticket-reap-pairing-prose.test.mjs +0 -63
  142. package/scripts/release-ticket.test.mjs +0 -5099
  143. package/scripts/renovate-release-contract.test.mjs +0 -379
  144. package/scripts/repo-root.test.mjs +0 -873
  145. package/scripts/reporter-output-rule-prose.test.mjs +0 -208
  146. package/scripts/review-agent-report-only.test.mjs +0 -49
  147. package/scripts/review-core-booking.test.mjs +0 -35
  148. package/scripts/review-core-cwd-isolation.test.mjs +0 -374
  149. package/scripts/review-core-reads.test.mjs +0 -478
  150. package/scripts/review-core-refuter-scratch.test.mjs +0 -148
  151. package/scripts/review-core-scratch-refusal.test.mjs +0 -64
  152. package/scripts/review-core-shared-test-run.test.mjs +0 -275
  153. package/scripts/review-core-snapshot-path.test.mjs +0 -830
  154. package/scripts/review-core-specialist-scratch.test.mjs +0 -191
  155. package/scripts/review-core-testcmd.test.mjs +0 -335
  156. package/scripts/review-core-unrun.test.mjs +0 -566
  157. package/scripts/review-core-unverified-discriminant.test.mjs +0 -208
  158. package/scripts/review-eval-resolver-path.test.mjs +0 -55
  159. package/scripts/review-host-fixture.mjs +0 -89
  160. package/scripts/review-in-run-retry.test.mjs +0 -211
  161. package/scripts/review-no-vendor-dispatch.test.mjs +0 -45
  162. package/scripts/review-path-default.test.mjs +0 -796
  163. package/scripts/review-runner-spawns.test.mjs +0 -95
  164. package/scripts/review-runner.test.mjs +0 -166
  165. package/scripts/review-tier-audit.test.mjs +0 -140
  166. package/scripts/run-artifact-pr-prose.test.mjs +0 -341
  167. package/scripts/run-merge-bot-prose.test.mjs +0 -1413
  168. package/scripts/run-team-local-hook.test.mjs +0 -442
  169. package/scripts/scratch-partition-invariant-prose.test.mjs +0 -74
  170. package/scripts/scripts-path-citation-sweep.test.mjs +0 -73
  171. package/scripts/section-between-guard-prose.test.mjs +0 -379
  172. package/scripts/select-dimensions.test.mjs +0 -674
  173. package/scripts/shared-refusal.test.mjs +0 -388
  174. package/scripts/shell-traps-prose.test.mjs +0 -504
  175. package/scripts/shortlist.test.mjs +0 -380
  176. package/scripts/slow-transport.mjs +0 -72
  177. package/scripts/snapshot-repo.test.mjs +0 -1006
  178. package/scripts/snapshot-runner-audience-prose.test.mjs +0 -130
  179. package/scripts/spend-view.test.mjs +0 -312
  180. package/scripts/staleness-qualifier-prose.test.mjs +0 -251
  181. package/scripts/staleness-verdict-prose.test.mjs +0 -142
  182. package/scripts/staleness.test.mjs +0 -893
  183. package/scripts/stalled-member-liveness-prose.test.mjs +0 -219
  184. package/scripts/stash-prohibition-prose.test.mjs +0 -313
  185. package/scripts/strip-comments.mjs +0 -44
  186. package/scripts/temp-dir.mjs +0 -47
  187. package/scripts/ticket-router.test.mjs +0 -981
  188. package/scripts/tier-check.test.mjs +0 -828
  189. package/scripts/tier-outcomes-header.test.mjs +0 -518
  190. package/scripts/tier-outcomes.test.mjs +0 -572
  191. package/scripts/tier-roles.test.mjs +0 -535
  192. package/scripts/tracker-block-copy-prose.test.mjs +0 -288
  193. package/scripts/triage-labels-gloss-prose.test.mjs +0 -97
  194. package/scripts/unattended-git-sweep.test.mjs +0 -142
  195. package/scripts/verify-sha-exit2-prose.test.mjs +0 -269
  196. package/scripts/verify-sha.test.mjs +0 -692
  197. package/scripts/watcher-degraded-block.test.mjs +0 -369
  198. package/scripts/watcher-key-prose.test.mjs +0 -106
  199. package/scripts/within-run-pair-prose.test.mjs +0 -212
  200. package/scripts/worktree-audit.test.mjs +0 -1408
  201. package/scripts/worktree-head-prose.test.mjs +0 -276
  202. package/scripts/worktree-listing-sweep.test.mjs +0 -217
  203. package/scripts/worktree-model-prose.test.mjs +0 -216
  204. package/scripts/worktree-porcelain.mjs +0 -35
  205. package/scripts/worktree-porcelain.test.mjs +0 -102
@@ -1,830 +0,0 @@
1
- import { test } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { readFileSync, readdirSync, mkdtempSync, rmSync, statSync } from "node:fs";
4
- import { tmpdir } from "node:os";
5
- import { execFileSync } from "node:child_process";
6
- import { join } from "node:path";
7
- import { stripComments } from "./strip-comments.mjs";
8
- import { between, phrase } from "./prose-pin.mjs";
9
- import { snapshotMissing as snapshotMissingRaw, runReview } from "./review-core.mjs";
10
- import { scriptedHost, SNAP as HOST_SNAP, ARGS, pipeline, parallel, review } from "./review-host-fixture.mjs";
11
-
12
- // `snap.path` used to reach every specialist prompt and every verifier prompt
13
- // unchecked: a well-formed string the schema required, but never confirmed to
14
- // name a real directory. A silently-failed 'git archive | tar -x' (bad auth,
15
- // a dead HEAD) leaves 'mkdir -p's directory standing, empty — so every
16
- // specialist got `No such file or directory` on every read and reasoned from
17
- // source instead of measuring, on all six dimensions at once (#140).
18
- //
19
- // `snapshotMissing` is the fix: a `pathVerified` boolean in the snapshot
20
- // schema's own `required` array, so the agent cannot silently omit it — read by
21
- // the CALLER rather than trusted from the agent's narration of the
22
- // byte-identity 'Verify it' step in the snapshot prompt.
23
- const REPO = join(import.meta.dirname, "..");
24
- const SOURCE = readFileSync(join(REPO, "scripts", "review-core.mjs"), "utf8");
25
-
26
- // Pins run against CODE, not SOURCE: review-core-reads.test.mjs and
27
- // review-core-testcmd.test.mjs each measured a source-text pin pass vacuously
28
- // against a field dead under a comment — same stripper, same policy here.
29
- const CODE = stripComments(SOURCE);
30
-
31
- // #1129 gave the guard a second parameter: the `${scratch}/pr${pr}/run-` prefix
32
- // the SCRIPT owns, which is what the reported `runRoot` is checked against. The
33
- // per-run segment itself is minted by the snapshot agent's shell (`mktemp -d`),
34
- // never by the caller, because two reviews sharing one scratch root must never
35
- // mint the same one (#1129) — a JS-side `Date.now()`/`Math.random()` in the
36
- // controller could not provision a directory on the specialist's own
37
- // filesystem anyway, so the shell was always the only place this could live.
38
-
39
- const PREFIX = "/scr/pr7/run-";
40
- const ROOT = `${PREFIX}ab12cd34`;
41
- const SNAP = `${ROOT}/snapshot-abc123`;
42
-
43
- // Every fixture in the tests that PREDATE the run-root check must satisfy that
44
- // check, or the check silently becomes the thing deciding them and the branch
45
- // each was written for stops being exercised. So the wrapper supplies a valid
46
- // `runRoot` and the prefix, and each fixture's `path` sits under it: the field
47
- // the test is about stays the only thing wrong with the report.
48
- const snapshotMissing = (snap) => snapshotMissingRaw(snap && { runRoot: ROOT, ...snap }, PREFIX);
49
-
50
- // The accept case: this is the ONLY shape the review/verify stages may
51
- // proceed on. A guard's false-positive class (wrongly refusing a healthy
52
- // snapshot) is not its false-negative class, and nothing above this line
53
- // exercises the ACCEPT path — every other test in this file feeds it input
54
- // it must reject.
55
- test("a fully verified snapshot is not missing", () => {
56
- const reason = snapshotMissing({ path: SNAP, head: "abc123", pathVerified: true });
57
- assert.equal(reason, null, "a snapshot with path, head and pathVerified:true must not be refused");
58
- });
59
-
60
- // Pre-existing behaviour (#140 must not regress it): no snapshot object at
61
- // all, or one missing path/head, was already refused before this ticket.
62
- // #539 splits the single "no tree" message this used to share across all six
63
- // inputs into three, so the three groups below are asserted separately —
64
- // otherwise a branch that can't actually tell path-missing from head-missing
65
- // would still pass a loop that only checks "some string came back".
66
- //
67
- // A falsy `snap` is the agent contract failing — it died, or the harness
68
- // exhausted structured-output retries and `agent()` returned null — not a
69
- // claim about the tree on disk, which may be perfectly good. The reason names
70
- // `died` and `exhausted` but never `rejected`: a schema REJECTION is handed
71
- // back to the model as a tool error and retried, and the rejections measured
72
- // under Claude Code all recovered on retry (docs/specs/2026-09-08-omp-eval-workflow-host.md,
73
- // Q2, quoting the "184 rejection events … every one recovered by retry"
74
- // comment that review-pr.js carried inside its FINDINGS_SCHEMA, in the
75
- // comment block above `required:`, until the omp-only cutover deleted that
76
- // file). A rejection is therefore a signature successful runs
77
- // carry, and naming it as the cause of a null would point an operator at the
78
- // wrong thing. review-eval.mjs's `ompAgent` comment records the omp side: a
79
- // rejected `.wait()` maps to null there.
80
- test("a falsy snapshot (agent died, or it exhausted its structured-output retries) names the agent contract, not a missing tree", () => {
81
- for (const dead of [null, undefined, false]) {
82
- const reason = snapshotMissing(dead);
83
- assert.equal(typeof reason, "string", `${JSON.stringify(dead)} must yield a reason`);
84
- assert.match(reason, /died/, "the reason no longer names a dead agent as a cause");
85
- assert.match(reason, /exhausted/, "the reason no longer names exhausted retries — the only structured-output state that yields a falsy snap");
86
- assert.doesNotMatch(reason, /rejected/, "the reason names a rejection, which is retried and recovers rather than returning null");
87
- }
88
- });
89
-
90
- // `{}` and `{ head: "abc123" }` are both missing `path`; the original
91
- // `!snap || !snap.path || !snap.head` chain checks `path` before `head`, so
92
- // both land on the same branch under the split too — the split preserves that
93
- // order rather than re-deciding it.
94
- test("a report missing path is refused, naming path and not head", () => {
95
- for (const report of [{}, { head: "abc123" }]) {
96
- const reason = snapshotMissing(report);
97
- assert.equal(typeof reason, "string", `${JSON.stringify(report)} must yield a reason`);
98
- assert.match(reason, /`path`/, "the reason no longer names path as the missing field");
99
- assert.doesNotMatch(reason, /`head`/, "a missing-path report must not mention `head` at all — the pin is what catches this branch returning the head branch's message");
100
- }
101
- });
102
-
103
- // `{ path: SNAP }` is the one input of the six with `path` present —
104
- // the only one that can reach the `head`-missing branch at all. It is also the
105
- // one branch of the three that must NOT borrow the "no tree to review" ending:
106
- // `path` is present and may name a perfectly good directory, so the absent sha
107
- // is the whole of what is wrong. #539 exists because one message misattributed
108
- // a handshake failure as a missing tree; this branch is where that would come
109
- // straight back.
110
- test("a report missing head (path present) is refused, naming head and not path", () => {
111
- const reason = snapshotMissing({ path: SNAP });
112
- assert.equal(typeof reason, "string", "a present path with no head must yield a reason");
113
- assert.match(reason, /`head`/, "the reason no longer names head as the missing field");
114
- assert.doesNotMatch(reason, /no tree/, "the head branch claims there is no tree, on the one branch whose path is present and whose tree may be fine");
115
- assert.doesNotMatch(reason, /`path`/, "a missing-head report must not mention `path` at all — the pin is what catches this branch returning the path branch's message");
116
- });
117
-
118
- // #140's actual case: path and head are both present, well-formed strings —
119
- // exactly what let a garbage path through before this ticket — but the
120
- // mechanical existence check came back false. The interpolation defect this
121
- // closes is only reachable through THIS branch, not the no-tree one above.
122
- test("a present path that failed its existence check is refused, naming the path", () => {
123
- const reason = snapshotMissing({ path: `${ROOT}/snapshot-empty`, head: "abc123", pathVerified: false });
124
- assert.equal(typeof reason, "string", "pathVerified:false must yield a reason");
125
- assert.match(reason, /snapshot-empty/, "the reason must name the unverified path");
126
- assert.match(reason, /not verified to exist/, "the reason no longer says the path was not verified");
127
- });
128
-
129
- // A specialist that skipped the required field entirely is the same fact as
130
- // one that ran the check and got false — the schema's `required` is what is
131
- // supposed to prevent this at the tool-call layer, but the pure function must
132
- // not read silence as success if that layer is ever bypassed.
133
- test("a snapshot that omitted pathVerified is refused, not assumed true", () => {
134
- const reason = snapshotMissing({ path: SNAP, head: "abc123" });
135
- assert.equal(typeof reason, "string", "an absent pathVerified must yield a reason, not pass through as verified");
136
- });
137
-
138
- // #1056 Finding 2: a string is not a boolean. `pathVerified` used to be
139
- // checked with `!snap.pathVerified` — a falsy check — so the STRING "false"
140
- // (truthy in JS) passed it silently, defeating the exact defect class this
141
- // field exists to guard against just as surely as an omitted field would.
142
- // `repoVerified`'s sibling check is `=== true` (snapshot-repo.test.mjs pins
143
- // it); this mirrors that guard onto `pathVerified`.
144
- test("a non-boolean truthy pathVerified is refused, not accepted as verified", () => {
145
- const falseString = snapshotMissing({ path: SNAP, head: "abc123", pathVerified: "false" });
146
- assert.equal(typeof falseString, "string", 'a `pathVerified` of the STRING "false" must still yield a reason — it is truthy, not the boolean the check requires');
147
- const trueString = snapshotMissing({ path: SNAP, head: "abc123", pathVerified: "true" });
148
- assert.equal(typeof trueString, "string", 'a `pathVerified` of the STRING "true" must still yield a reason — a schema bypass or a hand-built fixture can carry the word rather than the value');
149
- });
150
-
151
- // #532: the head compare already existed — in `usableDiff`, where a
152
- // mismatching head cost the review its DIFF and nothing else. The review
153
- // then ran to completion against a tree that was not the PR, on the fallback
154
- // read rules, and reported findings about code the PR does not contain. That is
155
- // the measured case: a carried-over worktree re-created with
156
- // `git worktree add <path> <branch>`, which checks out a leftover LOCAL branch
157
- // and never consults the remote, so the tree sat at a pre-rebase commit whose
158
- // subject line was byte-identical to the PR head's. Neither commit was an
159
- // ancestor of the other. The refusal is what the comparison was missing.
160
- test("a tree whose head is not the branch ref's is refused, naming both commits", () => {
161
- const reason = snapshotMissing({ path: SNAP, head: "cff7330", pathVerified: true, refHead: "9e8ee3d" });
162
- assert.equal(typeof reason, "string", "a present, mismatching refHead must yield a reason");
163
- assert.match(reason, /cff7330/, "the reason must name the commit the tree is actually at");
164
- assert.match(reason, /9e8ee3d/, "the reason must name the branch head it was measured against");
165
- });
166
-
167
- // #1513, and the expensive half of the mechanism #1168 fixed for worktree
168
- // dispatch. This refusal runs BEFORE `usableDiff`, so the operand it reads
169
- // decides whether the review happens AT ALL: against `prHead` — the PR object's
170
- // `headRefOid`, which sits on the pre-rebase sha for minutes after a rebase has
171
- // landed (~2 min in one merge-bot run and ~84s in the next, measured in
172
- // `run-merge-bot.md`'s step 1) — a snapshot cut from the CORRECT tree inside
173
- // that window cancelled the whole review, which is strictly worse than the
174
- // dropped diff the same operand cost `usableDiff`.
175
- test("a lagging PR object does not cancel the review of a tree that matches the ref", () => {
176
- const rebased = "62ba798" + "0".repeat(33);
177
- const stale = "c774756" + "0".repeat(33);
178
- assert.equal(
179
- snapshotMissing({ path: SNAP, pathVerified: true, head: rebased, refHead: rebased, prHead: stale }),
180
- null,
181
- "the review of a correct tree is refused because GitHub's PR object had not caught up",
182
- );
183
- // The other direction, which is #1168's own measured case: a worktree cut
184
- // from a stale remote-tracking ref leaves the tree AND the PR object on the
185
- // superseded sha, so a `prHead` compare reads EQUAL and admits it.
186
- assert.equal(
187
- typeof snapshotMissing({ path: SNAP, pathVerified: true, head: stale, refHead: rebased, prHead: stale }),
188
- "string",
189
- "a tree matching only the lagging PR object is admitted — the false pass #1168 removed",
190
- );
191
- });
192
-
193
- // The ACCEPT half, and the one this guard is most likely to get wrong. An
194
- // ABSENT `refHead` is not a mismatch: the ref read can still come back empty on
195
- // its own — an unreachable `origin`, or a read that failed — so turning missing
196
- // input into a refusal would let a network blip cancel a runnable review. That
197
- // is the rule `run-team/SKILL.md`'s phase-1 compare states as "an empty read is
198
- // neither equal nor a mismatch", here with a whole review behind it.
199
- // Absent and mismatching are different cases and stay different.
200
- //
201
- // A fork PR is NOT one of the absent cases any more (#1616), and it used to be
202
- // the whole class this refusal could never fire on: a fork's branch resolves
203
- // nowhere on `origin`, so the operand was permanently absent and a fork
204
- // snapshotted at the wrong commit was admitted in silence. The snapshot block
205
- // falls back to `refs/pull/<number>/head`, which the base repository carries
206
- // for fork-sourced and same-repo PRs alike, so a fork now reaches this compare
207
- // carrying its real head. What the fixture below pins is unchanged by that: a
208
- // snapshot with no ref head AT ALL still proceeds.
209
- //
210
- // The EMPTY read reaches the same verdict here whatever the guard does — `""`
211
- // is a prefix of every sha — so it is pinned where it is actually decidable:
212
- // the run-log test below, where a falsy `refHead` has to still NAME the skip.
213
- test("a snapshot with no refHead at all still proceeds", () => {
214
- assert.equal(
215
- snapshotMissing({ path: SNAP, head: "abc123", pathVerified: true }),
216
- null,
217
- "a missing refHead must not refuse an otherwise good snapshot",
218
- );
219
- });
220
-
221
- // #1129's whole value rests on one invariant: every consumer reads a tree
222
- // rooted under THIS run's own root. Before these three branches that invariant
223
- // was carried entirely by prompt prose asking the snapshot agent to copy
224
- // SNAPSHOT_DEST verbatim and not reconstruct it — and a refuter reverted that
225
- // paragraph and ran all 18 test files that read review-core.mjs, 276 tests, with
226
- // nothing turning red. Prose an agent is asked to obey is not an invariant.
227
- // These are, because the run root prefix is the caller's own string: a
228
- // reconstructed, stale, or mistranscribed path now costs the run instead of
229
- // sending six specialists into a tree that belongs to some other review.
230
- test("a report whose run root is not this run's is refused, naming both roots", () => {
231
- const reason = snapshotMissingRaw(
232
- { runRoot: "/scr/pr7/run-OTHER", path: "/scr/pr7/run-OTHER/snapshot-abc123", head: "abc123", pathVerified: true },
233
- "/scr/pr9/run-",
234
- );
235
- assert.equal(typeof reason, "string", "a run root outside the caller's prefix must yield a reason");
236
- assert.match(reason, /run-OTHER/, "the reason must name the root that was reported");
237
- assert.match(reason, /\/scr\/pr9\/run-/, "the reason must name the prefix it was measured against");
238
- });
239
-
240
- // The mistranscription this is really for: a path that is plausible, present,
241
- // and under a REAL run root — just not this run's. `pathVerified` cannot catch
242
- // it, because the tree it names genuinely exists.
243
- test("a snapshot path outside the reported run root is refused, naming both", () => {
244
- const reason = snapshotMissing({ path: `${PREFIX}99999999/snapshot-abc123`, head: "abc123", pathVerified: true });
245
- assert.equal(typeof reason, "string", "a path under a different run's root must yield a reason");
246
- assert.match(reason, /run-99999999/, "the reason must name the path that was reported");
247
- assert.match(reason, /ab12cd34/, "the reason must name this run's own root");
248
- });
249
-
250
- // A prefix test alone does not settle "under": a `..` segment carries the
251
- // prefix and resolves outside it. Asserted here rather than left to the prefix
252
- // check, which passes on every one of these.
253
- test("a snapshot path that climbs out of the run root with `..` is refused", () => {
254
- for (const path of [`${ROOT}/snapshot-abc/../../../etc`, `${ROOT}/snapshot-abc/..`]) {
255
- const reason = snapshotMissing({ path, head: "abc123", pathVerified: true });
256
- assert.equal(typeof reason, "string", `${path} carries the run root prefix and resolves outside it — it must yield a reason`);
257
- }
258
- });
259
-
260
- // The field cannot be silently omitted at the tool-call layer — the schema's
261
- // `required` covers that — but the pure function must not read silence as
262
- // "this run's tree" if that layer is ever bypassed, which is the same rule
263
- // `pathVerified` above follows.
264
- test("a report that omitted runRoot is refused, not assumed to be this run's", () => {
265
- const reason = snapshotMissingRaw({ path: SNAP, head: "abc123", pathVerified: true }, PREFIX);
266
- assert.equal(typeof reason, "string", "an absent runRoot must yield a reason");
267
- assert.match(reason, /`runRoot`/, "the reason no longer names runRoot as the missing field");
268
- });
269
-
270
- // The normal path, plus the abbreviation tolerance that keeps it normal.
271
- // `refHead` is 40 chars from `git ls-remote`; `head` is whatever the snapshot
272
- // for "the HEAD sha", and an agent may abbreviate it. Under a raw `!==` those
273
- // two matching shas compare unequal — which used to cost a diff and would now
274
- // cost the entire review, so the prefix tolerance is load-bearing in both
275
- // directions here in a way it was not before.
276
- test("a matching head proceeds, abbreviated on either side", () => {
277
- const full = "a".repeat(40);
278
- const ok = (snap) => snapshotMissing({ path: SNAP, pathVerified: true, ...snap });
279
- assert.equal(ok({ head: "abc123", refHead: "abc123" }), null, "an exact match must not be refused");
280
- assert.equal(ok({ head: full.slice(0, 7), refHead: full }), null, "an abbreviated head is the same commit");
281
- assert.equal(ok({ head: full, refHead: full.slice(0, 7) }), null, "and the same the other way round");
282
- // The tolerance must not swallow the case it sits beside: a genuinely
283
- // different sha still refuses, at short compare length too.
284
- assert.equal(
285
- typeof ok({ head: "abc1234", refHead: "abd" + "9".repeat(37) }),
286
- "string",
287
- "a different sha stays disqualifying however short the compare",
288
- );
289
- });
290
-
291
- // The refusal above raised the price of an unnormalized `head` from one diff to
292
- // the whole review: `refHead` is 40 lowercase hex from `git ls-remote`, `head`
293
- // is whatever an agent relayed for `git rev-parse HEAD`, and that command
294
- // prints a trailing newline. Measured before the fix: `"9e8ee3d\n"` against a
295
- // 40-char compare operand beginning `9e8ee3d` refused, naming two shas that
296
- // look identical.
297
- //
298
- // The normalization is a top-level statement rather than a function, so it is
299
- // lifted as TEXT and RUN. A presence pin would stay green on a normalization
300
- // that had stopped normalizing, which is the failure this test exists to catch.
301
- test("a relayed head is normalized before the refusal ever sees it", () => {
302
- // Anchored on the ASSIGNMENT, not on `.trim()`: anchoring on the operation
303
- // means a normalization that stops normalizing reads as one that was deleted,
304
- // and the assertions below never run to say what actually broke.
305
- const block = CODE.match(/if \(snap\) \{[^}]*snap\.head = [^}]*\}/);
306
- assert.ok(
307
- block,
308
- "no `if (snap) { … snap.head = … }` normalization ahead of snapshotMissing — it was deleted, or reshaped past what this pins",
309
- );
310
- assert.ok(
311
- CODE.indexOf(block[0]) < CODE.indexOf("const missingReason = snapshotMissing(snap, runRootPrefix);"),
312
- "the normalization runs AFTER the refusal — it can no longer keep a relay artifact from cancelling the review",
313
- );
314
- const normalize = new Function("snap", block[0]);
315
- const full = "deadbee" + "0".repeat(33);
316
- const after = (head, refHead) => {
317
- const snap = { path: SNAP, pathVerified: true, head, refHead };
318
- normalize(snap);
319
- return snapshotMissing(snap);
320
- };
321
- assert.equal(after("deadbee\n", full), null, "a rev-parse newline is a relay artifact, not a different commit");
322
- assert.equal(after(" deadbee ", full), null, "and neither is surrounding whitespace");
323
- assert.equal(after("DEADBEE", full), null, "and neither is case");
324
- // The tolerance must not swallow the case it sits beside, here either.
325
- assert.equal(typeof after("cff7330", full), "string", "a genuinely different sha still refuses after normalizing");
326
- // The OPERAND side, which the four rows above cannot reach: `refHead` arrives
327
- // through the same agent relay as `head`, and the rows above hand it a clean
328
- // 40-char sha, so every one of them stays green with `refHead`'s own pass
329
- // deleted. A leading space is what actually costs the review — the prefix
330
- // tolerance absorbs a TRAILING one on the longer side, so a trailing-newline
331
- // row would be green either way and pin nothing.
332
- assert.equal(
333
- after("deadbee", ` ${full}`),
334
- null,
335
- "a leading space on the ls-remote read cancels the review of a matching tree — `refHead` is not being normalized",
336
- );
337
- assert.equal(after("deadbee", full.toUpperCase()), null, "and neither is case, on the operand side either");
338
- const absent = { path: SNAP, pathVerified: true, head: "deadbee" };
339
- normalize(absent);
340
- assert.equal(snapshotMissing(absent), null, "normalizing must not invent a refHead the snapshot agent never sent");
341
- // `prHead` stopped being an operand in #1513, so no refusal can observe its
342
- // normalization any more — and the run log below is the only remaining reader
343
- // of the field, where a relayed newline splits one record into two. Asserting
344
- // the block's own output is the only place that pass is observable at all; a
345
- // `prHead` dropped from it leaves this green only by being deleted here too.
346
- const relayed = { path: SNAP, pathVerified: true, head: "deadbee", prHead: " CAFE123\n" };
347
- normalize(relayed);
348
- assert.equal(
349
- relayed.prHead,
350
- "cafe123",
351
- "the PR-object head reaches the run log with the relay's whitespace and case still on it",
352
- );
353
- // A dead snapshot agent returns falsy, and `snapshotMissing`'s first guard is
354
- // what names that. Normalizing must not beat it to the dereference.
355
- assert.doesNotThrow(() => normalize(null), "a falsy snap must reach snapshotMissing's own guard, not a TypeError here");
356
- });
357
-
358
- // `snapshotMissing`'s head compare is guarded on `snap.refHead &&`, so a failed
359
- // `ls-remote` skips the refusal — deliberately, per the test above — and the
360
- // run log used to be BYTE-IDENTICAL to a run where the two heads were compared
361
- // and matched. That is the #532 case with the evidence removed: a wrong-commit
362
- // review and a verified one read the same afterwards. Measured by running the
363
- // log statement itself, not by matching its source, so a line that stops
364
- // distinguishing the two reds here.
365
- test("the snapshot log line says when the head check was skipped", () => {
366
- const line = CODE.split("\n").find((l) => l.trim().startsWith("log(`snapshot "));
367
- assert.ok(line, "the snapshot run-log line is gone — the whole diff decision below it is unobservable without it");
368
- const say = (snap) => {
369
- let out;
370
- new Function("snap", "log", line)(snap, (m) => (out = m));
371
- return out;
372
- };
373
- const skipped = say({ path: SNAP, head: "deadbee" });
374
- const checked = say({ path: SNAP, head: "deadbee", refHead: "deadbee" + "0".repeat(33) });
375
- assert.notEqual(skipped, checked, "a skipped head check and a passed one log the same line — the two runs cannot be told apart");
376
- assert.match(skipped, /SKIPPED/, "the skip must be NAMED, not left to be inferred from a field the line does not print");
377
- // The EMPTY read, which is where this line's fallback and the compare's own
378
- // guard have to agree. `ls-remote` exits 0 and prints nothing when no ref
379
- // matches, and the compare tests TRUTHINESS — so a `??` fallback here printed
380
- // a blank where the skip belongs, and the run read as one where both heads
381
- // were compared and matched. The prompt asks the agent to omit the field
382
- // instead of reporting `""`, but prose is not the enforcement.
383
- assert.match(
384
- say({ path: SNAP, head: "deadbee", refHead: "" }),
385
- /SKIPPED/,
386
- "an empty ref read prints as a blank rather than naming the skip — the compare skipped and the log says it ran",
387
- );
388
- // #1513 left `prHead` reported but no longer compared. This line records it
389
- // first; the no-diff diagnostic below repeats it when the diff is rejected,
390
- // but nothing downstream compares it against the ref to detect the desync
391
- // itself — the PR-object desync `run-merge-bot.md`'s step 1 hands to a
392
- // controller. Dropping it from this line loses the fact silently, with the
393
- // refusal and the skip both still behaving exactly as they do here.
394
- const desynced = say({
395
- path: SNAP,
396
- head: "deadbee",
397
- refHead: "deadbee" + "0".repeat(33),
398
- prHead: "c774756" + "0".repeat(33),
399
- });
400
- assert.match(
401
- desynced,
402
- /c774756/,
403
- "the PR object's head is not printed — a run where it lagged the ref is indistinguishable from one where it agreed",
404
- );
405
- });
406
-
407
- // Bound at both ends via prose-pin.mjs's between() — an unbounded end lets the
408
- // specialist and refuter prompts further down satisfy the assertions instead,
409
- // the defect `review-core-testcmd.test.mjs`'s "the test-run prompt hands the
410
- // command over verbatim and rules 'tests 0' a failure" test records having
411
- // shipped. Same two anchors `review-core-reads.test.mjs`'s `slice()` and
412
- // `review-core-testcmd.test.mjs` already use.
413
- function snapshotBlock() {
414
- return between(CODE, "const snap = await agent(", "if (snap) {", "the snapshot agent dispatch");
415
- }
416
-
417
- // Every test above runs against the lifted `snapshotMissing`, which decides what
418
- // to do with `pathVerified` but never produces it. The thing that produces it is
419
- // two lines of review-core.mjs — a shell probe and the sentence binding the field
420
- // to that probe's output — and neither was pinned. Delete either and
421
- // `required: [..., "pathVerified"]` still passes, all four tests above still
422
- // pass, and the agent has lost the only instruction saying what value to report:
423
- // `pathVerified` degrades to a boolean it invents, silently reopening #140 under
424
- // a green suite. That is the exact shape `review-core-reads.test.mjs`'s "the
425
- // snapshot agent asks for the diff facts AND declares them in its schema"
426
- // measured on the diff facts — "deleting this paragraph outright left this file
427
- // at 12 pass, 0 fail".
428
- test("the snapshot prompt runs the emptiness probe AND binds pathVerified to its output", () => {
429
- const snapshot = snapshotBlock();
430
- assert.match(
431
- snapshot,
432
- /\[ -n "\$\(ls -A "\$SNAP"\)" \] && echo SNAPSHOT_NONEMPTY \|\| echo SNAPSHOT_EMPTY/,
433
- "the emptiness probe is gone — nothing mechanical stands behind pathVerified",
434
- );
435
- // These names live inside a template literal, so each backtick is a
436
- // BACKSLASH-backtick in the source text — `\\?` matches it either way, the
437
- // idiom review-core-reads.test.mjs and review-core-testcmd.test.mjs already use.
438
- // `\s+` spans the line wraps so a reflow of the same sentence stays green.
439
- const B = "\\\\?`";
440
- assert.match(
441
- snapshot,
442
- new RegExp(`Report\\s+${B}pathVerified${B}\\s+=\\s+true\\s+ONLY\\s+if\\s+the\\s+'ls -A'\\s+line\\s+printed\\s+SNAPSHOT_NONEMPTY`),
443
- "pathVerified is no longer bound to the probe's output — the agent may report whatever it likes",
444
- );
445
- });
446
-
447
- // The instruction that makes the round trip work at all, and the one thing in
448
- // #1129 that nothing held down: `snapshotMissing` REFUSES a reconstructed path,
449
- // but only this paragraph makes the agent report a correct one in the first
450
- // place. Delete it and every review still refuses — loudly, and having spent a
451
- // snapshot agent to get there. Measured on the pre-check version of this
452
- // paragraph: a refuter reverted it to the pre-#1129 wording and ran all 18 test
453
- // files that read review-core.mjs, and nothing turned red.
454
- //
455
- // So this pins the instruction, and the check pins the outcome. Neither
456
- // substitutes for the other: prose an agent is asked to obey is not an
457
- // invariant, and a refusal is not a working review.
458
- test("the snapshot prompt tells the agent to copy both printed values verbatim, never to reconstruct them", () => {
459
- const snapshot = snapshotBlock();
460
- const B = "\\\\?`";
461
- for (const [re, gone] of [
462
- [
463
- new RegExp(`Report\\s+${B}runRoot${B}\\s+=\\s+the\\s+SNAPSHOT_RUN_ROOT\\s+value`),
464
- "the agent is no longer told to report `runRoot` off the printed SNAPSHOT_RUN_ROOT — the caller's containment check now refuses every run instead of catching a wrong one",
465
- ],
466
- [
467
- new RegExp(`${B}path${B}\\s+=\\s+the\\s+SNAPSHOT_DEST\\s+value`),
468
- "the agent is no longer told to report `path` off the printed SNAPSHOT_DEST",
469
- ],
470
- [
471
- // phrase(), not a literal: the sentence wraps in the source, so a plain
472
- // space between "the" and "block" matches nothing and the pin reds on
473
- // prose that is present and correct.
474
- phrase("do not reconstruct it, and do not report a path the block did not print"),
475
- "the prohibition on reconstructing the destination is gone — both values end in components the shell substituted, so an agent invited to guess produces a path that reads plausible and belongs to no run",
476
- ],
477
- ]) {
478
- assert.match(snapshot, re, gone);
479
- }
480
- });
481
-
482
- // The ORDER is the guard, not the probe, and two different reorderings each
483
- // defeat it. Measured, both:
484
- // probe AFTER the symlink -> `ls -A` counts the symlink, so a `git archive`
485
- // that extracted NOTHING still prints SNAPSHOT_NONEMPTY, in every repo that
486
- // has node_modules (which is every repo the symlink exists for).
487
- // probe AFTER the `git init` -> the same thing one directory entry later, and
488
- // in EVERY repo rather than only the ones with node_modules: `.git` alone
489
- // makes `ls -A` non-empty (#1056).
490
- // guard MISSING -> the `find` deletes, so an empty `scratch` sends it at
491
- // '/pr<N>' — the directory this block's own `mkdir -p "${runRootParent}"`
492
- // creates — so what the guard buys is a NAMED refusal, not containment.
493
- // prune MISSING -> nothing ever removes a run root and the scratch tree grows
494
- // without bound (#1083). No probe here can see it: the growth is in SIBLING
495
- // roots and this run's own snapshot is perfectly good, which is why
496
- // `snapshot-repo.test.mjs` executes the prune against fixtures instead.
497
- // prune ABOVE the `mkdir -p` -> on a PR's first review the parent does not
498
- // exist yet, so `find` fails and a healthy run prints SNAPSHOT_PRUNE_FAILED,
499
- // training a reader to ignore the marker. That is POSITION, not presence, so
500
- // this pin is the one that catches it and the executed one cannot.
501
- // The two probe reorderings end the same way: the agent honestly reports
502
- // `pathVerified: true`, because that is what it was told to report. Hence a
503
- // sequence pin, not a presence pin — every one of these lines is in the right
504
- // place or the guard is decorative. The destination itself needs no wipe to
505
- // pin any more; #1129 measured what one cost (reviewing prB, the snapshot held
506
- // prA's file, across two PRs sharing one scratch) and retired it by making the
507
- // destination per-run instead of re-bounding it.
508
- //
509
- // #1129 moved the destination off `${scratch}/snapshot` and onto a per-run root
510
- // the SHELL mints, so the needles below address `$RUN` and `$SNAP`. The order is
511
- // the guard: an assignment that moved below its readers would leave them
512
- // addressing an unset (empty) variable, and one command still spelling the old
513
- // bare path would be a second destination this pin says nothing about.
514
- //
515
- // The needles are REGEXES, and every one that spans a shell word tolerates an
516
- // optional quote around it. A literal-substring needle pinned one arbitrary
517
- // quote placement: adding quotes to the `SNAP=` assignment — a no-op on the
518
- // right-hand side of a bash assignment, and what a shellcheck pass suggests —
519
- // red this test with a message claiming a #1129 collision regression that had
520
- // not happened. A pin that reds on correct changes gets weakened by the next
521
- // reader, so these match the shape that decides behaviour and nothing else.
522
- test("the snapshot block mints a per-run destination, then extracts, probes, and symlinks — in that order", () => {
523
- const snapshot = snapshotBlock();
524
- let prev = -1;
525
- for (const [needle, gone] of [
526
- [
527
- /unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_TEMPLATE_DIR/,
528
- "the ambient git vars are no longer cleared before this block runs — an inherited GIT_DIR/GIT_WORK_TREE/GIT_INDEX_FILE/GIT_TEMPLATE_DIR can retarget the SHA capture, the archive, the tree-hash compare, or the init's template silently, and nothing downstream in the block catches it (#1056)",
529
- ],
530
- [
531
- /\[ -n "\$\{scratch\}" \] \|\| \{ echo SNAPSHOT_SCRATCH_UNSET/,
532
- "the empty-scratch guard is gone — an empty interpolation now creates this run's artefacts at `/` instead of refusing by name",
533
- ],
534
- [
535
- /mkdir -p "?\$\{runRootParent\}"?/,
536
- "the run root's parent is no longer created — `mktemp -d` has nowhere to mint into and every run dies at the same line",
537
- ],
538
- [
539
- /RUN=\$\(mktemp -d "?\$\{runRootPrefix\}X{3,}"?\)/,
540
- "the run root is no longer minted by `mktemp -d` under the prefix the caller owns — two reviews sharing one scratch can collide again (#1129)",
541
- ],
542
- [
543
- /echo SNAPSHOT_RUN_ROOT="?\$RUN"?/,
544
- "the run root is never printed — the agent cannot report a `runRoot` it can no longer read off this prompt, and the caller's containment check has nothing to check",
545
- ],
546
- [
547
- /find "?\$\{runRootParent\}"?[^\n]*\|\| echo SNAPSHOT_PRUNE_FAILED/,
548
- "the stale-run-root prune is gone or no longer refuses by name — every review leaves a tree nothing removes (#1083), and `snapshot-repo.test.mjs`'s executed prune test is where its behaviour is measured",
549
- ],
550
- [
551
- /SHA=\$\(git -C \$\{worktree\} rev-parse --short HEAD\)/,
552
- "the archived commit is no longer captured into its own variable — a rev-parse failure goes back to shortening the destination silently",
553
- ],
554
- [
555
- /SNAP="?\$RUN\/snapshot-\$SHA"?/,
556
- "the destination is no longer this run's root plus the archived commit — it addresses something the run does not own",
557
- ],
558
- [
559
- /echo SNAPSHOT_DEST="?\$SNAP"?/,
560
- "the destination is never printed — the agent cannot report a path it can no longer read off this prompt",
561
- ],
562
- [/mkdir -p "?\$SNAP"?/, "the mkdir is gone — `tar -x` has nowhere to extract to"],
563
- [/git -C \$\{worktree\} archive HEAD/, "the archive is gone — there is no snapshot to review"],
564
- [/\[ -n "\$\(ls -A "\$SNAP"\)" \]/, "the emptiness probe is gone — nothing mechanical stands behind pathVerified"],
565
- [
566
- /\( cd "\$SNAP" && git init -q/,
567
- "the snapshot is no longer made a git repository — a bare extraction leaves it unmeasurable, and repo-needing tests silently skip or fail there (#1056)",
568
- ],
569
- [
570
- /git init -q && git add -A -f/,
571
- "the init no longer force-adds — a file a repo's own .gitignore covers is tracked at HEAD and present in the extraction, so plain `git add` leaves it out and the tree hash cannot match",
572
- ],
573
- [
574
- /commit -q --no-verify/,
575
- "the snapshot commit is gone — an index alone gives no HEAD, so nothing can compare the snapshot's tree against the reviewed commit's",
576
- ],
577
- [
578
- /SNAPTREE=\$\(git -C "?\$SNAP"? rev-parse 'HEAD\^\{tree\}'/,
579
- "the snapshot's own tree hash is never read — `repoVerified` has nothing mechanical behind it",
580
- ],
581
- [
582
- /echo SNAPSHOT_TREE_MATCH \|\| echo SNAPSHOT_TREE_MISMATCH/,
583
- "the tree compare no longer names its two outcomes — a failed init or a snapshot that is not the reviewed tree goes back to being reported as a verified environment",
584
- ],
585
- [/ln -s \$\{worktree\}\/node_modules/, "the node_modules symlink is gone — a derived `npm test --` cannot run"],
586
- ]) {
587
- const at = snapshot.search(needle);
588
- assert.notEqual(at, -1, gone);
589
- assert.ok(
590
- at > prev,
591
- `${needle} is out of sequence — the block must mint the run root, derive the destination, then extract, then probe, then symlink`,
592
- );
593
- prev = at;
594
- }
595
- });
596
-
597
- // Both failure clauses, pinned where they are decided. Neither 'mktemp' nor
598
- // 'rev-parse' failing stops the block on its own: each contributes a path
599
- // component, so an unread failure does not abort, it SHORTENS "$SNAP" to a path
600
- // another run could also produce — the collision this ticket closes, arriving by
601
- // a different route. The `|| { echo …; exit 1; }` is what makes each a named
602
- // refusal instead of an empty string.
603
- test("the run root and the sha each refuse by name rather than shortening the destination", () => {
604
- const snapshot = snapshotBlock();
605
- for (const [needle, gone] of [
606
- [/mktemp -d [^\n]*\|\| \{ echo SNAPSHOT_RUNROOT_FAILED; exit 1; \}/, "a failed `mktemp -d` no longer refuses by name — `$RUN` goes empty and every path below collapses to its suffix"],
607
- [/rev-parse --short HEAD\) \|\| \{ echo SNAPSHOT_REVPARSE_FAILED; exit 1; \}/, "a failed `rev-parse` no longer refuses by name — the sha goes empty and the destination stops naming the commit it holds"],
608
- ]) {
609
- assert.match(snapshot, needle, gone);
610
- }
611
- });
612
-
613
- // #1129. The destination used to be `scratch` plus a fixed literal, so two runs
614
- // handed one scratch root resolved to ONE absolute path — and the block wiped
615
- // its destination before extracting, so the second review deleted the tree the
616
- // first review's fix-applier was still citing. Nothing failed: the path still
617
- // existed, still held a plausible checkout of this repo, and answered a read
618
- // with another PR's code. Observed live, worked around by hand-feeding each
619
- // review a different scratch root.
620
- //
621
- // The per-run segment is minted by the SHELL, so the AC-1 property — two runs
622
- // never share a root — is a property of `mktemp -d`, not of any expression in
623
- // review-core.mjs. It is asserted by RUNNING the two lines that mint it, for the
624
- // reason the executed derivation it replaces gives: a presence pin over
625
- // `mktemp` would stay green on a block that had stopped varying. Only the lines
626
- // up to SNAPSHOT_RUN_ROOT are lifted — `mkdir`, `mktemp` and the echo, and the
627
- // block prints the root ahead of the sha precisely so those three stand alone.
628
- // So this needs no git at all, which is worth keeping even now that the review
629
- // snapshot is one: a test that shells out to git in the snapshot depends on the
630
- // very mechanism under review here (#1056), so a regression in the init would
631
- // surface as this pin failing on its environment instead of on the block it
632
- // pins. `snapshot-repo.test.mjs` is where git IS exercised, against fixture
633
- // repositories it builds itself. What the rest of the block does is pinned by
634
- // the sequence test.
635
- function mintScript(scratch) {
636
- const snapshot = snapshotBlock();
637
- const from = snapshot.search(/^ *mkdir -p "?\$\{runRootParent\}"?/m);
638
- const runRootLine = snapshot.search(/^ *echo SNAPSHOT_RUN_ROOT=/m);
639
- assert.ok(from !== -1, "the snapshot block no longer creates the run root's parent — this test lifts lines that are gone");
640
- assert.ok(runRootLine > from, "the snapshot block no longer prints SNAPSHOT_RUN_ROOT below the mint — this test lifts lines that are gone");
641
- const lines = snapshot.slice(from, snapshot.indexOf("\n", runRootLine));
642
- // Rendered, not string-replaced: the lines carry `${runRootParent}` and
643
- // `${runRootPrefix}` exactly as review-core.mjs interpolates them, and the two
644
- // are derived here by the same expressions the script uses — lifted below —
645
- // so a change to either derivation reaches this test instead of being
646
- // re-spelled in it.
647
- const derive = deriveRunRoot();
648
- const { runRootParent, runRootPrefix } = derive(scratch, 1129);
649
- return new Function("runRootParent", "runRootPrefix", "return `" + lines + "`")(runRootParent, runRootPrefix);
650
- }
651
-
652
- // The prefix is the half the SCRIPT still owns — it is what `snapshotMissing`
653
- // checks the reported root against — so it is lifted as TEXT and RUN, the idiom
654
- // the `snap.head` normalization above already uses. The `.match()` is guarded
655
- // and lives INSIDE the helper, never at module scope, so a reformat that
656
- // defeats the anchor reds named tests instead of taking the whole file down
657
- // before any of them registers.
658
- function deriveRunRoot() {
659
- const block = CODE.match(/^\s*const runRootParent = .+\n\s*const runRootPrefix = .+$/m);
660
- assert.ok(
661
- block,
662
- "review-core.mjs no longer derives `runRootParent` and `runRootPrefix` as adjacent top-level statements — the run root the caller owns was deleted, or reshaped past what this lifts",
663
- );
664
- assert.ok(
665
- CODE.indexOf(block[0]) < CODE.indexOf("const snap = await agent("),
666
- "the run root prefix is derived BELOW the snapshot dispatch that interpolates it",
667
- );
668
- return new Function("scratch", "pr", `${block[0]}\nreturn { runRootParent, runRootPrefix };`);
669
- }
670
-
671
- // AC-1, executed rather than read: two runs differing in nothing at all, both
672
- // minting into one scratch root. This is the half a per-PR path does NOT fix and
673
- // the one measured under #140 — one PR reviewed twice used to be one path twice,
674
- // so a re-review landed on the tree a live consumer of the first review was
675
- // citing.
676
- test("two review runs sharing one scratch root never mint the same artefact root", () => {
677
- const scratch = mkdtempSync(join(tmpdir(), "review-pr-mint-"));
678
- try {
679
- const run = () => {
680
- const out = execFileSync("sh", ["-c", mintScript(scratch)], { encoding: "utf8" });
681
- const m = out.match(/^SNAPSHOT_RUN_ROOT=(.+)$/m);
682
- assert.ok(m, `the mint printed no SNAPSHOT_RUN_ROOT line: ${JSON.stringify(out)}`);
683
- return m[1];
684
- };
685
- const roots = Array.from({ length: 8 }, run);
686
- assert.equal(
687
- new Set(roots).size,
688
- roots.length,
689
- `re-reviewing ONE PR minted a repeated artefact root — ${roots[0]} came back more than once, so a second review of the same PR still overwrites the first's tree`,
690
- );
691
- for (const root of roots) {
692
- assert.ok(statSync(root).isDirectory(), `${root} was reported but never created — a name alone cannot stop two runs meeting, only a directory that exists can`);
693
- // AC-2's PR half: a path that does not say which PR it holds is one a
694
- // consumer cannot tell a stale reference from a current one by reading.
695
- assert.match(root, /\/pr1129\/run-/, "the artefact root no longer names the PR — the roots are distinct but anonymous");
696
- }
697
- } finally {
698
- rmSync(scratch, { recursive: true, force: true });
699
- }
700
- });
701
-
702
- // The ACCEPT case, and the class this change could wrongly BREAK. Everything
703
- // downstream — the diff redirect, the specialists' own directories, the
704
- // controller that provisioned the root and expects to find the run's artefacts
705
- // beneath it — assumes what a run writes lands under the scratch argument it was
706
- // given. A mint that "fixed" collisions by putting artefacts somewhere unique
707
- // but OUTSIDE that root would satisfy the assertion above and break every one of
708
- // those consumers, so the containment is asserted in its own right.
709
- test("a run's artefact root stays under the scratch root the caller provisioned", () => {
710
- const derive = deriveRunRoot();
711
- for (const scratch of ["/scr", "/run/scratch", "/tmp/claude-501/session/scratchpad"]) {
712
- const { runRootPrefix } = derive(scratch, 1129);
713
- assert.ok(
714
- runRootPrefix.startsWith(`${scratch}/`),
715
- `a run under ${scratch} writes to ${runRootPrefix}, outside the root the caller provisioned — a caller that cleans up or inspects its own scratch root now finds nothing there`,
716
- );
717
- // A prefix alone does not settle "under": `/scr/../elsewhere` carries it and
718
- // resolves outside. Same escape the "a snapshot path that climbs out of the
719
- // run root with `..` is refused" test asserts of a reported path.
720
- assert.doesNotMatch(runRootPrefix, /\/\.\.(\/|$)/, `${runRootPrefix} climbs out of the provisioned root with a \`..\` segment`);
721
- }
722
- });
723
-
724
- // AC-6, and the pin that reds on a revert of ANY of the four artefact sites
725
- // rather than only the snapshot's. `${scratch}` reaching a path directly is the
726
- // whole defect: the snapshot, the captured diff behind `diffPath`, each
727
- // specialist's directory and each refuter's were all spelled that way, and
728
- // fixing one leaves the others colliding. Stated as a property over the source
729
- // rather than as a list of four expected paths, so an artefact added later is
730
- // covered without this test being remembered.
731
- //
732
- // The derivation itself is the one legitimate occurrence — it is where the
733
- // caller's root is consumed — so it is excluded by identity, not by counting.
734
- test("no artefact path is spelled off the bare scratch argument — every one hangs off the per-run root", () => {
735
- const offending = CODE.split("\n").filter((l) => l.includes("${scratch}/") && !l.includes("const runRootParent ="));
736
- assert.deepEqual(
737
- offending,
738
- [],
739
- `these lines still build a path from the caller's scratch argument directly, so two reviews in one session share it:\n ${offending.join("\n ")}`,
740
- );
741
- // The other direction: an empty list must not be satisfied by the derivation
742
- // having been deleted along with everything it fed. Bound to the derivation
743
- // CONSUMING the caller's root, not to its shape — pinning the literal here
744
- // would red this test on every reshaping the tests above already judge on
745
- // their own terms, which makes a failure say nothing about which property
746
- // broke.
747
- assert.ok(
748
- CODE.split("\n").some((l) => l.includes("const runRootParent =") && l.includes("${scratch}/")),
749
- "the run root no longer derives from the caller's scratch argument at all — the empty list above is vacuous",
750
- );
751
- });
752
-
753
- // The function is worthless if nothing calls it, and every test above tests a
754
- // COPY lifted from the source text: it stays green while the feature
755
- // disconnects. `review-core-testcmd.test.mjs`'s "runReview actually calls
756
- // resolveTestCmd once the snapshot is validated" records this exact defect for
757
- // resolveTestCmd, and `select-dimensions.test.mjs`'s "actually calls
758
- // resolveDimensions" pin does for the fan-out.
759
- // Delete the `snapshotMissing(snap)` call and its `throw` in review-core.mjs and
760
- // #140's refusal is dead code with this whole file green.
761
- test("runReview actually calls snapshotMissing and throws on its result", () => {
762
- assert.match(
763
- CODE,
764
- /^\s*const missingReason = snapshotMissing\(snap, runRootPrefix\);$/m,
765
- "the snapshotMissing call site changed — the #140 guard may be disconnected",
766
- );
767
- assert.match(
768
- CODE,
769
- /^\s*if \(missingReason\) throw new Error\(/m,
770
- "snapshotMissing's result is computed but never thrown on — the guard decides nothing",
771
- );
772
- // Ordering, same guardAt/callAt shape as review-core-testcmd.test.mjs's
773
- // "runReview actually calls resolveTestCmd once the snapshot is validated":
774
- // after the schema that produces `pathVerified`, and before the first thing
775
- // that reads `snap` — `resolveTestCmd`, which would otherwise derive a command
776
- // for a tree that was never confirmed to exist.
777
- const schemaAt = CODE.indexOf('required: ["runRoot", "path", "head", "pathVerified", "repoVerified"]');
778
- const callAt = CODE.indexOf("const missingReason = snapshotMissing(snap, runRootPrefix);");
779
- const testCmdAt = CODE.indexOf("const testCmd = resolveTestCmd(");
780
- assert.ok(schemaAt !== -1 && testCmdAt !== -1, "the schema or the resolveTestCmd call moved — update this test");
781
- assert.ok(schemaAt < callAt, "the guard runs above the schema that produces pathVerified");
782
- assert.ok(callAt < testCmdAt, "resolveTestCmd reads snap before the guard has cleared it");
783
- });
784
-
785
- // `usableDiff` carries no head check of its own (#1132), so a diff for a
786
- // head/refHead-skewed snapshot is safe only because the refusal above is FATAL
787
- // before any specialist is dispatched (#2203). The tests above pin the parts:
788
- // the unit tests red on a `refHead` clause gone from `snapshotMissing`, and the
789
- // text pin reds on a deleted `throw` or one replaced by a log. Neither notices a
790
- // throw softened while its text survives — wrapped in a `try` whose `catch`
791
- // logs — and a text pin on call ORDER would red on a reorder that dispatches
792
- // nothing while missing that. So this drives the real `runReview` and asserts
793
- // on what was dispatched.
794
- //
795
- // Asserted on `calls`, not only on the rejection: an unscripted label does
796
- // throw `unexpected dispatch`, but the fixture's `pipeline` swallows a stage
797
- // throw into `null`, so that throw alone would fail nothing. `scriptedHost`
798
- // counts a dispatch before it looks the label up, so `calls` sees every one.
799
- //
800
- // The fixture's `path` ends in `snapshot-abc123`, and the refusal quotes the
801
- // path, so a path that does not carry the head keeps `/abc123/` below reading
802
- // the sha the message reports rather than the path it quotes.
803
- function runWithRefHead(refHead) {
804
- const path = `${HOST_SNAP.runRoot}/snapshot-tree`;
805
- const snap = { ...HOST_SNAP, path, refHead, diffPath: `${HOST_SNAP.runRoot}/pr.diff`, diffLines: 40 };
806
- const { host, calls } = scriptedHost({ snapshot: [snap], "review:correctness": [review([])] });
807
- return { run: runReview({ ...host, pipeline, parallel }, ARGS), calls };
808
- }
809
-
810
- test("a head/refHead-skewed snapshot is refused before any specialist or refuter is dispatched", async () => {
811
- assert.equal(HOST_SNAP.head, "abc123", "the fixture's head changed — update this test's expected sha");
812
- const { run, calls } = runWithRefHead("9e8ee3d");
813
- await assert.rejects(run, (err) => {
814
- assert.match(err.message, /abc123/, "the refusal must name the commit the tree is at");
815
- assert.match(err.message, /9e8ee3d/, "the refusal must name the PR head it was measured against");
816
- return true;
817
- });
818
- assert.equal(calls.snapshot, 1, "the snapshot agent is the one dispatch that precedes the refusal");
819
- const leaked = Object.keys(calls).filter((label) => /^(review|verify):/.test(label));
820
- assert.deepEqual(leaked, [], "a skewed snapshot reached a specialist or refuter");
821
- });
822
-
823
- // The control: the identical snapshot with the heads agreeing is admitted and
824
- // reaches the specialist, so the refusal above comes from the head compare and
825
- // not from some other field of the fixture that `snapshotMissing` refuses.
826
- test("the same snapshot with refHead matching head reaches the specialist", async () => {
827
- const { run, calls } = runWithRefHead(HOST_SNAP.head);
828
- await run;
829
- assert.equal(calls["review:correctness"], 1, "an admitted snapshot must dispatch its specialist exactly once");
830
- });