@feigi/fleet-ctl 0.0.0 → 3.16.3

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 (153) hide show
  1. package/agents/{fleet-implementer.agent.md → fleet-implementer-slow-high.agent.md} +23 -2
  2. package/agents/fleet-implementer-slow-medium.agent.md +231 -0
  3. package/agents/fleet-implementer-smol-high.agent.md +231 -0
  4. package/agents/{fleet-implementer-alt.agent.md → fleet-implementer-task-high.agent.md} +23 -2
  5. package/agents/fleet-implementer-task-max.agent.md +231 -0
  6. package/agents/fleet-review-comments.agent.md +4 -2
  7. package/agents/fleet-review-correctness.agent.md +2 -1
  8. package/agents/fleet-review-runner.agent.md +14 -10
  9. package/agents/fleet-review-silent-failure.agent.md +4 -3
  10. package/agents/fleet-review-simplify.agent.md +2 -1
  11. package/agents/fleet-review-snapshot.agent.md +2 -1
  12. package/agents/fleet-review-test-run.agent.md +29 -0
  13. package/agents/fleet-review-tests.agent.md +10 -5
  14. package/agents/fleet-review-types.agent.md +4 -2
  15. package/agents/fleet-review-verifier.agent.md +4 -3
  16. package/commands/review-and-fix.md +7 -6
  17. package/commands/run-merge-bot.md +14 -4
  18. package/package.json +4 -2
  19. package/scripts/agent-test.test.mjs +36 -32
  20. package/scripts/ambient-git-vars-mjs-prose.test.mjs +23 -13
  21. package/scripts/apply-ruleset.test.mjs +4 -3
  22. package/scripts/arg-header-probes-prose.test.mjs +1 -0
  23. package/scripts/arg.test.mjs +18 -18
  24. package/scripts/board-cli.test.mjs +18 -21
  25. package/scripts/board-identity.test.mjs +9 -9
  26. package/scripts/board-liveness-banner.test.mjs +6 -6
  27. package/scripts/board-prev-shape.test.mjs +12 -13
  28. package/scripts/board-tryparse-null.test.mjs +7 -7
  29. package/scripts/board.mjs +4 -7
  30. package/scripts/board.test.mjs +57 -61
  31. package/scripts/candidates.test.mjs +228 -17
  32. package/scripts/ci-completes-premise-prose.test.mjs +1 -1
  33. package/scripts/ci-state-prose.test.mjs +2 -2
  34. package/scripts/ci-state.mjs +389 -187
  35. package/scripts/ci-state.test.mjs +458 -165
  36. package/scripts/citation-sweep-prose.test.mjs +59 -1
  37. package/scripts/claim-lifecycle.test.mjs +2 -1
  38. package/scripts/claim-ticket.test.mjs +35 -34
  39. package/scripts/closing-keyword-prose.test.mjs +1 -1
  40. package/scripts/cockpit-tick-nonblocking.test.mjs +8 -8
  41. package/scripts/compute-board.mjs +13 -3
  42. package/scripts/compute-board.test.mjs +64 -1
  43. package/scripts/compute-spend.mjs +46 -8
  44. package/scripts/compute-spend.test.mjs +64 -10
  45. package/scripts/cross-repo-citation-prose.test.mjs +18 -19
  46. package/scripts/delete-merged-branch.sh +218 -0
  47. package/scripts/delete-merged-branch.test.mjs +576 -0
  48. package/scripts/derive-testcmd.sh +18 -7
  49. package/scripts/derive-testcmd.test.mjs +9 -8
  50. package/scripts/diff-stats.mjs +2 -2
  51. package/scripts/diff-stats.test.mjs +7 -11
  52. package/scripts/dispatch-block-golden-prose.test.mjs +111 -6
  53. package/scripts/dispatch-block-pins-prose.test.mjs +5 -5
  54. package/scripts/dispositions-check.mjs +507 -0
  55. package/scripts/dispositions-check.test.mjs +843 -0
  56. package/scripts/dispositions-gate-prose.test.mjs +114 -0
  57. package/scripts/drop-merged-label.test.mjs +3 -4
  58. package/scripts/exec-stub.mjs +93 -0
  59. package/scripts/exec-stub.test.mjs +69 -0
  60. package/scripts/filing-bar-seat-prose.test.mjs +1 -1
  61. package/scripts/finisher-test-verdict-prose.test.mjs +102 -0
  62. package/scripts/fix-applier-correction-rules-prose.test.mjs +11 -10
  63. package/scripts/fleet-bootstrap +5 -20
  64. package/scripts/fleet-bootstrap.test.mjs +75 -0
  65. package/scripts/fleet-heartbeat.mjs +2 -2
  66. package/scripts/fleet-provenance +15 -24
  67. package/scripts/fleet-provenance.test.mjs +86 -12
  68. package/scripts/fleet-run.test.mjs +5 -5
  69. package/scripts/fleet-state.mjs +33 -11
  70. package/scripts/fleet-state.test.mjs +90 -3
  71. package/scripts/fleet-tick.mjs +346 -70
  72. package/scripts/fleet-tick.test.mjs +566 -16
  73. package/scripts/force-with-lease-reason-prose.test.mjs +1 -1
  74. package/scripts/frontmatter-check.mjs +3 -2
  75. package/scripts/frontmatter-check.test.mjs +6 -6
  76. package/scripts/immutable-body-claim-prose.test.mjs +53 -262
  77. package/scripts/implementer-model-tier.test.mjs +98 -506
  78. package/scripts/inflight.test.mjs +18 -127
  79. package/scripts/is-cli.mjs +26 -0
  80. package/scripts/is-cli.test.mjs +99 -0
  81. package/scripts/json.test.mjs +3 -3
  82. package/scripts/ledger-dispatch.test.mjs +368 -7
  83. package/scripts/ledger-grammar.mjs +85 -1
  84. package/scripts/ledger-grammar.test.mjs +86 -1
  85. package/scripts/ledger-read-require-file.test.mjs +7 -7
  86. package/scripts/ledger-rotate.test.mjs +142 -0
  87. package/scripts/ledger.mjs +181 -17
  88. package/scripts/ledger.test.mjs +12 -130
  89. package/scripts/main-checkout.mjs +312 -0
  90. package/scripts/main-checkout.test.mjs +332 -0
  91. package/scripts/member-outcomes-header.test.mjs +3 -3
  92. package/scripts/member-outcomes.mjs +4 -5
  93. package/scripts/member-outcomes.test.mjs +92 -18
  94. package/scripts/member-prompt-prose.test.mjs +17 -13
  95. package/scripts/member-record.mjs +8 -3
  96. package/scripts/member-record.test.mjs +5 -5
  97. package/scripts/member-write-guard.mjs +5 -5
  98. package/scripts/member-write-guard.test.mjs +6 -3
  99. package/scripts/no-undo-audit.sh +24 -21
  100. package/scripts/no-undo-audit.test.mjs +9 -13
  101. package/scripts/pointer-target-prose.test.mjs +1 -1
  102. package/scripts/pr-overlap.test.mjs +6 -9
  103. package/scripts/prompt-renderer.mjs +10 -9
  104. package/scripts/prose-pin.mjs +10 -11
  105. package/scripts/prove-merge.test.mjs +3 -3
  106. package/scripts/quiet-payload-prose.test.mjs +1 -1
  107. package/scripts/reap.test.mjs +3 -4
  108. package/scripts/release-label-split-prose.test.mjs +17 -2
  109. package/scripts/release-ticket.test.mjs +35 -44
  110. package/scripts/review-core-cwd-isolation.test.mjs +7 -6
  111. package/scripts/review-core-reads.test.mjs +1 -1
  112. package/scripts/review-core-scratch-refusal.test.mjs +64 -0
  113. package/scripts/review-core-shared-test-run.test.mjs +238 -0
  114. package/scripts/review-core-snapshot-path.test.mjs +59 -12
  115. package/scripts/review-core-specialist-scratch.test.mjs +12 -10
  116. package/scripts/review-core-testcmd.test.mjs +76 -45
  117. package/scripts/review-core-unrun.test.mjs +154 -168
  118. package/scripts/review-core.mjs +250 -56
  119. package/scripts/review-eval.mjs +11 -4
  120. package/scripts/review-host-fixture.mjs +12 -3
  121. package/scripts/review-in-run-retry.test.mjs +27 -3
  122. package/scripts/review-runner-spawns.test.mjs +5 -3
  123. package/scripts/review-runner.test.mjs +14 -3
  124. package/scripts/review-tier-audit.test.mjs +1 -1
  125. package/scripts/run-merge-bot-prose.test.mjs +29 -6
  126. package/scripts/scratch-partition-invariant-prose.test.mjs +1 -1
  127. package/scripts/section-between-guard-prose.test.mjs +4 -3
  128. package/scripts/select-dimensions.test.mjs +1 -1
  129. package/scripts/shell-traps-prose.test.mjs +6 -9
  130. package/scripts/shortlist.mjs +4 -1
  131. package/scripts/shortlist.test.mjs +30 -16
  132. package/scripts/snapshot-repo.test.mjs +177 -4
  133. package/scripts/stash-prohibition-prose.test.mjs +1 -1
  134. package/scripts/temp-dir.mjs +47 -0
  135. package/scripts/tier-check.mjs +95 -28
  136. package/scripts/tier-check.test.mjs +131 -29
  137. package/scripts/tier-outcomes-header.test.mjs +11 -54
  138. package/scripts/tier-outcomes.mjs +34 -12
  139. package/scripts/tier-outcomes.test.mjs +157 -4
  140. package/scripts/tier-roles.mjs +118 -29
  141. package/scripts/tier-roles.test.mjs +226 -61
  142. package/scripts/tracker-block-copy-prose.test.mjs +3 -3
  143. package/scripts/verify-sha.test.mjs +4 -5
  144. package/scripts/watcher-degraded-block.test.mjs +5 -8
  145. package/scripts/within-run-pair-prose.test.mjs +43 -75
  146. package/scripts/worktree-audit.test.mjs +2 -1
  147. package/skills/next-ticket/SKILL.md +2 -2
  148. package/skills/run-team/SKILL.md +433 -303
  149. package/skills/run-team/references/ci-and-staleness.md +7 -6
  150. package/skills/run-team/references/correction-tickets.md +3 -3
  151. package/skills/run-team/references/isolation.md +1 -1
  152. package/skills/sizing-a-ticket/SKILL.md +8 -8
  153. package/scripts/tier-guard-gate-prose.test.mjs +0 -216
@@ -16,8 +16,9 @@ const state = (over = {}) => ({
16
16
  implCap: 2, reviewerCap: 6, maxReviews: 6,
17
17
  implLive: 0, draining: null, tierMismatch: [], tierUnchecked: [], implNames: [],
18
18
  heads: [], supply: 0, shortlistStatus: "ok", refresh: null,
19
- reviewsLive: 0, fixLive: 0, fixDue: [], reviewDue: [],
19
+ reviewsLive: 0, fixLive: 0, fixDue: [], reviewDue: [], unlabelled: [],
20
20
  mergeBotLive: 0, mergeQueue: 0, mergeHeld: 0, mergeConflictHeld: 0,
21
+ mainCheckout: { state: "clean" },
21
22
  ...over,
22
23
  });
23
24
  const rowsOf = (s, role) => reconcile(s).filter((r) => r.role === role);
@@ -203,6 +204,30 @@ test("reviewers: work owed with every slot full is AT CAP", () => {
203
204
  assert.equal(row(state({ fixLive: 6, fixDue: [1], reviewDue: [2] }), "reviewers").action, "AT CAP");
204
205
  });
205
206
 
207
+ // #2331: a finisher that settled `labelled` on a PR still lacking
208
+ // `ready-to-merge` is repaired by one fresh finisher, and escalated past that.
209
+ // Finishers are uncapped, so neither row ever waits on a reviewer slot.
210
+ test("reviewers: one labelled finisher on an unlabelled PR dispatches a finisher, uncapped and actionable", () => {
211
+ const unlabelled = [{ pr: 40, labelled: ["finisher-pr-40"] }, { pr: 44, labelled: ["finisher-pr-44-b"] }];
212
+ const rs = rowsOf(state({ unlabelled }), "reviewers");
213
+ assert.deepEqual(rs.map((r) => r.action), ["DISPATCH finisher PR#40 PR#44"], "IDLE OK never prints beside it");
214
+ assert.equal(rs[0].acts, true);
215
+ assert.match(rs[0].detail, /finisher-pr-40, finisher-pr-44-b settled labelled; no ready-to-merge/);
216
+ const full = rowsOf(state({ fixLive: 6, fixDue: [1], unlabelled }), "reviewers");
217
+ assert.deepEqual(full.map((r) => r.action), ["AT CAP", "DISPATCH finisher PR#40 PR#44"], "a full reviewer side holds no finisher");
218
+ });
219
+
220
+ test("reviewers: a second labelled finisher in one stretch escalates instead — never actionable, never a dispatch", () => {
221
+ const rs = rowsOf(state({ unlabelled: [{ pr: 40, labelled: ["finisher-pr-40", "finisher-pr-40-b"] }] }), "reviewers");
222
+ assert.deepEqual(rs.map((r) => r.action), ["ESCALATE unlabelled PR#40"]);
223
+ assert.equal(rs[0].acts, false);
224
+ assert.match(rs[0].detail, /finisher-pr-40, finisher-pr-40-b settled labelled/);
225
+ const both = rowsOf(state({ fixDue: [7], unlabelled: [
226
+ { pr: 40, labelled: ["finisher-pr-40", "finisher-pr-40-b"] }, { pr: 41, labelled: ["finisher-pr-41"] },
227
+ ] }), "reviewers");
228
+ assert.deepEqual(both.map((r) => r.action), ["DISPATCH fix-pr PR#7", "DISPATCH finisher PR#41", "ESCALATE unlabelled PR#40"]);
229
+ });
230
+
206
231
  // ---------------------------------------------------------------------------
207
232
  // The merge-bot row.
208
233
 
@@ -280,6 +305,55 @@ test("actionable: exactly the rows that name work the controller can do unattend
280
305
  assert.equal(acts({ draining: "x", heads: [1] }), false, "HOLD (draining)");
281
306
  });
282
307
 
308
+ // ---------------------------------------------------------------------------
309
+ // The main-checkout hold (#2210): anything but `clean` holds every
310
+ // dispatching row.
311
+
312
+ const BUSY = {
313
+ heads: [412], fixDue: [346], reviewDue: [350], mergeQueue: 1,
314
+ refresh: { ok: true, entries: 3, lifted: 0, changed: true, trigger: "unclaimed 1 < cap 2" },
315
+ };
316
+ const summary = (s) => reconcile(s).map((r) => [r.role, r.action, r.acts]);
317
+
318
+ test("main checkout: dirty holds every dispatching row once per role, never actionable; the shortlist row still reports", () => {
319
+ const hold = "HOLD (main checkout dirty)";
320
+ assert.deepEqual(summary(state({ ...BUSY, mainCheckout: { state: "dirty", changed: ["x"] } })), [
321
+ ["implementers", hold, false],
322
+ ["reviewers", hold, false],
323
+ ["merge-bot", hold, false],
324
+ ["shortlist", "REFRESHED shortlist: 3 entries; 0 lifted", true],
325
+ ]);
326
+ const [impl] = reconcile(state({ ...BUSY, implLive: 1, mainCheckout: { state: "dirty", changed: ["x"] } }));
327
+ assert.equal(`${impl.actual}/${impl.target}`, "1/2", "the held row lost its counts");
328
+ });
329
+
330
+ test("main checkout: unknown holds too, never clean; so does a check that gave no answer at all", () => {
331
+ for (const mainCheckout of [{ state: "unknown", cause: "read", why: "boom" }, { state: "unknown", cause: "baseline", why: "x" }, undefined]) {
332
+ assert.deepEqual(summary(state({ ...BUSY, refresh: null, mainCheckout })), [
333
+ ["implementers", "HOLD (main checkout unknown)", false],
334
+ ["reviewers", "HOLD (main checkout unknown)", false],
335
+ ["merge-bot", "HOLD (main checkout unknown)", false],
336
+ ], JSON.stringify(mainCheckout));
337
+ }
338
+ });
339
+
340
+ test("main checkout: no baseline holds every dispatching row and asks the controller to record one", () => {
341
+ const rows = reconcile(state({ ...BUSY, refresh: null, mainCheckout: { state: "absent", baseline: "/x" } }));
342
+ assert.deepEqual(rows.map((r) => r.action), Array(3).fill("HOLD (main checkout no baseline)"));
343
+ assert.equal(actionable(rows), true);
344
+ });
345
+
346
+ test("main checkout: the hold outranks every role's own guards — drain and tier holds included", () => {
347
+ const s = state({ ...BUSY, refresh: null, draining: "x", tierMismatch: ["impl-1"], mainCheckout: { state: "dirty", changed: ["x"] } });
348
+ assert.equal(row(s, "implementers").action, "HOLD (main checkout dirty)");
349
+ assert.equal(actionable(reconcile(s)), false, "a tier mismatch under a dirty checkout still asks the controller to dispatch");
350
+ });
351
+
352
+ test("main checkout: clean holds nothing", () => {
353
+ assert.deepEqual(summary(state({ ...BUSY, refresh: null })).map(([, action]) => action),
354
+ ["PULL #412", "DISPATCH fix-pr PR#346", "DISPATCH review PR#350", "DISPATCH merge-bot"]);
355
+ });
356
+
283
357
  // ---------------------------------------------------------------------------
284
358
  // Reading the run: deriveRun() over `ledger.mjs read`'s payload and the open
285
359
  // PR list. Rows are spelled the way ledger.mjs dispatch/settle write them.
@@ -332,6 +406,19 @@ test("deriveRun: live reviewer units are in-flight reviews plus unsettled fix-ap
332
406
  assert.equal(r.fixLive, 1);
333
407
  });
334
408
 
409
+ test("deriveRun: live names every unsettled member and each in-flight review by its PR — a review=wf: run has no member token of its own", () => {
410
+ const r = run({
411
+ rows: [
412
+ "#10 impl-10=PR#20 → PR#20 · review=wf:run1",
413
+ "#11 impl-11=PR#21 → PR#21 · review=wf:run2 reviewed=abc1234:2/1/0 · fix-pr-21",
414
+ "#13 impl-13=PR#23 → PR#23 · review=wf:run3=failed",
415
+ "#15 impl-15",
416
+ ],
417
+ dispatched: ["fix-pr-21"],
418
+ }, [pr(20), pr(21), pr(23)]);
419
+ assert.deepEqual(r.live, ["fix-pr-21", "impl-15", "review:PR#20"], "run2 returned and run3 is dead, so neither is live");
420
+ });
421
+
335
422
  test("deriveRun: fix-pr is due on a returned review with survivors and no fix-applier since", () => {
336
423
  const r = run({
337
424
  rows: [
@@ -426,6 +513,110 @@ test("deriveRun: a past-pin halt is answered once the head is the reviewed one,
426
513
  assert.deepEqual(run({ rows: [halted] }, [pr(40, ["ready-to-merge"], [10], HEAD_B), pr(41, [], [], HEAD_B)]).reviewDue, []);
427
514
  });
428
515
 
516
+ test("deriveRun: a ticket row settled =PR#M shares PR M's state with M's own row, in either order (#2283)", () => {
517
+ // ledger.mjs's `settle impl-658-c=PR#724` names PR 724 on the ticket row, and
518
+ // a `#724` row can carry that PR's tokens beside it. Both rows are PR 724's:
519
+ // whichever sorts first must not swallow what the other records.
520
+ const prs = [pr(724, [], [658])];
521
+ const ticket = "#658 impl-658-c=PR#724";
522
+ for (const rows of [[ticket, "#724 review=member:review-pr-724"], ["#724 review=member:review-pr-724", ticket]]) {
523
+ const r = run({ rows }, prs);
524
+ assert.equal(r.reviewsLive, 1, `the live review is counted: ${rows}`);
525
+ assert.deepEqual(r.reviewDue, [], `a reviewed PR is not re-offered: ${rows}`);
526
+ }
527
+ for (const rows of [[ticket, "#724 review=member:review-pr-724 reviewed=abc1234:2/1/0"], ["#724 review=member:review-pr-724 reviewed=abc1234:2/1/0", ticket]]) {
528
+ const r = run({ rows }, prs);
529
+ assert.deepEqual([r.reviewsLive, r.fixDue, r.reviewDue], [0, [724], []], `${rows}`);
530
+ assert.ok(r.claimed.has(658), "the ticket row still reads as claimed");
531
+ }
532
+ });
533
+
534
+ // #2331: a finisher can settle `labelled` without ever adding the label. The
535
+ // open-PR list the tick already reads says so; a `label-off=<attempt>` token
536
+ // marks the controller's own deliberate removals, so they never read as a miss.
537
+ const LABELLED = "#10 impl-10=PR#40 → PR#40 · review=wf:a reviewed=abc1234:0/0/0 · finisher-pr-40=labelled";
538
+
539
+ test("deriveRun: a labelled finisher on a PR without ready-to-merge is unlabelled, and the tick dispatches a finisher", () => {
540
+ const r = run({ rows: [LABELLED], dispatched: ["finisher-pr-40=labelled"] }, [pr(40, ["minor"], [10])]);
541
+ assert.deepEqual(r.unlabelled, [{ pr: 40, labelled: ["finisher-pr-40"] }]);
542
+ const rows = reconcile({ ...state(), ...r }).filter((x) => x.role === "reviewers");
543
+ assert.deepEqual(rows.map((x) => x.action), ["DISPATCH finisher PR#40"]);
544
+ // Settled in `## Dispatched` alone, a bare row copy beside it: settled anywhere is settled.
545
+ assert.deepEqual(run({ rows: ["#10 impl-10=PR#40 → PR#40 · finisher-pr-40"], dispatched: ["finisher-pr-40=labelled"] },
546
+ [pr(40, ["minor"], [10])]).unlabelled, [{ pr: 40, labelled: ["finisher-pr-40"] }]);
547
+ });
548
+
549
+ test("deriveRun: a labelled finisher whose PR carries ready-to-merge is nothing — labelled settles exactly as before", () => {
550
+ const r = run({ rows: [LABELLED], dispatched: ["finisher-pr-40=labelled"] }, [pr(40, ["minor", "ready-to-merge"], [10])]);
551
+ assert.deepEqual(r.unlabelled, []);
552
+ assert.deepEqual(reconcile({ ...state(), ...r }).filter((x) => x.role === "reviewers").map((x) => x.action), ["IDLE OK"]);
553
+ });
554
+
555
+ test("deriveRun: only a settled-labelled LATEST attempt is a miss — live, halted, failed and closed PRs are not", () => {
556
+ const base = "#10 impl-10=PR#40 → PR#40";
557
+ const open = [pr(40, ["minor"], [10])];
558
+ for (const row of [
559
+ `${base} · finisher-pr-40`, // live, not yet reported
560
+ `${base} · finisher-pr-40=labelled · finisher-pr-40-b`, // the repair is live
561
+ `${base} · finisher-pr-40-b · finisher-pr-40=labelled`, // the same, by suffix not position
562
+ `${base} · finisher-pr-40=halted:rebase`, // a halt refused to label, and says so
563
+ `${base} · finisher-pr-40=labelled · finisher-pr-40-b=halted:past-pin`,
564
+ `${base} · finisher-pr-40=failed`, // #2359's, not this check's
565
+ `${base} · fix-pr-40=applied:def5678`, // no finisher at all
566
+ ]) {
567
+ assert.deepEqual(run({ rows: [row] }, open).unlabelled, [], row);
568
+ }
569
+ assert.deepEqual(run({ rows: [LABELLED] }, []).unlabelled, [], "a PR off the open list is nobody's work");
570
+ });
571
+
572
+ test("deriveRun: a label-off'd attempt is the controller's own removal — nothing until a later attempt labels again", () => {
573
+ const open = [pr(40, ["minor"], [10])];
574
+ for (const row of [
575
+ `${LABELLED} label-off=finisher-pr-40`,
576
+ "#10 label-off=finisher-pr-40 impl-10=PR#40 → PR#40 · finisher-pr-40=labelled", // before the attempt it names
577
+ `${LABELLED} · finisher-pr-40-b=labelled label-off=finisher-pr-40-b`,
578
+ `${LABELLED} · label-off=finisher-pr-40-b · finisher-pr-40-b=labelled`, // suffix order, never position
579
+ ]) {
580
+ assert.deepEqual(run({ rows: [row] }, open).unlabelled, [], row);
581
+ }
582
+ // A label-off resets the stretch: the attempt after it is the stretch's first.
583
+ assert.deepEqual(run({ rows: [`${LABELLED} label-off=finisher-pr-40 · finisher-pr-40-b=labelled`] }, open).unlabelled,
584
+ [{ pr: 40, labelled: ["finisher-pr-40-b"] }]);
585
+ // A label-off for another PR's attempt leaves this one's miss standing, wherever it sits.
586
+ assert.deepEqual(run({ rows: [`${LABELLED} label-off=finisher-pr-41`] }, open).unlabelled,
587
+ [{ pr: 40, labelled: ["finisher-pr-40"] }]);
588
+ // Two label-offs for one PR: the HIGHEST attempt named starts the stretch,
589
+ // whichever token comes first on the row.
590
+ const three = `${LABELLED} · finisher-pr-40-b=labelled · finisher-pr-40-c=labelled`;
591
+ for (const offs of ["label-off=finisher-pr-40-b label-off=finisher-pr-40", "label-off=finisher-pr-40 label-off=finisher-pr-40-b"]) {
592
+ assert.deepEqual(run({ rows: [`${three} ${offs}`] }, open).unlabelled, [{ pr: 40, labelled: ["finisher-pr-40-c"] }], offs);
593
+ }
594
+ });
595
+
596
+ test("deriveRun: two labelled attempts in one stretch escalate rather than dispatch a third", () => {
597
+ const open = [pr(40, ["minor"], [10])];
598
+ const r = run({ rows: [`${LABELLED} · finisher-pr-40-b=labelled`] }, open);
599
+ assert.deepEqual(r.unlabelled, [{ pr: 40, labelled: ["finisher-pr-40", "finisher-pr-40-b"] }]);
600
+ assert.deepEqual(reconcile({ ...state(), ...r }).filter((x) => x.role === "reviewers").map((x) => x.action),
601
+ ["ESCALATE unlabelled PR#40"]);
602
+ // A halt between the two still leaves both labelled ones in the stretch.
603
+ assert.deepEqual(run({ rows: [`${LABELLED} · finisher-pr-40-b=halted:live-editor · finisher-pr-40-c=labelled`] }, open).unlabelled,
604
+ [{ pr: 40, labelled: ["finisher-pr-40", "finisher-pr-40-c"] }]);
605
+ });
606
+
607
+ test("deriveRun: a finisher token on another PR's row is a stray — it neither makes nor masks a miss", () => {
608
+ const prs = [pr(40, ["minor"], [10]), pr(41, ["minor"], [11])];
609
+ const r = run({ rows: ["#10 impl-10=PR#40 → PR#40", "#11 impl-11=PR#41 → PR#41 · finisher-pr-40=labelled"] }, prs);
610
+ assert.deepEqual(r.unlabelled, []);
611
+ const masked = run({ rows: [LABELLED, "#11 impl-11=PR#41 → PR#41 · finisher-pr-40-b"] }, prs);
612
+ assert.deepEqual(masked.unlabelled, [{ pr: 40, labelled: ["finisher-pr-40"] }]);
613
+ });
614
+
615
+ test("deriveRun: a label-off naming no finisher-pr member refuses the ledger, naming the token", () => {
616
+ for (const tok of ["label-off=impl-10", "label-off=", "label-off=finisher-pr-40=labelled", "label-off=merge-bot-1"]) {
617
+ assert.throws(() => run({ rows: [`${LABELLED} ${tok}`] }, [pr(40, [], [10])]), (e) => e.message.includes(`'${tok}'`), tok);
618
+ }
619
+ });
429
620
  test("deriveRun: merge holds are held-behind rows whose premise PR is still open", () => {
430
621
  const r = run({
431
622
  rows: [
@@ -454,7 +645,7 @@ test("deriveRun: a conflict hold is fix-due until a fix-applier after it lands,
454
645
  HOLD_ROW(44, "conflict-hold:#44 · fix-pr-44=applied:def5678 · conflict-hold:#44"),
455
646
  // A fix-applier that died leaves the conflict where it was.
456
647
  HOLD_ROW(45, "conflict-hold:#45 · fix-pr-45=failed"),
457
- // A review after the cleared hold resets fixSince; the hold stays cleared.
648
+ // A review after the cleared hold leaves the hold cleared.
458
649
  HOLD_ROW(46, "conflict-hold:#46 · fix-pr-46=applied:def5678 · review=wf:x reviewed=def5678:0/1/0"),
459
650
  // A closed PR is nobody's work.
460
651
  HOLD_ROW(47, "conflict-hold:#47"),
@@ -492,12 +683,176 @@ test("deriveRun: a fix-applier settled in ## Dispatched clears a conflict hold e
492
683
  "the member settled in ## Dispatched, not the row's own stale bare copy");
493
684
  });
494
685
 
495
- test("deriveRun: a redundant re-hold on an already-unresolved conflict does not reset a live fix-applier's fixSince", () => {
686
+ test("deriveRun: a redundant re-hold on an already-unresolved conflict does not re-offer the PR to a second fix-applier while the first is live", () => {
496
687
  const r = run({ rows: [HOLD_ROW(40, "conflict-hold:#40 · fix-pr-40 · conflict-hold:#40")] }, [pr(40, ["ready-to-merge"])]);
497
688
  assert.deepEqual(r.fixDue, [], "a live fix-applier working the first hold is not re-offered by a duplicate hold token");
498
689
  assert.deepEqual([r.mergeHeld, r.mergeConflictHeld], [1, 1], "still held — the duplicate hold changes nothing about the merge gate");
499
690
  });
500
691
 
692
+ // #2328: a fix-applier dispatched on an unresolved hold is the conflict one —
693
+ // it rebases and never reads the review file — so its landing clears the hold
694
+ // and leaves a returned review's survivors exactly as unanswered as they were.
695
+ test("deriveRun: a landed conflict fix-applier clears the hold but not the survivors — a review fix-applier follows", () => {
696
+ const R = (tail) => `#20 impl-20=PR#21 → PR#21 · reviewed=abc1234:2/0/0 · ${tail}`;
697
+ const at = (tail, dispatched = []) => run({ rows: [R(tail)], dispatched }, [pr(21, ["ready-to-merge"])]);
698
+ const held = at("conflict-hold:#21");
699
+ assert.deepEqual([held.fixDue, held.conflictHeld], [[21], [21]]);
700
+ const working = at("conflict-hold:#21 · fix-pr-21");
701
+ assert.deepEqual([working.fixDue, working.conflictHeld], [[], [21]], "the live conflict fix-applier is not joined by a review one");
702
+ const landed = at("conflict-hold:#21 · fix-pr-21=applied:def5678");
703
+ assert.deepEqual([landed.fixDue, landed.conflictHeld, landed.mergeHeld], [[21], [], 0], "the survivors are re-offered, the hold is gone");
704
+ // The hold read before the review is the same conflict fix-applier.
705
+ assert.deepEqual(run({ rows: ["#20 impl-20=PR#21 → PR#21 · conflict-hold:#21 · reviewed=abc1234:2/0/0 · fix-pr-21=no-op"] }, [pr(21)]).fixDue, [21]);
706
+ // The review fix-applier that follows answers them.
707
+ assert.deepEqual(at("conflict-hold:#21 · fix-pr-21=applied:def5678 · fix-pr-21-b=applied:0123abc").fixDue, []);
708
+ assert.deepEqual(at("conflict-hold:#21 · fix-pr-21=applied:def5678 · fix-pr-21-b").fixDue, [], "…and is not re-offered while live");
709
+ assert.deepEqual(at("conflict-hold:#21 · fix-pr-21=applied:def5678 · fix-pr-21-b=failed").fixDue, [21], "a dead one leaves them due");
710
+ });
711
+
712
+ test("deriveRun: survivors a review fix-applier already answered stay answered through a later hold and its fix", () => {
713
+ const R = (tail) => `#20 impl-20=PR#21 → PR#21 · reviewed=abc1234:2/0/0 · fix-pr-21=applied:def5678 · ${tail}`;
714
+ const held = run({ rows: [R("conflict-hold:#21")] }, [pr(21)]);
715
+ assert.deepEqual([held.fixDue, held.conflictHeld], [[21], [21]], "the hold is due on its own");
716
+ const cleared = run({ rows: [R("conflict-hold:#21 · fix-pr-21-b=applied:0123abc")] }, [pr(21)]);
717
+ assert.deepEqual([cleared.fixDue, cleared.conflictHeld], [[], []], "nothing left: the survivors were answered before the hold");
718
+ // A live review fix-applier when the hold lands is not joined by a conflict one.
719
+ const live = run({ rows: ["#20 impl-20=PR#21 → PR#21 · reviewed=abc1234:2/0/0 · fix-pr-21 · conflict-hold:#21"] }, [pr(21)]);
720
+ assert.deepEqual([live.fixDue, live.conflictHeld], [[], [21]]);
721
+ });
722
+
723
+ test("deriveRun: a newer review's survivors are not offered beside a live fix-applier, and are due once it settles", () => {
724
+ // `dispatch` would refuse a second live one. Settled, it was dispatched
725
+ // before that review, so it never answered the newer survivors.
726
+ const rereviewed = (fix) => run({ rows: [`#20 impl-20=PR#21 → PR#21 · reviewed=abc1234:2/0/0 · ${fix} · review=wf:x reviewed=def5678:1/0/0`] }, [pr(21)]).fixDue;
727
+ assert.deepEqual(rereviewed("fix-pr-21"), []);
728
+ assert.deepEqual(rereviewed("fix-pr-21=applied:def5678"), [21]);
729
+ assert.deepEqual(rereviewed("fix-pr-21=failed"), [21]);
730
+ });
731
+
732
+ // One fix-applier does one job, so its landing folds once per PR however many
733
+ // copies of its token the rows carry — a whole-line `row` rewrite leaves bare
734
+ // copies wherever it chose, and the in-place settled copy is the one that says
735
+ // where it was dispatched.
736
+ test("deriveRun: duplicate copies of one fix-applier's token land it once — a conflict fix-applier never also answers the survivors", () => {
737
+ const R = "#20 impl-20=PR#21 → PR#21 · reviewed=abc1234:2/0/0";
738
+ const F = "fix-pr-21=applied:def5678";
739
+ const D = [F];
740
+ const due = (rows, dispatched = []) => {
741
+ const r = run({ rows, dispatched }, [pr(21)]);
742
+ return [r.fixDue, r.conflictHeld];
743
+ };
744
+ // A bare copy on the PR's own row, after the hold-clearing settled one.
745
+ assert.deepEqual(due([`${R} · conflict-hold:#21 · ${F}`, "#21 fix-pr-21"]), [[21], []]);
746
+ assert.deepEqual(due([`${R} · conflict-hold:#21 · ${F}`, "#21 fix-pr-21"], D), [[21], []]);
747
+ // The settled copy twice on one row.
748
+ assert.deepEqual(due([`${R} · conflict-hold:#21 · ${F} · ${F}`]), [[21], []]);
749
+ // A stale bare copy BEFORE the hold, the in-place settled one after it:
750
+ // the settled one cleared the hold, whatever `## Dispatched` says.
751
+ assert.deepEqual(due([`${R} · fix-pr-21 · conflict-hold:#21`, `#21 ${F}`]), [[21], []]);
752
+ assert.deepEqual(due([`${R} · fix-pr-21 · conflict-hold:#21`, `#21 ${F}`], D), [[21], []]);
753
+ // A review fix-applier that landed before a hold: a stale bare copy of it
754
+ // after the hold does not clear that hold.
755
+ assert.deepEqual(due([`${R} · ${F} · conflict-hold:#21 · fix-pr-21`], D), [[21], [21]]);
756
+ // Liveness is read off the member once every row is read: a bare copy on an
757
+ // earlier row of one a later row settled `failed` is dead, not live.
758
+ assert.deepEqual(due([`${R} · fix-pr-21`, "#21 fix-pr-21=failed"]), [[21], []]);
759
+ // Must accept: a DIFFERENT member after the conflict one still answers them.
760
+ assert.deepEqual(due([`${R} · conflict-hold:#21 · ${F} · fix-pr-21-b=no-op`, "#21 fix-pr-21"]), [[], []]);
761
+ });
762
+
763
+ // #2329: a fix-applier answers the PR its token names, like the finisher-pr
764
+ // rule beside it. `dispatch`/`settle` only ever put `fix-pr-<M>` on PR #M's
765
+ // row, so a foreign one there is a hand-written stray — it must read as if
766
+ // absent, never clear that PR's hold, answer its survivors or hold it off.
767
+ test("deriveRun: a fix-pr token for another PR leaves this PR's hold and survivors exactly as if it were absent", () => {
768
+ const H = "#20 impl-20=PR#21 · conflict-hold:#21";
769
+ const due = (rows, dispatched = [], prs = [pr(21)]) => {
770
+ const r = run({ rows, dispatched }, prs);
771
+ return [r.fixDue, r.conflictHeld];
772
+ };
773
+ assert.deepEqual(due([H]), [[21], [21]], "control: the hold stands and is due");
774
+ assert.deepEqual(due([`${H} · fix-pr-99=applied:def5678`]), [[21], [21]], "a foreign landed fix-applier does not clear the hold");
775
+ assert.deepEqual(due([`${H} · fix-pr-99-b=no-op`]), [[21], [21]], "…a retry-suffixed one neither");
776
+ assert.deepEqual(due([`${H} · fix-pr-99`]), [[21], [21]], "a foreign live fix-applier does not hold off this PR's own");
777
+ // The real fix-pr-99 settled elsewhere: a stray bare copy on #21's row
778
+ // inherits nothing from it.
779
+ assert.deepEqual(due([`${H} · fix-pr-99`], ["fix-pr-99=applied:def5678"]), [[21], [21]]);
780
+ assert.deepEqual(due([`${H} · fix-pr-99`, "#98 impl-98=PR#99 · fix-pr-99=applied:def5678"], [], [pr(21), pr(99)]), [[21], [21]]);
781
+ // Nor does a settled stray on #21's row stand in for PR #99's own in-place
782
+ // copy: #99's bare token, the only one on #99's row, still lands its member.
783
+ assert.deepEqual(
784
+ due(["#20 impl-20=PR#21 · fix-pr-99=applied:def5678", "#98 impl-98=PR#99 · conflict-hold:#99 · fix-pr-99"],
785
+ ["fix-pr-99=applied:def5678"], [pr(21), pr(99)]),
786
+ [[], []], "a foreign settled copy does not keep the owner's bare copy from landing");
787
+ // …and lends it no outcome: a settled stray of fix-pr-21 on #99's row, read
788
+ // before #21's own row, does not land #21's bare copy and clear its hold.
789
+ assert.deepEqual(run({ rows: ["#98 impl-98=PR#99 · fix-pr-21=applied:abc1234", `${H} · fix-pr-21`] }, [pr(21), pr(99)]).conflictHeld,
790
+ [21], "a foreign settled copy does not clear the owner's hold");
791
+ // A row naming no PR at all (no `#<n>` key, no `PR#`) is no PR's row, so a
792
+ // settled copy there is a stray as well: the owner's bare copy still lands.
793
+ assert.deepEqual(due(["notes fix-pr-21=applied:def5678", `${H} · fix-pr-21`], ["fix-pr-21=applied:def5678"]),
794
+ [[], []], "a settled copy on a PR-less row does not keep the owner's bare copy from landing");
795
+ // A row's PR is its `PR#` mention even where its key names the token's
796
+ // number: `fix-pr-21` on `#21 …=PR#22` is a stray on PR #22's row, neither
797
+ // clearing #22's hold nor standing in for PR #21's own copies.
798
+ const K = "#21 impl-21=PR#22 · conflict-hold:#22";
799
+ assert.deepEqual(due([`${K} · fix-pr-21=applied:def5678`], [], [pr(22)]), [[22], [22]], "the key does not make it #22's own");
800
+ assert.deepEqual(due([`${K} · fix-pr-21=applied:def5678`, `${H} · fix-pr-21`], ["fix-pr-21=applied:def5678"], [pr(21), pr(22)]),
801
+ [[22], [22]], "…nor keep PR #21's bare copy from landing");
802
+ // Nor does a foreign one answer a returned review's survivors.
803
+ assert.deepEqual(due(["#20 impl-20=PR#21 · reviewed=abc1234:2/0/0 · fix-pr-99=applied:def5678"]), [[21], []]);
804
+ // Must accept: the PR's own fix-applier, live and landed.
805
+ assert.deepEqual(due([`${H} · fix-pr-21`]), [[], [21]], "own live: not re-offered, still held");
806
+ assert.deepEqual(due([`${H} · fix-pr-21=applied:def5678`]), [[], []], "own landed: the hold is cleared");
807
+ // …and on the PR's own `#21` row, which names no `PR#` — its key is its PR.
808
+ assert.deepEqual(due([H, "#21 fix-pr-21=applied:def5678"]), [[], []]);
809
+ // An in-place settled copy on the ticket row, whose key is the ticket's and
810
+ // whose PR is its `PR#` mention, is the PR's own: it still says where its
811
+ // member landed, so a stale bare copy read first does not land it instead.
812
+ assert.deepEqual(
813
+ due(["#21 fix-pr-21", "#20 impl-20=PR#21 · reviewed=abc1234:2/0/0 · conflict-hold:#21 · fix-pr-21=applied:def5678"],
814
+ ["fix-pr-21=applied:def5678"]),
815
+ [[21], []], "own in-place copy on the ticket row: it cleared the hold and answered no survivor");
816
+ });
817
+
818
+ // #2391: the other direction of #2329 — a settled stray reaching its OWNER
819
+ // through the member record `fixRunning`/`fixLive` (and a finisher's
820
+ // `past-pin` read) share. A PR-bound member's outcome counts off `##
821
+ // Dispatched` and its own PR's row only, whichever order the rows sit in.
822
+ test("deriveRun: a settled stray of a PR-bound member on another PR's row does not settle its owner's live one", () => {
823
+ const own = "#20 impl-20=PR#21 · conflict-hold:#21 · fix-pr-21";
824
+ const stray = "#98 impl-98=PR#99 · fix-pr-21=applied:abc1234";
825
+ const seen = (rows, dispatched = []) => {
826
+ const r = run({ rows, dispatched }, [pr(21), pr(99)]);
827
+ return [r.fixDue, r.fixLive, r.reviewed.flatMap((x) => x.fixLive)];
828
+ };
829
+ for (const rows of [[own, stray], [stray, own], [own]]) {
830
+ const [due, n] = seen(rows);
831
+ assert.deepEqual([due, n], [[], 1], `fix-pr-21 is still working #21: ${JSON.stringify(rows)}`);
832
+ }
833
+ // The same reading through `reviewed.fixLive`, which gates the finisher.
834
+ const reviewed = "#20 impl-20=PR#21 · reviewed=abc1234:0/0/0 · fix-pr-21";
835
+ assert.deepEqual(seen([stray, reviewed])[2], ["fix-pr-21"]);
836
+ // Must accept: the member's real settle — in `## Dispatched` or on its own
837
+ // PR's row — still settles it, and a stray's own PR is unaffected.
838
+ assert.deepEqual(seen([own], ["fix-pr-21=applied:abc1234"]).slice(0, 2), [[], 0], "settled in ## Dispatched");
839
+ assert.deepEqual(seen(["#20 impl-20=PR#21 · conflict-hold:#21 · fix-pr-21=failed"]).slice(0, 2), [[21], 0], "settled on its own row");
840
+ // A stray's token still counts as a live member when nothing settles it.
841
+ assert.equal(seen(["#98 impl-98=PR#99 · fix-pr-21"])[1], 1);
842
+
843
+ // A finisher's `halted:past-pin` read follows the same rule: a settled stray
844
+ // on PR #99's row must not read PR #21's live finisher as halted past-pin,
845
+ // wherever the rows sit.
846
+ const fin = "#20 impl-20=PR#21 · reviewed=abc1234:0/0/0 · finisher-pr-21";
847
+ const finStray = "#98 impl-98=PR#99 · finisher-pr-21=halted:past-pin";
848
+ for (const rows of [[fin, finStray], [finStray, fin], [fin]]) {
849
+ assert.deepEqual(run({ rows }, [pr(21), pr(99)]).reviewDue, [99], `live finisher, no halt: ${JSON.stringify(rows)}`);
850
+ }
851
+ assert.deepEqual(
852
+ run({ rows: ["#20 impl-20=PR#21 · reviewed=abc1234:0/0/0 · finisher-pr-21=halted:past-pin"] }, [pr(21)]).reviewDue,
853
+ [21], "own-row halted:past-pin still re-offers the review");
854
+ });
855
+
501
856
  test("deriveRun: a conflict hold is read in either spelling and on a PR-keyed row", () => {
502
857
  assert.deepEqual(run({ rows: [HOLD_ROW(40, "conflict-hold-#40")] }, [pr(40)]).fixDue, [40]);
503
858
  assert.deepEqual(run({ rows: ["#350 review=wf:x reviewed=abc1234:0/1/0 · conflict-hold:#350"] }, [pr(350)]).fixDue, [350]);
@@ -551,6 +906,14 @@ test("deriveRun: a settled tier-mismatch keeps its own hold and is never also un
551
906
  assert.deepEqual([token.tierMismatch, token.tierUnchecked], [["impl-7"], []]);
552
907
  });
553
908
 
909
+ test("deriveRun: tier-unverifiable is a verdict for its own member — it clears unchecked, never reads as a mismatch, and a mismatch still outranks it", () => {
910
+ const r = run({ rows: ["#7 impl-7=killed · tier-unverifiable=impl-7:no-transcript"] });
911
+ assert.deepEqual([r.tierUnchecked, r.tierMismatch], [[], []]);
912
+ const both = run({ rows: ["#7 impl-7=tier-mismatch · tier-unverifiable=impl-7:no-transcript"] });
913
+ assert.deepEqual([both.tierMismatch, both.tierUnchecked], [["impl-7"], []]);
914
+ assert.deepEqual(run({ rows: ["#7 impl-7=killed · tier-unverifiable=impl-17:no-transcript"] }).tierUnchecked, ["impl-7"]);
915
+ });
916
+
554
917
  test("deriveRun: only the newest member of a ticket counts toward the tier holds", () => {
555
918
  const replaced = run({ rows: ["#8 impl-8=tier-mismatch · impl-8-b"], dispatched: ["impl-8=tier-mismatch", "impl-8-b"] });
556
919
  assert.deepEqual([replaced.tierMismatch, replaced.tierUnchecked], [[], ["impl-8-b"]], "the replacement is what is owed a check now");
@@ -674,6 +1037,7 @@ test("refreshWhy: short of the cap, missing or empty refreshes; draining never d
674
1037
 
675
1038
  import { spawnSync } from "node:child_process";
676
1039
  import { mkdtempSync, mkdirSync, writeFileSync, chmodSync, rmSync, readFileSync, realpathSync, existsSync } from "node:fs";
1040
+ import { writeExecStub } from "./exec-stub.mjs";
677
1041
  import { tmpdir } from "node:os";
678
1042
  import { join } from "node:path";
679
1043
  import { fileURLToPath } from "node:url";
@@ -683,10 +1047,49 @@ const SCRIPT = fileURLToPath(new URL("./fleet-tick.mjs", import.meta.url));
683
1047
  // or transitive — and ledger.mjs with its own, because the tick reads the
684
1048
  // ledger through `ledger.mjs read`. An unlisted sibling is a module-not-found
685
1049
  // at startup: exit 1, a shape no case below expects.
686
- const SIBLING_MODULES = ["arg.mjs", "fleet-state.mjs", "git-env.mjs", "ledger.mjs", "ledger-grammar.mjs"].map(
1050
+ const SIBLING_MODULES = ["arg.mjs", "fleet-state.mjs", "git-env.mjs", "is-cli.mjs", "ledger.mjs", "ledger-grammar.mjs", "main-checkout.mjs"].map(
687
1051
  (m) => [m, fileURLToPath(new URL(`./${m}`, import.meta.url))],
688
1052
  );
689
1053
 
1054
+ // Every subprocess below is spawned synchronously, so a hung one blocks this
1055
+ // file's event loop: no per-test or runner timeout can fire, and only the
1056
+ // runner's wall-clock kill ends it, as a cancelled file that reads like a hang
1057
+ // somewhere else (#2320). Every spawn goes through `spawnBounded`, which kills
1058
+ // the child at the bound and fails its own test naming the timeout and the
1059
+ // command. The bound is per spawn and generous on purpose: #2320's triage
1060
+ // measured the slowest whole case at ~1.5s solo on an idle host and ~3.85x
1061
+ // that under the full suite, but on a host loaded by other agents the slowest
1062
+ // case has taken ~13s solo, and a case can run several spawns.
1063
+ const SPAWN_TIMEOUT_MS = 60_000;
1064
+ const spawnBounded = (cmd, args, opts = {}) => {
1065
+ const r = spawnSync(cmd, args, { encoding: "utf8", ...opts, timeout: SPAWN_TIMEOUT_MS });
1066
+ if (r.error) {
1067
+ const what = [cmd, ...args].join(" ");
1068
+ throw new Error(r.error.code === "ETIMEDOUT"
1069
+ ? `timed out after ${SPAWN_TIMEOUT_MS}ms, killed with ${r.signal}: ${what}`
1070
+ : `could not run ${what}: ${r.error.message}`);
1071
+ }
1072
+ return r;
1073
+ };
1074
+
1075
+ // The bound holds only while every spawn takes it: a raw synchronous spawn
1076
+ // added anywhere else in this file brings #2320's unbounded hang back, and
1077
+ // every case still passes until the day that child hangs. So this reads the
1078
+ // file's own source and names any `spawnSync`/`execFileSync`/`execSync` call
1079
+ // outside the helper. A comment spelling one of them with its call paren fails
1080
+ // it too (the loud direction); an import renamed with `as` walks past it.
1081
+ test("CLI: every synchronous spawn in this file goes through spawnBounded (#2320)", () => {
1082
+ const src = readFileSync(fileURLToPath(import.meta.url), "utf8");
1083
+ const start = src.indexOf("const spawnBounded = ");
1084
+ assert.ok(start > 0, "the spawnBounded helper is gone; this sweep has nothing to measure against");
1085
+ const end = src.indexOf("\n};\n", start);
1086
+ const lineOf = (i) => src.slice(0, i).split("\n").length;
1087
+ const raw = [...src.matchAll(/\b(?:spawnSync|execFileSync|execSync)\s*\(/g)]
1088
+ .filter((m) => m.index < start || m.index > end)
1089
+ .map((m) => `line ${lineOf(m.index)}: ${m[0]}`);
1090
+ assert.deepEqual(raw, []);
1091
+ });
1092
+
690
1093
  // `pr list` for the open PRs, `issue view` for a behind-issue premise's state,
691
1094
  // `issue list --label in-progress` for the stall report's claimed count.
692
1095
  const GH_STUB = `#!/bin/sh
@@ -734,21 +1137,26 @@ const ledgerText = ({ rows = [], dispatched = [], drain = null } = {}) => {
734
1137
  };
735
1138
  const shortlistText = (ns, scanned = ns.length) => JSON.stringify({ scanned, shortlist: ns.map((n) => ({ n, t: `t${n}` })) });
736
1139
 
1140
+ // `baseline` records the run's main-checkout baseline the way Phase 0 does,
1141
+ // after `beforeRun`; `afterBaseline` is a stray write landing mid-run. The
1142
+ // repo ignores `.fleet/` and `.worktrees/` as a fleet repo's .gitignore does,
1143
+ // through info/exclude so no tracked file says so.
737
1144
  function runCli(args = [], {
738
1145
  prs = [], ledger, shortlist, refresh = shortlistText([]), refreshFail = false,
739
1146
  issueStates = {}, claimed = [], env: extraEnv = {}, defaultState = false, keep = false, beforeRun = () => {},
1147
+ baseline = true, afterBaseline = () => {},
740
1148
  } = {}) {
741
- // realpath, because on macOS tmpdir() is /var -> /private/var: a script COPY
742
- // under the unresolved path never runs its own main(), since import.meta.url
743
- // resolves the symlink and process.argv[1] does not.
1149
+ // On macOS tmpdir() is /var -> /private/var; resolving it up front makes
1150
+ // every path below the resolved one. (A symlinked path no longer stops a
1151
+ // copy running its own main(): is-cli.mjs compares by realpath.)
744
1152
  const dir = realpathSync(mkdtempSync(join(tmpdir(), "fleet-tick-")));
745
1153
  const bin = join(dir, "bin");
746
1154
  const repo = join(dir, "repo");
747
1155
  mkdirSync(bin);
748
1156
  mkdirSync(join(repo, ".fleet"), { recursive: true });
749
- assert.equal(spawnSync("git", ["init", "-q", repo], { encoding: "utf8" }).status, 0);
750
- writeFileSync(join(bin, "gh"), GH_STUB);
751
- chmodSync(join(bin, "gh"), 0o755);
1157
+ assert.equal(spawnBounded("git", ["init", "-q", repo]).status, 0);
1158
+ writeFileSync(join(repo, ".git", "info", "exclude"), ".fleet/\n.worktrees/\n");
1159
+ writeExecStub(join(bin, "gh"), GH_STUB);
752
1160
  const script = join(bin, "fleet-tick.mjs");
753
1161
  writeFileSync(script, readFileSync(SCRIPT));
754
1162
  for (const [name, path] of SIBLING_MODULES) writeFileSync(join(bin, name), readFileSync(path));
@@ -757,6 +1165,11 @@ function runCli(args = [], {
757
1165
  if (ledger !== undefined) writeFileSync(join(repo, ".fleet", "ledger.md"), ledgerText(ledger));
758
1166
  if (shortlist !== undefined) writeFileSync(join(repo, ".fleet", "shortlist.json"), shortlist);
759
1167
  beforeRun(repo);
1168
+ if (baseline) {
1169
+ const rec = spawnBounded(process.execPath, [join(bin, "main-checkout.mjs"), "--record"], { cwd: repo });
1170
+ assert.equal(rec.status, 0, rec.stderr);
1171
+ }
1172
+ afterBaseline(repo);
760
1173
  const refreshLog = fx("refresh.log", "");
761
1174
  const issueViewLog = fx("issue-view.log", "");
762
1175
  // Every case gets its own state file unless it names one: the default path
@@ -764,8 +1177,8 @@ function runCli(args = [], {
764
1177
  // make the fold cases order-dependent. `defaultState` opts out for the case
765
1178
  // whose subject IS that resolution.
766
1179
  const stateArg = args.includes("--state") || defaultState ? [] : ["--state", join(dir, "heartbeat.json")];
767
- const r = spawnSync(process.execPath, [script, ...args, ...stateArg], {
768
- cwd: repo, encoding: "utf8",
1180
+ const r = spawnBounded(process.execPath, [script, ...args, ...stateArg], {
1181
+ cwd: repo,
769
1182
  env: {
770
1183
  ...process.env, PATH: `${bin}:${process.env.PATH}`,
771
1184
  FIXTURE_PRS: fx("prs.json", JSON.stringify(prs)),
@@ -964,8 +1377,8 @@ test("CLI: a ledger ledger.mjs itself refuses is a refusal here too", () => {
964
1377
  // Two drain markers: ledger.mjs read exits 2 on the broken invariant.
965
1378
  const dir = runCli([], { shortlist: shortlistText([]), keep: true });
966
1379
  writeFileSync(join(dir.repo, ".fleet", "ledger.md"), `${ledgerText({ drain: "a" })}\n- b\n`);
967
- const r = spawnSync(process.execPath, [join(dir.dir, "bin", "fleet-tick.mjs"), "--state", join(dir.dir, "hb.json")], {
968
- cwd: dir.repo, encoding: "utf8",
1380
+ const r = spawnBounded(process.execPath, [join(dir.dir, "bin", "fleet-tick.mjs"), "--state", join(dir.dir, "hb.json")], {
1381
+ cwd: dir.repo,
969
1382
  env: { ...process.env, PATH: `${join(dir.dir, "bin")}:${process.env.PATH}`, FIXTURE_PRS: join(dir.dir, "prs.json") },
970
1383
  });
971
1384
  rmSync(dir.dir, { recursive: true, force: true });
@@ -1103,7 +1516,7 @@ test("CLI: a past-pin halt prints DISPATCH review for its PR (#2083)", () => {
1103
1516
 
1104
1517
  test("CLI: an ambient GIT_DIR naming another repository cannot move the shortlist read", () => {
1105
1518
  const decoy = realpathSync(mkdtempSync(join(tmpdir(), "fleet-tick-decoy-")));
1106
- spawnSync("git", ["init", "-q", decoy]);
1519
+ spawnBounded("git", ["init", "-q", decoy]);
1107
1520
  mkdirSync(join(decoy, ".fleet"));
1108
1521
  writeFileSync(join(decoy, ".fleet", "shortlist.json"), shortlistText([666]));
1109
1522
  const r = runCli([], { shortlist: shortlistText([7, 8]), env: { GIT_DIR: join(decoy, ".git") } });
@@ -1114,7 +1527,7 @@ test("CLI: an ambient GIT_DIR naming another repository cannot move the shortlis
1114
1527
 
1115
1528
  test("CLI: an inherited GIT_DIR cannot retarget the behind-issue premise probe", () => {
1116
1529
  const decoy = realpathSync(mkdtempSync(join(tmpdir(), "fleet-tick-decoy-gh-")));
1117
- spawnSync("git", ["init", "-q", decoy]);
1530
+ spawnBounded("git", ["init", "-q", decoy]);
1118
1531
  const r = runCli([], {
1119
1532
  shortlist: shortlistText([1, 2, 3]), ledger: { rows: ["#50 excluded · behind-issue:#9"] }, issueStates: { 9: "OPEN" },
1120
1533
  env: { GIT_DIR: join(decoy, ".git"), GH_REPO: "someone/else" },
@@ -1125,6 +1538,143 @@ test("CLI: an inherited GIT_DIR cannot retarget the behind-issue premise probe",
1125
1538
  assert.equal(r.refreshed, 0, "#9 is OPEN in the case's own repository — the exclusion stands");
1126
1539
  });
1127
1540
 
1541
+ // #2210, end to end: a real repo, a real baseline, a real stray write.
1542
+ const LIVE = {
1543
+ ledger: { rows: ["#412 impl-412 · tier-ok=impl-412:fleet-implementer"], dispatched: ["impl-412"] },
1544
+ shortlist: shortlistText([412, 420, 421]),
1545
+ };
1546
+ // One more tick over a kept runCli fixture, as the next wake would run it.
1547
+ const tickAgain = (r) => spawnBounded(process.execPath, [join(r.dir, "bin", "fleet-tick.mjs"), "--state", join(r.dir, "hb.json")], {
1548
+ cwd: r.repo,
1549
+ env: { ...process.env, PATH: `${join(r.dir, "bin")}:${process.env.PATH}`, FIXTURE_PRS: join(r.dir, "prs.json") },
1550
+ });
1551
+
1552
+ test("CLI: a stray write after the baseline prints MAIN-CHECKOUT-DIRTY first, naming the path and the live members, and holds every dispatching row", () => {
1553
+ const r = runCli([], {
1554
+ ...LIVE, prs: [pr(350)], keep: true,
1555
+ afterBaseline: (repo) => writeFileSync(join(repo, "stray.mjs"), "x\n"),
1556
+ });
1557
+ assert.equal(r.status, 0, r.stderr);
1558
+ const lines = r.stdout.trim().split("\n");
1559
+ assert.match(lines[0], /^MAIN-CHECKOUT-DIRTY stray\.mjs — changed since the run's baseline; live members: impl-412 — dispatch held: resolve the stray paths FIRST, then re-baseline with ~\/\.fleet\/bin\/fleet-run main-checkout\.mjs --record/);
1560
+ assert.match(r.stdout, /^implementers 1\/2 → HOLD \(main checkout dirty\)/m);
1561
+ assert.match(r.stdout, /^reviewers +0\/6 → HOLD \(main checkout dirty\)/m);
1562
+ assert.match(r.stdout, /^merge-bot +0\/1 → HOLD \(main checkout dirty\)/m);
1563
+ assert.doesNotMatch(r.stdout, /PULL|DISPATCH/);
1564
+
1565
+ // Not a one-tick warning: the next tick holds the same way, and only an
1566
+ // explicit re-baseline after the path is resolved lets dispatch through.
1567
+ assert.match(tickAgain(r).stdout, /^MAIN-CHECKOUT-DIRTY stray\.mjs /m);
1568
+ rmSync(join(r.repo, "stray.mjs"));
1569
+ const rec = spawnBounded(process.execPath, [join(r.dir, "bin", "main-checkout.mjs"), "--record"], { cwd: r.repo });
1570
+ assert.equal(rec.status, 0, rec.stderr);
1571
+ const after = tickAgain(r);
1572
+ rmSync(r.dir, { recursive: true, force: true });
1573
+ assert.equal(after.status, 0, after.stderr);
1574
+ assert.doesNotMatch(after.stdout, /MAIN-CHECKOUT|main checkout/);
1575
+ assert.match(after.stdout, /^implementers 1\/2 → PULL #420 /m);
1576
+ });
1577
+
1578
+ test("CLI: uncommitted work in the main checkout at run start does not hold the run", () => {
1579
+ const r = runCli([], {
1580
+ ...LIVE,
1581
+ beforeRun: (repo) => writeFileSync(join(repo, "my-notes.md"), "the maintainer's own\n"),
1582
+ });
1583
+ assert.equal(r.status, 0, r.stderr);
1584
+ assert.doesNotMatch(r.stdout, /MAIN-CHECKOUT|main checkout/);
1585
+ assert.match(r.stdout, /^implementers 1\/2 → PULL #420 /m);
1586
+ });
1587
+
1588
+ test("CLI: a run that never recorded a baseline is held, never read as clean", () => {
1589
+ const r = runCli([], { ...LIVE, baseline: false });
1590
+ assert.equal(r.status, 0, r.stderr);
1591
+ assert.match(r.stdout, /^MAIN-CHECKOUT-NO-BASELINE no baseline at .*\.fleet\/main-checkout\.sha — dispatch held: record it at run start with /);
1592
+ assert.match(r.stdout, /^implementers 1\/2 → HOLD \(main checkout no baseline\)/m);
1593
+ });
1594
+
1595
+ test("CLI: a main checkout git cannot read is MAIN-CHECKOUT-UNKNOWN and held, never clean", () => {
1596
+ const r = runCli([], {
1597
+ ...LIVE,
1598
+ afterBaseline: (repo) => writeFileSync(join(repo, ".git", "index"), "not an index"),
1599
+ });
1600
+ assert.equal(r.status, 0, r.stderr);
1601
+ assert.match(r.stdout, /^MAIN-CHECKOUT-UNKNOWN could not look: git status --porcelain -uall exited \d+.*; live members: impl-412 — .*NEVER re-baseline over it/);
1602
+ assert.match(r.stdout, /^implementers 1\/2 → HOLD \(main checkout unknown\)/m);
1603
+ });
1604
+
1605
+ // #2307: a folded tick under a dirty or unknown hold still names the hold, and
1606
+ // the hold stays non-actionable — `quiet` rises on every tick, the fold fires.
1607
+ // Three `--fold-unchanged` ticks over one kept fixture and one state file.
1608
+ const foldTicks = (fixture) => {
1609
+ const first = runCli(["--fold-unchanged"], { ...fixture, keep: true });
1610
+ const state = join(first.dir, "heartbeat.json");
1611
+ const quiet = () => JSON.parse(readFileSync(state, "utf8")).quiet;
1612
+ const ticks = [{ stdout: first.stdout, status: first.status, stderr: first.stderr, quiet: quiet() }];
1613
+ for (let i = 0; i < 2; i++) {
1614
+ const t = spawnBounded(process.execPath, [join(first.dir, "bin", "fleet-tick.mjs"), "--fold-unchanged", "--state", state], {
1615
+ cwd: first.repo,
1616
+ env: {
1617
+ ...process.env, PATH: `${join(first.dir, "bin")}:${process.env.PATH}`,
1618
+ FIXTURE_PRS: join(first.dir, "prs.json"), FIXTURE_CLAIMED: join(first.dir, "claimed.json"),
1619
+ FIXTURE_ISSUE_STATES: join(first.dir, "issue-states.json"), FIXTURE_REFRESH: join(first.dir, "refresh.json"),
1620
+ REFRESH_LOG: join(first.dir, "refresh.log"), ISSUE_VIEW_LOG: join(first.dir, "issue-view.log"),
1621
+ },
1622
+ });
1623
+ ticks.push({ stdout: t.stdout, status: t.status, stderr: t.stderr, quiet: quiet() });
1624
+ }
1625
+ rmSync(first.dir, { recursive: true, force: true });
1626
+ return ticks;
1627
+ };
1628
+
1629
+ for (const [state, afterBaseline] of [
1630
+ ["dirty", (repo) => writeFileSync(join(repo, "stray.mjs"), "x\n")],
1631
+ ["unknown", (repo) => writeFileSync(join(repo, ".git", "index"), "not an index")],
1632
+ ]) {
1633
+ test(`CLI: --fold-unchanged under a ${state} main checkout folds to one line naming the hold, quiet rising every tick`, () => {
1634
+ const ticks = foldTicks({ ...LIVE, afterBaseline });
1635
+ for (const t of ticks) assert.equal(t.status, 0, t.stderr);
1636
+ assert.match(ticks[0].stdout, new RegExp(`^implementers 1/2 → HOLD \\(main checkout ${state}\\)`, "m"));
1637
+ assert.deepEqual(ticks.map((t) => t.quiet), [1, 2, 3]);
1638
+ for (const [i, t] of ticks.slice(1).entries()) {
1639
+ assert.deepEqual(t.stdout.trim().split("\n"), [
1640
+ `fleet-tick: unchanged, nothing to act on (quiet=${i + 2}); HOLD (main checkout ${state}) persists — full rows on the next change`,
1641
+ ]);
1642
+ }
1643
+ });
1644
+ }
1645
+
1646
+ test("CLI: --fold-unchanged never folds a missing-baseline hold — it asks the controller to act", () => {
1647
+ const ticks = foldTicks({ ...LIVE, baseline: false });
1648
+ for (const t of ticks) {
1649
+ assert.equal(t.status, 0, t.stderr);
1650
+ assert.match(t.stdout, /^MAIN-CHECKOUT-NO-BASELINE /);
1651
+ assert.match(t.stdout, /^implementers 1\/2 → HOLD \(main checkout no baseline\)/m);
1652
+ assert.doesNotMatch(t.stdout, /nothing to act on/);
1653
+ assert.equal(t.quiet, 0);
1654
+ }
1655
+ assert.equal(ticks[2].stdout, ticks[1].stdout);
1656
+ });
1657
+
1658
+ test("CLI: an in-flight review with no member token is named as review:PR#<n> on the MAIN-CHECKOUT line", () => {
1659
+ const r = runCli([], {
1660
+ ledger: { rows: ["#51 review=wf:x"] }, shortlist: shortlistText([]), prs: [pr(51)],
1661
+ afterBaseline: (repo) => writeFileSync(join(repo, "stray.mjs"), "x\n"),
1662
+ });
1663
+ assert.equal(r.status, 0, r.stderr);
1664
+ assert.match(r.stdout, /^MAIN-CHECKOUT-DIRTY stray\.mjs — changed since the run's baseline; live members: review:PR#51 — /m);
1665
+ });
1666
+
1667
+ test("CLI: an ambient GIT_DIR naming a dirty repository does not move the main-checkout check", () => {
1668
+ const decoy = realpathSync(mkdtempSync(join(tmpdir(), "fleet-tick-decoy-mc-")));
1669
+ spawnBounded("git", ["init", "-q", decoy]);
1670
+ writeFileSync(join(decoy, "decoy-stray.txt"), "x\n");
1671
+ const r = runCli([], { ...LIVE, env: { GIT_DIR: join(decoy, ".git"), GIT_WORK_TREE: decoy } });
1672
+ rmSync(decoy, { recursive: true, force: true });
1673
+ assert.equal(r.status, 0, r.stderr);
1674
+ assert.doesNotMatch(r.stdout, /MAIN-CHECKOUT/);
1675
+ assert.match(r.stdout, /^implementers 1\/2 → PULL #420 /m);
1676
+ });
1677
+
1128
1678
  // ---------------------------------------------------------------------------
1129
1679
  // The heartbeat's half - #357. The tick is the only writer of the back-off
1130
1680
  // streak and the fold digest, so these pin the contract fleet-heartbeat.mjs