forgedock 1.67.0 → 1.68.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 (140) hide show
  1. package/bin/config-schema.mjs +1 -0
  2. package/bin/engine/outcome-codes.mjs +1 -0
  3. package/bin/engine-cli.mjs +99 -12
  4. package/bin/engine.mjs +10 -0
  5. package/bin/forgedock.mjs +17 -1
  6. package/bin/help-text.mjs +1 -0
  7. package/bin/lean/admission.mjs +21 -0
  8. package/bin/lean/admission.test.mjs +30 -0
  9. package/bin/lean/advisory.test.mjs +25 -10
  10. package/bin/lean/amendment-schema.mjs +3 -4
  11. package/bin/lean/attempts.mjs +34 -31
  12. package/bin/lean/attempts.test.mjs +33 -19
  13. package/bin/lean/basered.mjs +26 -0
  14. package/bin/lean/batch-health.mjs +17 -12
  15. package/bin/lean/batch-health.test.mjs +39 -11
  16. package/bin/lean/batch.test.mjs +51 -2
  17. package/bin/lean/ci-gate.mjs +2 -90
  18. package/bin/lean/ci-gate.test.mjs +1 -127
  19. package/bin/lean/ci-precheck.mjs +25 -8
  20. package/bin/lean/ci-precheck.test.mjs +24 -0
  21. package/bin/lean/clear-breaker.test.mjs +4 -3
  22. package/bin/lean/commentstate.mjs +10 -5
  23. package/bin/lean/commentstate.test.mjs +12 -1
  24. package/bin/lean/conformance.e2e.test.mjs +9 -6
  25. package/bin/lean/conformance.mjs +56 -196
  26. package/bin/lean/conformance.test.mjs +40 -376
  27. package/bin/lean/depcache.mjs +100 -10
  28. package/bin/lean/depcache.test.mjs +105 -0
  29. package/bin/lean/docsgate.mjs +0 -32
  30. package/bin/lean/docsgate.test.mjs +2 -23
  31. package/bin/lean/effects-cap.test.mjs +9 -1
  32. package/bin/lean/effects-killtree.test.mjs +35 -0
  33. package/bin/lean/effects.mjs +42 -24
  34. package/bin/lean/engine-readmit.test.mjs +35 -0
  35. package/bin/lean/envgap.mjs +93 -0
  36. package/bin/lean/envgap.test.mjs +53 -0
  37. package/bin/lean/execution.mjs +10 -4
  38. package/bin/lean/execution.test.mjs +12 -0
  39. package/bin/lean/failure-census.mjs +170 -0
  40. package/bin/lean/failure-census.test.mjs +59 -0
  41. package/bin/lean/guardgate.test.mjs +2 -3
  42. package/bin/lean/heavy.mjs +33 -4
  43. package/bin/lean/heavy.test.mjs +38 -6
  44. package/bin/lean/hotarea.mjs +0 -36
  45. package/bin/lean/hotarea.test.mjs +1 -22
  46. package/bin/lean/issuewatch-verify.mjs +19 -4
  47. package/bin/lean/issuewatch.mjs +21 -4
  48. package/bin/lean/issuewatch.test.mjs +48 -1
  49. package/bin/lean/lane-audit-gap.mjs +66 -0
  50. package/bin/lean/lane-audit-gap.test.mjs +59 -0
  51. package/bin/lean/lane-audit-llm.mjs +5 -0
  52. package/bin/lean/lane-audit-query.mjs +47 -0
  53. package/bin/lean/lane-audit-query.test.mjs +44 -0
  54. package/bin/lean/lane-audit-signatures.mjs +33 -0
  55. package/bin/lean/lane-audit.mjs +110 -0
  56. package/bin/lean/lane-audit.test.mjs +97 -0
  57. package/bin/lean/lane-recovery.test.mjs +33 -0
  58. package/bin/lean/lanecheck.mjs +5 -3
  59. package/bin/lean/lanecheck.test.mjs +6 -0
  60. package/bin/lean/lean.mjs +206 -148
  61. package/bin/lean/lean.test.mjs +406 -190
  62. package/bin/lean/limits.mjs +17 -0
  63. package/bin/lean/limits.test.mjs +15 -1
  64. package/bin/lean/live-execution.mjs +21 -2
  65. package/bin/lean/live-execution.test.mjs +39 -0
  66. package/bin/lean/orchestrate-attempts.test.mjs +17 -9
  67. package/bin/lean/orchestrate-envhold.test.mjs +47 -0
  68. package/bin/lean/orchestrate-heldroot.test.mjs +72 -0
  69. package/bin/lean/orchestrate-hostfallback.test.mjs +59 -1
  70. package/bin/lean/orchestrate-overload-recovery.test.mjs +37 -0
  71. package/bin/lean/orchestrate-pause.test.mjs +53 -1
  72. package/bin/lean/orchestrate-reconcile.test.mjs +17 -0
  73. package/bin/lean/orchestrate-relaunch-gates.test.mjs +57 -0
  74. package/bin/lean/orchestrate-stacking.test.mjs +10 -0
  75. package/bin/lean/orchestrate.mjs +188 -33
  76. package/bin/lean/postdeploy-check.test.mjs +1 -3
  77. package/bin/lean/precheck.mjs +20 -0
  78. package/bin/lean/preflight.mjs +100 -11
  79. package/bin/lean/preflight.test.mjs +44 -4
  80. package/bin/lean/prompts.mjs +10 -21
  81. package/bin/lean/recurrence.mjs +6 -148
  82. package/bin/lean/recurrence.test.mjs +11 -147
  83. package/bin/lean/release-flakes.mjs +14 -2
  84. package/bin/lean/release-flakes.test.mjs +17 -1
  85. package/bin/lean/release-ledger.mjs +19 -1
  86. package/bin/lean/release-ledger.test.mjs +23 -0
  87. package/bin/lean/release-preflight.mjs +28 -0
  88. package/bin/lean/release-preflight.test.mjs +42 -1
  89. package/bin/lean/release-review.mjs +40 -5
  90. package/bin/lean/release-review.test.mjs +43 -2
  91. package/bin/lean/release.mjs +43 -14
  92. package/bin/lean/release.test.mjs +32 -0
  93. package/bin/lean/retry.mjs +1 -1
  94. package/bin/lean/retry.test.mjs +6 -1
  95. package/bin/lean/rotator.mjs +9 -0
  96. package/bin/lean/rotator.test.mjs +11 -1
  97. package/bin/lean/sandbox-remote.mjs +16 -9
  98. package/bin/lean/schedd.mjs +11 -6
  99. package/bin/lean/schedd.test.mjs +65 -5
  100. package/bin/lean/selfreview.mjs +1 -1
  101. package/bin/lean/statuscomment.mjs +4 -1
  102. package/bin/lean/validate-catalog.mjs +108 -0
  103. package/bin/lean/validate-catalog.test.mjs +46 -1
  104. package/bin/lean/verify.mjs +1 -1
  105. package/bin/pool/affinity.test.mjs +91 -0
  106. package/bin/pool/agent.mjs +143 -9
  107. package/bin/pool/cache-sweep.mjs +31 -10
  108. package/bin/pool/ci-autoscale.mjs +160 -0
  109. package/bin/pool/cli.mjs +37 -8
  110. package/bin/pool/docker.mjs +3 -0
  111. package/bin/pool/engine-placement.test.mjs +94 -0
  112. package/bin/pool/lane-target.mjs +41 -0
  113. package/bin/pool/lane-tools.mjs +7 -2
  114. package/bin/pool/lane-tools.test.mjs +9 -0
  115. package/bin/pool/mirror-seed.mjs +15 -11
  116. package/bin/pool/router.mjs +88 -32
  117. package/bin/pool/version.mjs +29 -2
  118. package/bin/review-staging.mjs +11 -3
  119. package/bin/runner.mjs +59 -11
  120. package/bin/stats/release.mjs +7 -0
  121. package/bin/stats/release.test.mjs +20 -0
  122. package/bin/stats/scorecard.mjs +187 -0
  123. package/bin/stats/scorecard.test.mjs +89 -0
  124. package/docs/CONFIG.md +41 -0
  125. package/docs/OUTCOME-CODES.md +1 -0
  126. package/docs/STATS.md +17 -0
  127. package/package.json +1 -1
  128. package/pool/image/Dockerfile +14 -2
  129. package/pool/image/manifest.json +25 -0
  130. package/pool/image/mirror.sh +11 -2
  131. package/pool/install/install-agent.ps1 +11 -4
  132. package/scripts/ci-local/adapters/github-actions.mjs +8 -0
  133. package/scripts/ci-local/cli.mjs +1 -1
  134. package/scripts/ci-local/plan.mjs +3 -2
  135. package/scripts/ci-local.test.sh +11 -0
  136. package/scripts/failure-census.mjs +67 -0
  137. package/scripts/review-finalize.sh +5 -5
  138. package/scripts/review-finalize.test.sh +8 -1
  139. package/scripts/verify-phase-trail.sh +11 -0
  140. package/scripts/verify-phase-trail.test.sh +9 -0
@@ -60,3 +60,20 @@ export function openLimits(file = limitsFile(), { now = () => Date.now() } = {})
60
60
  list: () => Object.entries(read()).map(([id, h]) => ({ id, until: h.until, source: h.source ?? null, setAt: h.setAt ?? null })),
61
61
  };
62
62
  }
63
+
64
+ /** #5988: a hold expiry alert is posted this long before `expiresAt` (T-30 min). */
65
+ export const HOLD_EXPIRY_WARN_MS = 30 * 60000;
66
+
67
+ /**
68
+ * #5988: hold-info entries (`{issue: {expiresAt, ...}}`) whose expiry is within `leadMs` and not yet warned. `warned` is the
69
+ * caller's marker set (an issue is warned once per expiresAt). Pure; an entry without a valid future expiry is never listed.
70
+ * @returns {Array<{issue:number, expiresAt:string, inMs:number, key:string}>}
71
+ */
72
+ export function holdExpiryWarnings(info, { now = Date.now(), leadMs = HOLD_EXPIRY_WARN_MS, warned = new Set() } = {}) {
73
+ const out = [];
74
+ for (const [n, e] of Object.entries(info ?? {})) {
75
+ const at = Date.parse(e?.expiresAt), key = `${n}@${e?.expiresAt}`;
76
+ if (Number.isFinite(at) && at > now && at - now <= leadMs && !warned.has(key)) out.push({ issue: Number(n), expiresAt: e.expiresAt, inMs: at - now, key });
77
+ }
78
+ return out;
79
+ }
@@ -5,7 +5,7 @@ import assert from "node:assert/strict";
5
5
  import { readFileSync, writeFileSync } from "node:fs";
6
6
  import { join } from "node:path";
7
7
  import { tmpDir } from "../tests/_tmp.mjs";
8
- import { openLimits, laneBackendId, limitsFile } from "./limits.mjs";
8
+ import { openLimits, laneBackendId, limitsFile, holdExpiryWarnings, HOLD_EXPIRY_WARN_MS } from "./limits.mjs";
9
9
  import { orchestrate } from "./orchestrate.mjs";
10
10
  import { limitsFromCli } from "../engine-cli.mjs";
11
11
 
@@ -402,3 +402,17 @@ describe("tokenbaton rotation holds (#5205)", () => {
402
402
  onUpdate: (u) => { if (u.outcome === "paused") assert.equal(limits.holdUntil("A"), until); } });
403
403
  });
404
404
  });
405
+
406
+ describe("#5988: hold expiry warning", () => {
407
+ const at = (ms) => new Date(ms).toISOString();
408
+ it("lists a hold within 30 min of expiry once; never an open-ended, expired or distant hold", () => {
409
+ const now = 1_000_000, warned = new Set();
410
+ const info = { 1: { expiresAt: at(now + 20 * 60000) }, 2: { expiresAt: at(now + 3 * 3600000) }, 3: { expiresAt: null }, 4: { expiresAt: at(now - 1) } };
411
+ const w = holdExpiryWarnings(info, { now, warned });
412
+ assert.deepEqual(w.map((x) => x.issue), [1]);
413
+ assert.equal(HOLD_EXPIRY_WARN_MS, 30 * 60000);
414
+ warned.add(w[0].key);
415
+ assert.deepEqual(holdExpiryWarnings(info, { now, warned }), []);
416
+ assert.deepEqual(holdExpiryWarnings(null, { now }), []);
417
+ });
418
+ });
@@ -135,12 +135,25 @@ export function lazyWeight({ initial = null, compute = null } = {}) {
135
135
  * `placeLane` with the remote or hybrid facts); mode `local` places every new lane on the host. `onChange(exec)` is
136
136
  * called once each time the effective `{mode, maxRemote}` differs from the last one seen (the pinned one first).
137
137
  */
138
- export function liveRemote(base, { exec, readOverride = () => null, place, onChange = null }) {
138
+ export const BELOW_PINNED_WARN_HOURS = 6;
139
+ export function liveRemote(base, { exec, readOverride = () => null, place, onChange = null, onBelowPinned = null, belowPinnedHours = BELOW_PINNED_WARN_HOURS, now = Date.now }) {
139
140
  const keyOf = (e) => `${e.mode}|${e.maxRemote}`;
140
141
  let last = keyOf(effectiveExecution(exec, null));
142
+ let live = null; // the override applied by the last current() call
143
+ let belowSince = null, belowWarned = false; // #5746: since when a live max_remote has been below the pinned value
144
+ const noteBelow = () => {
145
+ const pinned = exec?.maxRemote;
146
+ if (!(live?.maxRemote !== undefined && Number.isInteger(pinned) && live.maxRemote < pinned)) { belowSince = null; belowWarned = false; return; }
147
+ const t = now();
148
+ belowSince ??= t;
149
+ const hours = Number(belowPinnedHours) > 0 ? Number(belowPinnedHours) : BELOW_PINNED_WARN_HOURS;
150
+ if (!belowWarned && t - belowSince > hours * 3600000) { belowWarned = true; try { onBelowPinned?.({ maxRemote: live.maxRemote, pinned, hours }); } catch { /* advisory */ } }
151
+ };
141
152
  const current = () => {
142
153
  let o = null;
143
154
  try { o = readOverride() ?? null; } catch { o = null; }
155
+ live = sanitizeOverride(o);
156
+ noteBelow();
144
157
  const e = effectiveExecution(exec, o);
145
158
  const k = keyOf(e);
146
159
  if (k !== last) { last = k; try { onChange?.(e); } catch { /* advisory */ } }
@@ -153,7 +166,13 @@ export function liveRemote(base, { exec, readOverride = () => null, place, onCha
153
166
  value: (n) => {
154
167
  const e = current();
155
168
  if (e.mode === "local") return { where: "local", reason: "live placement: local" };
156
- return place(e, n);
169
+ const p = place(e, n);
170
+ // #5746: remote mode with no remote slots holds the lane when the host is not allowed; else names the real cause
171
+ if (e.mode === "remote" && p?.where === "local" && !(Number.isInteger(e.maxRemote) && e.maxRemote >= 1)) {
172
+ const reason = live?.maxRemote !== undefined ? "max_remote 0 (live override)" : "max_remote 0";
173
+ return base.hostFallback === false ? { where: "remote", reason, hold: true } : { ...p, reason };
174
+ }
175
+ return p;
157
176
  },
158
177
  enumerable: true, configurable: true, writable: true,
159
178
  },
@@ -83,6 +83,45 @@ describe("#5138 live execution control", () => {
83
83
  });
84
84
  });
85
85
 
86
+ describe("#5746 live max_remote 0 in remote mode", () => {
87
+ const exec = { mode: "remote", maxRemote: 4 };
88
+ const place = (e) => ({ where: e.maxRemote >= 1 ? "remote" : "local", reason: e.maxRemote >= 1 ? "mode remote" : "max_remote 0" });
89
+ it("holds with the live-override reason when the host is not allowed", () => {
90
+ const r = liveRemote({ hostFallback: false }, { exec, readOverride: () => ({ maxRemote: 0 }), place });
91
+ assert.deepEqual(r.place(1), { where: "remote", reason: "max_remote 0 (live override)", hold: true });
92
+ });
93
+ it("names the live override but stays local when the host is allowed", () => {
94
+ const r = liveRemote({ hostFallback: true }, { exec, readOverride: () => ({ maxRemote: 0 }), place });
95
+ assert.deepEqual(r.place(1), { where: "local", reason: "max_remote 0 (live override)" });
96
+ });
97
+ });
98
+
99
+ describe("#5746 live max_remote below the pinned value warns once after N hours", () => {
100
+ it("warns once past the threshold, not before, and re-arms when restored", () => {
101
+ let t = 0, o = { maxRemote: 0 };
102
+ const warned = [];
103
+ const r = liveRemote({ onBudget: "stop" }, { exec: { mode: "remote", maxRemote: 3 }, readOverride: () => o, place: () => ({ where: "remote", reason: "r" }),
104
+ belowPinnedHours: 2, now: () => t, onBelowPinned: (w) => warned.push(w) });
105
+ void r.max;
106
+ t = 2 * 3600000; void r.max;
107
+ assert.equal(warned.length, 0);
108
+ t += 1; void r.max; void r.max;
109
+ assert.deepEqual(warned, [{ maxRemote: 0, pinned: 3, hours: 2 }]);
110
+ o = { maxRemote: 3 }; void r.max;
111
+ o = { maxRemote: 1 }; void r.max;
112
+ t += 3 * 3600000; void r.max;
113
+ assert.equal(warned.length, 2);
114
+ });
115
+ it("no warning without an override or with an override at or above the pinned value", () => {
116
+ let t = 0, o = null;
117
+ const warned = [];
118
+ const r = liveRemote({}, { exec: { mode: "remote", maxRemote: 2 }, readOverride: () => o, place: () => ({ where: "remote" }), belowPinnedHours: 1, now: () => t, onBelowPinned: (w) => warned.push(w) });
119
+ void r.max; t = 10 * 3600000; void r.max;
120
+ o = { maxRemote: 4 }; void r.max; t *= 2; void r.max;
121
+ assert.equal(warned.length, 0);
122
+ });
123
+ });
124
+
86
125
  describe("#5735 remoteLaneNote", () => {
87
126
  const lanes = (agents, total) => ({ agents, total });
88
127
  it("warns when max_remote exceeds the summed host lane ceiling and always prints the total", () => {
@@ -38,25 +38,33 @@ describe("#5986 attempts ledger in the batch runner", () => {
38
38
  assert.deepEqual(r.rows.map((x) => x.outcome), ["merged", "merged"], "root and its held dependent");
39
39
  });
40
40
 
41
- it("the 3rd identical-signature failure escalates once and stops; counters survive resumes (state.json)", async () => {
41
+ it("the 2nd identical-signature failure escalates once with one comment and stops; counters survive resumes (state.json)", async () => {
42
42
  const store = memStore(), h = { v: "H1" }, a = seam(h);
43
43
  await run(store, a, async () => FAIL);
44
- h.v = "H2"; await run(store, a, async () => FAIL);
45
44
  assert.equal(a.notes.filter((n) => n.code === "escalate").length, 0);
46
- h.v = "H3"; const third = await run(store, a, async () => FAIL);
47
- assert.equal(third.rows[0].outcome, "needs-human");
45
+ h.v = "H2"; const second = await run(store, a, async () => FAIL);
46
+ assert.equal(second.rows[0].outcome, "needs-human");
48
47
  assert.equal(a.notes.filter((n) => n.code === "escalate").length, 1, "one escalation");
49
- assert.equal(store.peek().attempts[1].attempts, 3);
50
- assert.equal(store.peek().attempts[1].signatures.length, 3);
48
+ assert.equal(store.peek().attempts[1].attempts, 2);
49
+ assert.equal(store.peek().attempts[1].signatures.length, 2);
51
50
  let ran = 0;
52
- const again = await run(store, a, async () => { ran++; return MERGED; }); // same hash H3, label removed
51
+ const again = await run(store, a, async () => { ran++; return MERGED; }); // same hash H2, label removed
53
52
  assert.equal(ran, 0);
54
53
  assert.equal(again.rows[0].outcome, "needs-human");
55
54
  assert.equal(a.notes.filter((n) => n.code === "escalate").length, 1, "still one escalation");
56
- h.v = "H4";
55
+ h.v = "H3";
57
56
  assert.equal((await run(store, a, async () => MERGED)).rows[0].outcome, "merged", "a new input hash readmits");
58
57
  });
59
-
58
+ it("#5931 a remote lane on another engine version ends env.engine_skew, never conformance", async () => {
59
+ const store = memStore();
60
+ const rows = await orchestrate({ issues: [1], parallel: 1, pollMs: 5, store, version: "1.63.0",
61
+ envHold: { version: () => "1.63.0", maxMs: 1, watchMs: 1 },
62
+ runOne: async () => ({ terminalReason: "needs-human", code: "recurrence.design_missing", detail: "gate fired", engineVersion: "1.61.2" }),
63
+ remote: { max: 2, isRemote: () => true, admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 } });
64
+ assert.equal(rows[0].code, "env.engine_skew");
65
+ assert.match(rows[0].detail, /env\.engine_skew/);
66
+ assert.equal(rows[0].outcome, "held");
67
+ });
60
68
  it("an engine-error that breaches the lifetime attempts cap ends needs-human (escalated)", async () => {
61
69
  const store = memStore(), h = { v: "H1" }, a = seam(h, { cfg: { maxAttempts: 1, maxIdentical: 5 } });
62
70
  const r = await run(store, a, async () => ({ terminalReason: "engine-error", detail: "boom" }));
@@ -292,6 +292,22 @@ describe("#5859 agent restart: correlated sandbox loss is sandbox.lost, not engi
292
292
  for (const n of issues) assert.equal(r.byIssue[n].outcome, "merged");
293
293
  });
294
294
 
295
+ // #5988: three sandboxes destroyed for max lifetime together are one batch-level event; the breaker stays closed and each lane is requeued.
296
+ it("3 sandboxes destroyed for max lifetime within 30 s: no breaker trip, lanes requeued, reported once (#5988)", async () => {
297
+ const MAXLIFE = (n) => ({ ...LOST(n), detail: `sandbox fake-${n} destroyed: max lifetime reached` });
298
+ const issues = [1, 2, 3], script = Object.fromEntries(issues.map((n) => [n, [MAXLIFE(n), MERGED]]));
299
+ const store = memStore(), logged = [];
300
+ store.log = (ev) => logged.push(ev);
301
+ const r = await harness({ script, issues, parallel: 3, store, envHold: undefined, extra: { envHold: null, breaker: BREAKER, remote: { agentHealthy: async () => true } } });
302
+ assert.ok(!r.updates.some((u) => u.outcome === "breaker"), "the breaker never trips");
303
+ for (const n of issues) assert.equal(r.byIssue[n].outcome, "merged", `#${n} requeued and relaunched`);
304
+ const st = store.load();
305
+ assert.deepEqual(st.errorTimes, []);
306
+ assert.equal(st.breaker, null);
307
+ assert.equal(logged.filter((e) => e.event === "agent.restarted").length, 1, "one batch-level event");
308
+ assert.equal(st.agentRestarts[0].requeued, 3);
309
+ });
310
+
295
311
  it("agent restart: failure after healthy is an ordinary engine-error", async () => {
296
312
  const store = memStore();
297
313
  const r = await harness({ script: { 1: [LOST(1), LOST(1), MERGED], 2: [LOST(2), MERGED], 3: [LOST(3), MERGED] }, issues: [1, 2, 3], parallel: 3, store,
@@ -322,3 +338,34 @@ describe("#5859 agent restart: correlated sandbox loss is sandbox.lost, not engi
322
338
  assert.ok(r.updates.some((u) => u.outcome === "breaker"));
323
339
  });
324
340
  });
341
+
342
+ describe("#5988: breaker scoped by signature and agent", () => {
343
+ it("12 sandbox.exited engine-errors on one agent quarantine only that agent; other agents keep admitting", async () => {
344
+ const issues = [...Array.from({ length: 12 }, (_, i) => i + 1), 50], quarantined = [], reseeds = [];
345
+ const sick = (n) => ({ terminalReason: "engine-error", code: "sandbox.exited", detail: `sandbox.exited before a result (run ${n})`, agent: "vm-a" });
346
+ const script = Object.fromEntries(issues.slice(0, 12).map((n) => [n, [sick(n), MERGED]]));
347
+ const r = await harness({ script, issues, parallel: 1, envHold: undefined,
348
+ extra: { envHold: null, breaker: { errors: 3, window_min: 10 }, quarantineAgent: (q) => quarantined.push(q), reseedCache: (q) => reseeds.push(q) } });
349
+ assert.deepEqual(quarantined.map((q) => q.agent), ["vm-a"], "that agent only, once");
350
+ assert.equal(reseeds.length, 1, "the cache is reseeded once");
351
+ assert.ok(!r.updates.some((u) => u.outcome === "breaker"), "the batch breaker never trips");
352
+ assert.equal(r.byIssue[50].outcome, "merged", "unaffected work keeps admitting");
353
+ assert.ok(r.updates.some((u) => u.outcome === "agent-quarantine"));
354
+ });
355
+
356
+ it("without placement callbacks the agent is still quarantined in-batch: its lanes are requeued, the breaker stays closed", async () => {
357
+ const sick = (n) => ({ terminalReason: "engine-error", code: "sandbox.exited", detail: `sandbox.exited (run ${n})`, agent: "vm-a" });
358
+ const r = await harness({ script: { 1: [sick(1), MERGED], 2: [sick(2), MERGED], 3: [sick(3), MERGED], 4: [sick(4), MERGED] }, issues: [1, 2, 3, 4, 50], parallel: 1, envHold: undefined,
359
+ extra: { envHold: null, breaker: { errors: 3, window_min: 10 } } });
360
+ assert.ok(r.updates.some((u) => u.outcome === "agent-quarantine"));
361
+ assert.ok(!r.updates.some((u) => u.outcome === "breaker"));
362
+ assert.equal(r.byIssue[50].outcome, "merged");
363
+ });
364
+
365
+ it("a persistently sick agent without placement callbacks cannot loop forever: the batch breaker counts it after bounded requeues", async () => {
366
+ const sick = (n) => ({ terminalReason: "engine-error", code: "sandbox.exited", detail: `sandbox.exited (run ${n})`, agent: "vm-a" });
367
+ const r = await harness({ script: Object.fromEntries([1, 2, 3, 4, 5].map((n) => [n, [sick(n)]])), issues: [1, 2, 3, 4, 5], parallel: 1, envHold: undefined,
368
+ extra: { envHold: null, breaker: { errors: 3, window_min: 10 } } });
369
+ assert.ok(r.updates.some((u) => u.outcome === "breaker"), "bounded: the batch breaker trips");
370
+ });
371
+ });
@@ -0,0 +1,72 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ // #5893: a needs-human root with held dependents is readmitted only when the label is really gone (fresh read) and its removal
4
+ // event post-dates the newest FORGE:NEEDS_HUMAN; an identical block (outcome code + ask key) needs a newer removal event.
5
+ import { describe, it } from "node:test";
6
+ import assert from "node:assert/strict";
7
+ import { orchestrate } from "./orchestrate.mjs";
8
+
9
+ const memStore = () => { let st = null; return { load: () => (st ? JSON.parse(JSON.stringify(st)) : null), save: (s) => { st = JSON.parse(JSON.stringify(s)); }, log: () => {}, peek: () => st }; };
10
+ const FAIL = { terminalReason: "needs-human", code: "spend.cap", detail: "needs a spend decision" };
11
+ const MERGED = { terminalReason: "merged", pr: 1 };
12
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
13
+
14
+ // Run 1 blocks root 1 (2 is held behind it); run 2 resumes the batch and watches the held root.
15
+ const resume = async (store, { issueLabels, heldFacts, ran, watchMs = 60 }) => {
16
+ const updates = [];
17
+ const p = orchestrate({ issues: [1, 2], parallel: 1, pollMs: 5, store, readBody: async (n) => (n === 2 ? "**Depends on**: #1" : ""), issueLabels, ...(heldFacts ? { heldFacts } : {}),
18
+ runOne: async (n) => { ran.push(n); return MERGED; }, onUpdate: (r) => updates.push(r) });
19
+ await Promise.race([p, sleep(watchMs)]);
20
+ return { updates, p };
21
+ };
22
+ const block = async (store) => orchestrate({ issues: [1, 2], parallel: 1, pollMs: 5, store, readBody: async (n) => (n === 2 ? "**Depends on**: #1" : ""), issueLabels: async () => ["needs-human"], runOne: async (n) => (n === 1 ? FAIL : MERGED) });
23
+
24
+ describe("#5893 held needs-human root readmit", () => {
25
+ it("no readmit while needs-human label is still on (stale cache vs fresh read)", async () => {
26
+ const store = memStore(); await block(store);
27
+ const ran = []; const calls = [];
28
+ // the memoized read lacks the label; only a fresh read sees it
29
+ const issueLabels = async (n, o) => { calls.push(o?.fresh === true); return o?.fresh ? ["needs-human"] : []; };
30
+ const { updates } = await resume(store, { issueLabels, ran });
31
+ assert.deepEqual(ran, []);
32
+ assert.ok(!updates.some((u) => u.outcome === "readmitted"));
33
+ assert.ok(calls.every(Boolean), "every held-root label read is fresh");
34
+ });
35
+
36
+ it("removal event before the NEEDS_HUMAN comment: no readmit; unreadable events: no readmit", async () => {
37
+ for (const heldFacts of [async () => ({ removedAt: 10, blockedAt: 20, askKey: "k" }), async () => { throw new Error("gh down"); }, async () => null]) {
38
+ const store = memStore(); await block(store);
39
+ const ran = [];
40
+ const { updates } = await resume(store, { issueLabels: async () => [], heldFacts, ran });
41
+ assert.deepEqual(ran, []);
42
+ assert.ok(!updates.some((u) => u.outcome === "readmitted"));
43
+ }
44
+ });
45
+
46
+ it("removal event after the block readmits once and the subtree follows", async () => {
47
+ const store = memStore(); await block(store);
48
+ const ran = [];
49
+ const { updates, p } = await resume(store, { issueLabels: async () => [], heldFacts: async () => ({ removedAt: 30, blockedAt: 20, askKey: "k" }), ran, watchMs: 200 });
50
+ await Promise.race([p, sleep(500)]);
51
+ assert.equal(updates.filter((u) => u.outcome === "readmitted" && u.issue === 1).length, 1);
52
+ assert.ok(ran.includes(1));
53
+ });
54
+
55
+ it("identical block is not readmitted twice without a newer removal event; sig survives resume", async () => {
56
+ const store = memStore(); await block(store);
57
+ const ran = [];
58
+ const facts = { removedAt: 30, blockedAt: 20, askKey: "k" };
59
+ const first = await resume(store, { issueLabels: async () => [], heldFacts: async () => facts, ran, watchMs: 200 });
60
+ await Promise.race([first.p, sleep(500)]);
61
+ assert.deepEqual(store.peek().heldSigs?.[1], { sig: "needs-human:k", removedAt: 30 }.sig ? { sig: "needs-human:k", removedAt: 30 } : null);
62
+ // the lane blocks again with the same ask; the old removal event is the only one
63
+ const st = store.peek();
64
+ st.results = { ...st.results, 1: { issue: 1, outcome: "needs-human", code: "spend.cap" }, 2: { issue: 2, outcome: "held", root: 1, waiting: [1] } };
65
+ st.pending = []; st.running = {};
66
+ const store2 = memStore(); store2.save(st);
67
+ const ran2 = [];
68
+ const again = await resume(store2, { issueLabels: async () => [], heldFacts: async () => facts, ran: ran2 });
69
+ assert.deepEqual(ran2, []);
70
+ assert.ok(!again.updates.some((u) => u.outcome === "readmitted"));
71
+ });
72
+ });
@@ -6,7 +6,7 @@ import { orchestrate } from "./orchestrate.mjs";
6
6
  import { hostFallbackAllowed } from "./execution.mjs";
7
7
 
8
8
  // #5652: host re-placement of a remote lane's env.tool_missing / env.capability_remote end follows host.role / execution.host_fallback.
9
- const go = async (code, cfg) => {
9
+ const go = async (code, cfg, rec = {}) => {
10
10
  const calls = [];
11
11
  const rows = await orchestrate({ issues: [5], parallel: 2, recovery: { maxAttempts: 1 }, readBody: async () => "",
12
12
  remote: { max: 2, isRemote: () => true, hostFallback: hostFallbackAllowed(cfg), place: () => ({ where: "remote", reason: "mode remote" }), admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 },
@@ -17,6 +17,18 @@ const go = async (code, cfg) => {
17
17
  return { rows, calls };
18
18
  };
19
19
 
20
+ // #5746: remote mode with host fallback off never re-places a mechanical recovery on the host
21
+ const goMech = async (hostFallback) => {
22
+ const calls = [];
23
+ await orchestrate({ issues: [5], parallel: 2, recovery: { maxAttempts: 1, mechanicalMaxAttempts: 2 }, readBody: async () => "",
24
+ remote: { max: 2, isRemote: () => true, hostFallback, admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 },
25
+ runOne: async (n, _l, ctx = {}) => {
26
+ calls.push(ctx.placement?.where);
27
+ return ctx.recover ? { terminalReason: "merged", pr: 9 } : { terminalReason: "needs-human", code: "env.repro_unrunnable", detail: "x", placement: { where: "remote" } };
28
+ } });
29
+ return calls;
30
+ };
31
+
20
32
  describe("#5652 host fallback placement", () => {
21
33
  for (const code of ["env.capability_remote", "env.tool_missing"]) {
22
34
  it(`${code}: host.role unset keeps the host re-placement`, async () => {
@@ -38,6 +50,52 @@ describe("#5652 host fallback placement", () => {
38
50
  const r = await go("env.repro_unrunnable", { hostRole: "orchestrator" });
39
51
  assert.ok(r.calls.length >= 1);
40
52
  });
53
+ it("#5746: remote mode with nothing set disallows the host; hybrid keeps it; explicit true wins", () => {
54
+ assert.equal(hostFallbackAllowed({ mode: "remote" }), false);
55
+ assert.equal(hostFallbackAllowed({ mode: "hybrid" }), true);
56
+ assert.equal(hostFallbackAllowed({ mode: "remote", hostFallback: true }), true);
57
+ assert.equal(hostFallbackAllowed({ mode: "remote", fallbackLocal: true }), false);
58
+ });
59
+ it("#5746: a #5371 mechanical recovery with host_fallback false retries remotely, not on the host", async () => {
60
+ const calls = await goMech(false);
61
+ assert.ok(calls.length >= 2);
62
+ assert.ok(calls.every((w) => w !== "local"), JSON.stringify(calls));
63
+ });
64
+ it("#5746: with host fallback on the #5371 recovery still goes to the host", async () => {
65
+ const calls = await goMech(true);
66
+ assert.equal(calls[1], "local");
67
+ });
68
+ for (const [name, remoteCfg] of [
69
+ ["fallback_local with max_remote 0", { max: 0, fallbackLocal: true, offlineFallback: true, admit: () => ({ ok: true }), onBudget: "stop" }],
70
+ ["execution budget under on_budget local", { max: 2, admit: () => ({ ok: false, reason: "budget cap" }), onBudget: "local" }],
71
+ ]) {
72
+ it(`#5746: host_fallback false: ${name} never runs the lane on the host`, async () => {
73
+ const ac = new AbortController(), where = [];
74
+ const run = orchestrate({ issues: [5], parallel: 2, readBody: async () => "", pollMs: 5, signal: ac.signal,
75
+ remote: { isRemote: () => true, hostFallback: false, place: () => ({ where: "remote", reason: "mode remote" }), costPerMinute: 0, ...remoteCfg },
76
+ runOne: async (_n, _l, ctx = {}) => { where.push(ctx.placement?.where); return { terminalReason: "merged", pr: 1 }; } }).catch(() => {});
77
+ await new Promise((r) => setTimeout(r, 120));
78
+ ac.abort();
79
+ await Promise.race([run, new Promise((r) => setTimeout(r, 1000))]);
80
+ assert.ok(!where.includes("local"), JSON.stringify(where));
81
+ });
82
+ }
83
+ it("#5746: remote mode with nothing set ends a host-capability lane without a host re-placement", async () => {
84
+ const r = await go("env.capability_remote", { mode: "remote" });
85
+ assert.equal(r.calls.length, 1);
86
+ });
87
+ it("#5746: max_remote 0 holds the lane (no host run) and announces waiting", async () => {
88
+ const events = [], ac = new AbortController();
89
+ let ran = 0;
90
+ const run = orchestrate({ issues: [5], parallel: 2, readBody: async () => "", pollMs: 5, signal: ac.signal, decide: (d) => events.push(d.what),
91
+ remote: { max: 0, isRemote: () => true, hostFallback: false, place: () => ({ where: "remote", reason: "max_remote 0 (live override)", hold: true }), admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 },
92
+ runOne: async () => { ran++; return { terminalReason: "merged", pr: 1 }; } }).catch(() => {});
93
+ await new Promise((r) => setTimeout(r, 150));
94
+ ac.abort();
95
+ await Promise.race([run, new Promise((r) => setTimeout(r, 1000))]);
96
+ assert.equal(ran, 0);
97
+ assert.ok(events.some((w) => /waiting: max_remote 0/.test(w)), JSON.stringify(events));
98
+ });
41
99
  });
42
100
 
43
101
  // #5808: a lane's slow post-result work (teardown) is its postRun: the dependent starts at once, the batch still waits for it.
@@ -0,0 +1,37 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ // #5749: an env.validate_timeout recovery lane waits while the host is overloaded; other recoveries are unchanged.
4
+ import { describe, it } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { orchestrate } from "./orchestrate.mjs";
7
+
8
+ const harness = ({ script, overloadedUntil }) => {
9
+ let t = 1_000_000; const calls = [], decisions = [];
10
+ return orchestrate({ issues: [7], parallel: 1, readBody: async () => "", now: () => t, pollMs: 1000,
11
+ sleep: async (ms) => { t += Math.max(1, Number(ms) || 0); },
12
+ recovery: { maxAttempts: 1, mechanicalMaxAttempts: 3 },
13
+ overload: () => ({ overloaded: overloadedUntil > 0 && t >= 1_000_500 && t < overloadedUntil }), // the first admission precedes the load spike
14
+ runOne: async (n, _l, ctx = {}) => { calls.push({ recover: ctx.recover?.attempt ?? 0, at: t }); t += 1000; const k = calls.length - 1; return script[Math.min(k, script.length - 1)]; },
15
+ decide: (d) => decisions.push(d), onUpdate: () => {} }).then((rows) => ({ rows, calls, decisions, start: 1_000_000 }));
16
+ };
17
+ const TIMEOUT = { terminalReason: "needs-human", code: "env.validate_timeout", detail: "timed out", cost_usd: 1 };
18
+ const UNIMPL = { terminalReason: "needs-human", code: "conformance.unimplemented", detail: "V1 missing", cost_usd: 1 };
19
+ const MERGED = { terminalReason: "merged", pr: 1 };
20
+
21
+ describe("#5749 overload defers env.validate_timeout recovery", () => {
22
+ it("#5749 env.validate_timeout recovery waits while overloaded", async () => {
23
+ const o = await harness({ script: [TIMEOUT, MERGED], overloadedUntil: 1_000_000 + 60_000 });
24
+ assert.equal(o.calls.length, 2);
25
+ assert.ok(o.calls[1].at >= 1_000_000 + 60_000, `recovery started at +${o.calls[1].at - o.start} ms, before the overload cleared`);
26
+ assert.ok(o.decisions.some((d) => /deferred: the host is overloaded/.test(d.what)));
27
+ const n = await harness({ script: [TIMEOUT, MERGED], overloadedUntil: 0 });
28
+ assert.ok(n.calls[1].at < 1_000_000 + 10_000, "no overload: the recovery starts at once");
29
+ assert.ok(!n.decisions.some((d) => /overloaded/.test(d.what)));
30
+ });
31
+ it("#5749 conformance.unimplemented keeps resume counts under overload", async () => {
32
+ const o = await harness({ script: [UNIMPL, MERGED], overloadedUntil: 1_000_000 + 60_000 });
33
+ assert.equal(o.calls.length, 2);
34
+ assert.equal(o.calls[1].recover, 1, "the same single recovery attempt as before");
35
+ assert.ok(!o.decisions.some((d) => /overloaded/.test(d.what)));
36
+ });
37
+ });
@@ -3,7 +3,7 @@
3
3
  // #5975: a batch-level pause stops admission for every issue (dependency merge, engine/env re-admit, expiry), never a running lane.
4
4
  import { describe, it } from "node:test";
5
5
  import assert from "node:assert/strict";
6
- import { orchestrate } from "./orchestrate.mjs";
6
+ import { orchestrate, AUTH_PROBE_MS, AUTH_ESCALATE_MS, HOLD_RAMP_STEP_MS } from "./orchestrate.mjs";
7
7
 
8
8
  const memStore = () => { let st = null; return { load: () => (st ? JSON.parse(JSON.stringify(st)) : null), save: (s) => { st = JSON.parse(JSON.stringify(s)); }, log: () => {} }; };
9
9
  const EE = (detail) => ({ terminalReason: "engine-error", detail });
@@ -60,6 +60,58 @@ describe("#5975: batch pause", () => {
60
60
  });
61
61
  });
62
62
 
63
+ // #5988: a backend.auth outage is probed every 5 min, rotated, escalated once at 30 min; hold expiry is paced and warned at T-30.
64
+ describe("#5988: auth outage probe and hold expiry", () => {
65
+ const AUTH = { terminalReason: "deferred", code: "backend.auth", retryInSeconds: 56 * 3600, detail: "login failed" };
66
+ const rot = (cur = { n: 1 }) => ({ accounts: [{ n: 1 }, { n: 2 }], current: () => cur.n, headroom: (ex) => [1, 2].some((n) => !(ex instanceof Map ? ex : new Map()).has(n)), resumeAt: (ex) => Math.max(0, ...[...(ex ?? new Map()).values()]) || null, isAccount: () => true,
67
+ pick: ({ exclude } = {}) => { const ex = new Set([...(exclude instanceof Map ? exclude.keys() : exclude ?? [])].map(Number)); const a = [1, 2].find((n) => !ex.has(n)); return a ? { account: a } : { account: null }; }, markLimited: (n) => { cur.n = n === 1 ? 2 : 1; return true; } });
68
+
69
+ it("login failure recovering at 10 min resumes within 5 min on the next account first, no operator action", async () => {
70
+ const resumed = await (async () => {
71
+ const c = { t: 5_000_000 }, s0 = c.t, ps = [], rows = [];
72
+ const out = await orchestrate({ issues: [1], parallel: 1, pollMs: 1000, readBody: async () => "", trusted: () => true, now: () => c.t, store: memStore(), rotator: rot(),
73
+ sleep: async (ms) => { c.t += Math.max(1, Number(ms) || 0); }, recovery: { maxAttempts: 1, mechanicalMaxAttempts: 3 },
74
+ authProbe: async ({ account }) => { ps.push({ account, at: c.t - s0 }); return { ok: c.t - s0 >= 10 * 60000 }; },
75
+ runOne: async () => { c.t += 1000; return c.t - s0 < 10 * 60000 ? AUTH : MERGED; }, onUpdate: (x) => rows.push({ ...x, at: c.t - s0 }) });
76
+ return { out, ps, rows };
77
+ })();
78
+ assert.equal(resumed.out[0].outcome, "merged");
79
+ assert.ok(Number.isInteger(resumed.ps[0].account), "the probe runs on the next rotator account, picked before the lane retries");
80
+ const back = resumed.rows.find((x) => x.outcome === "merged");
81
+ assert.ok(back && back.at <= 10 * 60000 + AUTH_PROBE_MS + 5000, "resumed within one probe interval of the recovery");
82
+ assert.ok(!resumed.rows.some((x) => x.outcome === "auth-escalation"));
83
+ });
84
+
85
+ it("a 56 h outage pauses at most 30 min and escalates exactly once", async () => {
86
+ const c = { t: 9_000_000 }, s0 = c.t, rows = [], esc = []; let k = 0;
87
+ await orchestrate({ issues: [1], parallel: 1, pollMs: 1000, readBody: async () => "", trusted: () => true, now: () => c.t, store: memStore(), rotator: rot(),
88
+ sleep: async (ms) => { c.t += Math.max(1, Number(ms) || 0); }, recovery: { maxAttempts: 1, mechanicalMaxAttempts: 3 },
89
+ authProbe: async () => ({ ok: false }), onEscalate: async (e) => esc.push(e),
90
+ runOne: async () => { c.t += 1000; return ++k <= 12 ? AUTH : MERGED; }, onUpdate: (x) => rows.push({ ...x, at: c.t - s0 }) });
91
+ assert.equal(esc.length, 1);
92
+ assert.equal(rows.filter((x) => x.outcome === "auth-escalation").length, 1);
93
+ assert.ok(rows.find((x) => x.outcome === "auth-escalation").at <= AUTH_ESCALATE_MS + 2 * AUTH_PROBE_MS);
94
+ assert.ok(c.t - s0 < 3 * 3600_000, "never a multi-hour pause");
95
+ });
96
+
97
+ it("expiry of 100 holds is announced once at T-30 and released at the controller's pace, not all at once", async () => {
98
+ const issues = Array.from({ length: 100 }, (_, i) => i + 1), clock = { t: 2_000_000 };
99
+ let held = new Set(issues), live = 0, peak = 0; const starts = [], release = clock.t + 20 * 60000;
100
+ const info = Object.fromEntries(issues.map((n) => [n, { owner: "op", since: "x", expiresAt: new Date(clock.t + 20 * 60000).toISOString() }]));
101
+ const rows = [];
102
+ await orchestrate({ issues, parallel: 4, pollMs: 1000, readBody: async () => "", trusted: () => true, now: () => clock.t, store: memStore(),
103
+ sleep: async (ms) => { clock.t += Math.max(1, Number(ms) || 0); }, recovery: { maxAttempts: 1, mechanicalMaxAttempts: 3 },
104
+ getHeld: () => [...held], getHoldInfo: () => info,
105
+ expireHolds: () => { if (clock.t < Date.parse(info[1].expiresAt) || !held.size) return []; const due = [...held].map((n) => ({ issue: n, owner: "op", since: "x" })); held = new Set(); return due; },
106
+ runOne: async () => { live++; peak = Math.max(peak, live); starts.push({ live, since: clock.t - release }); clock.t += 1000; await Promise.resolve(); live--; return MERGED; }, onUpdate: (x) => rows.push(x) });
107
+ assert.equal(rows.filter((x) => x.outcome === "hold-alert").length, 100, "one T-30 alert per hold");
108
+ assert.ok(peak <= 4, `peak ${peak} never exceeds the controller's cap`);
109
+ const early = starts.filter((x) => x.since < HOLD_RAMP_STEP_MS);
110
+ assert.ok(early.length > 0 && early.every((x) => x.live === 1), "the first step after expiry admits one lane, not the parallel cap of 4");
111
+ assert.equal(rows.filter((x) => x.outcome === "merged").length, 100);
112
+ });
113
+ });
114
+
63
115
  describe("#6008: hold and pause cover deferred retries and kept sandboxes", () => {
64
116
  const CAP = { terminalReason: "deferred", code: "sandbox.capacity", retryInSeconds: 30, detail: "no sandbox capacity" };
65
117
  it("a sandbox.capacity-deferred issue is not dispatched while held, including when its timer fires", async () => {
@@ -36,6 +36,23 @@ describe("selector reconcile (R2, R13)", () => {
36
36
  const d = diffSelection({ open: [{ number: 5 }], members: [5, 7, 9], pending: [7, 9], running: new Set(), results: new Map(), matched: new Set([5, 7]) });
37
37
  assert.deepEqual(d, { join: [], leave: [7] });
38
38
  });
39
+ it("#6029 a selector-matched member closed during a resume's downtime leaves; unmatched pending members still run", async () => {
40
+ const saves = [];
41
+ const store = { load: () => ({ v: 1, order: [7, 9], pending: [7, 9], results: {}, selMatched: [7] }), save: (s) => saves.push(s), log: () => {} };
42
+ const ac = new AbortController();
43
+ let polls = 0;
44
+ const r = await harness({ issues: [], reconcile: { everyMs: 5000, list: async () => { if (++polls >= 3) ac.abort(); return [{ number: 9 }]; } }, extra: { store, signal: ac.signal } });
45
+ assert.deepEqual(r.calls, [9]);
46
+ assert.ok(r.rows.find((x) => x.issue === 7)?.outcome !== "merged");
47
+ assert.ok(saves.some((s) => Array.isArray(s.selMatched) && s.selMatched.includes(9)), "save() persists selMatched");
48
+ });
49
+ it("#6029 old state without selMatched restores an empty set: a closed pending member does not leave", async () => {
50
+ const store = { load: () => ({ v: 1, order: [7], pending: [7], results: {} }), save: () => {}, log: () => {} };
51
+ const ac = new AbortController();
52
+ let polls = 0;
53
+ const r = await harness({ issues: [], reconcile: { everyMs: 5000, list: async () => { if (++polls >= 3) ac.abort(); return []; } }, extra: { store, signal: ac.signal } });
54
+ assert.deepEqual(r.calls, [7]);
55
+ });
39
56
  it("a failed read leaves nothing (parseSelected null)", () => {
40
57
  assert.equal(parseSelected("not json"), null);
41
58
  assert.deepEqual(parseSelected('[{"number":3,"labels":[{"name":"x"}]}]'), [{ number: 3, labels: ["x"] }]);
@@ -0,0 +1,57 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ // #6081: relaunch, recovery and requeue honour holds and pauses like fresh admission; an operator-stopped held lane is a hold, not an engine-error.
4
+ import { describe, it } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { orchestrate } from "./orchestrate.mjs";
7
+
8
+ const memStore = () => { let st = null; return { load: () => (st ? JSON.parse(JSON.stringify(st)) : null), save: (s) => { st = JSON.parse(JSON.stringify(s)); }, log: () => {} }; };
9
+ const EE = (detail) => ({ terminalReason: "engine-error", detail });
10
+ const STOPPED = EE("lane pid 4242 exited without a result; see lanes/1.log");
11
+ const MERGED = { terminalReason: "merged", pr: 9 };
12
+ const REC = { owner: "op@h", since: "2026-01-01T00:00:00.000Z", expiresAt: null, reason: "host reserved", ownerPid: null, ownerHost: null };
13
+
14
+ const run = ({ script, issues = [1], store = memStore(), held = { v: [] }, pause = { v: null }, onStart = () => {}, extra = {}, clock = { t: 1_000_000 } }) => {
15
+ const calls = [], updates = [];
16
+ const p = orchestrate({ issues, parallel: 2, pollMs: 1000, readBody: async () => "", trusted: () => true, now: () => clock.t, store,
17
+ sleep: async (ms) => { clock.t += Math.max(1, Number(ms) || 0); },
18
+ getHeld: () => held.v, getPause: () => pause.v, recovery: { maxAttempts: 1, mechanicalMaxAttempts: 3 },
19
+ breaker: { errors: 2, window_min: 30 },
20
+ runOne: async (n) => { calls.push(n); clock.t += 1000; onStart(n); const l = script[n] ?? [MERGED]; return l[Math.min(calls.filter((c) => c === n).length - 1, l.length - 1)]; },
21
+ onUpdate: (r) => updates.push(r), ...extra });
22
+ return p.then((rows) => ({ rows, calls, updates, byIssue: Object.fromEntries(rows.map((r) => [r.issue, r])) }));
23
+ };
24
+
25
+ describe("#6081: relaunch gates", () => {
26
+ it("held while running, then engine-error: no relaunch until --release", async () => {
27
+ const store = memStore(), held = { v: [] };
28
+ const a = await run({ script: { 1: [EE("boom"), MERGED] }, store, held, onStart: (n) => { if (n === 1) held.v = [1]; } });
29
+ assert.deepEqual(a.calls, [1], "the relaunch waits for the release");
30
+ assert.equal(a.byIssue[1].outcome, "held");
31
+ held.v = [];
32
+ const b = await run({ script: { 1: [MERGED] }, store, held });
33
+ assert.deepEqual(b.calls, [1]);
34
+ assert.equal(b.byIssue[1].outcome, "merged");
35
+ });
36
+
37
+ it("a batch pause blocks the engine-error relaunch; the running lane still finishes", async () => {
38
+ const store = memStore(), pause = { v: null };
39
+ const a = await run({ script: { 1: [EE("boom"), MERGED] }, store, pause, onStart: (n) => { if (n === 1) pause.v = REC; } });
40
+ assert.deepEqual(a.calls, [1]);
41
+ assert.equal(a.byIssue[1].outcome, "held");
42
+ pause.v = null;
43
+ const b = await run({ script: { 1: [MERGED] }, store, pause });
44
+ assert.equal(b.byIssue[1].outcome, "merged");
45
+ });
46
+
47
+ it("an operator-stopped held lane is a hold row, not an engine-error, and never counts toward the breaker", async () => {
48
+ const held = { v: [] };
49
+ const r = await run({ issues: [1, 2, 3], script: { 1: [STOPPED], 2: [STOPPED], 3: [MERGED] }, held,
50
+ onStart: (n) => { if (n === 1 || n === 2) held.v = [1, 2]; } });
51
+ assert.ok(!r.updates.some((u) => u.outcome === "breaker"), "no breaker trip");
52
+ assert.ok(!r.updates.some((u) => u.outcome === "engine-error"), "no engine-error row");
53
+ assert.ok(r.updates.some((u) => u.issue === 1 && u.outcome === "hold" && /stopped/.test(u.detail)));
54
+ assert.equal(r.byIssue[1].outcome, "held");
55
+ assert.equal(r.byIssue[3].outcome, "merged");
56
+ });
57
+ });
@@ -56,6 +56,16 @@ describe("orchestrate stacking (#5831)", () => {
56
56
  await h.run();
57
57
  assert.deepEqual(h.updates.filter((u) => u.issue === 2).map((u) => u.outcome), ["plan-failed", "merged"]);
58
58
  });
59
+ for (const reason of ["invalid", "needs-human", "decomposed", "budget-exceeded"]) {
60
+ it(`plan (#5909): a ${reason} plan end settles the issue; no build lane, no plan-failed`, async () => {
61
+ const h = harness({ planResult: { terminalReason: reason, detail: "verdict" } });
62
+ await h.run();
63
+ assert.equal(h.calls.filter((c) => c.n === 2 && !c.ctx.plan).length, 0, "no build lane");
64
+ const outs = h.updates.filter((u) => u.issue === 2).map((u) => u.outcome);
65
+ assert.equal(outs.includes("plan-failed"), false);
66
+ assert.equal(outs.at(-1), reason);
67
+ });
68
+ }
59
69
  it("plan: planned/planTried are persisted for --resume", async () => {
60
70
  let saved = null;
61
71
  const store = { load: () => null, save: (s) => { if (s.planTried) saved = s; }, log: () => {} };