@feigi/fleet-ctl 3.23.35 → 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,576 +0,0 @@
1
- // Regression gate for delete-merged-branch.sh — the merge bot's own branch
2
- // deletion (#2196), replacing the repo setting "Automatically delete head
3
- // branches" the fleet used to lean on.
4
- //
5
- // Zero deps: `node --test plugin/scripts/delete-merged-branch.test.mjs`.
6
- //
7
- // Every fixture is a REAL bare origin and a real clone; only `gh` is stubbed.
8
- // The assertion that matters is always read off the bare origin itself
9
- // (`ls-remote`), never off the script's exit status or payload: #2196's trap
10
- // is a merge step that reports success while the branch survives underneath
11
- // it, so a test that only checked "exit 0" or "the delete was issued" would
12
- // pass on exactly the broken implementation the ticket describes.
13
- //
14
- // The headline case puts the branch where every fleet-claimed ticket's branch
15
- // lives — checked out in a linked worktree at `.worktrees/<issue>-<slug>` —
16
- // which is where `gh pr merge --delete-branch`'s local cleanup dies with
17
- // `fatal: 'main' is already used by worktree`. It then runs reap.sh over the
18
- // result, so the whole post-merge chain is proved to leave no branch behind,
19
- // remote or local.
20
-
21
- import { test } from "node:test";
22
- import assert from "node:assert/strict";
23
- import { execFileSync, spawnSync } from "node:child_process";
24
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
25
- import { tmpdir } from "node:os";
26
- import { join } from "node:path";
27
- import { fileURLToPath } from "node:url";
28
-
29
- const SCRIPT = fileURLToPath(new URL("./delete-merged-branch.sh", import.meta.url));
30
- const REAP = fileURLToPath(new URL("./reap.sh", import.meta.url));
31
- const REAL_GIT = execFileSync("sh", ["-c", "command -v git"], { encoding: "utf8" }).trim();
32
-
33
- // The gh stub's `pr list` pipes through the real jq (the script itself needs
34
- // none: `gh --jq` is embedded). Without it every lookup would fail and the
35
- // suite would read exit 2 everywhere — fail loudly instead of vacuously.
36
- try {
37
- execFileSync("jq", ["--version"], { stdio: "ignore" });
38
- } catch {
39
- throw new Error("jq is required to stub `gh pr list --jq`; install it before running this suite");
40
- }
41
-
42
- // Pinned identity, no developer config, no inherited repo pointers.
43
- const ENV = {
44
- ...process.env,
45
- BASE_REF: undefined,
46
- GIT_DIR: undefined,
47
- GIT_WORK_TREE: undefined,
48
- GIT_TEMPLATE_DIR: undefined,
49
- GIT_INDEX_FILE: undefined,
50
- GIT_AUTHOR_NAME: "t",
51
- GIT_AUTHOR_EMAIL: "t@example.com",
52
- GIT_COMMITTER_NAME: "t",
53
- GIT_COMMITTER_EMAIL: "t@example.com",
54
- GIT_CONFIG_GLOBAL: "/dev/null",
55
- GIT_CONFIG_SYSTEM: "/dev/null",
56
- };
57
-
58
- const git = (cwd, ...args) => execFileSync("git", args, { cwd, env: ENV, encoding: "utf8" }).trim();
59
-
60
- const commit = (w, msg) => {
61
- git(w, "commit", "-q", "--allow-empty", "-m", msg);
62
- return git(w, "rev-parse", "HEAD");
63
- };
64
-
65
- /** Bare origin + clone with one commit on main, `.worktrees/` ignored as §2.5 requires. */
66
- function repo(t) {
67
- const root = realpathSync(mkdtempSync(join(tmpdir(), "delete-merged-branch-")));
68
- t.after(() => rmSync(root, { recursive: true, force: true }));
69
- const origin = join(root, "origin.git");
70
- const w = join(root, "w");
71
- execFileSync("git", ["-c", "init.defaultBranch=main", "init", "-q", "--bare", origin], { env: ENV });
72
- execFileSync("git", ["clone", "-q", origin, w], { env: ENV, stdio: "pipe" });
73
- writeFileSync(join(w, ".gitignore"), ".worktrees/\n.fleet/\n");
74
- git(w, "add", ".gitignore");
75
- commit(w, "root");
76
- git(w, "branch", "-M", "main");
77
- git(w, "push", "-q", "-u", "origin", "main");
78
- return { root, origin, w };
79
- }
80
-
81
- /** Whether refs/heads/<name> exists on the bare origin — the ground truth. */
82
- const onOrigin = (origin, name) =>
83
- spawnSync("git", ["ls-remote", "--exit-code", "--heads", origin, `refs/heads/${name}`], { env: ENV }).status === 0;
84
- const originTip = (origin, name) => git(origin, "rev-parse", `refs/heads/${name}`);
85
-
86
- /**
87
- * A fleet-claimed ticket, merged: branch `name` checked out in the linked
88
- * worktree `.worktrees/<wtName>`, pushed, merged `--no-ff` into main on origin
89
- * the way `gh pr merge --merge` does, and the remote branch LEFT IN PLACE — the
90
- * state a repo with auto-delete off is in after the merge. Returns the head
91
- * GitHub would report as `headRefOid`, and the worktree path.
92
- */
93
- function mergedInWorktree(w, name, wtName) {
94
- const wt = join(w, ".worktrees", wtName);
95
- git(w, "worktree", "add", "-q", wt, "-b", name, "main");
96
- const oid = commit(wt, `work on ${name}`);
97
- git(wt, "push", "-q", "-u", "origin", name);
98
- git(w, "merge", "-q", "--no-ff", "-m", `Merge ${name}`, name);
99
- git(w, "push", "-q", "origin", "main");
100
- return { oid, wt };
101
- }
102
-
103
- /**
104
- * A `gh` stub answering the script's `pr view` call and its two `pr list`
105
- * lookups, from env vars. Returns a call log reader and an env builder.
106
- *
107
- * `pr list` is a faithful fake rather than canned output: it filters
108
- * PR_LIST_JSON — every PR in the repo, `[{number,state,headRefName,
109
- * baseRefName,isCrossRepository}]` — by `--head`/`--base`/`--state` the way
110
- * GitHub does (`--head` matches a fork PR whose branch shares the name), then
111
- * pipes the result through the real `jq` with the script's own `--jq`
112
- * expression, so the selection the script asks for is under test rather than
113
- * hard-coded into the fixture. PR_LIST_FAIL=head|base makes that lookup exit
114
- * 1; PR_LIST_RAW_HEAD/PR_LIST_RAW_BASE replace its output verbatim at exit 0.
115
- */
116
- function ghStub(t, root) {
117
- const bin = join(root, "bin");
118
- mkdirSync(bin, { recursive: true });
119
- const log = join(root, "gh.log");
120
- writeFileSync(log, "");
121
- writeFileSync(
122
- join(bin, "gh"),
123
- `#!/bin/sh
124
- printf '%s\\n' "$*" >> "${log}"
125
- case "$*" in
126
- "pr view "*" --json state,isCrossRepository,headRefName,headRefOid,baseRefName --jq "*)
127
- [ "\${GH_FAIL:-0}" = 0 ] || { echo "gh: simulated failure" >&2; exit 1; }
128
- printf '%s\\037%s\\037%s\\037%s\\037%s\\n' "\${PR_STATE:-MERGED}" "\${PR_CROSS:-false}" "\$PR_HEAD" "\$PR_OID" "\${PR_BASE:-main}"
129
- exit 0
130
- ;;
131
- "pr list "*) ;;
132
- *) echo "gh: unstubbed call: $*" >&2; exit 1 ;;
133
- esac
134
- shift 2
135
- head= base= state= expr=. which= limit=30
136
- while [ $# -gt 0 ]; do
137
- case "$1" in
138
- --head) head=$2; which=head; shift 2 ;;
139
- --base) base=$2; which=base; shift 2 ;;
140
- --state) state=$2; shift 2 ;;
141
- --limit) limit=$2; shift 2 ;;
142
- --jq) expr=$2; shift 2 ;;
143
- *) shift ;;
144
- esac
145
- done
146
- [ "\${PR_LIST_FAIL:-}" = "$which" ] && { echo "gh: simulated pr list --$which failure" >&2; exit 1; }
147
- if [ "$which" = head ] && [ -n "\${PR_LIST_RAW_HEAD+set}" ]; then printf '%s\\n' "$PR_LIST_RAW_HEAD"; exit 0; fi
148
- if [ "$which" = base ] && [ -n "\${PR_LIST_RAW_BASE+set}" ]; then printf '%s\\n' "$PR_LIST_RAW_BASE"; exit 0; fi
149
- printf '%s' "\${PR_LIST_JSON:-[]}" |
150
- jq --arg head "$head" --arg base "$base" --arg state "$state" --argjson limit "$limit" \\
151
- '[.[] | select(($head == "" or .headRefName == $head) and ($base == "" or .baseRefName == $base) and ($state == "" or $state == "all" or (.state | ascii_downcase) == $state))] | .[:$limit]' |
152
- jq -r "$expr"
153
- `,
154
- { mode: 0o755 },
155
- );
156
- return {
157
- bin,
158
- calls: () => readFileSync(log, "utf8").trim().split("\n").filter(Boolean),
159
- env: (extra = {}) => ({ ...ENV, PATH: `${bin}:${ENV.PATH}`, ...extra }),
160
- };
161
- }
162
-
163
- /** One PR as GitHub's `gh pr list --json` would describe it. */
164
- const pr = (number, headRefName, baseRefName, state = "OPEN", isCrossRepository = false) => ({
165
- number,
166
- state,
167
- headRefName,
168
- baseRefName,
169
- isCrossRepository,
170
- });
171
-
172
- /** `json` is the script's one-line payload; exit 3 prints `branch-kept-#<n>` lines instead, read off `stdout`. */
173
- function run(cwd, args, env) {
174
- const r = spawnSync("sh", [SCRIPT, ...args], { cwd, env, encoding: "utf8" });
175
- const out = r.stdout.trim();
176
- return { code: r.status, stdout: r.stdout, json: out.startsWith("{") ? JSON.parse(out) : null, stderr: r.stderr };
177
- }
178
-
179
- test("a merged branch checked out in a .worktrees/<issue>-<slug> worktree is deleted from origin, and reap.sh then reaps it locally", (t) => {
180
- const { root, origin, w } = repo(t);
181
- const branch = "fix/2196-delete-branch";
182
- const { oid, wt } = mergedInWorktree(w, branch, "2196-delete-branch");
183
- assert.ok(onOrigin(origin, branch), "fixture: the branch must still be on origin after the merge");
184
- const gh = ghStub(t, root);
185
-
186
- const r = run(w, ["7"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
187
-
188
- assert.equal(r.code, 0, r.stderr);
189
- assert.deepEqual(r.json, { pr: 7, branch, deleted: true });
190
- assert.equal(onOrigin(origin, branch), false, "the branch must actually be gone from origin, not merely reported deleted");
191
- // Remote-only: the worktree and its local branch are untouched, so a held
192
- // worktree can neither make this step fail nor lose anything to it.
193
- assert.ok(existsSync(wt), "the worktree must survive this step — it is reap.sh's to remove");
194
- assert.equal(git(wt, "rev-parse", "HEAD"), oid);
195
- assert.doesNotMatch(r.stderr, /already used by worktree/);
196
-
197
- // The rest of the chain: the controller reaps on the merge bot's report.
198
- const reap = spawnSync("sh", [REAP, "--apply"], { cwd: w, env: ENV, encoding: "utf8" });
199
- assert.equal(reap.status, 0, reap.stderr);
200
- assert.deepEqual(JSON.parse(reap.stdout).reaped, [branch]);
201
- assert.equal(
202
- spawnSync("git", ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`], { cwd: w, env: ENV }).status,
203
- 1,
204
- "the local branch must be gone once reap.sh has run",
205
- );
206
- assert.equal(existsSync(wt), false, "the worktree must be gone once reap.sh has run");
207
- });
208
-
209
- test("a merged branch that was never checked out locally is deleted the same way — a hand-opened PR or the controller's own chore PR", (t) => {
210
- const { root, origin, w } = repo(t);
211
- // Pushed from a second clone, so this checkout has no worktree and no local
212
- // branch for it at all. The quote is legal in a refname and must survive
213
- // into the JSON payload escaped.
214
- const other = join(root, "other");
215
- execFileSync("git", ["clone", "-q", origin, other], { env: ENV });
216
- const branch = 'chore/run-artifacts-"x"';
217
- git(other, "switch", "-q", "-c", branch);
218
- const oid = commit(other, "artifacts");
219
- git(other, "push", "-q", "origin", branch);
220
- git(other, "switch", "-q", "main");
221
- git(other, "merge", "-q", "--no-ff", "-m", "merge", branch);
222
- git(other, "push", "-q", "origin", "main");
223
- const gh = ghStub(t, root);
224
-
225
- const r = run(w, ["8"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
226
-
227
- assert.equal(r.code, 0, r.stderr);
228
- assert.deepEqual(r.json, { pr: 8, branch, deleted: true });
229
- assert.equal(onOrigin(origin, branch), false);
230
- });
231
-
232
- // What this change must ACCEPT: a repo that still has auto-delete on (GitHub
233
- // removed the branch at the merge instant) must not turn every merge into a
234
- // failure report.
235
- test("a branch already gone from origin is success, and no delete is pushed", (t) => {
236
- const { root, origin, w } = repo(t);
237
- const branch = "feat/9-gone";
238
- const { oid } = mergedInWorktree(w, branch, "9-gone");
239
- git(w, "push", "-q", "origin", "--delete", branch);
240
- const gh = ghStub(t, root);
241
-
242
- const r = run(w, ["9"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
243
-
244
- assert.equal(r.code, 0, r.stderr);
245
- assert.deepEqual(r.json, { pr: 9, branch, deleted: false, alreadyGone: true });
246
- assert.doesNotMatch(r.stderr, /git push/);
247
- assert.equal(onOrigin(origin, branch), false);
248
- });
249
-
250
- test("a branch whose tip moved after the merge is NOT deleted — the lease refuses, exit 1", (t) => {
251
- const { root, origin, w } = repo(t);
252
- const branch = "fix/10-moved";
253
- const { oid, wt } = mergedInWorktree(w, branch, "10-moved");
254
- const later = commit(wt, "pushed after the merge");
255
- git(wt, "push", "-q", "origin", branch);
256
- const gh = ghStub(t, root);
257
-
258
- const r = run(w, ["10"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
259
-
260
- assert.equal(r.code, 1, r.stderr);
261
- assert.equal(r.json.deleted, false);
262
- assert.equal(r.json.tip, later);
263
- assert.match(r.json.reason, /a push landed after the merge/);
264
- assert.equal(originTip(origin, branch), later, "commits main never received must survive");
265
- });
266
-
267
- // The trap #2196 names: the delete is issued, reports success, and the
268
- // branch is still there. A `git` that swallows `push` at exit 0 is exactly
269
- // that, and only the read-back can catch it.
270
- test("a delete that exits 0 but leaves the branch on origin is a failure, never a success", (t) => {
271
- const { root, origin, w } = repo(t);
272
- const branch = "fix/11-silent";
273
- const { oid } = mergedInWorktree(w, branch, "11-silent");
274
- const gh = ghStub(t, root);
275
- writeFileSync(
276
- join(gh.bin, "git"),
277
- `#!/bin/sh\nfor a in "$@"; do [ "$a" = push ] && exit 0; done\nexec "${REAL_GIT}" "$@"\n`,
278
- { mode: 0o755 },
279
- );
280
-
281
- const r = run(w, ["11"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
282
-
283
- assert.equal(r.code, 1, r.stderr);
284
- assert.equal(r.json.deleted, false);
285
- assert.match(r.json.reason, /exited 0 and the branch is still on origin/);
286
- assert.ok(onOrigin(origin, branch));
287
- });
288
-
289
- test("a delete the remote refuses is exit 1 with the branch still reported", (t) => {
290
- const { root, origin, w } = repo(t);
291
- const branch = "fix/12-refused";
292
- const { oid } = mergedInWorktree(w, branch, "12-refused");
293
- writeFileSync(join(origin, "hooks", "pre-receive"), "#!/bin/sh\necho 'deletes are protected' >&2\nexit 1\n", { mode: 0o755 });
294
- const gh = ghStub(t, root);
295
-
296
- const r = run(w, ["12"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
297
-
298
- assert.equal(r.code, 1, r.stderr);
299
- assert.equal(r.json.tip, oid);
300
- assert.match(r.json.reason, /git push --delete exited [1-9]/);
301
- assert.ok(onOrigin(origin, branch));
302
- });
303
-
304
- // A push the script's own net budget kills is not a server's refusal: the
305
- // reason must say it was killed, the way remote_tip says it for ls-remote.
306
- test("a delete killed by the net budget says so, exit 1 with the branch still reported", (t) => {
307
- const { root, origin, w } = repo(t);
308
- const branch = "fix/19-stalled";
309
- const { oid } = mergedInWorktree(w, branch, "19-stalled");
310
- writeFileSync(join(origin, "hooks", "pre-receive"), "#!/bin/sh\nsleep 20\nexit 1\n", { mode: 0o755 });
311
- const gh = ghStub(t, root);
312
-
313
- const r = run(w, ["19"], gh.env({ PR_HEAD: branch, PR_OID: oid, FLEET_NET_TIMEOUT: "1" }));
314
-
315
- assert.equal(r.code, 1, r.stderr);
316
- assert.equal(r.json.tip, oid);
317
- assert.match(r.json.reason, /git push --delete did not finish within 1s and was killed/);
318
- assert.ok(onOrigin(origin, branch));
319
- });
320
-
321
- // The race the script's last branch exists for: the push fails, yet something
322
- // else (a repo still auto-deleting) removed the branch between the two reads.
323
- // The outcome this step exists for holds, so it is not a failure — but nor is
324
- // it this run's delete.
325
- test("a failed push whose branch is gone on the read-back is already gone, not deleted", (t) => {
326
- const { root, origin, w } = repo(t);
327
- const branch = "fix/20-raced";
328
- const { oid } = mergedInWorktree(w, branch, "20-raced");
329
- const gh = ghStub(t, root);
330
- writeFileSync(
331
- join(gh.bin, "git"),
332
- `#!/bin/sh\nfor a in "$@"; do [ "$a" = push ] && { "${REAL_GIT}" "$@"; exit 1; }; done\nexec "${REAL_GIT}" "$@"\n`,
333
- { mode: 0o755 },
334
- );
335
-
336
- const r = run(w, ["20"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
337
-
338
- assert.equal(r.code, 0, r.stderr);
339
- assert.deepEqual(r.json, { pr: 20, branch, deleted: false, alreadyGone: true });
340
- assert.equal(onOrigin(origin, branch), false);
341
- });
342
-
343
- test("a PR that is not merged is refused before any git call, branch untouched", (t) => {
344
- const { root, origin, w } = repo(t);
345
- const branch = "fix/13-open";
346
- const { oid } = mergedInWorktree(w, branch, "13-open");
347
- const gh = ghStub(t, root);
348
-
349
- for (const state of ["OPEN", "CLOSED"]) {
350
- const r = run(w, ["13"], gh.env({ PR_STATE: state, PR_HEAD: branch, PR_OID: oid }));
351
- assert.equal(r.code, 2, state);
352
- assert.match(r.stderr, new RegExp(`not merged \\(state=${state}\\)`));
353
- assert.doesNotMatch(r.stderr, /ls-remote|git push/);
354
- assert.equal(r.json, null);
355
- }
356
- assert.ok(onOrigin(origin, branch));
357
- });
358
-
359
- test("a fork PR is skipped — a same-named branch on our origin is not its head", (t) => {
360
- const { root, origin, w } = repo(t);
361
- const branch = "fix/14-fork";
362
- const { oid } = mergedInWorktree(w, branch, "14-fork");
363
- const gh = ghStub(t, root);
364
-
365
- const r = run(w, ["14"], gh.env({ PR_CROSS: "true", PR_HEAD: branch, PR_OID: oid }));
366
-
367
- assert.equal(r.code, 0, r.stderr);
368
- assert.deepEqual(r.json, { pr: 14, branch, deleted: false, skipped: "cross-repository" });
369
- assert.ok(onOrigin(origin, branch));
370
- });
371
-
372
- test("a head that names the base branch is refused, base untouched", (t) => {
373
- const { root, origin, w } = repo(t);
374
- const gh = ghStub(t, root);
375
- const main = originTip(origin, "main");
376
-
377
- const r = run(w, ["15"], gh.env({ PR_HEAD: "main", PR_OID: main }));
378
-
379
- assert.equal(r.code, 2);
380
- assert.match(r.stderr, /is its base branch 'main'/);
381
- assert.equal(originTip(origin, "main"), main);
382
- });
383
-
384
- test("usage errors refuse before calling gh", (t) => {
385
- const { root, w } = repo(t);
386
- const gh = ghStub(t, root);
387
- for (const args of [[], ["abc"], ["007"], ["01"], ["1", "2"]]) {
388
- const r = run(w, args, gh.env());
389
- assert.equal(r.code, 2, JSON.stringify(args));
390
- }
391
- assert.deepEqual(gh.calls(), []);
392
- });
393
-
394
- test("a failed gh read is exit 2, not a verdict", (t) => {
395
- const { root, w } = repo(t);
396
- const gh = ghStub(t, root);
397
- const r = run(w, ["16"], gh.env({ GH_FAIL: "1" }));
398
- assert.equal(r.code, 2);
399
- assert.match(r.stderr, /gh pr view 16 failed/);
400
- assert.equal(r.json, null);
401
- });
402
-
403
- // A tab is IFS whitespace, so a tab-joined read collapses an empty field and
404
- // shifts the rest left — the base branch then reads as the head commit.
405
- test("an empty head branch from gh is refused as missing, not misread as a later field", (t) => {
406
- const { root, w } = repo(t);
407
- const gh = ghStub(t, root);
408
- const r = run(w, ["21"], gh.env({ PR_HEAD: "", PR_OID: "a".repeat(40) }));
409
- assert.equal(r.code, 2);
410
- assert.match(r.stderr, /returned no head branch or head commit/);
411
- assert.equal(r.json, null);
412
- });
413
-
414
- test("an unreachable origin is exit 2, never read as an already-gone branch", (t) => {
415
- const { root, origin, w } = repo(t);
416
- const branch = "fix/17-unreachable";
417
- const { oid } = mergedInWorktree(w, branch, "17-unreachable");
418
- git(w, "remote", "set-url", "origin", join(root, "nowhere.git"));
419
- const gh = ghStub(t, root);
420
-
421
- const r = run(w, ["17"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
422
-
423
- assert.equal(r.code, 2);
424
- assert.match(r.stderr, /git ls-remote failed/);
425
- assert.equal(r.json, null);
426
- assert.ok(onOrigin(origin, branch));
427
- });
428
-
429
- // An ambient GIT_DIR naming another repository would point `ls-remote origin`
430
- // at THAT repository's origin, where the branch does not exist — read as
431
- // already gone, exit 0, with the real branch still on the real origin.
432
- test("an ambient GIT_DIR naming another repository does not redirect the delete", (t) => {
433
- const { root, origin, w } = repo(t);
434
- const branch = "fix/18-ambient";
435
- const { oid } = mergedInWorktree(w, branch, "18-ambient");
436
- const decoy = join(root, "decoy");
437
- execFileSync("git", ["-c", "init.defaultBranch=main", "init", "-q", decoy], { env: ENV });
438
- execFileSync("git", ["-c", "init.defaultBranch=main", "init", "-q", "--bare", join(root, "decoy-origin.git")], { env: ENV });
439
- git(decoy, "remote", "add", "origin", join(root, "decoy-origin.git"));
440
- const gh = ghStub(t, root);
441
-
442
- const r = run(w, ["18"], gh.env({ PR_HEAD: branch, PR_OID: oid, GIT_DIR: join(decoy, ".git") }));
443
-
444
- assert.equal(r.code, 0, r.stderr);
445
- assert.deepEqual(r.json, { pr: 18, branch, deleted: true });
446
- assert.equal(onOrigin(origin, branch), false);
447
- });
448
-
449
- // #2295: deleting a branch closes every open PR headed by it, and may close
450
- // rather than retarget every open PR based on it. Either one keeps the branch:
451
- // no push, one `branch-kept-#<pr>` line per such PR, exit 3. The proof that no
452
- // delete went out is read off the bare origin — the tip is still the merged head.
453
- function keptFixture(t, branch, wtName) {
454
- const { root, origin, w } = repo(t);
455
- const { oid } = mergedInWorktree(w, branch, wtName);
456
- return { origin, w, oid, gh: ghStub(t, root) };
457
- }
458
-
459
- test("an open PR headed by the branch keeps it — no push, branch-kept-#<that PR>, exit 3", (t) => {
460
- const branch = "fix/22-head";
461
- const { origin, w, oid, gh } = keptFixture(t, branch, "22-head");
462
- const list = [pr(22, branch, "main", "MERGED"), pr(31, branch, "release")];
463
-
464
- const r = run(w, ["22"], gh.env({ PR_HEAD: branch, PR_OID: oid, PR_LIST_JSON: JSON.stringify(list) }));
465
-
466
- assert.equal(r.code, 3, r.stderr);
467
- assert.equal(r.stdout, "branch-kept-#31\n");
468
- assert.match(r.stderr, /open PR #31 uses fix\/22-head as its head/);
469
- assert.doesNotMatch(r.stderr, /git push/);
470
- assert.equal(originTip(origin, branch), oid);
471
- });
472
-
473
- test("an open PR based on the branch keeps it — no push, branch-kept-#<that PR>, exit 3", (t) => {
474
- const branch = "fix/23-base";
475
- const { origin, w, oid, gh } = keptFixture(t, branch, "23-base");
476
- const list = [pr(23, branch, "main", "MERGED"), pr(40, "feat/40-stacked", branch)];
477
-
478
- const r = run(w, ["23"], gh.env({ PR_HEAD: branch, PR_OID: oid, PR_LIST_JSON: JSON.stringify(list) }));
479
-
480
- assert.equal(r.code, 3, r.stderr);
481
- assert.equal(r.stdout, "branch-kept-#40\n");
482
- assert.match(r.stderr, /open PR #40 uses fix\/23-base as its base/);
483
- assert.doesNotMatch(r.stderr, /git push/);
484
- assert.equal(originTip(origin, branch), oid);
485
- });
486
-
487
- test("open PRs of both kinds print one branch-kept-# line per PR, exit 3", (t) => {
488
- const branch = "fix/24-both";
489
- const { origin, w, oid, gh } = keptFixture(t, branch, "24-both");
490
- const list = [
491
- pr(24, branch, "main", "MERGED"),
492
- pr(51, branch, "release"),
493
- pr(9, "feat/9-stacked", branch),
494
- pr(60, "feat/60-stacked", branch),
495
- pr(70, "feat/70-old", branch, "CLOSED"),
496
- ];
497
-
498
- const r = run(w, ["24"], gh.env({ PR_HEAD: branch, PR_OID: oid, PR_LIST_JSON: JSON.stringify(list) }));
499
-
500
- assert.equal(r.code, 3, r.stderr);
501
- assert.deepEqual(r.stdout.trim().split("\n").sort(), ["branch-kept-#51", "branch-kept-#60", "branch-kept-#9"]);
502
- assert.doesNotMatch(r.stderr, /git push/);
503
- assert.equal(originTip(origin, branch), oid);
504
- });
505
-
506
- test("every open PR on the branch gets its branch-kept-# line, however many there are — gh lists 30 unless asked for more", (t) => {
507
- const branch = "fix/25-many";
508
- const { origin, w, oid, gh } = keptFixture(t, branch, "25-many");
509
- const list = [pr(25, branch, "main", "MERGED")];
510
- for (let n = 100; n < 140; n++) list.push(pr(n, `feat/${n}-stacked`, branch));
511
-
512
- const r = run(w, ["25"], gh.env({ PR_HEAD: branch, PR_OID: oid, PR_LIST_JSON: JSON.stringify(list) }));
513
-
514
- assert.equal(r.code, 3, r.stderr);
515
- assert.equal(r.stdout.trim().split("\n").length, 40);
516
- assert.equal(originTip(origin, branch), oid);
517
- });
518
-
519
- test("a failed or unparsable open-PR lookup is exit 2, names the lookup, and pushes nothing", (t) => {
520
- const branch = "fix/25-unknown";
521
- const { origin, w, oid, gh } = keptFixture(t, branch, "25-unknown");
522
- const cases = [
523
- [{ PR_LIST_FAIL: "head" }, /lookup `gh pr list --head fix\/25-unknown` failed/],
524
- [{ PR_LIST_FAIL: "base" }, /lookup `gh pr list --base fix\/25-unknown` failed/],
525
- [{ PR_LIST_RAW_HEAD: "[]" }, /lookup `gh pr list --head fix\/25-unknown` answered with something that is not a list of PR numbers/],
526
- [{ PR_LIST_RAW_BASE: "40\nnull" }, /lookup `gh pr list --base fix\/25-unknown` answered with something that is not a list of PR numbers/],
527
- ];
528
- for (const [extra, named] of cases) {
529
- const r = run(w, ["25"], gh.env({ PR_HEAD: branch, PR_OID: oid, ...extra }));
530
- const label = JSON.stringify(extra);
531
- assert.equal(r.code, 2, `${label}: ${r.stderr}`);
532
- assert.match(r.stderr, named, label);
533
- assert.doesNotMatch(r.stderr, /git push/, label);
534
- assert.equal(r.stdout, "", label);
535
- }
536
- assert.equal(originTip(origin, branch), oid);
537
- });
538
-
539
- // What the guard must ACCEPT: none of these PRs is affected by the delete —
540
- // the merged PR itself, closed PRs, a merged PR based on the branch, a fork PR
541
- // whose own branch merely shares the name (`--head` matches it; it lives in the
542
- // fork), and an open PR on an unrelated branch. A guard that kept on any of them
543
- // would stop every delete.
544
- test("PRs the delete cannot affect do not keep the branch — it is deleted, exit 0", (t) => {
545
- const branch = "fix/26-clear";
546
- const { origin, w, oid, gh } = keptFixture(t, branch, "26-clear");
547
- const list = [
548
- pr(26, branch, "main", "MERGED"),
549
- pr(27, branch, "main", "CLOSED"),
550
- pr(28, "feat/28-old", branch, "MERGED"),
551
- pr(29, branch, "main", "OPEN", true),
552
- pr(30, "feat/30-other", "main"),
553
- ];
554
-
555
- const r = run(w, ["26"], gh.env({ PR_HEAD: branch, PR_OID: oid, PR_LIST_JSON: JSON.stringify(list) }));
556
-
557
- assert.equal(r.code, 0, r.stderr);
558
- assert.deepEqual(r.json, { pr: 26, branch, deleted: true });
559
- assert.equal(onOrigin(origin, branch), false);
560
- });
561
-
562
- // The lookups guard a delete; a branch already gone has none left to guard,
563
- // so a lookup that would fail cannot turn the outcome this step exists for
564
- // into "can't tell", and nothing is kept to report.
565
- test("a branch already gone is success even when an open-PR lookup would fail", (t) => {
566
- const { root, origin, w } = repo(t);
567
- const branch = "feat/32-gone";
568
- const { oid } = mergedInWorktree(w, branch, "32-gone");
569
- git(w, "push", "-q", "origin", "--delete", branch);
570
- const gh = ghStub(t, root);
571
-
572
- const r = run(w, ["32"], gh.env({ PR_HEAD: branch, PR_OID: oid, PR_LIST_FAIL: "head" }));
573
-
574
- assert.equal(r.code, 0, r.stderr);
575
- assert.deepEqual(r.json, { pr: 32, branch, deleted: false, alreadyGone: true });
576
- });