@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,1006 +0,0 @@
1
- // #1056. The review snapshot was cut with `git archive HEAD | tar -x` and
2
- // nothing more, so it was not a git repository — and this repo's suite has
3
- // whole files that ask git what ships rather than walking the directory, which
4
- // need a `.git` at or above them. Measured at `ffa9026`, one commit three ways,
5
- // `env -u FORCE_COLOR node --test` from each tree's root:
6
- //
7
- // a worktree tests 2401 pass 2401 fail 0 skipped 0
8
- // a bare `git archive` extraction tests 2401 pass 2382 fail 0 skipped 19
9
- // an extraction this block initialized tests 2401 pass 2401 fail 0 skipped 0
10
- //
11
- // The middle row is what every dimension used to report: the same `tests`
12
- // total, `fail 0`, and 19 checks that never ran — invisible, because a total
13
- // that matches reads as a suite that ran. Before those files learned to decline
14
- // (#1149) the same cause hard-FAILED them instead, and two dimensions in one
15
- // run filed nothing at all over a red they could not attribute.
16
- //
17
- // EXECUTED, not text-pinned, and that distinction is the whole point of this
18
- // file: `review-core-snapshot-path.test.mjs` pins the block's lines and their
19
- // ORDER as text, which stays green on a sequence that is spelled right and does
20
- // not work — a `git add` that skips a tracked-but-ignored file, an init that a
21
- // stale `GIT_DIR` sends elsewhere, a commit an unconfigured identity refuses.
22
- // Each of those is a real environment an unattended snapshot agent runs in, and
23
- // none of them is visible in the source text. So every test below RUNS the
24
- // block's own lines, lifted from review-core.mjs, against a fixture
25
- // repository it builds itself.
26
- //
27
- // Fixtures only: every test here builds its own repository under `$TMPDIR`, so
28
- // none of them needs an ambient working tree and none declines in an extraction
29
- // (the condition this ticket is about). The one thing they need is `git`.
30
- //
31
- // Zero deps: `node --test plugin/scripts/snapshot-repo.test.mjs`.
32
- import { test } from "node:test";
33
- import assert from "node:assert/strict";
34
- import { execFileSync, spawnSync } from "node:child_process";
35
- import { chmodSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
36
- import { tmpdir } from "node:os";
37
- import { dirname, join } from "node:path";
38
- import { environmentNote } from "./review-core.mjs";
39
- import { between, phrase } from "./prose-pin.mjs";
40
- import { stripComments } from "./strip-comments.mjs";
41
- import { writeExecStub } from "./exec-stub.mjs";
42
-
43
- const REPO = join(import.meta.dirname, "..");
44
- const SOURCES = [["scripts/review-core.mjs", join(REPO, "scripts", "review-core.mjs")]];
45
-
46
- // Every git identity is scrubbed — both config files and all four `GIT_*` name
47
- // and email variables — so the commit the block takes can only be the one the
48
- // block's own `-c user.name`/`-c user.email` supply. That does NOT make the
49
- // commit impossible without them: measured here, git auto-detects an identity
50
- // from the OS and committed as `Christian Ziegler <chris@Mac.fritz.box>` with
51
- // both config files pointed at /dev/null
52
- // (`env -u GIT_AUTHOR_NAME … GIT_CONFIG_GLOBAL=/dev/null git commit`). So the
53
- // flags are pinned by the AUTHOR assertion below rather than by a refusal:
54
- // unflagged, a review stamps whoever's machine ran it onto a commit nobody
55
- // wrote, and on a host whose name gives git no address it can form the commit
56
- // fails outright instead.
57
- //
58
- // `GIT_DIR`/`GIT_WORK_TREE`/`GIT_INDEX_FILE` are cleared for a different
59
- // reason: inherited, `git init` exits 0 and creates nothing in the target, so a
60
- // fixture built under an ambient GIT_DIR would be no repository at all while
61
- // every status check passed (repo-root.test.mjs's own measurement).
62
- // `GIT_TEMPLATE_DIR` joins them (#1056): an ambient template directory with no
63
- // `info/` subdirectory makes `git init` produce no `.git/info`, so the block's
64
- // `.git/info/exclude` append silently fails and every fixture below would be
65
- // measuring the ambient host's template instead of the hazard this file
66
- // exists to catch.
67
- const ENV = {
68
- ...process.env,
69
- GIT_DIR: undefined,
70
- GIT_WORK_TREE: undefined,
71
- GIT_INDEX_FILE: undefined,
72
- GIT_TEMPLATE_DIR: undefined,
73
- GIT_AUTHOR_NAME: undefined,
74
- GIT_AUTHOR_EMAIL: undefined,
75
- GIT_COMMITTER_NAME: undefined,
76
- GIT_COMMITTER_EMAIL: undefined,
77
- GIT_CONFIG_GLOBAL: "/dev/null",
78
- GIT_CONFIG_SYSTEM: "/dev/null",
79
- };
80
-
81
- const git = (dir, ...args) => execFileSync("git", ["-C", dir, ...args], { env: ENV, encoding: "utf8" }).trim();
82
-
83
- function scratch(t, prefix) {
84
- const dir = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
85
- t.after(() => rmSync(dir, { recursive: true, force: true }));
86
- return dir;
87
- }
88
-
89
- /**
90
- * A repository standing in for the worktree under review. Deliberately carries
91
- * the three shapes that separate a faithful snapshot from a plausible one: a
92
- * nested path, an executable bit, and a file this repo's own `.gitignore`
93
- * covers while git tracks it anyway — legal, present in `git archive`'s output,
94
- * and skipped by a plain `git add`.
95
- *
96
- * `exportIgnore` marks one tracked file `export-ignore`, which is the one way a
97
- * `git archive` legitimately does NOT carry the whole tree. That fixture is the
98
- * honest-refusal case, not a bug to fix: the snapshot really is not the
99
- * reviewed tree, and the block has to say so rather than report a match.
100
- */
101
- function reviewedRepo(t, { exportIgnore = false } = {}) {
102
- const dir = scratch(t, "snapshot-repo-src-");
103
- git(dir, "init", "-q");
104
- mkdirSync(join(dir, "nested"), { recursive: true });
105
- writeFileSync(join(dir, "nested", "run.sh"), "#!/bin/sh\necho ran\n", { mode: 0o755 });
106
- writeFileSync(join(dir, "plain.txt"), "content\n");
107
- writeFileSync(join(dir, ".gitignore"), "ignored.txt\n");
108
- writeFileSync(join(dir, "ignored.txt"), "tracked anyway\n");
109
- if (exportIgnore) writeFileSync(join(dir, ".gitattributes"), "plain.txt export-ignore\n");
110
- git(dir, "add", "-A", "-f");
111
- git(dir, "-c", "user.name=fixture", "-c", "user.email=fixture@invalid", "commit", "-q", "-m", "fixture");
112
- return dir;
113
- }
114
-
115
- /**
116
- * The lines under test, lifted from review-core.mjs's snapshot prompt and rendered
117
- * with the same `${worktree}` interpolation the script performs: the archive,
118
- * the emptiness probe, the init/commit, the tree compare, the exclude and the
119
- * symlink. `$SNAP` and `$SHA` are the shell's, supplied by `cut` below — the
120
- * lines that mint them are pinned by `review-core-snapshot-path.test.mjs`'s own
121
- * executed mint test, and repeating that here would test its subject twice
122
- * while testing this one no better.
123
- */
124
- function cutLines(path) {
125
- const code = stripComments(readFileSync(path, "utf8"));
126
- const from = code.search(/^ *git -C \$\{worktree\} archive HEAD/m);
127
- const to = code.search(/^ *if \[ -n "\$SNAP" \] && \[ -d \$\{worktree\}\/node_modules \]/m);
128
- assert.ok(
129
- from !== -1 && to > from,
130
- `${path} no longer runs from a \`git archive\` down to the node_modules symlink — the block was reshaped past what this test lifts; update it or restore the block`,
131
- );
132
- return code.slice(from, code.indexOf("\n", to));
133
- }
134
-
135
- /** `cutLines`, rendered for one worktree. */
136
- const render = (path, worktree) => new Function("worktree", "return `" + cutLines(path) + "`")(worktree);
137
-
138
- const DAY = 24 * 60 * 60 * 1000;
139
-
140
- /**
141
- * The stale-run-root prune, lifted by its own named marker rather than by the
142
- * `find` expression that currently implements it. The marker is the line's
143
- * identity in this block's output vocabulary, so a rewrite of the expression
144
- * still lifts and only a prune that is GONE reds the assertion here — the
145
- * distinction `review-core-snapshot-path.test.mjs`'s own needle comment draws
146
- * about pinning "the shape that decides behaviour and nothing else".
147
- *
148
- * The line carries no shell variables, only the script's `${runRootParent}`,
149
- * so it renders to a standalone command and needs none of `cut`'s scaffolding.
150
- */
151
- function pruneLine(path) {
152
- const code = stripComments(readFileSync(path, "utf8"));
153
- const m = code.match(/^ *[^\n]*SNAPSHOT_PRUNE_FAILED[^\n]*$/m);
154
- assert.ok(
155
- m,
156
- `${path} no longer prunes stale run roots out of the per-PR parent — #1083's growth half is back, and every review leaves a tree nothing ever removes`,
157
- );
158
- return m[0].trim();
159
- }
160
-
161
- /** `pruneLine`, rendered for one per-PR parent directory. */
162
- const renderPrune = (path, runRootParent) =>
163
- new Function("runRootParent", "return `" + pruneLine(path) + "`")(runRootParent);
164
-
165
- /**
166
- * A `run-` root under `parent` holding a `locked` directory with no permission
167
- * bits at all, aged `days`. `nested` puts a second such directory, `deeper`,
168
- * inside `locked`, and the file moves into it. On darwin, optionally, the file
169
- * carries `fileFlag` (`uchg` or `uappnd`), and every locked directory carries
170
- * `dirFlag` — set after the mode, so a directory's mode cannot be changed back
171
- * until the flag is gone. `rootFlag` locks the run root itself the same way,
172
- * with no permission bits and that flag. `fileMode` is the file's own mode:
173
- * one that already grants owner rwx leaves `chmod -R u+rwx` nothing to change
174
- * on the file, so that pass exits 0 over a flagged file. Aged before the root
175
- * is locked: creating children sets the root's mtime to now, and a flagged
176
- * root refuses `utimes`.
177
- */
178
- function lockedRunRoot(parent, name, days, { fileFlag = null, fileMode = 0o644, dirFlag = null, rootFlag = null, nested = false } = {}) {
179
- const root = join(parent, name);
180
- const locked = join(root, "locked");
181
- const dirs = nested ? [join(locked, "deeper"), locked] : [locked];
182
- mkdirSync(dirs[0], { recursive: true });
183
- const file = join(dirs[0], "inner.txt");
184
- writeFileSync(file, "");
185
- chmodSync(file, fileMode);
186
- if (fileFlag) execFileSync("chflags", [fileFlag, file]);
187
- // Deepest first: once a directory is 000, nothing below it can be reached.
188
- for (const dir of dirs) {
189
- chmodSync(dir, 0);
190
- if (dirFlag) execFileSync("chflags", [dirFlag, dir]);
191
- }
192
- const when = (Date.now() - days * DAY) / 1000;
193
- utimesSync(root, when, when);
194
- if (rootFlag) {
195
- chmodSync(root, 0);
196
- execFileSync("chflags", [rootFlag, root]);
197
- }
198
- return root;
199
- }
200
-
201
- /**
202
- * Undoes `lockedRunRoot` so the scratch teardown can remove what a prune left.
203
- * A flagged directory's mode is only changeable once its flag is gone, and a
204
- * directory below it only reachable once that mode is back, so each directory
205
- * is unlocked before `find` descends into it.
206
- */
207
- function unlock(parent) {
208
- spawnSync("sh", ["-c", 'chmod -R u+rwx "$1"; if command -v chflags >/dev/null; then find "$1" -type d -exec chflags nouchg,nouappnd {} ";" -exec chmod u+rwx {} ";"; chflags -R nouchg,nouappnd "$1"; fi; :', "sh", parent], { env: ENV });
209
- }
210
-
211
- /**
212
- * The snapshot block's whole first shell block — from the ambient-var clearing
213
- * line down to the node_modules symlink, the prune and everything around it —
214
- * rendered with the script's own `${runRootParent}`/`${runRootPrefix}`
215
- * derivation lifted from the source, so a stray mutation anywhere in it runs
216
- * here rather than only one on the lines `pruneLine` lifts.
217
- */
218
- function snapshotBlock(path, scratchRoot, pr, worktree) {
219
- const code = stripComments(readFileSync(path, "utf8"));
220
- const derive = code.match(/^\s*const runRootParent = .+\n\s*const runRootPrefix = .+$/m);
221
- assert.ok(derive, `${path} no longer derives \`runRootParent\` and \`runRootPrefix\` as adjacent statements — reshaped past what this test lifts`);
222
- const { runRootParent, runRootPrefix } = new Function("scratch", "pr", `${derive[0]}\nreturn { runRootParent, runRootPrefix };`)(scratchRoot, pr);
223
- const from = code.search(/^ *unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_TEMPLATE_DIR *$/m);
224
- const to = code.search(/^ *if \[ -n "\$SNAP" \] && \[ -d \$\{worktree\}\/node_modules \]/m);
225
- assert.ok(from !== -1 && to > from, `${path} no longer runs from the ambient-var clearing line down to the node_modules symlink — the block was reshaped past what this test lifts`);
226
- const script = new Function("scratch", "runRootParent", "runRootPrefix", "worktree", "return `" + code.slice(from, code.indexOf("\n", to)) + "`")(
227
- scratchRoot,
228
- runRootParent,
229
- runRootPrefix,
230
- worktree,
231
- );
232
- return { runRootParent, script };
233
- }
234
-
235
- /**
236
- * `cutLines`'s slice, prefixed with the block's own ambient-var clearing
237
- * line — pulled from the source by its literal text rather than assumed, so
238
- * a rewrap or a dropped var still fails this the same way
239
- * review-core-snapshot-path.test.mjs's own sequence pin would. Neither
240
- * `cutLines` nor `render` widen to include it: in the real script the
241
- * clearing line sits ABOVE `${scratch}`/`${runRootParent}`, and pulling it
242
- * into `render`'s narrow, worktree-only `new Function` would need those too.
243
- */
244
- function withUnset(path) {
245
- const code = stripComments(readFileSync(path, "utf8"));
246
- const m = code.match(/^ *unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_TEMPLATE_DIR *$/m);
247
- assert.ok(m, `${path} no longer clears the ambient git vars before the snapshot block — the hoist this test depends on is gone (#1056)`);
248
- return `${m[0]}\n${cutLines(path)}`;
249
- }
250
-
251
- /** `withUnset`, rendered for one worktree. */
252
- const renderWithUnset = (path, worktree) => new Function("worktree", "return `" + withUnset(path) + "`")(worktree);
253
-
254
- /**
255
- * The ref-selection lines and the line that prints their answer, lifted from
256
- * review-core.mjs's snapshot prompt (#1616). `$branch` and `$crossRepo` are the
257
- * shell's, minted by the `gh pr view` lines just above them — supplied by
258
- * `readRef` below, because `gh` cannot run against a fixture and those two
259
- * values are the only things these lines take from it.
260
- */
261
- function refLines(path) {
262
- const code = stripComments(readFileSync(path, "utf8"));
263
- const from = code.search(/^ *ref=""$/m);
264
- const to = code.search(/^ *echo "\$ref"$/m);
265
- assert.ok(
266
- from !== -1 && to > from,
267
- `${path} no longer selects the ref by crossRepo and echoes the result — the reads were reshaped past what this test lifts; update it or restore them`,
268
- );
269
- return code.slice(from, code.indexOf("\n", to));
270
- }
271
-
272
- /** `refLines`, rendered for one worktree and PR number. */
273
- const renderRefs = (path, worktree, pr) => new Function("worktree", "pr", "return `" + refLines(path) + "`")(worktree, pr);
274
-
275
- const REAL_GIT = execFileSync("sh", ["-c", "command -v git"], { env: ENV, encoding: "utf8" }).trim();
276
- const BRANCH = "contributor/fork-feature";
277
- const PR = 1616;
278
-
279
- /**
280
- * A bare repository standing in for `origin`, carrying whichever of the two
281
- * refs the case under test needs, plus a worktree whose `origin` remote points
282
- * at it.
283
- *
284
- * The two refs hold DIFFERENT commits deliberately. That is what makes "which
285
- * ref answered" observable at all: with one sha under both names every
286
- * ordering of the two reads prints the same thing, and the same-repo case
287
- * could not be told apart from the fork case by the value.
288
- */
289
- function remoteFixture(t, { branchRef = true, pullRef = true } = {}) {
290
- const src = scratch(t, "snapshot-refs-src-");
291
- const commit = (m) => git(src, "-c", "user.name=fixture", "-c", "user.email=fixture@invalid", "commit", "-q", "-m", m);
292
- git(src, "init", "-q");
293
- writeFileSync(join(src, "a.txt"), "the branch head\n");
294
- git(src, "add", "-A");
295
- commit("branch head");
296
- const branchSha = git(src, "rev-parse", "HEAD");
297
- writeFileSync(join(src, "a.txt"), "the PR head\n");
298
- git(src, "add", "-A");
299
- commit("pull head");
300
- const pullSha = git(src, "rev-parse", "HEAD");
301
- assert.notEqual(branchSha, pullSha, "the fixture minted one sha for both refs, so every case below would prove nothing");
302
-
303
- const origin = scratch(t, "snapshot-refs-origin-");
304
- git(origin, "init", "-q", "--bare");
305
- git(src, "remote", "add", "origin", origin);
306
- git(src, "push", "-q", "origin", "HEAD:refs/fixture/objects");
307
- if (branchRef) git(origin, "update-ref", `refs/heads/${BRANCH}`, branchSha);
308
- if (pullRef) git(origin, "update-ref", `refs/pull/${PR}/head`, pullSha);
309
-
310
- const worktree = scratch(t, "snapshot-refs-wt-");
311
- git(worktree, "init", "-q");
312
- git(worktree, "remote", "add", "origin", origin);
313
- return { worktree, branchSha, pullSha };
314
- }
315
-
316
- /**
317
- * A `git` that records every invocation before delegating to the real one, so
318
- * "the PR ref is not consulted" is measured as a READ COUNT rather than
319
- * inferred from the value. The value cannot carry that claim on its own: a
320
- * block that ran both reads and kept the first prints exactly what one that
321
- * stopped after the first prints, and the second network round-trip a
322
- * same-repo PR must not pay is invisible in the output.
323
- */
324
- function tracingGit(t) {
325
- const dir = scratch(t, "snapshot-refs-bin-");
326
- const log = join(dir, "calls.log");
327
- writeExecStub(join(dir, "git"), `#!/bin/sh\nprintf '%s\\n' "$*" >> ${JSON.stringify(log)}\nexec ${JSON.stringify(REAL_GIT)} "$@"\n`);
328
- return {
329
- dir,
330
- reads: () => (existsSync(log) ? readFileSync(log, "utf8").split("\n").filter((l) => l.includes("ls-remote")) : []),
331
- };
332
- }
333
-
334
- /** Runs the rendered ref reads with `$branch` and `$crossRepo` supplied and the tracing git first on PATH. */
335
- function readRef(script, bin, branch = BRANCH, crossRepo = "false") {
336
- const r = spawnSync(
337
- "sh",
338
- ["-c", [`branch=${JSON.stringify(branch)}`, `crossRepo=${JSON.stringify(crossRepo)}`, script].join("\n")],
339
- { env: { ...ENV, PATH: `${bin}:${process.env.PATH}` }, encoding: "utf8" },
340
- );
341
- return { out: (r.stdout ?? "").trim(), err: r.stderr ?? "", status: r.status };
342
- }
343
-
344
- /**
345
- * Runs a rendered block and returns what it printed plus where it wrote. The
346
- * status is returned rather than asserted: two tests below are about a block
347
- * whose `git archive` FAILS, and that is a scenario, not a test failure.
348
- */
349
- function cut(t, script, { snapName = "snapshot-deadbee", env = ENV } = {}) {
350
- const runRoot = scratch(t, "snapshot-repo-run-");
351
- const snap = join(runRoot, snapName);
352
- const r = spawnSync(
353
- "sh",
354
- ["-c", ["SHA=deadbee", `SNAP=${JSON.stringify(snap)}`, 'mkdir -p "$SNAP"', script].join("\n")],
355
- { env, encoding: "utf8" },
356
- );
357
- return { snap, out: r.stdout ?? "", err: r.stderr ?? "", status: r.status };
358
- }
359
-
360
- for (const [name, path] of SOURCES) {
361
- // The accept case, and the property the whole ticket turns on: the snapshot
362
- // is a repository, and it is a repository holding the REVIEWED tree. The tree
363
- // hash is what settles the second half — two commits whose trees hash the
364
- // same hold byte-identical content, every file, which is strictly more than
365
- // the "confirm a couple of the diff's files" spot check this replaced.
366
- test(`${name}: the block leaves a repository whose commit holds the reviewed tree`, (t) => {
367
- const worktree = reviewedRepo(t);
368
- const { snap, out, status } = cut(t, render(path, worktree));
369
-
370
- assert.match(out, /SNAPSHOT_NONEMPTY/, `the extraction came back empty: ${out}`);
371
- assert.doesNotMatch(out, /SNAPSHOT_INIT_FAILED/, `the init or the commit failed: ${out}`);
372
- assert.match(out, /SNAPSHOT_TREE_MATCH/, `the block did not settle that the snapshot is the reviewed tree: ${out}`);
373
- assert.equal(status, 0, "the block exited non-zero — a snapshot agent reads that as a failed cut");
374
-
375
- assert.ok(existsSync(join(snap, ".git")), "there is no `.git` in the snapshot — every suite that asks git what ships declines or fails there");
376
- assert.equal(
377
- git(snap, "rev-parse", "HEAD^{tree}"),
378
- git(worktree, "rev-parse", "HEAD^{tree}"),
379
- "the snapshot's commit does not hold the reviewed tree",
380
- );
381
- // The identity flags, pinned where they have an observable effect. The
382
- // snapshot commit is a mechanism, not a contribution, and nothing about it
383
- // is the operator's: unflagged, git auto-detects a name and address off the
384
- // machine (measured in the header) and every review in the fleet stamps
385
- // whoever ran it onto a commit nobody wrote.
386
- assert.equal(
387
- git(snap, "log", "-1", "--format=%an <%ae>"),
388
- "fleet <fleet@invalid>",
389
- "the snapshot commit is not attributed to the block's own synthetic identity",
390
- );
391
- // The `-f` on `git add`, measured rather than read off the flag: this file
392
- // is tracked at HEAD, so `git archive` carries it, and the extraction's own
393
- // `.gitignore` is what would make a plain `git add -A` skip it. Dropping
394
- // `-f` also breaks the tree compare above — but this assertion names the
395
- // cause, and the hash comparison cannot.
396
- assert.equal(
397
- git(snap, "ls-files", "--error-unmatch", "ignored.txt"),
398
- "ignored.txt",
399
- "a tracked file the repo's own .gitignore covers did not make it into the snapshot's index",
400
- );
401
- // The exec bit is part of the tree object, so a mode the extraction lost
402
- // would already have reddened the hash. Asserted anyway because it is the
403
- // one property a reader checks by hand when a suite behaves differently in
404
- // the snapshot, and a named assertion beats re-deriving it from a hash.
405
- assert.match(git(snap, "ls-files", "-s", "nested/run.sh"), /^100755 /, "the executable bit did not survive into the snapshot");
406
- });
407
-
408
- // The negative control for the test above. Without it, "there is a repository
409
- // at the snapshot" is satisfiable by an ambient repository ABOVE the snapshot
410
- // — `$TMPDIR` inside a checkout, a stray `.git` in a temp root — and the pin
411
- // would pass with the init deleted.
412
- test(`${name}: without the block's init the same extraction is not a repository`, (t) => {
413
- const worktree = reviewedRepo(t);
414
- const lines = render(path, worktree).split("\n");
415
- const extractOnly = lines.filter((l) => /archive HEAD/.test(l) || /ls -A/.test(l));
416
- assert.equal(extractOnly.length, 2, "the archive and the probe are no longer one line each — update this control");
417
- const { snap, out } = cut(t, extractOnly.join("\n"));
418
-
419
- assert.match(out, /SNAPSHOT_NONEMPTY/, "the control's own extraction failed, so it controls nothing");
420
- assert.ok(!existsSync(join(snap, ".git")), "the control extraction has a `.git` — it is not the pre-fix shape and proves nothing");
421
- const probe = spawnSync("git", ["-C", snap, "rev-parse", "--show-toplevel"], {
422
- env: { ...ENV, GIT_CEILING_DIRECTORIES: dirname(snap) },
423
- encoding: "utf8",
424
- });
425
- assert.notEqual(probe.status, 0, "git answered for a bare extraction — the ceiling is wrong, or this environment nests the snapshot inside a repository");
426
- assert.match(
427
- probe.stderr,
428
- /not a git repository/,
429
- "the bare extraction failed for some reason OTHER than having no repository, so it is not the condition #1056 describes",
430
- );
431
- });
432
-
433
- // The ordering, executed. `review-core-snapshot-path.test.mjs` pins that the
434
- // probe sits above the init as TEXT; this is why that order is load-bearing.
435
- // A `git archive` that produced nothing — no auth, a dead HEAD — leaves the
436
- // directory `mkdir -p` made, and `.git` is enough to make it look populated,
437
- // in every repo rather than only the ones with node_modules.
438
- test(`${name}: the emptiness probe still sees an empty extraction, and would not above the init`, (t) => {
439
- const notARepo = scratch(t, "snapshot-repo-norepo-");
440
- const lines = render(path, notARepo).split("\n");
441
- const probeAt = lines.findIndex((l) => /ls -A/.test(l));
442
- const initAt = lines.findIndex((l) => /git init -q/.test(l));
443
- assert.ok(probeAt !== -1 && initAt > probeAt, "the block no longer probes above its init — the text pin in review-core-snapshot-path.test.mjs is the one to read first");
444
-
445
- const real = cut(t, lines.join("\n"));
446
- assert.match(
447
- real.out,
448
- /SNAPSHOT_EMPTY/,
449
- `a failed archive must report SNAPSHOT_EMPTY so the caller refuses the tree (#140): ${real.out}`,
450
- );
451
- assert.doesNotMatch(real.out, /SNAPSHOT_NONEMPTY/, "the probe called a failed extraction non-empty");
452
- assert.match(real.out, /SNAPSHOT_TREE_MISMATCH/, "a failed archive is also not the reviewed tree, and the block must say so");
453
-
454
- const moved = [...lines];
455
- moved.splice(initAt, 1);
456
- moved.splice(probeAt, 0, lines[initAt]);
457
- const swapped = cut(t, moved.join("\n"));
458
- assert.match(
459
- swapped.out,
460
- /SNAPSHOT_NONEMPTY/,
461
- "moving the init above the probe no longer fools the probe — if that is genuinely true the order is free, but it was measured false and the pin above rests on it",
462
- );
463
- });
464
-
465
- // What this change can wrongly REFUSE, and the answer it must give when it
466
- // does: `export-ignore` keeps a tracked file out of `git archive`, so the
467
- // snapshot genuinely is not the reviewed tree. The block reports that rather
468
- // than a match — and the review still RUNS, because refusing would trade a
469
- // wrong test count for no coverage at all, which is this defect's own
470
- // expensive half (two dimensions in one run filed nothing over a suite they
471
- // could not attribute).
472
- test(`${name}: a snapshot the archive could not fill reports the mismatch and does not cancel the review`, (t) => {
473
- const worktree = reviewedRepo(t, { exportIgnore: true });
474
- const { snap, out } = cut(t, render(path, worktree));
475
-
476
- assert.ok(!existsSync(join(snap, "plain.txt")), "the export-ignore fixture did not actually drop a file, so it exercises nothing");
477
- assert.match(out, /SNAPSHOT_TREE_MISMATCH/, `an archive missing a tracked file must not report a match: ${out}`);
478
- assert.doesNotMatch(out, /SNAPSHOT_TREE_MATCH/, "the block reported both outcomes");
479
- assert.match(out, /SNAPSHOT_TREE_MISMATCH=snapshot [0-9a-f]{40} vs commit [0-9a-f]{40}/, "the mismatch names neither hash — a reader cannot tell which tree was measured");
480
- });
481
-
482
- // Both prompts that order a suite run, and the payload. A fact reported to
483
- // the caller and never told to the agent measuring in that environment is
484
- // half a fix: the specialist is the one deciding whether a red is a finding.
485
- test(`${name}: both suite-running prompts and the payload carry what the run is evidence about`, () => {
486
- const code = stripComments(readFileSync(path, "utf8"));
487
- const specialist = between(code, "READ ONLY FROM THE SNAPSHOT", "Report only what you RAN", "the specialist prompt");
488
- const refuter = between(code, "Try to REFUTE this finding", "{ label: `verify:", "the refuter prompt");
489
- assert.match(specialist, /\$\{environmentNote\(snap\)\}/, "the specialist prompt no longer says what its own suite run is evidence about — a dimension then reads a skip or a red as a fact about the tree");
490
- assert.match(refuter, /\$\{environmentNote\(snap\)\}/, "the refuter prompt no longer carries it — a refuter that runs the suite to check a finding draws the same wrong conclusion");
491
- assert.match(code, /testEnvironment: environmentNote\(snap\)/, "the returned payload no longer carries the measurement environment — the controller is back to reading a count with nothing saying where it was taken");
492
- });
493
-
494
- // #1056 Finding 3: `unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE` used to sit
495
- // INSIDE the init's own subshell, so the SHA capture, the archive and the
496
- // tree-hash compare — all of them OUTSIDE that subshell — ran with an
497
- // ambient GIT_DIR still outranking every `-C`. Measured: pointed at an
498
- // unrelated repository, the old block archived and compared THAT repo
499
- // instead of the worktree, and reported SNAPSHOT_TREE_MATCH for it. The
500
- // fix hoists the clearing to the top of the whole block.
501
- test(`${name}: an ambient GIT_DIR naming an unrelated repository does not retarget the snapshot`, (t) => {
502
- const worktree = reviewedRepo(t);
503
- const stranger = scratch(t, "snapshot-repo-stranger-");
504
- git(stranger, "init", "-q");
505
- writeFileSync(join(stranger, "stranger.txt"), "stranger\n");
506
- git(stranger, "add", "-A");
507
- git(stranger, "-c", "user.name=fixture", "-c", "user.email=fixture@invalid", "commit", "-q", "-m", "stranger");
508
-
509
- const { snap, out } = cut(t, renderWithUnset(path, worktree), { env: { ...ENV, GIT_DIR: join(stranger, ".git") } });
510
-
511
- assert.ok(!existsSync(join(snap, "stranger.txt")), `an ambient GIT_DIR retargeted the archive at the unrelated repository: ${out}`);
512
- assert.ok(existsSync(join(snap, "plain.txt")), `the archive did not pull from the worktree under review: ${out}`);
513
- assert.match(out, /SNAPSHOT_TREE_MATCH\b/, `an ambient GIT_DIR pointed at an unrelated repository must not stop the block from settling the real tree: ${out}`);
514
- });
515
-
516
- // #1056 Finding 4: an ambient GIT_TEMPLATE_DIR with no `info/` subdirectory
517
- // makes `git init` skip populating `.git/info`, so the block's own
518
- // `.git/info/exclude` append has nowhere to land and node_modules goes back
519
- // to being untracked but NOT excluded — the exact dirty-status regression
520
- // the symlink tests above guard against, reachable through the host's
521
- // environment instead of through the diff.
522
- test(`${name}: an ambient GIT_TEMPLATE_DIR with no info/ still leaves the snapshot clean`, (t) => {
523
- const worktree = reviewedRepo(t);
524
- mkdirSync(join(worktree, "node_modules"), { recursive: true });
525
- const emptyTemplate = scratch(t, "snapshot-repo-template-");
526
- const { snap, out } = cut(t, renderWithUnset(path, worktree), { env: { ...ENV, GIT_TEMPLATE_DIR: emptyTemplate } });
527
-
528
- assert.match(out, /SNAPSHOT_TREE_MATCH/, `an ambient GIT_TEMPLATE_DIR must not stop the init from settling the tree: ${out}`);
529
- assert.ok(
530
- existsSync(join(snap, ".git", "info", "exclude")),
531
- "an ambient GIT_TEMPLATE_DIR without info/ leaves the exclude file missing — node_modules is untracked but not excluded",
532
- );
533
- assert.equal(
534
- git(snap, "status", "--porcelain", "--untracked-files=all"),
535
- "",
536
- "an ambient GIT_TEMPLATE_DIR left the snapshot reading dirty",
537
- );
538
- });
539
-
540
- // #1083's remaining half, executed. #1129 gave every run its own root and
541
- // said in the same breath that nothing removes it; this is the line that
542
- // does, and every fixture below kills one distinct mutant of it:
543
- //
544
- // the line DELETED -> `run-staleaa` survives
545
- // `-mtime +7` dropped -> `run-recentb` is deleted
546
- // `-maxdepth 1` dropped -> the nested `run-` under a LIVE root goes
547
- // `-name 'run-*'` dropped -> `snapshot-keep-me` goes
548
- // `-type d` dropped -> the stale FILE goes
549
- //
550
- // Nine days and five, rather than one age and a fresh directory: the pair
551
- // BRACKETS the cutoff, so widening it to a decade (a prune that never fires
552
- // again) reds on the nine-day root and tightening it to a day reds on the
553
- // five-day one. A fresh directory would pin neither, and this run's OWN root
554
- // is excluded by the same gate the five-day fixture measures, at four orders
555
- // of magnitude more margin — `mktemp -d` creates it milliseconds earlier —
556
- // so it is not a sixth fixture here.
557
- test(`${name}: the prune takes run roots nothing has touched for a week and leaves every other entry standing`, (t) => {
558
- const parent = join(scratch(t, "snapshot-repo-prune-"), "pr7");
559
- const stale = join(parent, "run-staleaa");
560
- const recent = join(parent, "run-recentb");
561
- const nested = join(recent, "verify-types", "run-nestedc");
562
- const foreign = join(parent, "snapshot-keep-me");
563
- const staleFile = join(parent, "run-stalefile");
564
-
565
- mkdirSync(nested, { recursive: true });
566
- mkdirSync(stale, { recursive: true });
567
- mkdirSync(foreign, { recursive: true });
568
- writeFileSync(staleFile, "");
569
- // Deepest first. Creating a child sets its parent's mtime to now, so
570
- // `recent` has to be aged after `nested` exists or the fixture ages nothing
571
- // and the depth assertion below passes vacuously.
572
- const age = (p, days) => {
573
- const when = (Date.now() - days * DAY) / 1000;
574
- utimesSync(p, when, when);
575
- };
576
- age(nested, 9);
577
- age(stale, 9);
578
- age(foreign, 9);
579
- age(staleFile, 9);
580
- age(recent, 5);
581
-
582
- const r = spawnSync("sh", ["-c", renderPrune(path, parent)], { env: ENV, encoding: "utf8" });
583
-
584
- assert.equal(r.status, 0, `the prune exited non-zero on a healthy per-PR parent: ${r.stderr}`);
585
- assert.doesNotMatch(
586
- r.stdout ?? "",
587
- /SNAPSHOT_PRUNE_FAILED/,
588
- `the prune named a failure on a parent it could read and write: ${r.stderr}`,
589
- );
590
-
591
- assert.ok(
592
- !existsSync(stale),
593
- "a run root nothing has touched for nine days survived the prune — #1083's growth half is back and the tree grows without bound",
594
- );
595
- assert.ok(
596
- existsSync(recent),
597
- "a five-day-old run root was removed — a fix-applier outlives the review that produced its findings and reads absolute paths into that tree (#1129), which is the trade that ticket refused",
598
- );
599
- assert.ok(
600
- existsSync(nested),
601
- "the prune descended into a live run root and took a refuter's own `run-`-named fixture with it — the depth bound is gone, so the prune now reaches inside trees it must not touch",
602
- );
603
- assert.ok(
604
- existsSync(foreign),
605
- "the prune removed an entry outside the `run-` namespace this script mints — its blast radius is no longer the roots it owns, and the per-PR parent holds whatever the caller put there",
606
- );
607
- assert.ok(
608
- existsSync(staleFile),
609
- "the prune removed a stale FILE named like a run root — a run root is a directory `mktemp -d` created, and `-type d` is what says so",
610
- );
611
- });
612
-
613
- // #2322. A fixture that drops its own read bit, or a darwin file carrying the
614
- // user-immutable flag, made the plain `rm -rf` fail on that root — so it
615
- // stayed forever and every later review of the PR printed
616
- // SNAPSHOT_PRUNE_FAILED. The prune now restores owner rwx and clears darwin's
617
- // user flags on the roots it SELECTED, then removes them.
618
- test(`${name}: the prune removes an aged run root a chmod 000 directory used to wedge`, (t) => {
619
- const parent = join(scratch(t, "snapshot-repo-prune-perm-"), "pr7");
620
- const stale = lockedRunRoot(parent, "run-staleaa", 9);
621
- try {
622
- const r = spawnSync("sh", ["-c", renderPrune(path, parent)], { env: ENV, encoding: "utf8" });
623
-
624
- assert.doesNotMatch(r.stdout ?? "", /SNAPSHOT_PRUNE_FAILED/, `the prune named a failure on a root it can normalise: ${r.stderr}`);
625
- assert.equal(r.status, 0, `the prune exited non-zero: ${r.stderr}`);
626
- assert.ok(!existsSync(stale), "an aged run root holding a chmod 000 directory survived the prune — it now stays forever and every later review prints SNAPSHOT_PRUNE_FAILED");
627
- } finally {
628
- unlock(parent);
629
- }
630
- });
631
-
632
- // The other half: normalising is a mutation, and one applied before
633
- // selection, or to the whole parent, would rewrite modes in trees a
634
- // fix-applier still reads — pinned by mode rather than by existence. Run
635
- // through the whole first shell block, not the prune line alone: a stray
636
- // `chmod -R` on the parent on a line of its own never runs in a test that
637
- // lifts only the prune. SNAPSHOT_TREE_MATCH is the control that the block
638
- // ran to its end, past every line that could have done it.
639
- test(`${name}: the snapshot block leaves the modes inside a run root younger than the cut-off alone`, (t) => {
640
- const worktree = reviewedRepo(t);
641
- const { runRootParent, script } = snapshotBlock(path, scratch(t, "snapshot-repo-block-"), 7, worktree);
642
- const stale = lockedRunRoot(runRootParent, "run-staleaa", 9);
643
- const recent = lockedRunRoot(runRootParent, "run-recentb", 5);
644
- try {
645
- const r = spawnSync("sh", ["-c", script], { env: ENV, encoding: "utf8" });
646
-
647
- assert.match(r.stdout ?? "", /SNAPSHOT_TREE_MATCH/, `the block did not run to its end, so it measured nothing past the line it stopped on: ${r.stdout}${r.stderr}`);
648
- assert.doesNotMatch(r.stdout ?? "", /SNAPSHOT_PRUNE_FAILED/, `the prune named a failure on a root it can normalise: ${r.stderr}`);
649
- assert.ok(!existsSync(stale), "the aged run root survived the block, so its prune selected nothing and the young root's modes prove nothing");
650
- assert.equal(
651
- statSync(join(recent, "locked")).mode & 0o777,
652
- 0,
653
- "the snapshot block changed a mode inside a run root younger than the cut-off — normalisation reached a tree the prune did not select",
654
- );
655
- } finally {
656
- unlock(runRootParent);
657
- }
658
- });
659
-
660
- // #2322, #2370. On darwin a user flag wedges the removal too: `uchg` refuses
661
- // every change and `uappnd` refuses the unlink, and on a directory either
662
- // one also refuses the `chmod` that makes a `000` directory readable again —
663
- // while `chflags -R` cannot read a `000` directory it has just unflagged. So
664
- // a directory's flag and mode have to come off together, before anything
665
- // inside it is read, at every depth and on the run root itself. The `uappnd`
666
- // file whose mode already grants owner rwx is the shape where `chmod -R`
667
- // exits 0 over a flag.
668
- for (const [shape, opts] of [
669
- ["a uchg file inside a chmod 000 directory", { fileFlag: "uchg" }],
670
- ["a uappnd file whose own mode leaves chmod nothing to change", { fileFlag: "uappnd", fileMode: 0o700 }],
671
- ["a directory that is both uchg and chmod 000", { dirFlag: "uchg" }],
672
- ["a directory that is both uappnd and chmod 000", { dirFlag: "uappnd" }],
673
- ["a uchg file inside a directory that is both uchg and chmod 000", { fileFlag: "uchg", dirFlag: "uchg" }],
674
- ["a uchg, chmod 000 directory inside another", { dirFlag: "uchg", nested: true }],
675
- ["its own uchg and chmod 000 bits", { rootFlag: "uchg" }],
676
- ["its own uappnd and chmod 000 bits", { rootFlag: "uappnd" }],
677
- ["its own uchg and chmod 000 bits over a uchg, chmod 000 directory", { rootFlag: "uchg", dirFlag: "uchg" }],
678
- ]) {
679
- test(`${name}: on darwin the prune removes an aged run root with ${shape}`, { skip: process.platform !== "darwin" && "chflags/uchg/uappnd are darwin's" }, (t) => {
680
- const parent = join(scratch(t, "snapshot-repo-prune-flags-"), "pr7");
681
- const stale = lockedRunRoot(parent, "run-staleaa", 9, opts);
682
- try {
683
- const r = spawnSync("sh", ["-c", renderPrune(path, parent)], { env: ENV, encoding: "utf8" });
684
-
685
- assert.doesNotMatch(r.stdout ?? "", /SNAPSHOT_PRUNE_FAILED/, `the prune named a failure on a root it can normalise: ${r.stderr}`);
686
- assert.equal(r.status, 0, `the prune exited non-zero: ${r.stderr}`);
687
- assert.ok(!existsSync(stale), `an aged run root with ${shape} survived the prune — it now stays forever and every later review prints SNAPSHOT_PRUNE_FAILED`);
688
- } finally {
689
- unlock(parent);
690
- }
691
- });
692
- }
693
-
694
- // GNU find (Linux) refuses an `-exec ... {} +` whose argument list holds the
695
- // `{}` placeholder more than once — and counts a `{}` written inside an
696
- // `sh -c` script argument as one. BSD find (darwin) does not, so a dev
697
- // machine passes a prune that fails every Linux CI run. This shim enforces
698
- // GNU's rule over the real `find`, so the case holds on either host.
699
- test(`${name}: the prune's find invocation keeps to GNU find's one-placeholder rule for -exec ... +`, (t) => {
700
- const parent = join(scratch(t, "snapshot-repo-prune-gnu-"), "pr7");
701
- const stale = lockedRunRoot(parent, "run-staleaa", 9);
702
- const bin = scratch(t, "snapshot-repo-prune-gnu-bin-");
703
- const realFind = execFileSync("sh", ["-c", "command -v find"], { env: ENV, encoding: "utf8" }).trim();
704
- writeFileSync(
705
- join(bin, "find"),
706
- `#!/bin/sh
707
- # GNU find: with a terminating '+', only one argument may contain {}.
708
- n=0; plus=0; prev=
709
- for a in "$@"; do
710
- case "$a" in *'{}'*) n=$((n + 1));; esac
711
- [ "$a" = "+" ] && [ "$prev" = '{}' ] && plus=1
712
- prev=$a
713
- done
714
- if [ "$plus" = 1 ] && [ "$n" -gt 1 ]; then
715
- echo "find: Only one instance of {} is supported with -exec ... +" >&2
716
- exit 1
717
- fi
718
- exec "${realFind}" "$@"
719
- `,
720
- { mode: 0o755 },
721
- );
722
- const env = { ...ENV, PATH: `${bin}:${ENV.PATH}` };
723
- try {
724
- const r = spawnSync("sh", ["-c", renderPrune(path, parent)], { env, encoding: "utf8" });
725
-
726
- assert.doesNotMatch(r.stdout ?? "", /SNAPSHOT_PRUNE_FAILED/, `a GNU-rule find rejected the prune: ${r.stderr}`);
727
- assert.doesNotMatch(r.stderr ?? "", /Only one instance of \{\}/, "the prune's find tripped GNU's one-placeholder rule");
728
- assert.ok(!existsSync(stale), "the aged run root survived a find that enforces GNU's placeholder rule");
729
- } finally {
730
- unlock(parent);
731
- }
732
- });
733
-
734
- // The accept case on a host without `chflags`: the flag step is skipped, not
735
- // treated as a failure, so the permission case still succeeds there.
736
- test(`${name}: without chflags on PATH the prune still removes an aged run root holding a chmod 000 directory`, (t) => {
737
- const parent = join(scratch(t, "snapshot-repo-prune-noflags-"), "pr7");
738
- const stale = lockedRunRoot(parent, "run-staleaa", 9);
739
- const bin = scratch(t, "snapshot-repo-prune-bin-");
740
- for (const tool of ["sh", "find", "chmod", "rm"]) {
741
- const real = execFileSync("sh", ["-c", `command -v ${tool}`], { env: ENV, encoding: "utf8" }).trim();
742
- symlinkSync(real, join(bin, tool));
743
- }
744
- const env = { ...ENV, PATH: bin };
745
- try {
746
- const probe = spawnSync(join(bin, "sh"), ["-c", "command -v chflags"], { env, encoding: "utf8" });
747
- assert.notEqual(probe.status, 0, "chflags is still reachable on the narrowed PATH, so this case measures nothing");
748
-
749
- const r = spawnSync(join(bin, "sh"), ["-c", renderPrune(path, parent)], { env, encoding: "utf8" });
750
-
751
- assert.doesNotMatch(r.stdout ?? "", /SNAPSHOT_PRUNE_FAILED/, `a host without chflags reported a prune failure: ${r.stderr}`);
752
- assert.equal(r.status, 0, `the prune exited non-zero without chflags: ${r.stderr}`);
753
- assert.ok(!existsSync(stale), "without chflags the prune left an aged run root holding a chmod 000 directory");
754
- } finally {
755
- unlock(parent);
756
- }
757
- });
758
-
759
- // A removal normalisation cannot rescue still refuses by name, and the
760
- // snapshot step goes on: a parent the prune cannot write is outside what it
761
- // normalises, so `rm -rf` genuinely fails there.
762
- test(`${name}: a removal that still fails prints SNAPSHOT_PRUNE_FAILED and the step continues`, { skip: process.getuid?.() === 0 && "root ignores the read-only parent" }, (t) => {
763
- const parent = join(scratch(t, "snapshot-repo-prune-fail-"), "pr7");
764
- const stale = lockedRunRoot(parent, "run-staleaa", 9);
765
- chmodSync(parent, 0o555);
766
- try {
767
- const r = spawnSync("sh", ["-c", `${renderPrune(path, parent)}\necho AFTER_PRUNE`], { env: ENV, encoding: "utf8" });
768
-
769
- assert.match(r.stdout ?? "", /SNAPSHOT_PRUNE_FAILED/, `a run root the prune could not remove went unreported: ${r.stdout}`);
770
- assert.match(r.stdout ?? "", /AFTER_PRUNE/, "a failed prune stopped the snapshot step");
771
- assert.equal(r.status, 0, `a failed prune ended the step non-zero: ${r.stderr}`);
772
- assert.ok(existsSync(stale), "the fixture's run root was removed, so this case exercised no failure");
773
- } finally {
774
- unlock(parent);
775
- }
776
- });
777
-
778
- // #1616. The ref-head operand, measured where it is PRODUCED rather than
779
- // where it is consumed — the two guards that compare against it were never
780
- // the defect, and this ticket changed neither. Six shapes, because the
781
- // class is neither the fork/same-repo binary it first reads as, nor the
782
- // resolves/resolves-nowhere binary the original fallback assumed: a
783
- // same-repo PR, whose branch ref resolves; a cross-repo PR whose branch
784
- // NAME collides with an unrelated branch `origin` already carries (this
785
- // fix's own target — the old empty-triggered fallback let that collision
786
- // silently answer with the wrong repository's commit); a cross-repo PR
787
- // whose branch simply resolves nowhere, the ordinary case; a same-repo PR
788
- // whose branch ref resolves nowhere (a branch since deleted on `origin`,
789
- // unrelated to crossRepo); a PR where neither ref answers; and an origin
790
- // that cannot be reached at all. The last two are the accept-on-absent path
791
- // this ticket deliberately left alone, pinned here so "the fallback fires"
792
- // cannot quietly become "something is always reported".
793
- test(`${name}: a PR whose branch ref resolves reports it, and never reads the PR ref`, (t) => {
794
- const { worktree, branchSha, pullSha } = remoteFixture(t);
795
- const bin = tracingGit(t);
796
- const r = readRef(renderRefs(path, worktree, PR), bin.dir);
797
-
798
- assert.equal(r.status, 0, `the reads exited non-zero against a healthy origin: ${r.err}`);
799
- assert.equal(
800
- r.out,
801
- branchSha,
802
- "a same-repo PR no longer reports the branch ref — #1513 chose that operand and the fallback was not allowed to move it",
803
- );
804
- const reads = bin.reads();
805
- assert.equal(
806
- reads.length,
807
- 1,
808
- `a PR whose branch ref answered paid ${reads.length} ref reads instead of 1 — the fallback is either unguarded or runs first, and every same-repo review now pays a second network round-trip: ${reads.join(" | ")}`,
809
- );
810
- assert.match(reads[0], /refs\/heads\//, `the one read was not the branch ref: ${reads[0]}`);
811
- });
812
-
813
- // #1616's actual defect, reproduced directly: `isCrossRepository` was never
814
- // read, so a fork PR whose branch happens to share a NAME with something
815
- // `origin` can already resolve — a real base-repo branch, not a
816
- // hypothetical — silently answered with THAT commit instead of the fork's
817
- // own head. GitHub does not require a fork's branch name to be unique
818
- // against the base repository, so this fixture (the SAME one the accept
819
- // test above uses — `refs/heads/<branch>` on `origin` carrying an unrelated
820
- // commit, plus the base repo's own copy of the fork's real head under
821
- // `refs/pull/<pr>/head`) is exactly what a colliding fork PR looks like on
822
- // the base repo's remote, not a contrived edge case.
823
- test(`${name}: a cross-repo PR whose branch collides with a base-repo branch reports the PR's own head, never the collision`, (t) => {
824
- const { worktree, branchSha, pullSha } = remoteFixture(t);
825
- const bin = tracingGit(t);
826
- const r = readRef(renderRefs(path, worktree, PR), bin.dir, BRANCH, "true");
827
-
828
- assert.equal(r.status, 0, `the reads exited non-zero against a colliding origin: ${r.err}`);
829
- assert.notEqual(
830
- r.out,
831
- branchSha,
832
- "a cross-repo PR reported the base repo's same-named branch instead of its own head — the collision this ticket exists to close",
833
- );
834
- assert.equal(r.out, pullSha, "a cross-repo PR did not report its own head from refs/pull/<pr>/head");
835
- const reads = bin.reads();
836
- assert.equal(
837
- reads.length,
838
- 1,
839
- `a cross-repo PR paid ${reads.length} ref reads instead of 1 — the branch-ref read must not run at all once the PR is cross-repo, colliding name or not: ${reads.join(" | ")}`,
840
- );
841
- assert.match(reads[0], new RegExp(`refs/pull/${PR}/head`), `the one read was not the PR's own ref on the base repo: ${reads[0]}`);
842
- });
843
-
844
- // The ordinary fork, no collision: `refs/heads/<branch>` does not exist on
845
- // `origin` at all. `isCrossRepository` gates on the repository relationship,
846
- // not on whether a collision happens to be present, so this case must also
847
- // skip the branch-ref read entirely rather than attempt-then-fall-back.
848
- test(`${name}: a cross-repo PR with no colliding branch skips the branch-ref read entirely`, (t) => {
849
- const { worktree, pullSha } = remoteFixture(t, { branchRef: false });
850
- const bin = tracingGit(t);
851
- const r = readRef(renderRefs(path, worktree, PR), bin.dir, BRANCH, "true");
852
-
853
- assert.equal(r.status, 0, `the reads exited non-zero against a fork-shaped origin: ${r.err}`);
854
- assert.equal(r.out, pullSha, "a cross-repo PR did not report its own head from refs/pull/<pr>/head");
855
- const reads = bin.reads();
856
- assert.equal(
857
- reads.length,
858
- 1,
859
- `a cross-repo PR paid ${reads.length} ref reads instead of 1 — the branch-ref read must not even be attempted once the PR is cross-repo: ${reads.join(" | ")}`,
860
- );
861
- assert.match(reads[0], new RegExp(`refs/pull/${PR}/head`), `the one read was not the PR's own ref on the base repo: ${reads[0]}`);
862
- });
863
-
864
- // The residual empty-triggered fallback, unrelated to crossRepo: a
865
- // same-repo PR (`isCrossRepository` false) whose branch was deleted on
866
- // `origin` after the PR opened. This is the shape the ORIGINAL #1616 fix
867
- // covered and this ticket's own fix must not have narrowed.
868
- test(`${name}: a same-repo PR whose branch ref resolves nowhere falls back to the PR's own ref on the base repo`, (t) => {
869
- const { worktree, pullSha } = remoteFixture(t, { branchRef: false });
870
- const bin = tracingGit(t);
871
- const r = readRef(renderRefs(path, worktree, PR), bin.dir);
872
-
873
- assert.equal(r.status, 0, `the reads exited non-zero against a fork-shaped origin: ${r.err}`);
874
- assert.equal(
875
- r.out,
876
- pullSha,
877
- "a same-repo PR whose branch ref resolves nowhere still reports no ref head — the operand stays permanently absent and the wrong-commit backstop cannot fire",
878
- );
879
- const reads = bin.reads();
880
- assert.equal(reads.length, 2, `expected the branch read and then the PR-ref read, got: ${reads.join(" | ")}`);
881
- assert.match(reads[0], /refs\/heads\//, `the branch ref was not read FIRST: ${reads[0]}`);
882
- assert.match(reads[1], new RegExp(`refs/pull/${PR}/head`), `the fallback did not read the PR's own ref on the base repo: ${reads[1]}`);
883
- });
884
-
885
- test(`${name}: neither ref resolving reports nothing, and does not fail the cut`, (t) => {
886
- const { worktree } = remoteFixture(t, { branchRef: false, pullRef: false });
887
- const r = readRef(renderRefs(path, worktree, PR), tracingGit(t).dir);
888
-
889
- assert.equal(r.out, "", `a PR neither ref names reported something as its ref head: ${r.out}`);
890
- assert.equal(r.status, 0, `the reads exited non-zero with both refs absent: ${r.err}`);
891
- });
892
-
893
- // The reason the compares treat an absent operand as "no opinion" in the
894
- // first place, and the one this ticket must not have turned into a refusal:
895
- // an unreachable origin has to come back empty, never as a value and never as
896
- // a non-zero exit the snapshot agent reads as a failed cut.
897
- test(`${name}: an unreachable origin reports nothing rather than failing the cut`, (t) => {
898
- const worktree = scratch(t, "snapshot-refs-wt-");
899
- git(worktree, "init", "-q");
900
- git(worktree, "remote", "add", "origin", join(worktree, "no-such-remote.git"));
901
- const r = readRef(renderRefs(path, worktree, PR), tracingGit(t).dir);
902
-
903
- assert.equal(r.out, "", `a failed read put a value in the operand: ${r.out}`);
904
- assert.equal(
905
- r.status,
906
- 0,
907
- "a failed ref read exits non-zero out of the block — an unreachable origin now cancels a runnable review instead of skipping the compare",
908
- );
909
- });
910
- }
911
-
912
- // `environmentNote`'s two regimes, read as a consumer reads them.
913
- test("environmentNote says a verified snapshot measures the tree, and an unverified one does not", () => {
914
- const verified = environmentNote({ repoVerified: true });
915
- assert.doesNotMatch(verified, /UNVERIFIED/, "a verified environment is reported as unverified — every run now reads as degraded, and a reader who sees that on healthy runs stops reading it");
916
- // `phrase()`, not a literal: this prose is hard-wrapped at ~78 columns, so
917
- // every inter-word gap in it may be a newline, and a pin that reds on a
918
- // rewrap is one the next reader edits around.
919
- assert.match(verified, phrase("what a checkout at that commit does"), "the verified branch no longer says the suite measures what a checkout does, which is the whole claim the tree-hash compare buys");
920
-
921
- const failed = environmentNote({ repoVerified: false, repoError: "SNAPSHOT_INIT_FAILED" });
922
- assert.match(failed, /UNVERIFIED/, "a degraded environment is not announced");
923
- assert.match(failed, /SNAPSHOT_INIT_FAILED/, "the reason is dropped — the payload says the environment differs without saying why, which is what a reader needs to tell an artifact from a regression");
924
- assert.match(failed, phrase("NOT a validation of the tree"), "the consequence is dropped — a reader is left to infer that the counts mean less than they look like");
925
-
926
- // Absent, not false: an agent that omitted the field must not read as a
927
- // verified environment. The schema's `required` is what should prevent it;
928
- // this is the same belt-and-braces `snapshotMissing` applies to
929
- // `pathVerified`, at the layer that has to be right if that one is bypassed.
930
- assert.match(environmentNote({}), /UNVERIFIED/, "an omitted repoVerified reads as a verified environment");
931
- assert.match(environmentNote(null), /UNVERIFIED/, "a dead snapshot agent reads as a verified environment");
932
- // A string is not a boolean: `=== true` is deliberate, since a schema bypass
933
- // or a hand-built fixture can carry the word rather than the value.
934
- assert.match(environmentNote({ repoVerified: "true" }), /UNVERIFIED/, "a non-boolean truthy value reads as a verified environment");
935
-
936
- // #1056 Finding 5: SNAPSHOT_TREE_MISMATCH means the init SUCCEEDED — the
937
- // snapshot IS a git repository, just not one holding the reviewed tree —
938
- // which is a different cause than SNAPSHOT_INIT_FAILED (no repository at
939
- // all). Repo-gated tests behave differently under it: they actually RUN
940
- // there, so a failure is a real measurement of a DIFFERENT tree, not the
941
- // "every test that needs one skips or fails" story the init-failed case
942
- // tells.
943
- const mismatched = environmentNote({ repoVerified: false, repoError: "SNAPSHOT_TREE_MISMATCH=snapshot aaa vs commit bbb" });
944
- assert.match(mismatched, /UNVERIFIED/, "a mismatched tree is not announced as degraded");
945
- assert.match(mismatched, /SNAPSHOT_TREE_MISMATCH=snapshot aaa vs commit bbb/, "the mismatch reason is dropped — a reader cannot tell which tree was measured");
946
- assert.match(mismatched, phrase("the snapshot IS a git repository"), "the mismatch case no longer says the init succeeded — it reads as no repository at all, which is the wrong cause");
947
- assert.doesNotMatch(
948
- mismatched,
949
- phrase("NOT a validation of the tree"),
950
- "the mismatch case still carries the init-failed consequence, which claims repo-gated tests skip or fail there when they actually RUN against the wrong tree",
951
- );
952
- });
953
-
954
- // The snapshot is handed a node_modules symlink AFTER its commit, so it is
955
- // untracked by construction — and an untracked entry makes every `git status`
956
- // in the snapshot read dirty, which is the one signal that would otherwise say
957
- // "this tree is exactly the reviewed commit". Excluded rather than committed:
958
- // in the index it would change the tree hash the verification rests on.
959
- test("a snapshot carrying the node_modules symlink still reads clean", (t) => {
960
- const worktree = reviewedRepo(t);
961
- const modules = join(worktree, "node_modules");
962
- mkdirSync(modules, { recursive: true });
963
- writeFileSync(join(modules, "marker"), "");
964
- const { snap, out } = cut(t, render(SOURCES[0][1], worktree));
965
-
966
- assert.match(out, /SNAPSHOT_TREE_MATCH/, `the fixture's own cut failed: ${out}`);
967
- assert.ok(existsSync(join(snap, "node_modules", "marker")), "the symlink is missing — a derived `npm test --` cannot run in there");
968
- assert.equal(
969
- git(snap, "status", "--porcelain", "--untracked-files=all"),
970
- "",
971
- "the snapshot reads dirty — the symlink is neither excluded nor committed, so `git status` there no longer says the tree is the reviewed commit",
972
- );
973
- // And it is NOT tracked: committed instead of excluded, the tree hash would
974
- // stop matching the reviewed commit's and every review would report a
975
- // mismatch it cannot act on.
976
- assert.equal(
977
- spawnSync("git", ["-C", snap, "ls-files", "--error-unmatch", "node_modules"], { env: ENV, encoding: "utf8" }).status !== 0,
978
- true,
979
- "node_modules is tracked in the snapshot — the tree hash cannot match the reviewed commit's",
980
- );
981
- });
982
-
983
- // The symlink the test above needs is created by the block's last line, whose
984
- // own guard is pinned as text elsewhere. This asserts the fixture actually
985
- // exercised that line rather than passing because nothing made a symlink.
986
- test("the block only symlinks node_modules where the reviewed tree has one", (t) => {
987
- const worktree = reviewedRepo(t);
988
- const { snap } = cut(t, render(SOURCES[0][1], worktree));
989
- // `existsSync` resolves through a symlink, so a mutation that bypasses the
990
- // `-d ${worktree}/node_modules` guard by producing a DANGLING symlink at
991
- // this path would still read as "nothing here" and pass silently.
992
- // `lstatSync` inspects the entry itself, dangling or not.
993
- let entry = true;
994
- try {
995
- lstatSync(join(snap, "node_modules"));
996
- } catch {
997
- entry = false;
998
- }
999
- assert.ok(!entry, "a snapshot of a repo with no node_modules carries one anyway — the guard on the symlink is gone");
1000
- assert.ok(existsSync(join(snap, ".git", "info", "exclude")), "the exclude file is missing, so the clean-status property above rests on nothing");
1001
- assert.match(
1002
- readFileSync(join(snap, ".git", "info", "exclude"), "utf8"),
1003
- /^node_modules$/m,
1004
- "node_modules is no longer excluded in the snapshot's own repository",
1005
- );
1006
- });