@feigi/fleet-ctl 3.23.36 → 3.23.37

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 (204) hide show
  1. package/package.json +1 -1
  2. package/scripts/main-checkout.mjs +1 -1
  3. package/scripts/member-write-guard.mjs +1 -1
  4. package/scripts/repo-root.mjs +1 -1
  5. package/skills/run-team/references/reaping.md +1 -1
  6. package/scripts/agent-test-dir-prose.test.mjs +0 -59
  7. package/scripts/agent-test.test.mjs +0 -1640
  8. package/scripts/ambient-git-vars-mjs-prose.test.mjs +0 -397
  9. package/scripts/ambient-git-vars-prose.test.mjs +0 -192
  10. package/scripts/ancestry-check-position-prose.test.mjs +0 -175
  11. package/scripts/apply-ruleset.test.mjs +0 -421
  12. package/scripts/arg-header-probes-prose.test.mjs +0 -394
  13. package/scripts/arg.test.mjs +0 -1354
  14. package/scripts/board-cli.test.mjs +0 -710
  15. package/scripts/board-identity.test.mjs +0 -429
  16. package/scripts/board-liveness-banner.test.mjs +0 -119
  17. package/scripts/board-prev-shape.test.mjs +0 -228
  18. package/scripts/board-tryparse-null.test.mjs +0 -119
  19. package/scripts/board.test.mjs +0 -3121
  20. package/scripts/brief-after-cut-prose.test.mjs +0 -53
  21. package/scripts/candidates-exit3-prose.test.mjs +0 -302
  22. package/scripts/candidates.test.mjs +0 -2312
  23. package/scripts/caveat-unification-prose.test.mjs +0 -98
  24. package/scripts/cell-readout.test.mjs +0 -615
  25. package/scripts/ci-comment-rot-prose.test.mjs +0 -2025
  26. package/scripts/ci-completes-premise-prose.test.mjs +0 -257
  27. package/scripts/ci-state-prose.test.mjs +0 -113
  28. package/scripts/ci-state.test.mjs +0 -1933
  29. package/scripts/ci-vacuous-green.test.mjs +0 -368
  30. package/scripts/citation-sweep-prose.test.mjs +0 -1712
  31. package/scripts/claim-lifecycle.test.mjs +0 -187
  32. package/scripts/claim-ticket.test.mjs +0 -1122
  33. package/scripts/closing-keyword-prose.test.mjs +0 -193
  34. package/scripts/cockpit-launch-idempotent-prose.test.mjs +0 -165
  35. package/scripts/cockpit-tick-nonblocking.test.mjs +0 -210
  36. package/scripts/compute-board.test.mjs +0 -1214
  37. package/scripts/compute-spend.test.mjs +0 -517
  38. package/scripts/consumer-technology-prose.test.mjs +0 -126
  39. package/scripts/cross-repo-citation-prose.test.mjs +0 -155
  40. package/scripts/cwd-isolation-pins.mjs +0 -83
  41. package/scripts/dedupe-guard-prose.test.mjs +0 -243
  42. package/scripts/delete-merged-branch.test.mjs +0 -576
  43. package/scripts/derive-testcmd.test.mjs +0 -595
  44. package/scripts/diff-stats.test.mjs +0 -404
  45. package/scripts/dispatch-block-golden-prose.test.mjs +0 -1130
  46. package/scripts/dispatch-block-pins-prose.test.mjs +0 -615
  47. package/scripts/dispositions-check.test.mjs +0 -936
  48. package/scripts/dispositions-gate-prose.test.mjs +0 -129
  49. package/scripts/drop-merged-label.test.mjs +0 -479
  50. package/scripts/exec-stub.mjs +0 -93
  51. package/scripts/exec-stub.test.mjs +0 -69
  52. package/scripts/expected-jobs-prose.test.mjs +0 -80
  53. package/scripts/fan-out-authorization-prose.test.mjs +0 -80
  54. package/scripts/filing-bar-seat-prose.test.mjs +0 -242
  55. package/scripts/filing-claim-bar-prose.test.mjs +0 -166
  56. package/scripts/finisher-died-prose.test.mjs +0 -31
  57. package/scripts/finisher-dispatch-premise-prose.test.mjs +0 -312
  58. package/scripts/finisher-halt-prose.test.mjs +0 -106
  59. package/scripts/finisher-name-prose.test.mjs +0 -134
  60. package/scripts/finisher-own-tree-prose.test.mjs +0 -299
  61. package/scripts/finisher-pin-race-prose.test.mjs +0 -339
  62. package/scripts/finisher-test-verdict-prose.test.mjs +0 -102
  63. package/scripts/fix-applier-correction-rules-prose.test.mjs +0 -202
  64. package/scripts/fix-applier-result-file-prose.test.mjs +0 -149
  65. package/scripts/fleet-bootstrap.test.mjs +0 -75
  66. package/scripts/fleet-heartbeat.test.mjs +0 -450
  67. package/scripts/fleet-provenance.test.mjs +0 -138
  68. package/scripts/fleet-run.test.mjs +0 -90
  69. package/scripts/fleet-state.test.mjs +0 -460
  70. package/scripts/fleet-tick-prose.test.mjs +0 -300
  71. package/scripts/fleet-tick.test.mjs +0 -2444
  72. package/scripts/force-with-lease-reason-prose.test.mjs +0 -184
  73. package/scripts/frontmatter-check.test.mjs +0 -436
  74. package/scripts/git-env.test.mjs +0 -149
  75. package/scripts/git-status-untracked-mode-sweep.test.mjs +0 -216
  76. package/scripts/gone-walk.test.mjs +0 -213
  77. package/scripts/gp-sep-invariant-prose.test.mjs +0 -188
  78. package/scripts/head-moved-after-label-prose.test.mjs +0 -233
  79. package/scripts/immutable-body-claim-prose.test.mjs +0 -204
  80. package/scripts/implementer-model-tier.test.mjs +0 -235
  81. package/scripts/inflight-citation-prose.test.mjs +0 -144
  82. package/scripts/inflight-exit2-prose.test.mjs +0 -81
  83. package/scripts/inflight-probe-guard-prose.test.mjs +0 -109
  84. package/scripts/inflight-scan-scope-prose.test.mjs +0 -57
  85. package/scripts/inflight.test.mjs +0 -2882
  86. package/scripts/injection-control-prose.test.mjs +0 -404
  87. package/scripts/install-root-audit.test.mjs +0 -464
  88. package/scripts/instrument-check-prose.test.mjs +0 -235
  89. package/scripts/instruments.test.mjs +0 -787
  90. package/scripts/is-cli.test.mjs +0 -99
  91. package/scripts/issue-tracker-prose.test.mjs +0 -71
  92. package/scripts/json.test.mjs +0 -364
  93. package/scripts/ledger-dispatch.test.mjs +0 -927
  94. package/scripts/ledger-grammar.test.mjs +0 -227
  95. package/scripts/ledger-read-require-file.test.mjs +0 -197
  96. package/scripts/ledger-rotate.test.mjs +0 -142
  97. package/scripts/ledger.test.mjs +0 -3436
  98. package/scripts/line-distance-prose.test.mjs +0 -245
  99. package/scripts/liveness-rationale-prose.test.mjs +0 -83
  100. package/scripts/locale-pin-prose.test.mjs +0 -189
  101. package/scripts/main-checkout.test.mjs +0 -332
  102. package/scripts/member-outcome-prose.test.mjs +0 -167
  103. package/scripts/member-outcomes-header.test.mjs +0 -129
  104. package/scripts/member-outcomes-prose.test.mjs +0 -63
  105. package/scripts/member-outcomes.test.mjs +0 -638
  106. package/scripts/member-prompt-prose.test.mjs +0 -165
  107. package/scripts/member-record.test.mjs +0 -541
  108. package/scripts/member-write-guard.test.mjs +0 -214
  109. package/scripts/merge-commit-probe-prose.test.mjs +0 -122
  110. package/scripts/merge-gate.test.mjs +0 -613
  111. package/scripts/muted-git-guard-sweep.test.mjs +0 -493
  112. package/scripts/net-ssh-precedence-prose.test.mjs +0 -91
  113. package/scripts/net-watchdog-prose.test.mjs +0 -79
  114. package/scripts/net.test.mjs +0 -211
  115. package/scripts/no-ci-gate-prose.test.mjs +0 -108
  116. package/scripts/no-undo-audit.test.mjs +0 -3961
  117. package/scripts/no-wave.test.mjs +0 -138
  118. package/scripts/node-floor-sweep.test.mjs +0 -611
  119. package/scripts/pointer-target-prose.test.mjs +0 -186
  120. package/scripts/pr-cost.test.mjs +0 -521
  121. package/scripts/pr-overlap.test.mjs +0 -692
  122. package/scripts/printf-die-sweep.test.mjs +0 -384
  123. package/scripts/prompt-renderer.mjs +0 -40
  124. package/scripts/prompt-renderer.test.mjs +0 -68
  125. package/scripts/prose-pin.mjs +0 -807
  126. package/scripts/prose-pin.test.mjs +0 -1034
  127. package/scripts/prove-merge.test.mjs +0 -995
  128. package/scripts/pull-table-relabel-prose.test.mjs +0 -60
  129. package/scripts/quiet-payload-prose.test.mjs +0 -222
  130. package/scripts/reap-cherry-check-prose.test.mjs +0 -80
  131. package/scripts/reap.test.mjs +0 -4432
  132. package/scripts/reaping-prose.test.mjs +0 -239
  133. package/scripts/reaping-reap-authorizers-prose.test.mjs +0 -112
  134. package/scripts/reaping-release-authorizers-prose.test.mjs +0 -85
  135. package/scripts/recipe-derivation-prose.test.mjs +0 -112
  136. package/scripts/recipe-prove.test.mjs +0 -1042
  137. package/scripts/refuter-scratch-prose.test.mjs +0 -135
  138. package/scripts/release-label-required-prose.test.mjs +0 -71
  139. package/scripts/release-label-split-prose.test.mjs +0 -184
  140. package/scripts/release-ticket-reap-pairing-prose.test.mjs +0 -63
  141. package/scripts/release-ticket.test.mjs +0 -5099
  142. package/scripts/renovate-release-contract.test.mjs +0 -379
  143. package/scripts/repo-root.test.mjs +0 -873
  144. package/scripts/reporter-output-rule-prose.test.mjs +0 -208
  145. package/scripts/review-agent-report-only.test.mjs +0 -49
  146. package/scripts/review-core-booking.test.mjs +0 -35
  147. package/scripts/review-core-cwd-isolation.test.mjs +0 -374
  148. package/scripts/review-core-reads.test.mjs +0 -478
  149. package/scripts/review-core-refuter-scratch.test.mjs +0 -148
  150. package/scripts/review-core-scratch-refusal.test.mjs +0 -64
  151. package/scripts/review-core-shared-test-run.test.mjs +0 -275
  152. package/scripts/review-core-snapshot-path.test.mjs +0 -830
  153. package/scripts/review-core-specialist-scratch.test.mjs +0 -191
  154. package/scripts/review-core-testcmd.test.mjs +0 -335
  155. package/scripts/review-core-unrun.test.mjs +0 -566
  156. package/scripts/review-core-unverified-discriminant.test.mjs +0 -208
  157. package/scripts/review-eval-resolver-path.test.mjs +0 -55
  158. package/scripts/review-host-fixture.mjs +0 -89
  159. package/scripts/review-in-run-retry.test.mjs +0 -211
  160. package/scripts/review-no-vendor-dispatch.test.mjs +0 -45
  161. package/scripts/review-path-default.test.mjs +0 -796
  162. package/scripts/review-runner-spawns.test.mjs +0 -95
  163. package/scripts/review-runner.test.mjs +0 -166
  164. package/scripts/review-tier-audit.test.mjs +0 -140
  165. package/scripts/run-artifact-pr-prose.test.mjs +0 -341
  166. package/scripts/run-merge-bot-prose.test.mjs +0 -1413
  167. package/scripts/run-team-local-hook.test.mjs +0 -442
  168. package/scripts/scratch-partition-invariant-prose.test.mjs +0 -74
  169. package/scripts/scripts-path-citation-sweep.test.mjs +0 -73
  170. package/scripts/section-between-guard-prose.test.mjs +0 -379
  171. package/scripts/select-dimensions.test.mjs +0 -674
  172. package/scripts/shared-refusal.test.mjs +0 -388
  173. package/scripts/shell-traps-prose.test.mjs +0 -504
  174. package/scripts/shortlist.test.mjs +0 -380
  175. package/scripts/slow-transport.mjs +0 -72
  176. package/scripts/snapshot-repo.test.mjs +0 -1006
  177. package/scripts/snapshot-runner-audience-prose.test.mjs +0 -130
  178. package/scripts/spend-view.test.mjs +0 -312
  179. package/scripts/staleness-qualifier-prose.test.mjs +0 -251
  180. package/scripts/staleness-verdict-prose.test.mjs +0 -142
  181. package/scripts/staleness.test.mjs +0 -893
  182. package/scripts/stalled-member-liveness-prose.test.mjs +0 -219
  183. package/scripts/stash-prohibition-prose.test.mjs +0 -313
  184. package/scripts/strip-comments.mjs +0 -44
  185. package/scripts/temp-dir.mjs +0 -47
  186. package/scripts/ticket-router.test.mjs +0 -981
  187. package/scripts/tier-check.test.mjs +0 -828
  188. package/scripts/tier-outcomes-header.test.mjs +0 -518
  189. package/scripts/tier-outcomes.test.mjs +0 -572
  190. package/scripts/tier-roles.test.mjs +0 -535
  191. package/scripts/tracker-block-copy-prose.test.mjs +0 -288
  192. package/scripts/triage-labels-gloss-prose.test.mjs +0 -97
  193. package/scripts/unattended-git-sweep.test.mjs +0 -142
  194. package/scripts/verify-sha-exit2-prose.test.mjs +0 -269
  195. package/scripts/verify-sha.test.mjs +0 -692
  196. package/scripts/watcher-degraded-block.test.mjs +0 -369
  197. package/scripts/watcher-key-prose.test.mjs +0 -106
  198. package/scripts/within-run-pair-prose.test.mjs +0 -212
  199. package/scripts/worktree-audit.test.mjs +0 -1408
  200. package/scripts/worktree-head-prose.test.mjs +0 -276
  201. package/scripts/worktree-listing-sweep.test.mjs +0 -217
  202. package/scripts/worktree-model-prose.test.mjs +0 -216
  203. package/scripts/worktree-porcelain.mjs +0 -35
  204. package/scripts/worktree-porcelain.test.mjs +0 -102
@@ -1,995 +0,0 @@
1
- // Regression gate for prove-merge.sh, the proof that says which head actually
2
- // landed. Zero deps: `node --test plugin/scripts/prove-merge.test.mjs`.
3
- //
4
- // A shell script that reasons about git history can only be tested against real
5
- // git history, so the cases below that reason about history build a throwaway
6
- // origin+clone in a temp dir and run the script for real; a case that reasons
7
- // about the script's source text directly does not.
8
- //
9
- // The load-bearing case is `un-rebased head that merged cleanly still proves
10
- // false` — that attack is the whole reason the script exists, and relaxing the
11
- // pre-rebase ancestor gate for the no-rebase path is exactly the change that
12
- // could silently drop it.
13
-
14
- import { test } from "node:test";
15
- import assert from "node:assert/strict";
16
- import { execFileSync, spawnSync } from "node:child_process";
17
- import { copyFileSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
18
- import { tmpdir } from "node:os";
19
- import { join } from "node:path";
20
- import { fileURLToPath } from "node:url";
21
- import { slowTransport, SSH_URL } from "./slow-transport.mjs";
22
- import { writeExecStub } from "./exec-stub.mjs";
23
-
24
- const SCRIPT = fileURLToPath(new URL("./prove-merge.sh", import.meta.url));
25
-
26
- // Pin identity and cut the developer's ~/.gitconfig out of the fixture, so a
27
- // local `pull.rebase` or hook cannot change what these repos look like.
28
- const ENV = {
29
- ...process.env,
30
- // The script reads BASE_REF, and the fleet harness is exactly the caller that
31
- // would have it set — inheriting it points every fixture at local `main` and
32
- // the suite stays green while measuring the wrong ref. Same for the GIT_* vars,
33
- // which redirect the fixtures out of their own temp dirs.
34
- BASE_REF: undefined,
35
- GIT_DIR: undefined,
36
- GIT_WORK_TREE: undefined,
37
- GIT_TEMPLATE_DIR: undefined,
38
- GIT_INDEX_FILE: undefined,
39
- GIT_AUTHOR_NAME: "t",
40
- GIT_AUTHOR_EMAIL: "t@example.com",
41
- GIT_COMMITTER_NAME: "t",
42
- GIT_COMMITTER_EMAIL: "t@example.com",
43
- GIT_CONFIG_GLOBAL: "/dev/null",
44
- GIT_CONFIG_SYSTEM: "/dev/null",
45
- // Two cases below assert on git's OWN diagnostic text, across three strings,
46
- // and one of those strings is gettext-translatable: rev-parse's "Needed a
47
- // single revision" is `die(_("..."))` in builtin/rev-parse.c, and git ships a
48
- // live German msgstr for it. cat-file's "Not a valid object name" and
49
- // object-name.c's "dereferences to %s type" are unwrapped today — pinning the
50
- // locale is what stops any of the three turning on which git build CI runs.
51
- LANG: "C",
52
- LC_ALL: "C",
53
- };
54
-
55
- const git = (cwd, ...args) =>
56
- execFileSync("git", args, { cwd, env: ENV, encoding: "utf8" }).trim();
57
-
58
- // Absolute path to the real git, for the one test that shadows `git` on PATH.
59
- const REAL_GIT = execFileSync("sh", ["-c", "command -v git"], { encoding: "utf8" }).trim();
60
-
61
- // Absolute path to the real sed, for the two cases that shadow `sed` on PATH.
62
- const REAL_SED = execFileSync("sh", ["-c", "command -v sed"], { encoding: "utf8" }).trim();
63
-
64
- /** Empty commit on the current branch; returns its sha. */
65
- const commit = (w, msg) => {
66
- git(w, "commit", "-q", "--allow-empty", "-m", msg);
67
- return git(w, "rev-parse", "HEAD");
68
- };
69
-
70
- /** Bare origin + working clone with one commit on main. Returns the clone dir. */
71
- function repo(t) {
72
- const root = mkdtempSync(join(tmpdir(), "prove-merge-"));
73
- t.after(() => rmSync(root, { recursive: true, force: true }));
74
- const origin = join(root, "origin.git");
75
- const w = join(root, "w");
76
- execFileSync("git", ["-c", "init.defaultBranch=main", "init", "-q", "--bare", origin], { env: ENV });
77
- execFileSync("git", ["clone", "-q", origin, w], { env: ENV });
78
- commit(w, "root");
79
- git(w, "branch", "-M", "main");
80
- git(w, "push", "-q", "-u", "origin", "main");
81
- return w;
82
- }
83
-
84
- /** Merge `head` into main with a real merge commit; returns the merge sha. */
85
- function mergeNoFf(w, head, msg) {
86
- git(w, "checkout", "-q", "main");
87
- git(w, "merge", "-q", "--no-ff", "-m", msg, head);
88
- return git(w, "rev-parse", "HEAD");
89
- }
90
-
91
- function prove(cwd, pre, post, merge) {
92
- const r = spawnSync("sh", [SCRIPT, pre, post, merge], { cwd, env: ENV, encoding: "utf8" });
93
- const json = r.stdout.trim() ? JSON.parse(r.stdout) : null;
94
- // #18. The `gates` object's entire contract: `proved` is true exactly when
95
- // every value in it is true. Checked here rather than in one test of its own,
96
- // so every fixture in this file — each verdict, each attack — pins it, and a
97
- // gate that stops being load-bearing cannot be added or dropped in silence.
98
- if (json) {
99
- assert.equal(
100
- json.proved,
101
- Object.values(json.gates).every((v) => v === true),
102
- "proved must be exactly the conjunction of the gates object",
103
- );
104
- }
105
- return { code: r.status, json, stderr: r.stderr };
106
- }
107
-
108
- test("already-current merge (pre == post, behind_by=0) proves true", (t) => {
109
- const w = repo(t);
110
- // Advance main first and cut the branch from the new tip. Branching off the
111
- // root instead would make headWasCurrent hold trivially — every commit
112
- // descends from the root — and the case would pass without measuring currency.
113
- commit(w, "main moves on before the branch is cut");
114
- git(w, "push", "-q", "origin", "main");
115
- const mainTip = git(w, "rev-parse", "main");
116
- git(w, "checkout", "-q", "-b", "feat");
117
- const head = commit(w, "feature work");
118
- const merge = mergeNoFf(w, head, "merge feat");
119
- git(w, "push", "-q", "origin", "main");
120
- assert.equal(git(w, "rev-parse", `${merge}^1`), mainTip, "fixture: main really had moved");
121
-
122
- const { code, json } = prove(w, head, head, merge);
123
- assert.equal(json.proved, true, "an already-current merge must not false-negative");
124
- assert.equal(json.proofPath, "no-rebase");
125
- assert.equal(json.headWasCurrent, true);
126
- assert.equal(json.secondParent, head);
127
- assert.equal(json.firstParent, mainTip, "the main tip the merge was built on");
128
- assert.equal(code, 0);
129
- // Leg 1 wants this false, and here it cannot be: the merge landed, so leg 2
130
- // makes pre — the same commit — an ancestor too. Legs 1 and 2 are jointly
131
- // unsatisfiable when pre == post, which is why leg 1 is dropped on this path.
132
- assert.equal(json.preIsAncestor, true);
133
- // #18: and that true reading sits next to proved:true without contradiction
134
- // only because it is an observation here, not a gate. Its ABSENCE from `gates`
135
- // is the machine-readable form of "leg 1 was dropped on this path" — the thing
136
- // a consumer previously had to infer from `proofPath`.
137
- assert.deepEqual(json.gates, {
138
- postIsAncestor: true,
139
- secondParentIsHead: true,
140
- exactlyTwoParents: true,
141
- headWasCurrent: true,
142
- });
143
- assert.ok(!("preDidNotLand" in json.gates), "leg 1 is not a gate when pre == post");
144
- });
145
-
146
- test("rebase-then-merge (pre != post) proves true on the rebase path", (t) => {
147
- const w = repo(t);
148
- const branchPoint = git(w, "rev-parse", "main");
149
- git(w, "checkout", "-q", "main");
150
- commit(w, "main moves on");
151
- git(w, "push", "-q", "origin", "main");
152
-
153
- git(w, "checkout", "-q", "-b", "feat", branchPoint);
154
- const pre = commit(w, "feature work");
155
- git(w, "rebase", "-q", "main");
156
- const post = git(w, "rev-parse", "HEAD");
157
- // Not `notEqual(pre, post)` — that only proves the sha moved, which an amend
158
- // would also do. The rebase is real only if the head now sits on the main tip.
159
- assert.equal(git(w, "rev-parse", `${post}^`), git(w, "rev-parse", "main"));
160
-
161
- const merge = mergeNoFf(w, post, "merge feat");
162
- git(w, "push", "-q", "origin", "main");
163
-
164
- const { code, json } = prove(w, pre, post, merge);
165
- assert.equal(json.proved, true);
166
- assert.equal(json.proofPath, "rebase");
167
- assert.deepEqual(
168
- { pre: json.preIsAncestor, post: json.postIsAncestor, second: json.secondParent },
169
- { pre: false, post: true, second: post },
170
- );
171
- // #18. Leg 1 IS a gate here, and the gate reads true while the observation it
172
- // is derived from reads false — the polarity a bare list of gate NAMES could
173
- // not carry, and the reason `gates` holds booleans rather than field names.
174
- assert.deepEqual(json.gates, {
175
- preDidNotLand: true,
176
- postIsAncestor: true,
177
- secondParentIsHead: true,
178
- exactlyTwoParents: true,
179
- headWasCurrent: true,
180
- });
181
- assert.equal(code, 0);
182
- });
183
-
184
- test("rebase path still fails leg 1 when the branch was updated by merging main in", (t) => {
185
- // Not a rebase: main was merged *into* the branch, so the pre head survives as
186
- // an ancestor of main. pre != post, so the leg-1 gate stays mandatory here.
187
- const w = repo(t);
188
- const branchPoint = git(w, "rev-parse", "main");
189
- git(w, "checkout", "-q", "main");
190
- commit(w, "main moves on");
191
- git(w, "push", "-q", "origin", "main");
192
-
193
- git(w, "checkout", "-q", "-b", "feat", branchPoint);
194
- const pre = commit(w, "feature work");
195
- git(w, "merge", "-q", "--no-ff", "-m", "merge main into feat", "main");
196
- const post = git(w, "rev-parse", "HEAD");
197
-
198
- const merge = mergeNoFf(w, post, "merge feat");
199
- git(w, "push", "-q", "origin", "main");
200
-
201
- const { code, json } = prove(w, pre, post, merge);
202
- assert.equal(json.preIsAncestor, true);
203
- assert.equal(json.proved, false, "leg 1 must still bite on the rebase path");
204
- assert.equal(code, 1);
205
- });
206
-
207
- test("ATTACK: un-rebased head that merged cleanly still proves false", (t) => {
208
- // The head was built on an older main, main moved, and it was merged without
209
- // ever being rebased. The caller then claims "no rebase was needed" by passing
210
- // pre == post. The no-rebase path must not accept this.
211
- const w = repo(t);
212
- const stalePoint = git(w, "rev-parse", "main");
213
- git(w, "checkout", "-q", "-b", "stale", stalePoint);
214
- const head = commit(w, "stale feature work");
215
-
216
- git(w, "checkout", "-q", "main");
217
- commit(w, "main moved on without the branch");
218
- const merge = mergeNoFf(w, head, "merge stale branch WITHOUT rebasing");
219
- git(w, "push", "-q", "origin", "main");
220
-
221
- // Everything the relaxed path looks at except currency is satisfied:
222
- assert.equal(git(w, "rev-parse", `${merge}^2`), head, "fixture: the stale head really did land");
223
-
224
- const { code, json } = prove(w, head, head, merge);
225
- assert.equal(json.headWasCurrent, false, "prior main tip is not an ancestor of the merged head");
226
- assert.equal(json.proved, false, "an un-rebased head must never prove true");
227
- assert.equal(code, 1);
228
- });
229
-
230
- test("gates.postIsAncestor is false when the claimed head never landed", (t) => {
231
- // No existing fixture drives a false postIsAncestor through to the payload:
232
- // the only way `post` itself fails to be an ancestor while `merge` still
233
- // lands is to hand the script a `post` that is not the merge's real second
234
- // parent at all — every fixture where they DO match has post_anc forced true
235
- // by transitivity (post is a parent of merge, merge lands, so post lands).
236
- const w = repo(t);
237
- // A real, unrelated merge that landed on main.
238
- git(w, "checkout", "-q", "-b", "feat");
239
- const realHead = commit(w, "feature work");
240
- const merge = mergeNoFf(w, realHead, "merge feat");
241
- git(w, "push", "-q", "origin", "main");
242
-
243
- // A head that never merged anywhere, passed as the claimed post/pre.
244
- git(w, "checkout", "-q", "-b", "unmerged", "main");
245
- const claimedHead = commit(w, "an unmerged head passed as the claimed post");
246
-
247
- const { code, json } = prove(w, claimedHead, claimedHead, merge);
248
- assert.equal(json.postIsAncestor, false, "fixture: the claimed head really never landed");
249
- assert.equal(json.gates.postIsAncestor, false);
250
- assert.equal(json.proved, false);
251
- assert.equal(code, 1);
252
- });
253
-
254
- test("ATTACK: wrong head — merge second parent is not the verified-green head", (t) => {
255
- // Leg 3 has to be the *only* gate that bites here, or this test proves nothing
256
- // about leg 3. So the green head really does land (leg 2 passes) and the wrong
257
- // merge's first parent really is an ancestor of it (headWasCurrent passes).
258
- const w = repo(t);
259
- const base = git(w, "rev-parse", "main");
260
- git(w, "checkout", "-q", "-b", "green", base);
261
- const green = commit(w, "the head that was verified green");
262
- git(w, "checkout", "-q", "-b", "other", base);
263
- const other = commit(w, "a different head entirely");
264
- const wrongMerge = mergeNoFf(w, other, "merge the wrong branch");
265
- mergeNoFf(w, green, "merge the green branch too, later");
266
- git(w, "push", "-q", "origin", "main");
267
-
268
- const { code, json } = prove(w, green, green, wrongMerge);
269
- assert.deepEqual(
270
- { post: json.postIsAncestor, current: json.headWasCurrent, parents: json.parentCount },
271
- { post: true, current: true, parents: 2 },
272
- "every other gate must pass, so only leg 3 can explain the disproof",
273
- );
274
- assert.equal(json.secondParent, other);
275
- // Leg 3 is the only false gate, so the object names the cause on its own —
276
- // without the caller diffing `secondParent` against a head it has to remember.
277
- assert.equal(json.gates.secondParentIsHead, false);
278
- assert.equal(json.proved, false);
279
- assert.equal(code, 1);
280
- });
281
-
282
- test("ATTACK: a merge commit the caller fabricated is an error, not a proof", (t) => {
283
- // Every gate that reads structure reads it off <merge>. Hand over an object
284
- // built to satisfy them — first parent an ancestor of the head, second parent
285
- // the head itself — and without the reachability anchor it proves true.
286
- const w = repo(t);
287
- const branchPoint = git(w, "rev-parse", "main");
288
- git(w, "checkout", "-q", "-b", "feat");
289
- const head = commit(w, "feature work");
290
- mergeNoFf(w, head, "the real merge");
291
- git(w, "push", "-q", "origin", "main");
292
-
293
- const tree = git(w, "rev-parse", `${head}^{tree}`);
294
- const fake = git(w, "commit-tree", tree, "-p", branchPoint, "-p", head, "-m", "fabricated");
295
- assert.equal(
296
- spawnSync("git", ["merge-base", "--is-ancestor", fake, "origin/main"], { cwd: w, env: ENV }).status,
297
- 1,
298
- "fixture: the fabricated merge really is unreachable from the base ref",
299
- );
300
-
301
- const { code, json, stderr } = prove(w, head, head, fake);
302
- assert.equal(json, null, "an unreachable merge must not emit a proof at all");
303
- assert.equal(code, 2, "that merge did not land — an error, not a disproof");
304
- assert.match(stderr, /is not reachable from/);
305
- });
306
-
307
- test("currency is required on the rebase path too, not just the no-rebase one", (t) => {
308
- // Rebased early onto B, then a sibling landed C, then merged without re-rebasing.
309
- // Leg 1 is satisfied — the pre head really was orphaned — so only headWasCurrent
310
- // can catch that the merged head was stale at merge time.
311
- const w = repo(t);
312
- const branchPoint = git(w, "rev-parse", "main");
313
- git(w, "checkout", "-q", "main");
314
- commit(w, "main -> B");
315
- git(w, "push", "-q", "origin", "main");
316
-
317
- git(w, "checkout", "-q", "-b", "feat", branchPoint);
318
- const pre = commit(w, "feature work");
319
- git(w, "rebase", "-q", "main");
320
- const post = git(w, "rev-parse", "HEAD");
321
-
322
- git(w, "checkout", "-q", "main");
323
- commit(w, "a sibling lands -> C");
324
- const merge = mergeNoFf(w, post, "merge feat WITHOUT re-rebasing onto C");
325
- git(w, "push", "-q", "origin", "main");
326
-
327
- const { code, json } = prove(w, pre, post, merge);
328
- assert.deepEqual(
329
- { path: json.proofPath, pre: json.preIsAncestor, second: json.secondParent },
330
- { path: "rebase", pre: false, second: post },
331
- "leg 1 passes here, so only headWasCurrent can explain the disproof",
332
- );
333
- assert.equal(json.headWasCurrent, false);
334
- assert.equal(json.proved, false, "a head that went stale between rebase and merge is not proved");
335
- assert.equal(code, 1);
336
- });
337
-
338
- test("ATTACK: a dishonest `pre` cannot downgrade the proof to the weaker path", (t) => {
339
- // Same stale un-rebased merge the ATTACK case above pins at false. The caller
340
- // claims a rebase happened by passing any commit that never landed as `pre`,
341
- // which routes to the rebase path and satisfies leg 1. headWasCurrent is the
342
- // only gate left that is derived from history rather than from the arguments.
343
- const w = repo(t);
344
- const stalePoint = git(w, "rev-parse", "main");
345
- git(w, "checkout", "-q", "-b", "stale", stalePoint);
346
- const head = commit(w, "stale feature work");
347
- git(w, "checkout", "-q", "-b", "junk", stalePoint);
348
- const junk = commit(w, "an abandoned attempt that never landed");
349
-
350
- git(w, "checkout", "-q", "main");
351
- commit(w, "main moved on without the branch");
352
- const merge = mergeNoFf(w, head, "merge stale branch WITHOUT rebasing");
353
- git(w, "push", "-q", "origin", "main");
354
-
355
- const { code, json } = prove(w, junk, head, merge);
356
- assert.equal(json.proofPath, "rebase", "fixture: the lie really does route to the rebase path");
357
- assert.equal(json.preIsAncestor, false, "fixture: leg 1 really is satisfied by the lie");
358
- assert.equal(json.proved, false, "the same merge must not prove true just because `pre` changed");
359
- assert.equal(code, 1);
360
- });
361
-
362
- test("a <merge-commit> that also names a file is read as a revision", (t) => {
363
- // `git rev-list --parents -n 1 mrg` is fatal when `mrg` is both a ref and a
364
- // path. The old code read `${merge}^2`, where the suffix disambiguated for free.
365
- const w = repo(t);
366
- git(w, "checkout", "-q", "-b", "feat");
367
- const head = commit(w, "feature work");
368
- const merge = mergeNoFf(w, head, "merge feat");
369
- git(w, "branch", "mrg", merge);
370
- writeFileSync(join(w, "mrg"), "a file with the same name as the branch\n");
371
- git(w, "add", "mrg");
372
- commit(w, "add a file named mrg");
373
- git(w, "push", "-q", "origin", "main");
374
-
375
- const { code, json } = prove(w, head, head, "mrg");
376
- assert.equal(json?.proved, true, "an ambiguous name must resolve as a revision, not error out");
377
- assert.equal(code, 0);
378
- });
379
-
380
- test("a git failure reading the parents is an error, never a silent disproof", (t) => {
381
- // `set -- $(cmd)` discards cmd's status, and an empty result trips `shift`
382
- // under `set -e` — exit 1 with no stdout, which a caller cannot tell apart
383
- // from a legitimate proved=false. Shim only `rev-list`; everything else is
384
- // real git, so the script gets all the way to the parents read.
385
- const w = repo(t);
386
- git(w, "checkout", "-q", "-b", "feat");
387
- const head = commit(w, "feature work");
388
- const merge = mergeNoFf(w, head, "merge feat");
389
- git(w, "push", "-q", "origin", "main");
390
-
391
- const bin = mkdtempSync(join(tmpdir(), "prove-merge-shim-"));
392
- t.after(() => rmSync(bin, { recursive: true, force: true }));
393
- // Ask the shell where git is, rather than deriving it from `--exec-path`:
394
- // that answer is `<prefix>/libexec/git-core` on macOS but `/usr/lib/git-core`
395
- // on Debian, where a `libexec` rewrite matches nothing and the shim execs a
396
- // DIRECTORY — "Permission denied", the fetch fails first, and the parents are
397
- // never read, so this test measures the wrong failure. Resolved out here,
398
- // where PATH is still the real one; inside the shim, `git` is the shim.
399
- writeExecStub(
400
- join(bin, "git"),
401
- `#!/bin/sh\n[ "$1" = rev-list ] && exit 128\nexec ${REAL_GIT} "$@"\n`,
402
- );
403
-
404
- const r = spawnSync("sh", [SCRIPT, head, head, merge], {
405
- cwd: w,
406
- env: { ...ENV, PATH: `${bin}:${ENV.PATH ?? process.env.PATH}` },
407
- encoding: "utf8",
408
- });
409
- assert.equal(r.stdout.trim(), "", "fixture: the shim really did break the parents read");
410
- assert.equal(r.status, 2, "a git failure is exit 2, not the exit 1 that means disproved");
411
- assert.match(r.stderr, /cannot read the parents of/);
412
- });
413
-
414
- test("a non-merge commit as <merge-commit> is a usage error, not a disproof", (t) => {
415
- const w = repo(t);
416
- git(w, "checkout", "-q", "-b", "feat");
417
- const head = commit(w, "feature work");
418
- mergeNoFf(w, head, "merge feat");
419
- git(w, "push", "-q", "origin", "main");
420
-
421
- const { code, json, stderr } = prove(w, head, head, head);
422
- assert.equal(json, null);
423
- assert.equal(code, 2);
424
- assert.match(stderr, /has no second parent/);
425
- });
426
-
427
- test("pre and post are compared as commits, not as the strings the caller typed", (t) => {
428
- // `feat` and its sha are the same commit, so this is the already-current case
429
- // and must take the no-rebase path. Comparing raw arguments would read it as a
430
- // rebase and reintroduce exactly the false negative this script was fixed for.
431
- const w = repo(t);
432
- git(w, "checkout", "-q", "-b", "feat");
433
- const head = commit(w, "feature work");
434
- const merge = mergeNoFf(w, head, "merge feat");
435
- git(w, "push", "-q", "origin", "main");
436
-
437
- for (const spelling of ["feat", head.slice(0, 8)]) {
438
- const { code, json } = prove(w, spelling, head, merge);
439
- assert.equal(json.proofPath, "no-rebase", `\`${spelling}\` names the same commit as its sha`);
440
- assert.equal(json.proved, true);
441
- assert.equal(code, 0);
442
- }
443
- });
444
-
445
- test("ATTACK: octopus merge dragging in an unreviewed third parent proves false", (t) => {
446
- const w = repo(t);
447
- const base = git(w, "rev-parse", "main");
448
- git(w, "checkout", "-q", "-b", "feat", base);
449
- const head = commit(w, "feature work");
450
- git(w, "checkout", "-q", "-b", "smuggled", base);
451
- commit(w, "unreviewed code riding along");
452
-
453
- git(w, "checkout", "-q", "main");
454
- git(w, "merge", "-q", "--no-ff", "-m", "octopus", "feat", "smuggled");
455
- const merge = git(w, "rev-parse", "HEAD");
456
- git(w, "push", "-q", "origin", "main");
457
-
458
- assert.equal(git(w, "rev-parse", `${merge}^2`), head, "fixture: ^2 still looks right");
459
-
460
- const { code, json } = prove(w, head, head, merge);
461
- assert.equal(json.parentCount, 3);
462
- // The gate, not just the observation: `parentCount >= 2` is a precondition
463
- // that dies at exit 2, while `== 2` is what decides this verdict, and only the
464
- // second one belongs in `gates`.
465
- assert.equal(json.gates.exactlyTwoParents, false);
466
- assert.equal(json.proved, false, "only a two-parent merge can be proved");
467
- assert.equal(code, 1);
468
- });
469
-
470
- test("post-fetch: a correct merge stays true once origin/main has moved past it", (t) => {
471
- // The script fetches before it checks, so by the time it runs the merge is
472
- // already in the base ref — and when one merge-bot run merges several PRs,
473
- // main has moved on again. Neither may, by itself, flip a correct merge to
474
- // false.
475
- const w = repo(t);
476
- git(w, "checkout", "-q", "-b", "feat");
477
- const head = commit(w, "feature work");
478
- const merge = mergeNoFf(w, head, "merge feat");
479
- git(w, "push", "-q", "origin", "main");
480
-
481
- // A later merge in the same merge-bot run lands on top.
482
- git(w, "checkout", "-q", "-b", "feat2");
483
- const head2 = commit(w, "the next PR in the same run");
484
- mergeNoFf(w, head2, "merge feat2");
485
- git(w, "push", "-q", "origin", "main");
486
-
487
- const { code, json } = prove(w, head, head, merge);
488
- assert.equal(json.proved, true, "a correct merge must survive the base ref moving past it");
489
- assert.equal(code, 0);
490
- });
491
-
492
- test("exit code tracks proved; usage errors exit 2", (t) => {
493
- const w = repo(t);
494
- git(w, "checkout", "-q", "-b", "feat");
495
- const head = commit(w, "feature work");
496
- const merge = mergeNoFf(w, head, "merge feat");
497
- git(w, "push", "-q", "origin", "main");
498
-
499
- const ok = prove(w, head, head, merge);
500
- assert.deepEqual([ok.json.proved, ok.code], [true, 0]);
501
-
502
- const priorTip = git(w, "rev-parse", `${merge}^1`);
503
- const bad = prove(w, priorTip, priorTip, merge);
504
- assert.deepEqual([bad.json.proved, bad.code], [false, 1]);
505
-
506
- const usage = spawnSync("sh", [SCRIPT, head], { cwd: w, env: ENV, encoding: "utf8" });
507
- assert.equal(usage.status, 2);
508
- const unknown = prove(w, head, head, "0".repeat(40));
509
- assert.equal(unknown.code, 2, "an unresolvable commit is an error, not a disproof");
510
- });
511
-
512
- test("a base ref the probe cannot answer for reports the probe failure, not a disproof", (t) => {
513
- // #267. `die` inside `$(...)` exits the subshell only, and `[ ]` throws that
514
- // status away — `set -e` never fires, control falls through to the outer die,
515
- // and "that merge did not land" is printed for a merge-base that never
516
- // answered. The honest cause prints first, but the *verdict* is the wrong one.
517
- //
518
- // A tree as BASE_REF is the way in, with no fault injection and no PATH shim:
519
- // $base is only `rev-parse --verify`'d and never commit-checked, so a tree
520
- // clears the gate and reaches the probe, where git exits 128 rather than 1.
521
- // Every commit already carries one, so no file has to be written to get it.
522
- const w = repo(t);
523
- git(w, "checkout", "-q", "-b", "feat");
524
- const head = commit(w, "feature work");
525
- const merge = mergeNoFf(w, head, "merge feat");
526
- git(w, "push", "-q", "origin", "main");
527
-
528
- const tree = git(w, "rev-parse", `${head}^{tree}`);
529
- assert.equal(git(w, "cat-file", "-t", tree), "tree", "fixture: BASE_REF really names a tree");
530
-
531
- const r = spawnSync("sh", [SCRIPT, head, head, merge], {
532
- cwd: w,
533
- env: { ...ENV, BASE_REF: tree },
534
- encoding: "utf8",
535
- });
536
- assert.match(r.stderr, /failed — cannot prove anything/, "fixture: the probe really did fail");
537
- assert.doesNotMatch(
538
- r.stderr,
539
- /did not land/,
540
- "a probe that could not answer must never be reported as a disproof it never established",
541
- );
542
- assert.equal(r.stdout.trim(), "", "a probe that did not answer emits no proof");
543
- // Not the discriminator: `die` is `exit 2` unconditionally, so this held before
544
- // the fix too. The stderr assertion above is what separates the two messages.
545
- assert.equal(r.status, 2, "a die is exit 2 — the question was not answered, so no exit 1 for a `no`");
546
-
547
- // The other half: the same fixture, with a base that CAN answer, must still be
548
- // accepted. Assigning the probe first makes `set -e` live on this line, so a
549
- // suite that only ever fed it a failing probe would not notice it aborting on
550
- // a good one — the false positive that a fix for a false negative invites.
551
- const { code, json } = prove(w, head, head, merge);
552
- assert.equal(json.proved, true, "a merge that did land must still prove true");
553
- assert.equal(code, 0);
554
- });
555
-
556
- test("an object that is present but is not a commit is not reported as absent", (t) => {
557
- const w = repo(t);
558
- git(w, "checkout", "-q", "-b", "feat");
559
- const head = commit(w, "feature work");
560
-
561
- // A tree, so the object really is in this repository. Every commit already
562
- // carries one, so no file has to be written to get it.
563
- const tree = git(w, "rev-parse", `${head}^{tree}`);
564
- // <merge-commit> is `head`, not a merge: the cat-file loop dies on its FIRST
565
- // element, so the third argument is never reached and a real merge here would
566
- // only be scenery.
567
- const { code, json, stderr } = prove(w, tree, head, head);
568
- assert.equal(code, 2);
569
- assert.equal(json, null);
570
- assert.match(stderr, /cannot resolve .+ to a commit in this repository/);
571
- // The old wording asserted this object "is not a commit in this repository".
572
- // It is in this repository — git reads it and reports its real type, which is
573
- // the half `2>/dev/null` was throwing away.
574
- assert.match(stderr, /dereferences to tree type/, "git's own diagnosis must survive to stderr");
575
- // Names which guard fired: the two guards above are also exit 2 with no stdout.
576
- assert.doesNotMatch(stderr, /fetch failed|does not resolve/, "the guards above this one passed");
577
-
578
- // The discriminator the old message threw away: a sha that really is absent
579
- // used to print the identical die line, and now carries a different git line.
580
- const absent = prove(w, "0".repeat(40), head, head);
581
- assert.equal(absent.code, 2);
582
- assert.match(absent.stderr, /Not a valid object name 0{40}/);
583
- assert.doesNotMatch(
584
- absent.stderr,
585
- /dereferences to/,
586
- "an absent sha and a present non-commit must not collapse into one message",
587
- );
588
- });
589
-
590
- test("ATTACK: an annotated tag is refused at the guard, not silently mishandled into a false disproof (#585)", (t) => {
591
- // cat-file -e peels a tag to the commit underneath, so the existence guard
592
- // above accepted a tag on its own — and then bare `git rev-parse` handed
593
- // back the TAG's own sha, not the commit's, which the identity test later in
594
- // this script could never match. Every other leg still read healthy, so a
595
- // perfectly good merge came back proved=false with no hint the mismatch was
596
- // in argument handling rather than history. The guard now also checks
597
- // $obj's own (unpeeled) type and refuses anything that is not itself a
598
- // commit, so the tag never reaches that comparison at all.
599
- const w = repo(t);
600
- git(w, "checkout", "-q", "-b", "feat");
601
- const head = commit(w, "feature work");
602
- const merge = mergeNoFf(w, head, "merge feat");
603
- // Load-bearing, not scenery: without the merge on origin, the PRE-fix script
604
- // dies at `not reachable from origin/main` — exit 2, no proof — and every
605
- // `code === 2` below passes on the bug it exists to catch.
606
- git(w, "push", "-q", "origin", "main");
607
- git(w, "tag", "-a", "v1", "-m", "annotated", head);
608
-
609
- const { code, json, stderr } = prove(w, "v1", "v1", merge);
610
- assert.equal(code, 2, "could not answer — never the 1 that means disproved, and not 0");
611
- assert.equal(json, null, "a refused input must not emit a proof at all");
612
- assert.match(stderr, /v1 is a tag, not a commit/, "the message names the object and its type");
613
-
614
- // The tag in the SECOND position alone: the call above dies on the loop's
615
- // first element, so it never reaches $post — and $post_full is the one value
616
- // `[ "$second" = "$post_full" ]` compares, the mismatch #585 is made of. A
617
- // real commit in position 1 is what carries the loop that far.
618
- const postOnly = prove(w, head, "v1", merge);
619
- assert.equal(postOnly.code, 2);
620
- assert.equal(postOnly.json, null);
621
- assert.match(postOnly.stderr, /v1 is a tag, not a commit/);
622
-
623
- // Same refusal in the third position: the merge-commit argument is never
624
- // handed to bare rev-parse downstream, but the guard's contract is that it
625
- // proves things about commits, uniformly, on all three positions.
626
- git(w, "tag", "-a", "vm", "-m", "annotated", merge);
627
- const merged = prove(w, head, head, "vm");
628
- assert.equal(merged.code, 2);
629
- assert.equal(merged.json, null);
630
- assert.match(merged.stderr, /vm is a tag, not a commit/);
631
- });
632
-
633
- test("a lightweight tag is accepted exactly like a sha — it resolves directly to a commit", (t) => {
634
- // The control for the refusal above: a lightweight tag is a ref pointing
635
- // straight at a commit, with no tag object in between, so it must clear the
636
- // new type check exactly as a sha or branch name does, and the proof must
637
- // come back byte-identical to the sha-driven control.
638
- const w = repo(t);
639
- commit(w, "main moves on before the branch is cut");
640
- git(w, "push", "-q", "origin", "main");
641
- const mainTip = git(w, "rev-parse", "main");
642
- git(w, "checkout", "-q", "-b", "feat");
643
- const head = commit(w, "feature work");
644
- const merge = mergeNoFf(w, head, "merge feat");
645
- git(w, "push", "-q", "origin", "main");
646
- git(w, "tag", "lw", head);
647
-
648
- const { code, json } = prove(w, "lw", "lw", merge);
649
- assert.equal(code, 0);
650
- assert.equal(json.proved, true);
651
- assert.equal(json.proofPath, "no-rebase");
652
- assert.equal(json.secondParent, head);
653
- assert.equal(json.firstParent, mainTip);
654
- });
655
-
656
- test("a base ref that does not resolve carries git's own cause", (t) => {
657
- // Real git throughout, no shim: the fetch succeeds against a live origin, so
658
- // the guard under test is the only one that can fire. BASE_REF is the
659
- // caller-facing way in, and needs no fault injection.
660
- const w = repo(t);
661
- git(w, "checkout", "-q", "-b", "feat");
662
- const head = commit(w, "feature work");
663
-
664
- // <merge-commit> is `head`, not a merge: this guard runs before the cat-file
665
- // loop, so the third argument is never reached and a real merge here would
666
- // only be scenery.
667
- const r = spawnSync("sh", [SCRIPT, head, head, head], {
668
- cwd: w,
669
- env: { ...ENV, BASE_REF: "nosuchref" },
670
- encoding: "utf8",
671
- });
672
- assert.equal(r.status, 2);
673
- assert.equal(r.stdout.trim(), "", "no proof for a question that was never answered");
674
- assert.match(r.stderr, /nosuchref does not resolve/);
675
- // `--quiet` made this guard exit 1 with zero bytes of explanation attached.
676
- assert.match(r.stderr, /Needed a single revision/, "git's own diagnosis must survive to stderr");
677
- // Names which guard fired: the fetch above is also exit 2 with no stdout.
678
- assert.doesNotMatch(r.stderr, /fetch failed/, "the fetch passed — this is the guard after it");
679
- });
680
-
681
- test("a healthy run stays quiet — the unmuted guards add nothing to stderr", (t) => {
682
- const w = repo(t);
683
- // Build and push the merge from a SECOND clone, so `w`'s own fetch has real
684
- // objects to transfer: an already-up-to-date fetch would not exercise the
685
- // path that could go noisy.
686
- const other = join(w, "..", "other");
687
- git(w, "clone", "-q", git(w, "remote", "get-url", "origin"), other);
688
- git(other, "checkout", "-q", "-b", "feat");
689
- const head = commit(other, "feature work");
690
- const merge = mergeNoFf(other, head, "merge feat");
691
- git(other, "push", "-q", "origin", "main");
692
- const first = git(other, "rev-parse", `${merge}^1`);
693
-
694
- const { code, json, stderr } = prove(w, head, head, merge);
695
- assert.equal(code, 0);
696
- assert.equal(json.proved, true);
697
- // Exact, not a /fatal:/ sniff. Dropping `--quiet` from one guard and
698
- // `2>/dev/null` from another is only safe while both stay silent when they
699
- // succeed, and this script's stderr is what the merge bot reads. Anything git
700
- // starts printing on an ordinary run shows up here as a fourteenth line.
701
- assert.deepEqual(stderr.split("\n").filter(Boolean), [
702
- "$ git fetch --quiet origin",
703
- `$ git merge-base --is-ancestor ${merge} origin/main`,
704
- `$ git merge-base --is-ancestor ${head} origin/main`,
705
- " pre is-ancestor = true",
706
- `$ git merge-base --is-ancestor ${head} origin/main # expect SUCCESS`,
707
- " post is-ancestor = true (want true)",
708
- ` ${merge}^1 = ${first} (2 parents)`,
709
- ` ${merge}^2 = ${head}`,
710
- ` claimed head = ${head}`,
711
- `$ git merge-base --is-ancestor ${first} ${head}`,
712
- " no rebase (pre == post) — leg 1 dropped, headWasCurrent carries it",
713
- " headWasCurrent = true (want true, both paths)",
714
- "prove-merge: proved=true (path=no-rebase)",
715
- ]);
716
- });
717
-
718
- test("no probe in prove-merge.sh has its status discarded by `[ ]`", () => {
719
- // A cheap lint for the one spelling this file uses, not for the whole class:
720
- // `test "$(...)"` and `x=$(...) || true` discard the status just as thoroughly
721
- // and this regex never sees them. What closes the class is the behavioural test
722
- // directly above, which is fault-agnostic; this one catches the same mistake at
723
- // the spelling, before anyone has to write a fixture for it.
724
- //
725
- // `die` inside a substitution can only kill the subshell, so the status has to
726
- // land somewhere `set -e` reads it. A bare assignment does; the word-expansion
727
- // slot of `[ ]` does not. This script has no legitimate `[ "$(...)" ]`: "a
728
- // proof must never read a failure as a leg it likes" is the reason is_ancestor
729
- // dies at all. Split any new one into an assignment and a test, the way every
730
- // is_ancestor call does.
731
- const offenders = readFileSync(SCRIPT, "utf8")
732
- .split("\n")
733
- .map((line, i) => [i + 1, line])
734
- .filter(([, line]) => !line.trimStart().startsWith("#"))
735
- .filter(([, line]) => /(^|\s)\[\s/.test(line) && line.includes("$("));
736
- assert.deepEqual(offenders, [], "assign the substitution to a variable first");
737
- });
738
-
739
- // --- #119: the payload's string fields, wrapped for uniformity.
740
- //
741
- // No reachability fixture here, and that is a measurement rather than an
742
- // omission. `$secondParent` and `$firstParent` come from `git rev-parse`, which
743
- // emits 40 hex characters and nothing else, and `$proofPath` is this script's
744
- // own `rebase`/`no-rebase` literal. None of the three can carry a quote today.
745
- // They go through `jstr` anyway, the same reason inflight.sh wraps `$pr`:
746
- // uniformity against a later edit that changes where a field comes from, at no
747
- // cost. Inventing a fixture that "proves" an unreachable vector would pin
748
- // fiction; what is pinned instead is that wrapping them changed no byte of the
749
- // payload, and that the library's absence is a refusal rather than a verdict.
750
- //
751
- // Byte-identical is exactly why the test below it cannot discriminate: measured,
752
- // stripping all three `jstr` calls and interpolating the raw values leaves the
753
- // whole suite green. So the unwrap vector is pinned at the SOURCE
754
- // instead — the one place a regression here is visible without a fixture that
755
- // does not exist.
756
- test("wrapping the string fields left the payload byte-identical", (t) => {
757
- const w = repo(t);
758
- commit(w, "main moves on before the branch is cut");
759
- git(w, "push", "-q", "origin", "main");
760
- const mainTip = git(w, "rev-parse", "main");
761
- git(w, "checkout", "-q", "-b", "feat");
762
- const head = commit(w, "feature work");
763
- const merge = mergeNoFf(w, head, "merge feat");
764
- git(w, "push", "-q", "origin", "main");
765
-
766
- const { code, json } = prove(w, head, head, merge);
767
-
768
- assert.equal(code, 0);
769
- assert.equal(json.secondParent, head, "40 hex characters, unchanged by the escaping");
770
- assert.equal(json.firstParent, mainTip);
771
- assert.equal(json.proofPath, "no-rebase", "the script's own literal, unchanged");
772
- assert.equal(json.proved, true);
773
- });
774
-
775
- // Source-level, because no payload fixture can tell the two apart. Deleting the
776
- // escaping line also deletes its `|| die`, so this pins the guard as well.
777
- test("the printf still reads the ESCAPED proof fields, not the raw ones", () => {
778
- const src = readFileSync(SCRIPT, "utf8")
779
- .split("\n")
780
- .filter((line) => !line.trimStart().startsWith("#"));
781
-
782
- const escaped = src.filter((line) => /second_j=\$\(jstr/.test(line));
783
- assert.equal(escaped.length, 1, "the three proof fields are escaped in one `&&` chain");
784
- assert.match(escaped[0], /\|\| die|\\$/, "and that chain carries or continues to a `|| die`");
785
-
786
- const call = src.find((line) => line.includes('"$second_j"'));
787
- assert.ok(call, "printf's argument list interpolates $second_j, never $second directly");
788
- assert.match(call, /"\$first_j"/, "and $first_j");
789
- assert.match(call, /"\$path_j"/, "and $path_j");
790
- });
791
-
792
- // `.` is a POSIX special builtin, so failing to open its operand aborts a
793
- // non-interactive shell before any `||` on the line can run — measured, /bin/sh
794
- // (macOS bash 3.2), bash 3.2 and `bash --posix` all exit 1 with the guard
795
- // unfired. Exit 1 out of THIS script means "the proof is a no", which the merge
796
- // bot reads as a reason to refuse a merge. A missing file must not be able to
797
- // say that.
798
- test("a missing json.sh is exit 2, never the exit 1 that means `not proved`", (t) => {
799
- const w = repo(t);
800
- commit(w, "main moves on");
801
- git(w, "push", "-q", "origin", "main");
802
- git(w, "checkout", "-q", "-b", "feat");
803
- const pre = commit(w, "feature work");
804
- const merge = mergeNoFf(w, pre, "merge feat");
805
- git(w, "push", "-q", "origin", "main");
806
- const lone = mkdtempSync(join(tmpdir(), "prove-merge-nolib-"));
807
- t.after(() => rmSync(lone, { recursive: true, force: true }));
808
- copyFileSync(SCRIPT, join(lone, "prove-merge.sh"));
809
-
810
- const r = spawnSync("sh", [join(lone, "prove-merge.sh"), pre, pre, merge], { cwd: w, env: ENV, encoding: "utf8" });
811
-
812
- assert.equal(r.status, 2,
813
- "a missing library is `the question could not be answered`. Exit 1 would report a genuinely good merge as unproved and the bot would refuse it.");
814
- assert.match(r.stderr, /json\.sh/, "and it names the file rather than blaming a gate that never ran");
815
- assert.equal(r.stdout, "", "no payload: nothing was proved either way");
816
- });
817
-
818
- // --- #896: that guard's FATALITY, which neither case above reaches. Both of
819
- // them assert what a WORKING escaper produces, so nothing here runs the
820
- // `|| die` covering the escaper itself failing — measured, downgrading it to a
821
- // message-preserving warning left this whole file green.
822
- //
823
- // The downgrade does not emit a malformed payload. `second_j`, `first_j` and
824
- // `path_j` are assigned by one `&&` chain, so the first `jstr` that fails
825
- // short-circuits the rest and leaves those names unset; with the guard advisory
826
- // the payload `printf` reads one and `set -u` aborts the shell instead.
827
- //
828
- // Exit 1 out of THIS script is a verdict — "the proof is a no", the answer the
829
- // merge bot reads as a reason to refuse. The fixture below is a merge that
830
- // genuinely proves TRUE, every gate already answered `true` on stderr before
831
- // the escaping runs, so under a bash-family `sh` the downgrade is a false
832
- // DISPROOF: a good merge refused over a `sed` that was not on PATH.
833
- //
834
- // Which abort it is, though, is the shell's to choose and not this script's,
835
- // and dash's lands on 2 — the very status a firing guard returns. This file
836
- // spawns a bare `sh`, and `.github/workflows/ci.yml`'s `check` job runs on
837
- // `ubuntu-latest`, where that name resolves to dash: an exit-code assertion
838
- // therefore pins this guard on a developer's Mac and lets the mutant through
839
- // on the runner that gates the merge, and a wording assertion pins whichever
840
- // shell uses that wording. `first_j` is what discriminates instead — both
841
- // shells name it, and it reaches stderr only from that nounset abort: no
842
- // healthy run, no genuine `proved=false` and no firing of this guard puts it
843
- // there.
844
- //
845
- // `jstr` escapes through a `sed`/`tr` pipeline and this script calls `sed`
846
- // nowhere else, so shadowing `sed` breaks the escaper and nothing ahead of it.
847
- // The `proved=` trace is echoed only once every gate has answered, so it proves
848
- // the run cleared them all, and the shim's own line proves the escaper is what
849
- // failed; between them no other failure can produce this signature. That trace
850
- // is pinned verbatim by "a healthy run stays quiet", so it cannot be reworded
851
- // out from under this assertion unseen, and no assertion here names a `die`
852
- // message — rewording any of them, this guard's own included, leaves the pin
853
- // standing.
854
-
855
- /** A dir holding a `sed` shim with the given body, prepended to PATH. */
856
- function sedShim(t, body) {
857
- const bin = mkdtempSync(join(tmpdir(), "prove-merge-sed-shim-"));
858
- t.after(() => rmSync(bin, { recursive: true, force: true }));
859
- writeExecStub(join(bin, "sed"), `#!/bin/sh\n${body}\n`);
860
- return `${bin}:${ENV.PATH ?? process.env.PATH}`;
861
- }
862
-
863
- /** The fixture both cases below share: a merge that really does prove true. */
864
- function provenMerge(t) {
865
- const w = repo(t);
866
- commit(w, "main moves on before the branch is cut");
867
- git(w, "push", "-q", "origin", "main");
868
- const mainTip = git(w, "rev-parse", "main");
869
- git(w, "checkout", "-q", "-b", "feat");
870
- const head = commit(w, "feature work");
871
- const merge = mergeNoFf(w, head, "merge feat");
872
- git(w, "push", "-q", "origin", "main");
873
- return { w, head, merge, mainTip };
874
- }
875
-
876
- test("an escaper that cannot run is exit 2, never the exit 1 that means `not proved`", (t) => {
877
- const { w, head, merge } = provenMerge(t);
878
-
879
- const r = spawnSync("sh", [SCRIPT, head, head, merge], {
880
- cwd: w,
881
- env: { ...ENV, PATH: sedShim(t, 'echo "sed: outage" >&2\nexit 1') },
882
- encoding: "utf8",
883
- });
884
-
885
- // Whether this fixture measured the guard at all is settled before its
886
- // verdict is read: an assertion that fails masks every one after it, and
887
- // "the shim broke something else" and "the guard is not fatal" are not
888
- // interchangeable diagnoses.
889
- assert.match(r.stderr, /sed: outage/, "the escaper ran and failed, which is the failure under test");
890
- assert.match(r.stderr, /proved=true \(path=no-rebase\)/,
891
- "every gate answered — this is the guard after them, not an earlier one the shim happened to break");
892
-
893
- assert.equal(r.status, 2,
894
- "a proof that could not be escaped is `the question could not be answered`. Exit 1 would report a merge that passed every gate as unproved, and the merge bot refuses on that answer.");
895
- assert.equal(r.stdout, "", "no proof may be printed for a payload that was never escaped");
896
- assert.doesNotMatch(r.stderr, /first_j/,
897
- "the guard must stop the script, not warn and leave the payload `printf` reading names the `&&` chain never assigned. The NAME, never the wording: bash says `first_j: unbound variable` at exit 1 and dash `first_j: parameter not set` at exit 2, so the exit-2 assertion above and any wording match each pass on the mutant under the shell CI actually runs.");
898
- });
899
-
900
- test("a shadowed `sed` that works still proves the merge — the guard refuses only a real outage", (t) => {
901
- // The false-positive half, and the control the case above needs: shadowing
902
- // `sed` on PATH is not by itself fatal to this script. Same fixture and the
903
- // same shadowed name, a passthrough body — so the exit 2 up there is the
904
- // escaper failing, not the shim's mere presence. Without this, that case
905
- // could be measuring a PATH it broke wholesale and still read green.
906
- const { w, head, merge, mainTip } = provenMerge(t);
907
-
908
- const r = spawnSync("sh", [SCRIPT, head, head, merge], {
909
- cwd: w,
910
- env: { ...ENV, PATH: sedShim(t, `exec "${REAL_SED}" "$@"`) },
911
- encoding: "utf8",
912
- });
913
-
914
- assert.equal(r.status, 0, "the merge IS proved — a working escaper must not change the verdict");
915
- const json = JSON.parse(r.stdout);
916
- assert.equal(json.proved, true);
917
- assert.equal(json.secondParent, head, "and the escaped fields carry the real shas, not the empty slots a failed chain leaves");
918
- assert.equal(json.firstParent, mainTip);
919
- assert.equal(json.proofPath, "no-rebase");
920
- });
921
-
922
- // #1039. The bounded-fetch pattern's coverage used to stop at the shared
923
- // helper: net.sh's budget, its stalled-signal arm and its kill-tree walk are
924
- // each pinned, and unattended-git-sweep.test.mjs pins that this script still
925
- // sources net.sh and still reaches net_git — but nothing ever ran this
926
- // script's OWN stalled-versus-failed wrapper. Measured on #1030's head:
927
- // replacing `${fetch_budget}` in the stalled branch with an unbound variable,
928
- // so `set -eu` aborts where `die` was meant to render, left this suite at its
929
- // baseline pass count, byte-identical.
930
- //
931
- // One pair, the shape net.test.mjs uses for verify-sha.sh and
932
- // inflight.test.mjs for probe 2: one real slow transport, a budget above its
933
- // delay and a budget under it. The WORDING is the assertion target, because
934
- // this script's `die` gives a killed fetch and a refused one the same exit 2 —
935
- // the status alone cannot tell them apart, which is the whole reason the
936
- // branch exists.
937
- test("a slow but working fetch still proves the merge — the budget is not a stopwatch on success", (t) => {
938
- const { w, head, merge, mainTip } = provenMerge(t);
939
- // provenMerge's own `git push origin main` above already advanced this
940
- // clone's local `origin/main` past the merge, so the ancestor gate below
941
- // would already pass before the bounded fetch ever runs. Moving the local
942
- // tracking ref back to the pre-merge tip makes `proved` reachable only
943
- // through a fetch that genuinely lands, not through the fixture's own
944
- // prior push (#1039 review, finding 3).
945
- git(w, "update-ref", "refs/remotes/origin/main", mainTip);
946
- // Read back rather than rebuilt: `repo` returns the clone alone, and a
947
- // second spelling of the origin path is a fixture that can point the stub at
948
- // a repo the clone never used.
949
- const origin = git(w, "remote", "get-url", "origin");
950
- const sshCommand = slowTransport(origin);
951
- git(w, "remote", "set-url", "origin", SSH_URL);
952
-
953
- const r = spawnSync("sh", [SCRIPT, head, head, merge], {
954
- cwd: w,
955
- env: { ...ENV, GIT_SSH_COMMAND: sshCommand, FLEET_NET_TIMEOUT: "20" },
956
- encoding: "utf8",
957
- timeout: 60_000,
958
- });
959
-
960
- assert.equal(r.error, undefined, `the run did not come back: ${JSON.stringify(r)}`);
961
- assert.equal(r.status, 0,
962
- `a budget above the delay must leave the verdict alone — exit 2 here is an outage invented on a link that worked: ${JSON.stringify(r)}`);
963
- const json = JSON.parse(r.stdout);
964
- assert.equal(json.proved, true, "the refs really came back, so the proof is the one an unbounded fetch reaches");
965
- assert.equal(json.firstParent, mainTip,
966
- "and it is established from the history the slow transport actually returned, not from a stale ref");
967
- assert.doesNotMatch(r.stderr, /did not finish within/,
968
- "and nothing claims a budget elapsed, which is the wording the failure path owns");
969
- });
970
-
971
- test("a fetch killed by its budget refuses to prove a merge on stale refs, in this script's own words", (t) => {
972
- const { w, head, merge } = provenMerge(t);
973
- const origin = git(w, "remote", "get-url", "origin");
974
- const sshCommand = slowTransport(origin);
975
- git(w, "remote", "set-url", "origin", SSH_URL);
976
-
977
- const r = spawnSync("sh", [SCRIPT, head, head, merge], {
978
- cwd: w,
979
- env: { ...ENV, GIT_SSH_COMMAND: sshCommand, FLEET_NET_TIMEOUT: "1" },
980
- encoding: "utf8",
981
- timeout: 60_000,
982
- });
983
-
984
- assert.equal(r.error, undefined, `the run did not come back: ${JSON.stringify(r)}`);
985
- assert.equal(r.status, 2,
986
- "`the question could not be answered`, never the exit 1 that means `not proved` — the merge bot refuses on that answer");
987
- assert.match(
988
- r.stderr,
989
- /prove-merge: git fetch did not finish within 1s and was killed — refusing to prove a merge on stale refs/,
990
- "this script's own decline, rendered, with the budget named in it: collapsing the stalled arm into the generic `fetch failed` decline keeps the same exit 2, so only this wording — not the status check — catches it",
991
- );
992
- assert.doesNotMatch(r.stderr, /fetch failed — refusing to prove a merge/,
993
- "and not the refused-fetch wording, which names a cause this run never observed");
994
- assert.equal(r.stdout, "", "no proof may be printed off refs the script could not refresh");
995
- });