@feigi/fleet-ctl 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/.claude-plugin/plugin.json +9 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +18 -0
  4. package/agents/fleet-finisher.agent.md +7 -0
  5. package/agents/fleet-implementer-alt.agent.md +210 -0
  6. package/agents/fleet-implementer.agent.md +210 -0
  7. package/agents/fleet-merge-bot.agent.md +7 -0
  8. package/agents/fleet-review-comments.agent.md +40 -0
  9. package/agents/fleet-review-correctness.agent.md +43 -0
  10. package/agents/fleet-review-runner.agent.md +73 -0
  11. package/agents/fleet-review-silent-failure.agent.md +49 -0
  12. package/agents/fleet-review-simplify.agent.md +46 -0
  13. package/agents/fleet-review-snapshot.agent.md +24 -0
  14. package/agents/fleet-review-tests.agent.md +46 -0
  15. package/agents/fleet-review-types.agent.md +41 -0
  16. package/agents/fleet-review-verifier.agent.md +29 -0
  17. package/commands/review-and-fix.md +98 -0
  18. package/commands/run-merge-bot.md +357 -0
  19. package/commands/run-team-help.md +17 -0
  20. package/package.json +23 -0
  21. package/scripts/agent-test-dir-prose.test.mjs +59 -0
  22. package/scripts/agent-test.test.mjs +1636 -0
  23. package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
  24. package/scripts/ambient-git-vars-prose.test.mjs +192 -0
  25. package/scripts/ancestry-check-position-prose.test.mjs +175 -0
  26. package/scripts/apply-ruleset.test.mjs +420 -0
  27. package/scripts/arg-header-probes-prose.test.mjs +393 -0
  28. package/scripts/arg.mjs +600 -0
  29. package/scripts/arg.test.mjs +1354 -0
  30. package/scripts/board-cli.test.mjs +694 -0
  31. package/scripts/board-identity.test.mjs +429 -0
  32. package/scripts/board-liveness-banner.test.mjs +119 -0
  33. package/scripts/board-prev-shape.test.mjs +229 -0
  34. package/scripts/board-tryparse-null.test.mjs +119 -0
  35. package/scripts/board.html +471 -0
  36. package/scripts/board.mjs +2037 -0
  37. package/scripts/board.test.mjs +3086 -0
  38. package/scripts/brief-after-cut-prose.test.mjs +53 -0
  39. package/scripts/candidates-exit3-prose.test.mjs +302 -0
  40. package/scripts/candidates.mjs +674 -0
  41. package/scripts/candidates.test.mjs +2101 -0
  42. package/scripts/caveat-unification-prose.test.mjs +98 -0
  43. package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
  44. package/scripts/ci-completes-premise-prose.test.mjs +257 -0
  45. package/scripts/ci-state-prose.test.mjs +113 -0
  46. package/scripts/ci-state.mjs +761 -0
  47. package/scripts/ci-state.test.mjs +1640 -0
  48. package/scripts/ci-vacuous-green.test.mjs +368 -0
  49. package/scripts/citation-sweep-prose.test.mjs +1572 -0
  50. package/scripts/claim-lifecycle.test.mjs +185 -0
  51. package/scripts/claim-ticket.sh +417 -0
  52. package/scripts/claim-ticket.test.mjs +1121 -0
  53. package/scripts/closing-keyword-prose.test.mjs +193 -0
  54. package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
  55. package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
  56. package/scripts/compute-board.mjs +579 -0
  57. package/scripts/compute-board.test.mjs +1060 -0
  58. package/scripts/compute-spend.mjs +329 -0
  59. package/scripts/compute-spend.test.mjs +451 -0
  60. package/scripts/cross-repo-citation-prose.test.mjs +156 -0
  61. package/scripts/cwd-isolation-pins.mjs +83 -0
  62. package/scripts/dedupe-guard-prose.test.mjs +243 -0
  63. package/scripts/derive-testcmd.sh +239 -0
  64. package/scripts/derive-testcmd.test.mjs +380 -0
  65. package/scripts/diff-stats.mjs +231 -0
  66. package/scripts/diff-stats.test.mjs +408 -0
  67. package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
  68. package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
  69. package/scripts/drop-merged-label.sh +173 -0
  70. package/scripts/drop-merged-label.test.mjs +480 -0
  71. package/scripts/expected-jobs-prose.test.mjs +80 -0
  72. package/scripts/filing-bar-seat-prose.test.mjs +242 -0
  73. package/scripts/filing-claim-bar-prose.test.mjs +166 -0
  74. package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
  75. package/scripts/finisher-halt-prose.test.mjs +106 -0
  76. package/scripts/finisher-name-prose.test.mjs +134 -0
  77. package/scripts/finisher-own-tree-prose.test.mjs +285 -0
  78. package/scripts/finisher-pin-race-prose.test.mjs +339 -0
  79. package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
  80. package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
  81. package/scripts/fleet-bootstrap +155 -0
  82. package/scripts/fleet-heartbeat.mjs +272 -0
  83. package/scripts/fleet-heartbeat.test.mjs +450 -0
  84. package/scripts/fleet-provenance +207 -0
  85. package/scripts/fleet-provenance.test.mjs +64 -0
  86. package/scripts/fleet-run +148 -0
  87. package/scripts/fleet-run.test.mjs +90 -0
  88. package/scripts/fleet-state.mjs +400 -0
  89. package/scripts/fleet-state.test.mjs +373 -0
  90. package/scripts/fleet-tick-prose.test.mjs +299 -0
  91. package/scripts/fleet-tick.mjs +832 -0
  92. package/scripts/fleet-tick.test.mjs +1332 -0
  93. package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
  94. package/scripts/frontmatter-allowlist.json +64 -0
  95. package/scripts/frontmatter-check.mjs +256 -0
  96. package/scripts/frontmatter-check.test.mjs +436 -0
  97. package/scripts/git-env.mjs +124 -0
  98. package/scripts/git-env.test.mjs +149 -0
  99. package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
  100. package/scripts/gone-walk.test.mjs +213 -0
  101. package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
  102. package/scripts/head-moved-after-label-prose.test.mjs +233 -0
  103. package/scripts/immutable-body-claim-prose.test.mjs +413 -0
  104. package/scripts/implementer-model-tier.test.mjs +643 -0
  105. package/scripts/inflight-citation-prose.test.mjs +144 -0
  106. package/scripts/inflight-exit2-prose.test.mjs +81 -0
  107. package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
  108. package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
  109. package/scripts/inflight.sh +1106 -0
  110. package/scripts/inflight.test.mjs +2984 -0
  111. package/scripts/injection-control-prose.test.mjs +404 -0
  112. package/scripts/install-root-audit.test.mjs +464 -0
  113. package/scripts/instrument-check-prose.test.mjs +235 -0
  114. package/scripts/instruments.sh +394 -0
  115. package/scripts/instruments.test.mjs +787 -0
  116. package/scripts/issue-tracker-prose.test.mjs +71 -0
  117. package/scripts/json.sh +248 -0
  118. package/scripts/json.test.mjs +364 -0
  119. package/scripts/ledger-dispatch.test.mjs +516 -0
  120. package/scripts/ledger-grammar.mjs +85 -0
  121. package/scripts/ledger-grammar.test.mjs +142 -0
  122. package/scripts/ledger-read-require-file.test.mjs +197 -0
  123. package/scripts/ledger.mjs +1753 -0
  124. package/scripts/ledger.test.mjs +3554 -0
  125. package/scripts/line-distance-prose.test.mjs +245 -0
  126. package/scripts/liveness-rationale-prose.test.mjs +83 -0
  127. package/scripts/locale-pin-prose.test.mjs +189 -0
  128. package/scripts/member-outcome-prose.test.mjs +167 -0
  129. package/scripts/member-outcomes-header.test.mjs +148 -0
  130. package/scripts/member-outcomes-prose.test.mjs +63 -0
  131. package/scripts/member-outcomes.mjs +231 -0
  132. package/scripts/member-outcomes.test.mjs +507 -0
  133. package/scripts/member-prompt-prose.test.mjs +161 -0
  134. package/scripts/member-record.mjs +605 -0
  135. package/scripts/member-record.test.mjs +516 -0
  136. package/scripts/member-write-guard.mjs +279 -0
  137. package/scripts/member-write-guard.test.mjs +211 -0
  138. package/scripts/merge-commit-probe-prose.test.mjs +122 -0
  139. package/scripts/merge-gate.mjs +262 -0
  140. package/scripts/merge-gate.test.mjs +613 -0
  141. package/scripts/muted-git-guard-sweep.test.mjs +493 -0
  142. package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
  143. package/scripts/net-watchdog-prose.test.mjs +79 -0
  144. package/scripts/net.sh +409 -0
  145. package/scripts/net.test.mjs +211 -0
  146. package/scripts/no-ci-gate-prose.test.mjs +108 -0
  147. package/scripts/no-undo-audit.sh +1134 -0
  148. package/scripts/no-undo-audit.test.mjs +3965 -0
  149. package/scripts/no-wave.test.mjs +138 -0
  150. package/scripts/node-floor-sweep.test.mjs +611 -0
  151. package/scripts/pointer-target-prose.test.mjs +186 -0
  152. package/scripts/pr-overlap.mjs +417 -0
  153. package/scripts/pr-overlap.test.mjs +695 -0
  154. package/scripts/printf-die-sweep.test.mjs +384 -0
  155. package/scripts/prompt-renderer.mjs +39 -0
  156. package/scripts/prompt-renderer.test.mjs +68 -0
  157. package/scripts/prose-pin.mjs +808 -0
  158. package/scripts/prose-pin.test.mjs +1034 -0
  159. package/scripts/prove-merge.sh +228 -0
  160. package/scripts/prove-merge.test.mjs +995 -0
  161. package/scripts/pull-table-relabel-prose.test.mjs +60 -0
  162. package/scripts/quiet-payload-prose.test.mjs +222 -0
  163. package/scripts/reap.sh +1768 -0
  164. package/scripts/reap.test.mjs +4395 -0
  165. package/scripts/reaping-prose.test.mjs +159 -0
  166. package/scripts/refuter-scratch-prose.test.mjs +135 -0
  167. package/scripts/release-label-required-prose.test.mjs +71 -0
  168. package/scripts/release-label-split-prose.test.mjs +169 -0
  169. package/scripts/release-ticket.sh +1716 -0
  170. package/scripts/release-ticket.test.mjs +5106 -0
  171. package/scripts/renovate-release-contract.test.mjs +379 -0
  172. package/scripts/repo-root.mjs +544 -0
  173. package/scripts/repo-root.test.mjs +873 -0
  174. package/scripts/reporter-output-rule-prose.test.mjs +208 -0
  175. package/scripts/review-agent-report-only.test.mjs +49 -0
  176. package/scripts/review-core-cwd-isolation.test.mjs +374 -0
  177. package/scripts/review-core-reads.test.mjs +478 -0
  178. package/scripts/review-core-refuter-scratch.test.mjs +148 -0
  179. package/scripts/review-core-snapshot-path.test.mjs +777 -0
  180. package/scripts/review-core-specialist-scratch.test.mjs +189 -0
  181. package/scripts/review-core-testcmd.test.mjs +288 -0
  182. package/scripts/review-core-unrun.test.mjs +530 -0
  183. package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
  184. package/scripts/review-core.mjs +1028 -0
  185. package/scripts/review-eval-resolver-path.test.mjs +55 -0
  186. package/scripts/review-eval.mjs +197 -0
  187. package/scripts/review-host-fixture.mjs +73 -0
  188. package/scripts/review-in-run-retry.test.mjs +187 -0
  189. package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
  190. package/scripts/review-path-default.test.mjs +796 -0
  191. package/scripts/review-runner-spawns.test.mjs +93 -0
  192. package/scripts/review-runner.test.mjs +155 -0
  193. package/scripts/review-tier-audit.test.mjs +140 -0
  194. package/scripts/run-artifact-pr-prose.test.mjs +341 -0
  195. package/scripts/run-merge-bot-prose.test.mjs +1391 -0
  196. package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
  197. package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
  198. package/scripts/section-between-guard-prose.test.mjs +378 -0
  199. package/scripts/select-dimensions.test.mjs +674 -0
  200. package/scripts/shared-refusal.test.mjs +388 -0
  201. package/scripts/shell-traps-prose.test.mjs +507 -0
  202. package/scripts/shortlist.mjs +355 -0
  203. package/scripts/shortlist.test.mjs +366 -0
  204. package/scripts/slow-transport.mjs +72 -0
  205. package/scripts/snapshot-repo.test.mjs +772 -0
  206. package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
  207. package/scripts/spend-view.test.mjs +312 -0
  208. package/scripts/staleness-qualifier-prose.test.mjs +251 -0
  209. package/scripts/staleness-verdict-prose.test.mjs +142 -0
  210. package/scripts/staleness.mjs +414 -0
  211. package/scripts/staleness.test.mjs +893 -0
  212. package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
  213. package/scripts/stash-prohibition-prose.test.mjs +313 -0
  214. package/scripts/strip-comments.mjs +44 -0
  215. package/scripts/tier-check.mjs +468 -0
  216. package/scripts/tier-check.test.mjs +726 -0
  217. package/scripts/tier-guard-gate-prose.test.mjs +216 -0
  218. package/scripts/tier-outcomes-header.test.mjs +586 -0
  219. package/scripts/tier-outcomes.mjs +441 -0
  220. package/scripts/tier-outcomes.test.mjs +342 -0
  221. package/scripts/tier-roles.mjs +250 -0
  222. package/scripts/tier-roles.test.mjs +316 -0
  223. package/scripts/tracker-block-copy-prose.test.mjs +288 -0
  224. package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
  225. package/scripts/unattended-git-sweep.test.mjs +142 -0
  226. package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
  227. package/scripts/verify-sha.sh +117 -0
  228. package/scripts/verify-sha.test.mjs +693 -0
  229. package/scripts/watcher-degraded-block.test.mjs +372 -0
  230. package/scripts/watcher-key-prose.test.mjs +106 -0
  231. package/scripts/within-run-pair-prose.test.mjs +208 -0
  232. package/scripts/worktree-audit.sh +482 -0
  233. package/scripts/worktree-audit.test.mjs +1407 -0
  234. package/scripts/worktree-head-prose.test.mjs +276 -0
  235. package/scripts/worktree-listing-sweep.test.mjs +217 -0
  236. package/scripts/worktree-model-prose.test.mjs +216 -0
  237. package/scripts/worktree.sh +470 -0
  238. package/skills/next-ticket/SKILL.md +138 -0
  239. package/skills/run-team/SKILL.md +3603 -0
  240. package/skills/run-team/references/ci-and-staleness.md +75 -0
  241. package/skills/run-team/references/correction-tickets.md +37 -0
  242. package/skills/run-team/references/isolation.md +23 -0
  243. package/skills/run-team/references/member-lifecycle.md +73 -0
  244. package/skills/run-team/references/reaping.md +73 -0
  245. package/skills/sizing-a-ticket/SKILL.md +39 -0
@@ -0,0 +1,149 @@
1
+ // This file covers both of git-env.mjs's exports. `gitEnv()` is the one place
2
+ // the scrub #1599 asks every `.mjs` git caller to route through;
3
+ // `workspaceDirFromGitCommonDir()` is the one place #1658 asks every caller
4
+ // that turns a `--git-common-dir` answer into a workspace directory to route
5
+ // through — see git-env.mjs's own header for why each is a helper rather than
6
+ // one more hand-spelled copy.
7
+ //
8
+ // What matters for gitEnv() is observable: the two names are gone from what
9
+ // it returns, everything else survives, an override cannot smuggle either
10
+ // name back in, and the input is never mutated — a caller passing
11
+ // `process.env` itself must not have it silently rewritten out from under
12
+ // every OTHER thing in this process that reads it.
13
+ import { test } from "node:test";
14
+ import assert from "node:assert/strict";
15
+ import { mkdtempSync, mkdirSync, symlinkSync, realpathSync, rmSync } from "node:fs";
16
+ import { tmpdir } from "node:os";
17
+ import { join } from "node:path";
18
+ import { gitEnv, workspaceDirFromGitCommonDir } from "./git-env.mjs";
19
+
20
+ test("GIT_DIR and GIT_WORK_TREE are absent from the result, even when the base carries them", () => {
21
+ const base = { GIT_DIR: "/somewhere/.git", GIT_WORK_TREE: "/somewhere", PATH: "/bin" };
22
+ const env = gitEnv({}, base);
23
+ assert.equal("GIT_DIR" in env, false);
24
+ assert.equal("GIT_WORK_TREE" in env, false);
25
+ assert.equal(env.PATH, "/bin", "an unrelated var must survive the scrub");
26
+ });
27
+
28
+ test("a base carrying neither name is unaffected beyond the copy", () => {
29
+ const base = { PATH: "/bin", LANG: "C" };
30
+ assert.deepEqual(gitEnv({}, base), { PATH: "/bin", LANG: "C" });
31
+ });
32
+
33
+ test("overrides are merged in, alongside the scrub", () => {
34
+ const base = { GIT_DIR: "/somewhere/.git", PATH: "/bin" };
35
+ const env = gitEnv({ LC_ALL: "C", GH_REPO: "" }, base);
36
+ assert.equal(env.LC_ALL, "C");
37
+ assert.equal(env.GH_REPO, "");
38
+ assert.equal(env.PATH, "/bin");
39
+ assert.equal("GIT_DIR" in env, false, "an override alongside the scrub must not resurrect it");
40
+ });
41
+
42
+ test("an override that itself names GIT_DIR or GIT_WORK_TREE cannot smuggle either back in", () => {
43
+ // The deletes run AFTER the merge, precisely so a caller cannot defeat the
44
+ // scrub by accident — an override map built from some other source that
45
+ // happens to carry either key must not undo what this function exists to
46
+ // do.
47
+ const env = gitEnv({ GIT_DIR: "/attacker/.git", GIT_WORK_TREE: "/attacker" }, { PATH: "/bin" });
48
+ assert.equal("GIT_DIR" in env, false);
49
+ assert.equal("GIT_WORK_TREE" in env, false);
50
+ });
51
+
52
+ test("the base object passed in is never mutated", () => {
53
+ const base = { GIT_DIR: "/somewhere/.git", GIT_WORK_TREE: "/somewhere", PATH: "/bin" };
54
+ const before = { ...base };
55
+ gitEnv({}, base);
56
+ assert.deepEqual(base, before, "a caller passing its own long-lived object must get it back unchanged");
57
+ });
58
+
59
+ test("with no base given, process.env itself is read — not a frozen or empty stand-in", () => {
60
+ const hadDir = "GIT_DIR" in process.env;
61
+ const prevDir = process.env.GIT_DIR;
62
+ process.env.GIT_DIR = "/ambient/.git";
63
+ process.env.FLEET_GIT_ENV_PROBE = "present";
64
+ try {
65
+ const env = gitEnv();
66
+ assert.equal("GIT_DIR" in env, false, "the real ambient GIT_DIR must be scrubbed, not merely a fixture's stand-in for it");
67
+ assert.equal(env.FLEET_GIT_ENV_PROBE, "present", "an unrelated real process.env var must still come through by default");
68
+ } finally {
69
+ if (hadDir) process.env.GIT_DIR = prevDir; else delete process.env.GIT_DIR;
70
+ delete process.env.FLEET_GIT_ENV_PROBE;
71
+ }
72
+ });
73
+
74
+ // ---------------------------------------------------------------------------
75
+ // workspaceDirFromGitCommonDir() — the resolution the three callers of #1658
76
+ // used to hand-spell one apiece: ledger.mjs's defaultLedgerPath(),
77
+ // fleet-state.mjs's statePath() and board.mjs's resolveCockpitInstance().
78
+ // What is observable: which directory a given `--git-common-dir` answer
79
+ // names, that an answer carrying nothing is `null` rather than a
80
+ // plausible-looking path, and that canonicalisation is an opt-in the two
81
+ // non-board callers deliberately do not take.
82
+
83
+ test("an absolute --git-common-dir names the directory holding it", () => {
84
+ assert.equal(workspaceDirFromGitCommonDir("/w/repo/.git", "/elsewhere"), "/w/repo");
85
+ });
86
+
87
+ test("a relative --git-common-dir resolves against the passed cwd, never process.cwd()", () => {
88
+ // git answers this RELATIVE — a bare `.git` — when it runs from a
89
+ // checkout's top level. A resolve() that reached for process.cwd() instead
90
+ // would answer with this test runner's own checkout, which is a real path
91
+ // and therefore a silent wrong answer rather than a failure.
92
+ assert.equal(workspaceDirFromGitCommonDir(".git", "/w/repo"), "/w/repo");
93
+ });
94
+
95
+ test("a real git answer's trailing newline still resolves to the parent directory", () => {
96
+ assert.equal(workspaceDirFromGitCommonDir("/w/repo/.git\n", "/w/repo"), "/w/repo");
97
+ });
98
+
99
+ // Three distinct shapes of "git told us nothing usable", one per way a caller
100
+ // can arrive here: `git` exited 0 with an empty stdout, it answered with a
101
+ // bare newline, and there was no stdout to read at all (a spawn that never
102
+ // ran, or one killed by its own timeout). All three must be `null` — the
103
+ // signal each call site's degrade arm branches on. A resolved-looking path
104
+ // here would put the run's ledger, its heartbeat or its board under whatever
105
+ // `dirname("")` happens to name.
106
+ for (const [label, value] of [["an empty answer", ""], ["a newline-only answer", " \n"], ["no answer at all", undefined]]) {
107
+ test(`${label} resolves to null, never a path`, () => {
108
+ assert.equal(workspaceDirFromGitCommonDir(value, "/w/repo"), null);
109
+ });
110
+ }
111
+
112
+ test("by default the answer is NOT canonicalised — a symlinked route keeps the spelling it arrived with", () => {
113
+ // This default is what ledger.mjs and fleet-state.mjs read (#1658): both
114
+ // PRINT the path they resolve — the ledger in `check`'s JSON and both in
115
+ // their degrade warnings — so canonicalising for them would change their
116
+ // output, not merely their code shape.
117
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "git-env-ws-")));
118
+ try {
119
+ mkdirSync(join(root, "repo"));
120
+ symlinkSync(join(root, "repo"), join(root, "link"));
121
+ assert.equal(workspaceDirFromGitCommonDir(join(root, "link", ".git"), root), join(root, "link"));
122
+ } finally { rmSync(root, { recursive: true, force: true }); }
123
+ });
124
+
125
+ test("canonicalise: true collapses a symlinked route onto the one real workspace", () => {
126
+ // board.mjs's opt-in, and the reason it has one: a second spelling of one
127
+ // workspace derives a second port and a second state directory for a
128
+ // cockpit already being served (#1582).
129
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "git-env-ws-link-")));
130
+ try {
131
+ const real = join(root, "repo");
132
+ mkdirSync(real);
133
+ const link = join(root, "link");
134
+ symlinkSync(real, link);
135
+ const viaLink = workspaceDirFromGitCommonDir(join(link, ".git"), root, { canonicalise: true });
136
+ assert.equal(viaLink, real, "the symlinked route must canonicalise onto the real workspace, not merely agree with itself");
137
+ assert.equal(viaLink, workspaceDirFromGitCommonDir(join(real, ".git"), root, { canonicalise: true }));
138
+ } finally { rmSync(root, { recursive: true, force: true }); }
139
+ });
140
+
141
+ test("canonicalise: true on a directory that does not exist answers the uncanonicalised path rather than throwing", () => {
142
+ // A workspace removed out from under a running cockpit must not turn
143
+ // resolution into a throw: the caller still gets a usable key, just an
144
+ // uncanonicalised one.
145
+ assert.equal(
146
+ workspaceDirFromGitCommonDir("/no-such-root-1658/repo/.git", "/", { canonicalise: true }),
147
+ "/no-such-root-1658/repo",
148
+ );
149
+ });
@@ -0,0 +1,216 @@
1
+ // Regression gate for #730's own structural gap, named as unverified finding 4
2
+ // in this PR's own review: every known site got hand-patched, but nothing
3
+ // would catch an EIGHTH one added tomorrow without the flag. The class:
4
+ // `status.showUntrackedFiles = no` makes `git status --porcelain` exit 0 with
5
+ // EMPTY output over a worktree holding untracked work, so any probe whose
6
+ // EMPTY answer licenses a keep/reap/release/rebase decision has to pin an
7
+ // explicit untracked-files mode (`-uall`/`-unormal`/`-uno`) on the command
8
+ // line — the config cannot be trusted to leave it at the default. reap.sh's
9
+ // branch sweep states the class in full; this file is the enforcement that
10
+ // does not depend on remembering to re-derive it by hand next time.
11
+ //
12
+ // So the pin is not "the seven known sites carry the flag" — that is exactly
13
+ // the fix that ships without closing its own gap. It is the property: no
14
+ // fleet shell script runs `git status --porcelain` (directly, or through
15
+ // reap.sh's `git_probe` wrapper, which only forwards to `git`) without an
16
+ // explicit untracked-files mode, except the one named, deliberate exception.
17
+ //
18
+ // instruments.sh's bare `--porcelain` is the sole allowed exception: it
19
+ // prints to stderr to say WHAT changed, after a digest over `git ls-files`
20
+ // (tracked files only) has already refused — a report, not a gate, so the
21
+ // silenced mode cannot hide the thing being reported.
22
+ //
23
+ // Zero deps: `node --test plugin/scripts/git-status-untracked-mode-sweep.test.mjs`.
24
+
25
+ import { test } from "node:test";
26
+ import assert from "node:assert/strict";
27
+ import { readFileSync } from "node:fs";
28
+ import { join } from "node:path";
29
+ import { fileURLToPath } from "node:url";
30
+ import { repoRoot, skipWithoutRepo, trackedShellScripts } from "./repo-root.mjs";
31
+
32
+ const DIR = fileURLToPath(new URL(".", import.meta.url));
33
+
34
+ // Needs an ambient git working tree — same precondition, same reason, as the
35
+ // other sweeps in this directory (repo-root.mjs's own header). Where there is
36
+ // none (a `git archive` extraction) the tests below DECLINE with a reason
37
+ // rather than running, per #1149.
38
+ const ROOT = repoRoot(DIR);
39
+ const SKIP_WITHOUT_REPO = skipWithoutRepo(ROOT, "this sweep over what ships");
40
+
41
+ /**
42
+ * Every tracked `*.sh` in the repo, so a new script cannot join unnoticed.
43
+ *
44
+ * Empty ONLY because the root lookup could not answer, in which case every
45
+ * test below is skipped. A root that answers and lists nothing is a
46
+ * different condition and must reach the non-vacuity test below and fail
47
+ * there.
48
+ */
49
+ const SHELL_SCRIPTS = ROOT === null ? [] : trackedShellScripts(ROOT);
50
+
51
+ /**
52
+ * Drop a trailing `#` comment. Quote-aware: a `#` inside a `die` message or a
53
+ * printed banner is text, not a comment marker — stripping at it would cut a
54
+ * real command in half. Same shape as muted-git-guard-sweep.test.mjs's
55
+ * `stripComment`, independently kept here rather than shared: the two files
56
+ * police different commands and a shared helper would couple them for no
57
+ * reason either needs.
58
+ */
59
+ function stripComment(line) {
60
+ let quote = null;
61
+ for (let i = 0; i < line.length; i++) {
62
+ const c = line[i];
63
+ if (quote) {
64
+ if (c === quote) quote = null;
65
+ else if (c === "\\" && quote === '"') i++;
66
+ } else if (c === "'" || c === '"') {
67
+ quote = c;
68
+ } else if (c === "#" && (i === 0 || /\s/.test(line[i - 1]))) {
69
+ return line.slice(0, i);
70
+ }
71
+ }
72
+ return line;
73
+ }
74
+
75
+ /**
76
+ * One logical shell statement per element (with its starting line number),
77
+ * comments already gone, trailing-backslash continuations joined.
78
+ *
79
+ * None of the seven pinned sites in this repo actually span lines, but a
80
+ * scanner that only sees physical lines pins one way of typing the command
81
+ * rather than the command — see worktree-listing-sweep.test.mjs's identical
82
+ * reasoning for `git worktree list \` + newline continuation.
83
+ */
84
+ function statements(text) {
85
+ const out = [];
86
+ const phys = text.split("\n").map(stripComment);
87
+ let buf = "";
88
+ let start = 0;
89
+ for (let i = 0; i < phys.length; i++) {
90
+ if (buf === "") start = i + 1;
91
+ const line = buf === "" ? phys[i] : phys[i].replace(/^\s+/, "");
92
+ const joined = buf === "" ? line : `${buf} ${line}`;
93
+ if (/\\$/.test(line)) {
94
+ buf = joined.slice(0, -1);
95
+ continue;
96
+ }
97
+ if (joined.trim() !== "") out.push([start, joined]);
98
+ buf = "";
99
+ }
100
+ if (buf.trim() !== "") out.push([start, buf]);
101
+ return out;
102
+ }
103
+
104
+ /**
105
+ * Is the character at `idx` inside an open quote? Same shape as
106
+ * worktree-listing-sweep.test.mjs's `quoted` — a banner
107
+ * (`printf '$ git … status --porcelain -uall\n'`) NAMES the command inside a
108
+ * quote rather than running it, and must not be scanned as an invocation.
109
+ */
110
+ function quoted(line, idx) {
111
+ let q = null;
112
+ for (let i = 0; i < idx; i++) {
113
+ const c = line[i];
114
+ if (q) {
115
+ if (c === q) q = null;
116
+ } else if (c === '"' || c === "'") {
117
+ q = c;
118
+ }
119
+ }
120
+ return q !== null;
121
+ }
122
+
123
+ // `git` or `git_probe` (reap.sh's own wrapper, which only forwards its args
124
+ // to `git "$@"` — grep confirms it is the sole definition and reap.sh the
125
+ // sole file that defines or calls it, but the sweep matches the spelling
126
+ // rather than trusting that to stay true) followed, anywhere later on the
127
+ // same logical statement, by `status` and then `--porcelain`. Requiring
128
+ // `status` in between is what keeps `git worktree list --porcelain` (a
129
+ // different subcommand, no untracked-files mode to speak of) out of this
130
+ // sweep without a file-by-file exclusion list.
131
+ const INVOCATION = /\b(?:git|git_probe)\b[^\n]*?\bstatus\b[^\n]*?--porcelain\b/;
132
+
133
+ /** Logical statements of `src` that INVOKE `status --porcelain`, not merely name it in a quote. */
134
+ function invocations(src) {
135
+ return statements(src)
136
+ .map(([n, line]) => [n, line, INVOCATION.exec(line)])
137
+ .filter(([, , m]) => m !== null)
138
+ .filter(([, line, m]) => !quoted(line, m.index))
139
+ .map(([n, line]) => [n, line]);
140
+ }
141
+
142
+ /** An explicit untracked-files mode, short or long form. Absence is the defect. */
143
+ const HAS_MODE = /(?:^|\s)(?:-u(?:no|normal|all)?|--untracked-files(?:=|\s))/;
144
+
145
+ /**
146
+ * The one deliberate exception, named exactly rather than by file: a report
147
+ * line run AFTER a digest over tracked files (`git ls-files`) has already
148
+ * refused, so the silenced mode cannot hide what it prints (reap.sh's
149
+ * comment states this in full). Matched on file AND a fragment of the actual
150
+ * command, not the file alone — a second, real gate added later to
151
+ * instruments.sh must not inherit this exemption for free.
152
+ */
153
+ const ALLOWED = [
154
+ { file: "plugin/scripts/instruments.sh", fragment: 'status --porcelain -- $set' },
155
+ ];
156
+
157
+ function isAllowed(file, line) {
158
+ return ALLOWED.some((a) => a.file === file && line.includes(a.fragment));
159
+ }
160
+
161
+ // A guard on the guard: a bad glob, a moved directory, or a `git ls-files`
162
+ // that answers nothing turns the sweep below into a vacuous pass over an
163
+ // empty list — green, and blind. Named sites, because those are exactly the
164
+ // ones this ticket's own review found undercounted once by hand.
165
+ test("the sweep sees the scripts it is supposed to police", { skip: SKIP_WITHOUT_REPO }, () => {
166
+ for (const f of [
167
+ "plugin/scripts/reap.sh",
168
+ "plugin/scripts/release-ticket.sh",
169
+ "plugin/scripts/worktree-audit.sh",
170
+ "plugin/scripts/no-undo-audit.sh",
171
+ "plugin/scripts/claim-ticket.sh",
172
+ "plugin/scripts/instruments.sh",
173
+ ]) {
174
+ assert.ok(
175
+ SHELL_SCRIPTS.includes(f),
176
+ `${f} is not in the tracked-script list — the glob or the root above is broken, not the script`,
177
+ );
178
+ }
179
+ });
180
+
181
+ test("every git status --porcelain invocation pins an explicit untracked-files mode", { skip: SKIP_WITHOUT_REPO }, () => {
182
+ const offenders = SHELL_SCRIPTS
183
+ .flatMap((f) => invocations(readFileSync(join(ROOT, f), "utf8")).map(([n, l]) => [f, n, l]))
184
+ .filter(([f, , l]) => !HAS_MODE.test(l) && !isAllowed(f, l))
185
+ .map(([f, n, l]) => `${f}:${n}: ${l.trim()}`);
186
+ assert.deepEqual(
187
+ offenders,
188
+ [],
189
+ "a probe whose EMPTY answer licenses an action must pin an explicit -u mode — "
190
+ + "status.showUntrackedFiles=no silences a bare --porcelain at rc 0 (#730)",
191
+ );
192
+ });
193
+
194
+ // The other direction. Without it the assertion above passes just as happily
195
+ // over a tree where NOTHING invokes `status --porcelain` at all — every
196
+ // caller renamed to a different subcommand, or the flag check itself broken
197
+ // so it matches nothing — and the gate would be pinning the absence of a
198
+ // population rather than the shape of one.
199
+ test("the sweep really is seeing status --porcelain invocations, not matching nothing", { skip: SKIP_WITHOUT_REPO }, () => {
200
+ const total = SHELL_SCRIPTS.flatMap((f) => invocations(readFileSync(join(ROOT, f), "utf8")));
201
+ assert.ok(total.length >= 7, `expected at least the seven #730 sites, found ${total.length}`);
202
+ });
203
+
204
+ // The allowlist itself has to still name a real, current exception — an
205
+ // `instruments.sh` rewrite that drops the report line would leave `ALLOWED`
206
+ // pointing at nothing, and the sweep above would read as "nothing to
207
+ // exempt" rather than "the exemption stopped applying".
208
+ test("the allowed exception is a real line in the file it names", { skip: SKIP_WITHOUT_REPO }, () => {
209
+ for (const { file, fragment } of ALLOWED) {
210
+ const src = readFileSync(join(ROOT, file), "utf8");
211
+ assert.ok(
212
+ src.includes(fragment),
213
+ `${file} no longer contains ${JSON.stringify(fragment)} — update or drop the allowlist entry`,
214
+ );
215
+ }
216
+ });
@@ -0,0 +1,213 @@
1
+ // Regression gate for `gone()`, the established-absent predicate the fleet's
2
+ // worktree scripts share. Zero deps:
3
+ // `node --test plugin/scripts/gone-walk.test.mjs`.
4
+ //
5
+ // #725 moved it out of the three byte-identical copies into worktree.sh, so
6
+ // this file now pins ONE definition and the sourcing that reaches it.
7
+ //
8
+ // The CALLERS are covered in their own suites (release-ticket.test.mjs,
9
+ // reap.test.mjs, worktree-audit.test.mjs, claim-ticket.test.mjs). Three of them
10
+ // can only reach the predicate through `git worktree list`, which never yields
11
+ // an empty path and never yields a relative one. This suite exists for the
12
+ // inputs that route leaves unreachable — `gone ""` above all, the case the
13
+ // rejected form of the #178 fix (`[ -n "$look" ] || look=/` placed AFTER the
14
+ // loop) flips from 1 to 0 while every caller-level test stays green.
15
+ //
16
+ // #727 added the fourth, and it is the exception that makes the `relative/…`
17
+ // rows below reachable rather than theoretical: claim-ticket.sh CONSTRUCTS the
18
+ // path it asks about (`.worktrees/$issue-$slug`) instead of reading it back from
19
+ // git, so it is the one caller that can hand this predicate a relative path.
20
+ // Measured on that spelling, the walk stops at the unstrippable `.worktrees`
21
+ // component and answers 1 for a repo that simply has no worktrees yet — every
22
+ // first claim a refusal. It passes `$PWD/$wt` for that reason, and its own suite
23
+ // pins the accept case; the rows here are what say why the absolute form is not
24
+ // decoration.
25
+ //
26
+ // The caller inventory is DERIVED here rather than stated. The stated one was
27
+ // wrong — it credited release-ticket.sh with two call sites when that file has
28
+ // several, and #725's remedy question ("fix in the predicate, or at every call
29
+ // site?") turned on exactly that figure. A number written into a comment is
30
+ // false the moment the next commit lands; an assertion over the tree is not.
31
+ //
32
+ // It reads the function out of the script rather than restating it, so the
33
+ // matrix below cannot drift away from the code it claims to pin.
34
+
35
+ import { test } from "node:test";
36
+ import assert from "node:assert/strict";
37
+ import { spawnSync } from "node:child_process";
38
+ import { chmodSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync } from "node:fs";
39
+ import { tmpdir } from "node:os";
40
+ import { join } from "node:path";
41
+ import { fileURLToPath } from "node:url";
42
+
43
+ // The scripts that ASK the question. Spelled out rather than discovered, for
44
+ // the reason arg.test.mjs spells out its own CONSUMERS list: a discovered set
45
+ // silently shrinks when a script drops its call, which is one of the
46
+ // regressions being pinned. A fourth caller has to be added here deliberately.
47
+ const CALLERS = ["reap.sh", "release-ticket.sh", "worktree-audit.sh", "claim-ticket.sh"];
48
+
49
+ // The one file the definition is allowed to live in.
50
+ const HOME = "worktree.sh";
51
+
52
+ const read = (name) => readFileSync(fileURLToPath(new URL(`./${name}`, import.meta.url)), "utf8");
53
+
54
+ /** The `gone()` definition, verbatim, as it appears in worktree.sh. */
55
+ function extract(name = HOME) {
56
+ const src = read(name);
57
+ // Global, and pinned to exactly ONE match: /bin/sh runs whichever definition
58
+ // was read last, while this lift takes the first, so a second `gone()` further
59
+ // down would leave both tests below green against a predicate the scripts
60
+ // never execute. Zero matches fails the same assert — `undefined !== 1`.
61
+ const all = src.match(/^gone\(\) \{\n[\s\S]*?^\}$/gm);
62
+ assert.equal(all?.length, 1, `${name} must define gone() exactly once, at column 0`);
63
+ return all[0];
64
+ }
65
+
66
+ // #466 landed the second and third copies and #178 exists because a fix to one
67
+ // was a fix to none — then #725 found the third failure of the same shape, a
68
+ // dangling symlink read as established-absent in two of three copies while the
69
+ // third compensated at a call site. So the pin is no longer "the copies agree";
70
+ // it is "there are no copies".
71
+ // `\s*\{` and no end anchor, where this required the opening line to be
72
+ // byte-for-byte `gone() {`. One syntactic form is not the class: measured, the
73
+ // pre-PR body reintroduced under `gone() { # local override` walked straight
74
+ // through and left all four tests here green. A redefinition arrives WITH a
75
+ // comment excusing it far more plausibly than without one, so the one spelling
76
+ // the anchor missed is the likely one.
77
+ test("gone() is defined once in the tree, in worktree.sh", () => {
78
+ extract(HOME);
79
+ for (const name of CALLERS) {
80
+ assert.doesNotMatch(
81
+ read(name),
82
+ /^gone\(\)\s*\{/m,
83
+ `${name} must source ${HOME}, never redefine gone() — a second definition is what #725 found`,
84
+ );
85
+ }
86
+ });
87
+
88
+ // The sourcing is what makes the single definition reachable, and a caller that
89
+ // lost it fails on `gone: not found` at run time — late, and in a delete script.
90
+ test("every caller of gone() sources worktree.sh", () => {
91
+ for (const name of CALLERS) {
92
+ const src = read(name);
93
+ assert.match(src, /\. "\$wt_lib" \|\| die/, `${name} must source ${HOME}`);
94
+ assert.ok(
95
+ src.includes('gone "'),
96
+ `${name} is listed as a caller but never calls gone — drop it from CALLERS or restore the call`,
97
+ );
98
+ }
99
+ });
100
+
101
+ // The inventory #725's remedy question turned on, derived rather than stated.
102
+ // The comment this file used to carry named a figure for release-ticket.sh that
103
+ // its own source contradicted, so "fix at every call site" was sized against a
104
+ // number nothing checked.
105
+ test("the caller inventory matches the tree", () => {
106
+ const counts = Object.fromEntries(
107
+ CALLERS.map((name) => [name, (read(name).match(/(?:^|[^\w-])gone "/g) ?? []).length]),
108
+ );
109
+ for (const [name, n] of Object.entries(counts)) {
110
+ assert.ok(n > 0, `${name} must call gone() at least once`);
111
+ }
112
+ // release-ticket.sh is the file the old stated inventory undercounted, and the
113
+ // reason it did is that its call sites are spread across four guards rather
114
+ // than gathered. Pinned against the OTHER two so the assertion says something
115
+ // about shape rather than restating a number: it is the file that asks the
116
+ // question most often, and a change that levels that out is worth a look.
117
+ assert.ok(
118
+ counts["release-ticket.sh"] > counts["reap.sh"],
119
+ "release-ticket.sh asks gone() more often than reap.sh — the asymmetry the old inventory flattened",
120
+ );
121
+ assert.ok(
122
+ counts["release-ticket.sh"] > counts["worktree-audit.sh"],
123
+ "release-ticket.sh asks gone() more often than worktree-audit.sh",
124
+ );
125
+ });
126
+
127
+ /**
128
+ * Run `gone` over `inputs` in a fresh /bin/sh and return one exit status each.
129
+ *
130
+ * `timeout`, not a bare run: the loop's termination is a property under test
131
+ * here (`${p%/*}` returns p unchanged on a path with no slash, which is what
132
+ * the `!=` guard is for), and a spin would otherwise hang the suite rather
133
+ * than fail it.
134
+ */
135
+ function probe(body, inputs) {
136
+ const script = `${body}\nfor p in "$@"; do if gone "$p"; then echo 0; else echo 1; fi; done\n`;
137
+ const r = spawnSync("/bin/sh", ["-c", script, "sh", ...inputs], { encoding: "utf8", timeout: 30_000 });
138
+ assert.equal(r.signal, null, `gone() must terminate on every input: ${r.signal}`);
139
+ assert.equal(r.status, 0, `harness itself must not fail: ${r.stderr}`);
140
+ const out = r.stdout.trim().split("\n");
141
+ assert.equal(out.length, inputs.length, "one answer per input");
142
+ return out;
143
+ }
144
+
145
+ test("gone() answers the full input matrix, 0 only for established absence", (t) => {
146
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "gone-walk-")));
147
+ t.after(() => {
148
+ // try: the hook is registered before the fixture exists, so on a setup
149
+ // failure `noperm` is not there to restore — and a throwing chmod would
150
+ // take the rmSync below with it and leak the temp dir.
151
+ try {
152
+ chmodSync(join(root, "noperm"), 0o755);
153
+ } catch {
154
+ // Never built; nothing to restore. The rmSync is the part that matters.
155
+ }
156
+ rmSync(root, { recursive: true, force: true });
157
+ });
158
+ mkdirSync(join(root, "exists"));
159
+ mkdirSync(join(root, "noperm", "inner"), { recursive: true });
160
+ chmodSync(join(root, "noperm"), 0o000);
161
+ // #725's fixtures. `dangling` is the defect itself; `live` is the control that
162
+ // stops the fix becoming a blanket refusal of every symlink; `danganc/link` is
163
+ // the sibling the loop-condition placement answers for free — a dangling link
164
+ // standing in for an ANCESTOR rather than for the path itself.
165
+ symlinkSync(join(root, "nowhere"), join(root, "dangling"));
166
+ symlinkSync(join(root, "exists"), join(root, "live"));
167
+ mkdirSync(join(root, "danganc"));
168
+ symlinkSync(join(root, "nowhere"), join(root, "danganc", "link"));
169
+
170
+ // `/nonexistent-top-level-178` is never created and needs no fixture: what
171
+ // makes it the shape #178 is about is that its FIRST component is missing,
172
+ // so the walk runs out of ancestors below `/` and has only the root left to
173
+ // test. Reachable in production through a hand-added worktree outside the
174
+ // checkout whose ancestor chain was removed (`git worktree add /scratch/wt`,
175
+ // then `rm -rf /scratch`) — the population release-ticket.sh's stray guard
176
+ // exists to handle.
177
+ const cases = [
178
+ ["", "1", "no path is not an absent path — the after-the-loop form of this fix flips exactly this one"],
179
+ ["/nonexistent-top-level-178", "0", "first component missing, root searchable: established absent (#178)"],
180
+ ["/nonexistent-top-level-178/child", "0", "same, one level down (#178)"],
181
+ ["/", "1", "the root exists, so it is not an absence — and it is where the walk now stops"],
182
+ [join(root, "exists"), "1", "a path that is there is not an absence"],
183
+ [join(root, "exists", "absent"), "0", "surviving ancestor below / — the case that already worked"],
184
+ [join(root, "noperm", "inner"), "1", "unsearchable prefix stays unknown, never absent"],
185
+ ["relative-no-slash", "1", "no slash: the walk cannot climb, so it cannot establish anything"],
186
+ ["relative/with/slash", "1", "relative prefix is not searchable from here either"],
187
+ // #725. `-e` STATS, so it is false through a dangling link while `-L` is
188
+ // true: the path is occupied as far as `git worktree add` is concerned, and
189
+ // calling it established-absent is what let reap.sh predict a removal and
190
+ // worktree-audit.sh report `MISSING on disk` over a live claim. A dangling
191
+ // worktree link arrives BOTH as rc-0 residue and as release-ticket.sh's
192
+ // rc-255 halt path with the branch and the label still alive, so "not
193
+ // established-absent" is the only answer true of both (#728).
194
+ [join(root, "dangling"), "1", "a dangling symlink is occupied, never an absence (#725)"],
195
+ [join(root, "danganc", "link", "child"), "1", "a dangling symlink ANCESTOR is not an absence either (#725)"],
196
+ // The accept side. Without it the matrix pins that the fix refuses, not that
197
+ // it discriminates: a `gone` hard-wired to 1 passes every reject row above.
198
+ [join(root, "live"), "1", "a symlink to a real directory is present, as it always was"],
199
+ [join(root, "nowhere"), "0", "the dangling links point HERE, and it is still an ordinary absence"],
200
+ ]
201
+ // Root reads every directory, so the unsearchable prefix the `noperm` row
202
+ // needs cannot be fixtured under uid 0. Drop that ONE row there, never the
203
+ // matrix: the other eight need no permission fixture, and `gone ""` among
204
+ // them is the only case that separates this fix from the rejected
205
+ // after-the-loop form — skipping the whole test hands uid 0 a green suite
206
+ // against the very placement it was written to reject.
207
+ .filter(([p]) => process.getuid?.() !== 0 || !p.startsWith(join(root, "noperm")));
208
+
209
+ const answers = probe(extract(), cases.map(([p]) => p));
210
+ for (const [i, [p, want, why]] of cases.entries()) {
211
+ assert.equal(answers[i], want, `gone "${p}" must be ${want}: ${why}`);
212
+ }
213
+ });