@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,366 @@
1
+ // Regression gate for shortlist.mjs — the Shortlist as a script (ADR 0013 §1,
2
+ // §3): candidates.mjs's oldest-first rows, minus open blockers, minus live
3
+ // Exclusions, minus whatever inflight.sh reports taken or cannot answer,
4
+ // written to `.fleet/shortlist.json` under the git common dir.
5
+ //
6
+ // What is real and what is stubbed, and why:
7
+ //
8
+ // - candidates.mjs and ledger.mjs are the REAL scripts, copied beside the
9
+ // script under test. candidates.mjs is what orders the rows and extracts
10
+ // `d` from a body, so a stub there would pin a sort and a dependency scan
11
+ // this file never ran; ledger.mjs is the only writer of the `excluded ·`
12
+ // rows the exclusion rule reads, so every row below is written by it
13
+ // rather than hand-spelled in a format that could drift from the real one.
14
+ // - `gh` is a PATH stub. `issue list` applies the jq expression gh was
15
+ // handed to a fixture (the fleet-tick.test.mjs pattern), and answers `[]`
16
+ // unless the search carries `label:"ready-for-agent"` — so every case that
17
+ // expects rows back also proves the label was asked for. `issue view` and
18
+ // `pr view` answer `{"state": …}` from a per-case state table, and fail the
19
+ // way real gh does for a number or branch the table does not name. It is
20
+ // NOT env-blind: `issue view`/`pr view` ask `git rev-parse --git-common-dir`
21
+ // of their own inherited env first, the way real gh's remote resolution
22
+ // follows an ambient GIT_DIR too (#1811 review), and answer from a SECOND
23
+ // table when that resolves to a decoy repository — so a probe call that
24
+ // forgot to scrub GIT_DIR/GIT_WORK_TREE answers for the wrong one here
25
+ // exactly as it would for the real gh.
26
+ // - inflight.sh is a stub, because the real one needs a remote, a PR list and
27
+ // python3 to say anything; its own suite is inflight.test.mjs. The stub
28
+ // keeps the real exit contract: 0 free, 1 taken, 2 could not answer.
29
+ import { test } from "node:test";
30
+ import assert from "node:assert/strict";
31
+ import { spawnSync } from "node:child_process";
32
+ import {
33
+ mkdtempSync, mkdirSync, writeFileSync, readFileSync, copyFileSync, chmodSync, existsSync, rmSync, realpathSync,
34
+ } from "node:fs";
35
+ import { tmpdir } from "node:os";
36
+ import { join } from "node:path";
37
+ import { fileURLToPath } from "node:url";
38
+ import { gitEnv } from "./git-env.mjs";
39
+
40
+ const HERE = fileURLToPath(new URL(".", import.meta.url));
41
+ // Every file the copied shortlist.mjs reaches at run time: its own imports,
42
+ // and the two sibling scripts it spawns for real. A missing import is a
43
+ // MODULE_NOT_FOUND at startup, so add a row whenever any of these gains one.
44
+ const COPIED = ["shortlist.mjs", "candidates.mjs", "ledger.mjs", "ledger-grammar.mjs", "arg.mjs", "git-env.mjs"];
45
+
46
+ const GH_STUB = `#!/bin/sh
47
+ case " $* " in *" --fleet-warm "*) exit 0 ;; esac
48
+ case "$1 $2" in
49
+ "issue list")
50
+ [ -n "$ISSUE_LIST_FAIL" ] && { echo "gh: HTTP 502" >&2; exit 1; }
51
+ expr=""
52
+ search=""
53
+ while [ $# -gt 0 ]; do
54
+ case "$1" in
55
+ --jq) shift; expr="$1" ;;
56
+ --search) shift; search="$1" ;;
57
+ esac
58
+ shift
59
+ done
60
+ case "$search" in
61
+ *'label:"ready-for-agent"'*) exec jq -c "$expr" "$FIXTURE_ISSUES" ;;
62
+ *) echo '[]' ;;
63
+ esac ;;
64
+ "issue view"|"pr view")
65
+ # Real gh's own remote resolution follows an ambient GIT_DIR/GIT_WORK_TREE
66
+ # exactly as git's does (#1811 review) — so this stub asks git too, with
67
+ # the identical probe shortlistPath() uses, --git-common-dir (measured:
68
+ # unlike --show-toplevel, it DOES follow GIT_DIR alone, no GIT_WORK_TREE
69
+ # needed) — and answers from FIXTURE_OTHER_STATES instead of
70
+ # FIXTURE_STATES whenever that resolves to FIXTURE_OTHER_GITDIR, the way
71
+ # a genuinely unscrubbed gh call would silently answer for the wrong
72
+ # repository.
73
+ gitdir=$(git rev-parse --git-common-dir 2>/dev/null)
74
+ if [ -n "$FIXTURE_OTHER_GITDIR" ] && [ "$gitdir" = "$FIXTURE_OTHER_GITDIR" ]; then
75
+ states="$FIXTURE_OTHER_STATES"
76
+ else
77
+ states="$FIXTURE_STATES"
78
+ fi
79
+ state=$(jq -r --arg k "$1" --arg id "$3" '.[$k][$id] // ""' "$states")
80
+ case "$state" in
81
+ "") echo "GraphQL: Could not resolve to an issue or pull request with the number of $3." >&2; exit 1 ;;
82
+ FAIL) echo "gh: HTTP 502 Bad Gateway" >&2; exit 1 ;;
83
+ esac
84
+ printf '{"state":"%s"}\\n' "$state" ;;
85
+ *) echo "unexpected gh $*" >&2; exit 1 ;;
86
+ esac
87
+ `;
88
+
89
+ const INFLIGHT_STUB = `#!/bin/sh
90
+ for t in $INFLIGHT_SLOW; do [ "$t" = "$1" ] && sleep 1; done
91
+ for t in $INFLIGHT_TAKEN; do
92
+ [ "$t" = "$1" ] && { printf '{"issue":%s,"taken":true,"hits":["pr"],"unknown":[]}\\n' "$1"; exit 1; }
93
+ done
94
+ for t in $INFLIGHT_UNKNOWN; do
95
+ [ "$t" = "$1" ] && { printf '{"issue":%s,"taken":false,"hits":[],"unknown":["gh pr list failed"]}\\n' "$1"; exit 2; }
96
+ done
97
+ printf '{"issue":%s,"taken":false,"hits":[],"unknown":[]}\\n' "$1"
98
+ `;
99
+
100
+ const git = (cwd, ...args) => {
101
+ const r = spawnSync("git", args, { cwd, encoding: "utf8", env: gitEnv() });
102
+ assert.equal(r.status, 0, `git ${args.join(" ")}: ${r.stderr}`);
103
+ return r.stdout;
104
+ };
105
+
106
+ // `blockedBy` becomes a `## Blocked by` list in the body — the shape
107
+ // to-tickets publishes — so the real candidates.mjs extracts `d` from it.
108
+ const issue = (number, blockedBy = []) => ({
109
+ number,
110
+ title: `t${number}`,
111
+ labels: [{ name: "ready-for-agent" }],
112
+ body: blockedBy.length ? `## Blocked by\n\n${blockedBy.map((b) => `- #${b}`).join("\n")}\n` : "",
113
+ });
114
+
115
+ // One throwaway workspace: a git repository (the run's workspace), a
116
+ // directory of scripts (shortlist.mjs and what it reaches), and a bin/ holding
117
+ // the gh stub. realpath, because on macOS tmpdir() sits behind a symlink and
118
+ // git answers --git-common-dir with the resolved path.
119
+ function fixture(t) {
120
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "shortlist-")));
121
+ t.after(() => rmSync(root, { recursive: true, force: true }));
122
+ const repo = join(root, "repo");
123
+ mkdirSync(repo);
124
+ git(repo, "init", "-q");
125
+ git(repo, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "--allow-empty", "-m", "init");
126
+ const scripts = join(root, "scripts");
127
+ mkdirSync(scripts);
128
+ for (const f of COPIED) copyFileSync(join(HERE, f), join(scripts, f));
129
+ writeFileSync(join(scripts, "inflight.sh"), INFLIGHT_STUB);
130
+ const bin = join(root, "bin");
131
+ mkdirSync(bin);
132
+ const gh = join(bin, "gh");
133
+ writeFileSync(gh, GH_STUB);
134
+ chmodSync(gh, 0o755);
135
+ // The first exec of a freshly written executable pays an OS scan that
136
+ // ledger.test.mjs measured at seconds under fleet load (#1199); pay it here,
137
+ // outside the bound shortlist.mjs puts on each gh probe.
138
+ //
139
+ // 120 s, not 30 s: a warm-up killed mid-scan leaves the scan unpaid for the
140
+ // gh probe after it — PR #2224 measured 15-16 s first execs under load ~25,
141
+ // and a first exec killed at 500 ms still took 14.5-15.0 s next time (#2229).
142
+ // GH_STUB's `--fleet-warm` arm exits 0 before any other line, so no stub
143
+ // stall can hide in the longer bound; it only lets the scan finish, and stays
144
+ // finite so a truly hung exec still ends the case.
145
+ spawnSync(gh, ["--fleet-warm"], { timeout: 120_000 });
146
+ const issuesFile = join(root, "issues.json");
147
+ const statesFile = join(root, "states.json");
148
+ const shortlistFile = join(repo, ".fleet", "shortlist.json");
149
+
150
+ return {
151
+ root, repo, shortlistFile,
152
+ run({ issues = [], states = {}, env = {}, cwd = repo, args = [] } = {}) {
153
+ writeFileSync(issuesFile, JSON.stringify(issues));
154
+ writeFileSync(statesFile, JSON.stringify({ issue: {}, pr: {}, ...states }));
155
+ const r = spawnSync(process.execPath, [join(scripts, "shortlist.mjs"), ...args], {
156
+ cwd, encoding: "utf8",
157
+ env: {
158
+ ...gitEnv(), PATH: `${bin}:${process.env.PATH}`,
159
+ FIXTURE_ISSUES: issuesFile, FIXTURE_STATES: statesFile, ...env,
160
+ },
161
+ });
162
+ return r;
163
+ },
164
+ // Written by the real ledger.mjs, into the real default ledger the
165
+ // workspace resolves — the same file shortlist.mjs has to find.
166
+ row(ticket, text) {
167
+ const r = spawnSync(process.execPath, [join(scripts, "ledger.mjs"), "row", String(ticket), text], {
168
+ cwd: repo, encoding: "utf8", env: gitEnv(),
169
+ });
170
+ assert.equal(r.status, 0, `ledger.mjs row ${ticket}: ${r.stderr}`);
171
+ },
172
+ written() {
173
+ return JSON.parse(readFileSync(shortlistFile, "utf8"));
174
+ },
175
+ };
176
+ }
177
+
178
+ const numbers = (payload) => payload.shortlist.map((e) => e.n);
179
+ const ok = (r) => assert.equal(r.status, 0, `exit ${r.status}\n${r.stderr}`);
180
+
181
+ test("writes the oldest-first survivors and the scanned count to .fleet/shortlist.json", (t) => {
182
+ const f = fixture(t);
183
+ // #1730 is dropped (an unreadable blocker) so `scanned` and
184
+ // `shortlist.length` diverge — otherwise a `scanned: survivors.length` bug
185
+ // would still pass this test (#1811 review).
186
+ const r = f.run({ issues: [issue(1720), issue(1701), issue(1710), issue(1730, [99])] });
187
+ ok(r);
188
+ assert.deepEqual(f.written(), {
189
+ scanned: 4,
190
+ shortlist: [{ n: 1701, t: "t1701" }, { n: 1710, t: "t1710" }, { n: 1720, t: "t1720" }],
191
+ });
192
+ // stdout is the same payload, plus where it was written.
193
+ assert.deepEqual(JSON.parse(r.stdout), { file: f.shortlistFile, ...f.written() });
194
+ });
195
+
196
+ test("a linked worktree writes the workspace's one shortlist, not a copy of its own", (t) => {
197
+ const f = fixture(t);
198
+ const wt = join(f.repo, ".worktrees", "1701-x");
199
+ git(f.repo, "worktree", "add", "-q", "-b", "x", wt);
200
+ const r = f.run({ issues: [issue(1701)], cwd: wt });
201
+ ok(r);
202
+ assert.deepEqual(numbers(f.written()), [1701]);
203
+ assert.equal(existsSync(join(wt, ".fleet", "shortlist.json")), false, "the worktree grew its own shortlist");
204
+ });
205
+
206
+ test("an ambient GIT_DIR naming another repository cannot move the shortlist there", (t) => {
207
+ const f = fixture(t);
208
+ const other = join(f.root, "other");
209
+ mkdirSync(other);
210
+ git(other, "init", "-q");
211
+ const r = f.run({ issues: [issue(1701)], env: { GIT_DIR: join(other, ".git") } });
212
+ ok(r);
213
+ assert.deepEqual(numbers(f.written()), [1701]);
214
+ assert.equal(existsSync(join(other, ".fleet")), false, "the shortlist followed GIT_DIR into another repository");
215
+ });
216
+
217
+ // Regression (#1811 review): probeState()'s own `gh … view` call must be
218
+ // scrubbed exactly as shortlistPath()'s git call above is — gh's own remote
219
+ // resolution follows an ambient GIT_DIR/GIT_WORK_TREE too (ledger.mjs's
220
+ // tracker-query probe measured this first), so an unscrubbed probeState
221
+ // could answer a blocker or exclusion-premise check from a DIFFERENT
222
+ // repository while `.fleet/shortlist.json` still landed in the right one.
223
+ test("an inherited GIT_DIR cannot retarget probeState's gh calls to another repository", (t) => {
224
+ const f = fixture(t);
225
+ const other = join(f.root, "other");
226
+ mkdirSync(other);
227
+ git(other, "init", "-q");
228
+ const otherStates = join(f.root, "other-states.json");
229
+ // In `other`, PR #60 reads MERGED — the opposite of `repo`'s OPEN — so a
230
+ // gh call retargeted there would wrongly lift #1702's exclusion.
231
+ writeFileSync(otherStates, JSON.stringify({ issue: {}, pr: { 60: "MERGED" } }));
232
+ f.row(1702, "excluded · behind-pr:#60");
233
+ const r = f.run({
234
+ issues: [issue(1701), issue(1702)],
235
+ states: { pr: { 60: "OPEN" } },
236
+ env: { GIT_DIR: join(other, ".git"), FIXTURE_OTHER_GITDIR: join(other, ".git"), FIXTURE_OTHER_STATES: otherStates },
237
+ });
238
+ ok(r);
239
+ assert.deepEqual(numbers(f.written()), [1701]);
240
+ assert.match(r.stderr, /#1702 dropped — excluded · behind-pr:#60, which is OPEN/);
241
+ });
242
+
243
+ test("dependency scan: an open blocker drops the ticket; a closed or merged one does not", (t) => {
244
+ const f = fixture(t);
245
+ const r = f.run({
246
+ issues: [
247
+ issue(1701, [50]), // open issue
248
+ issue(1702, [51]), // closed issue
249
+ issue(1703, [52]), // merged PR — `gh issue view` answers a PR's state too
250
+ issue(1704, [53]), // state unreadable
251
+ issue(1705, [1707]), // blocked by another candidate, which is open by construction
252
+ issue(1706, [1706]), // names itself: not a blocker
253
+ issue(1707),
254
+ ],
255
+ states: { issue: { 50: "OPEN", 51: "CLOSED", 52: "MERGED", 53: "FAIL" } },
256
+ });
257
+ ok(r);
258
+ assert.deepEqual(f.written(), {
259
+ scanned: 7,
260
+ shortlist: [1702, 1703, 1706, 1707].map((n) => ({ n, t: `t${n}` })),
261
+ });
262
+ assert.match(r.stderr, /#1701 dropped — open blocker #50\b/);
263
+ assert.match(r.stderr, /#1704 dropped — blocker #53's state could not be read/);
264
+ assert.match(r.stderr, /#1705 dropped — open blocker #1707\b/);
265
+ });
266
+
267
+ test("inflight.sh exit 1 (taken) and exit 2 (unanswered) drop the ticket; exit 2 is logged by number", (t) => {
268
+ const f = fixture(t);
269
+ const r = f.run({
270
+ issues: [issue(1701), issue(1702), issue(1703), issue(1704), issue(1705)],
271
+ // The probes run concurrently and 1701 and 1703 answer last, so verdicts
272
+ // gathered in completion order rather than candidate order either hand
273
+ // 1701's `taken` to a free ticket or put 1703 at the tail — both red.
274
+ env: { INFLIGHT_TAKEN: "1701", INFLIGHT_UNKNOWN: "1702", INFLIGHT_SLOW: "1701 1703" },
275
+ });
276
+ ok(r);
277
+ assert.deepEqual(numbers(f.written()), [1703, 1704, 1705]);
278
+ assert.equal(f.written().scanned, 5);
279
+ assert.match(r.stderr, /#1701 dropped — taken \(inflight\.sh exit 1/);
280
+ assert.match(r.stderr, /#1702 dropped — in-flight check could not answer \(inflight\.sh exit 2\): gh pr list failed/);
281
+ });
282
+
283
+ test("a live exclusion drops the ticket, and it re-enters in its oldest-first slot once the premise closes", (t) => {
284
+ const f = fixture(t);
285
+ f.row(1702, "excluded · behind-pr:#60");
286
+ f.row(1703, "excluded · behind-pr:#62");
287
+ f.row(1704, "excluded · behind-issue:#61");
288
+ const issues = [1701, 1702, 1703, 1704, 1705].map((n) => issue(n));
289
+
290
+ const held = f.run({ issues, states: { pr: { 60: "OPEN", 62: "CLOSED" }, issue: { 61: "OPEN" } } });
291
+ ok(held);
292
+ // An abandoned (CLOSED, unmerged) PR lifts a behind-pr premise as surely
293
+ // as a merge does, so #1703 is admitted from the start.
294
+ assert.deepEqual(numbers(f.written()), [1701, 1703, 1705]);
295
+ assert.equal(f.written().scanned, 5);
296
+ assert.match(held.stderr, /#1702 dropped — excluded · behind-pr:#60, which is OPEN/);
297
+ assert.match(held.stderr, /#1704 dropped — excluded · behind-issue:#61, which is OPEN/);
298
+
299
+ const lifted = f.run({ issues, states: { pr: { 60: "MERGED", 62: "CLOSED" }, issue: { 61: "CLOSED" } } });
300
+ ok(lifted);
301
+ assert.deepEqual(numbers(f.written()), [1701, 1702, 1703, 1704, 1705]);
302
+ assert.match(lifted.stderr, /#1702 lifted — behind-pr:#60 is MERGED/);
303
+ assert.match(lifted.stderr, /#1704 lifted — behind-issue:#61 is CLOSED/);
304
+ });
305
+
306
+ // The other half of the exclusion rule: what it must ADMIT. Only a row whose
307
+ // text opens with `excluded` is an exclusion, and a premise may name the
308
+ // branch a PR is not yet open for (ADR 0013 §3), which gh resolves by name.
309
+ test("only an `excluded` row excludes; a branch premise resolves through gh pr view; an unreadable premise stands", (t) => {
310
+ const f = fixture(t);
311
+ f.row(1701, "impl-1701 · class=routine");
312
+ f.row(1702, "excluded · behind-pr:#implementer/1690-slug");
313
+ f.row(1703, "excluded · behind-pr:#implementer/1691-slug");
314
+ f.row(1704, "excluded · collides with something, no premise recorded");
315
+ f.row(1705, "impl-1705 · previously excluded · behind-pr:#60");
316
+ f.row(9999, "excluded · behind-pr:#60");
317
+ const r = f.run({
318
+ issues: [1701, 1702, 1703, 1704, 1705, 1706].map((n) => issue(n)),
319
+ // No entry for implementer/1691-slug: gh answers "no pull requests found",
320
+ // which is a premise nobody could read, not one that closed.
321
+ states: { pr: { "implementer/1690-slug": "MERGED", 60: "OPEN" } },
322
+ });
323
+ ok(r);
324
+ assert.deepEqual(numbers(f.written()), [1701, 1702, 1705, 1706]);
325
+ assert.match(r.stderr, /#1702 lifted — behind-pr:#implementer\/1690-slug is MERGED/);
326
+ assert.match(r.stderr, /#1703 dropped — excluded · behind-pr:#implementer\/1691-slug, whose state could not be read/);
327
+ assert.match(r.stderr, /#1704 dropped — excluded with no behind-pr:\/behind-issue: premise/);
328
+ });
329
+
330
+ test("an empty queue is an answer: exit 0, and the file says so", (t) => {
331
+ const f = fixture(t);
332
+ mkdirSync(join(f.repo, ".fleet"));
333
+ writeFileSync(f.shortlistFile, JSON.stringify({ scanned: 1, shortlist: [{ n: 1, t: "stale" }] }));
334
+ const r = f.run({ issues: [] });
335
+ ok(r);
336
+ assert.deepEqual(f.written(), { scanned: 0, shortlist: [] });
337
+ });
338
+
339
+ // Every refusal leaves the previous file exactly as it was: an empty
340
+ // shortlist written in its place would read as "no work" to the tick.
341
+ test("a failed scan, an unreadable ledger or a stray argument refuses at exit 2 and leaves the file untouched", (t) => {
342
+ const f = fixture(t);
343
+ mkdirSync(join(f.repo, ".fleet"));
344
+ const before = JSON.stringify({ scanned: 1, shortlist: [{ n: 1701, t: "t1701" }] });
345
+ writeFileSync(f.shortlistFile, before);
346
+ const issues = [issue(1701)];
347
+
348
+ const scan = f.run({ issues, env: { ISSUE_LIST_FAIL: "1" } });
349
+ assert.equal(scan.status, 2, scan.stderr);
350
+ assert.match(scan.stderr, /shortlist: candidates\.mjs exited 2/);
351
+ assert.equal(readFileSync(f.shortlistFile, "utf8"), before);
352
+
353
+ const stray = f.run({ issues, args: ["--bogus"] });
354
+ assert.equal(stray.status, 2, stray.stderr);
355
+ assert.match(stray.stderr, /shortlist: takes no arguments, got --bogus/);
356
+ assert.equal(readFileSync(f.shortlistFile, "utf8"), before);
357
+
358
+ if (process.getuid?.() === 0) return t.skip("root reads a mode-000 file, so the ledger refusal cannot be staged");
359
+ f.row(1701, "excluded · behind-pr:#60");
360
+ const ledger = join(f.repo, ".fleet", "ledger.md");
361
+ chmodSync(ledger, 0o000);
362
+ const unread = f.run({ issues, states: { pr: { 60: "OPEN" } } });
363
+ assert.equal(unread.status, 2, unread.stderr);
364
+ assert.match(unread.stderr, /shortlist: ledger\.mjs read exited 2/);
365
+ assert.equal(readFileSync(f.shortlistFile, "utf8"), before);
366
+ });
@@ -0,0 +1,72 @@
1
+ // The slow-but-working git transport that every bounded-fetch caller's
2
+ // end-to-end pair is measured against (#346, #347, #1039).
3
+ //
4
+ // An ssh stub that sleeps and then serves a REAL bare repo through
5
+ // `git upload-pack`, so refs genuinely come back: the accept path is exercised
6
+ // against a working transport, not a mock of one. Paired with a budget under
7
+ // the delay — and neither half is worth much alone, because an accept-only
8
+ // case passes just as well against a watchdog that never fires, which is to
9
+ // say against no watchdog at all.
10
+ //
11
+ // A module rather than a copy per suite. Each caller of net.sh asserts its OWN
12
+ // stalled wording, so the wording is the part that cannot be shared and this
13
+ // fixture is the part that can; two copies of the stub are how the copies come
14
+ // to disagree about what "slow but working" means, the argument net.sh's own
15
+ // header makes about restating net_stalled's signal set.
16
+ //
17
+ // Deliberately not a `.test.mjs`: `node --test plugin/scripts/*.test.mjs` does
18
+ // not load it as a suite, and importing a test file to reach a fixture inside
19
+ // it would register that file's own tests a second time in whichever suite
20
+ // imported it.
21
+
22
+ // No executable is written here, and that is the load-bearing part (#2221).
23
+ // macOS scans a freshly written executable on its FIRST exec, and that scan is
24
+ // a system-daemon latency with no bound under load — measured at 15.0-16.0s
25
+ // per fresh file at load average ~25 on 14 cores, against 1.0s for the same
26
+ // one-second script exec'd a second time, run as `sh <file>`, or run as
27
+ // `sh -c` with no file at all. The stub used to be such a file, exec'd from
28
+ // INSIDE the region each caller's budget bounds. #1099 moved that scan out
29
+ // with a warm-up exec under a 10s timeout, but the scan outgrew the timeout
30
+ // under load, and a first exec killed before it finishes leaves the scan
31
+ // unpaid: the next exec of that file measured 14.5-15.0s again. So the
32
+ // bounded call paid it anyway, and a ~6s transport crossed a 20s budget — the
33
+ // two slow-but-working failures #2221 reports, from a full-suite run.
34
+
35
+ // Seconds the stub sleeps before it serves anything. Module-internal on
36
+ // purpose: no consumer computes a budget from it, so exporting it would only
37
+ // create a second place for the number to be read from.
38
+ const SLOW_DELAY_S = 3;
39
+
40
+ /**
41
+ * The ssh-shaped URL a fixture points `origin` at.
42
+ *
43
+ * `example.invalid` is never resolved: GIT_SSH_COMMAND replaces ssh outright.
44
+ * The URL only has to be ssh-SHAPED, which is what routes git to it at all.
45
+ */
46
+ export const SSH_URL = "ssh://git@example.invalid/x/y.git";
47
+
48
+ /**
49
+ * A GIT_SSH_COMMAND value for an ssh stub that sleeps `SLOW_DELAY_S` before it
50
+ * serves the bare repo at `origin` through `git upload-pack`.
51
+ *
52
+ * `SLOW_DELAY_S` (3s) is the sleep PER INVOCATION, not the cost a bounded
53
+ * caller actually pays: git's ssh transport invokes this stub TWICE for
54
+ * every network command routed through it — once with `-G` to resolve the
55
+ * connection before it opens one, once for the real session — for a fetch
56
+ * and an ls-remote alike (measured, git 2.50.1). So the region a caller's
57
+ * budget bounds really costs ~2 × SLOW_DELAY_S (~6s measured), and that
58
+ * doubled number, not the 3s constant alone, is what each caller's pair is
59
+ * chosen against: one budget above it, one under.
60
+ *
61
+ * A command line rather than a script path, so the only programs it execs are
62
+ * `sh`, `sleep` and `git`, none of them freshly written (see the header). git
63
+ * runs the value through a shell and appends its own arguments — `-G`, the
64
+ * host, the remote command, and whatever `-o` options the caller under test
65
+ * adds — which land after `$0` and are ignored; `$0` is `origin`, single-
66
+ * quote-escaped before interpolation so an origin containing `'` cannot
67
+ * break out of the quoted argument.
68
+ */
69
+ export function slowTransport(origin) {
70
+ const safeOrigin = origin.replace(/'/g, "'\\''");
71
+ return `sh -c 'sleep ${SLOW_DELAY_S}; exec git upload-pack "$0"' '${safeOrigin}'`;
72
+ }