forgedock 1.63.0 → 1.65.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 (89) hide show
  1. package/bin/config-schema.mjs +3 -0
  2. package/bin/engine/outcome-codes.mjs +5 -0
  3. package/bin/engine-cli.mjs +88 -12
  4. package/bin/env/cli.mjs +18 -1
  5. package/bin/lean/basered.mjs +56 -11
  6. package/bin/lean/basered.test.mjs +58 -5
  7. package/bin/lean/batch-health.mjs +46 -4
  8. package/bin/lean/batch-health.test.mjs +55 -1
  9. package/bin/lean/batch.mjs +8 -1
  10. package/bin/lean/batch.test.mjs +71 -6
  11. package/bin/lean/ceiling.mjs +47 -3
  12. package/bin/lean/ceiling.test.mjs +32 -1
  13. package/bin/lean/clear-breaker.mjs +15 -0
  14. package/bin/lean/clear-breaker.test.mjs +100 -0
  15. package/bin/lean/conformance.e2e.test.mjs +32 -6
  16. package/bin/lean/conformance.mjs +57 -13
  17. package/bin/lean/conformance.test.mjs +93 -1
  18. package/bin/lean/execution.mjs +18 -8
  19. package/bin/lean/execution.test.mjs +44 -3
  20. package/bin/lean/issuewatch-reconcile.mjs +2 -0
  21. package/bin/lean/issuewatch-reconcile.test.mjs +25 -0
  22. package/bin/lean/issuewatch.mjs +3 -0
  23. package/bin/lean/lanecheck.test.mjs +13 -1
  24. package/bin/lean/lean.mjs +157 -28
  25. package/bin/lean/lean.test.mjs +289 -21
  26. package/bin/lean/live-execution.mjs +25 -0
  27. package/bin/lean/live-execution.test.mjs +35 -1
  28. package/bin/lean/merged-park.mjs +76 -0
  29. package/bin/lean/merged-park.test.mjs +64 -0
  30. package/bin/lean/mergetrain.mjs +357 -0
  31. package/bin/lean/mergetrain.test.mjs +348 -0
  32. package/bin/lean/mirror-bundle.mjs +84 -0
  33. package/bin/lean/orchestrate-envhold.test.mjs +62 -0
  34. package/bin/lean/orchestrate-stacking.test.mjs +23 -1
  35. package/bin/lean/orchestrate-train.test.mjs +130 -0
  36. package/bin/lean/orchestrate-transient-git.test.mjs +53 -0
  37. package/bin/lean/orchestrate.mjs +170 -13
  38. package/bin/lean/prompts.mjs +4 -3
  39. package/bin/lean/release-review.mjs +8 -1
  40. package/bin/lean/release-review.test.mjs +42 -2
  41. package/bin/lean/release-status.test.mjs +53 -1
  42. package/bin/lean/release.mjs +6 -3
  43. package/bin/lean/render.mjs +6 -1
  44. package/bin/lean/sandbox-provider.contract.test.mjs +6 -0
  45. package/bin/lean/sandbox-remote.mjs +43 -3
  46. package/bin/lean/sched.mjs +19 -2
  47. package/bin/lean/sched.test.mjs +33 -1
  48. package/bin/lean/schedd-health.mjs +2 -1
  49. package/bin/lean/schedd-health.test.mjs +7 -0
  50. package/bin/lean/schedd.mjs +58 -7
  51. package/bin/lean/schedd.test.mjs +78 -1
  52. package/bin/lean/stacking.mjs +45 -0
  53. package/bin/lean/stacking.test.mjs +25 -1
  54. package/bin/lean/statuscomment.mjs +14 -8
  55. package/bin/lean/statuscomment.test.mjs +18 -1
  56. package/bin/lean/validate-catalog.mjs +1 -1
  57. package/bin/lean/validate-catalog.test.mjs +3 -0
  58. package/bin/lean/worktree.mjs +8 -3
  59. package/bin/lean/worktree.test.mjs +18 -0
  60. package/bin/pool/agent.mjs +309 -33
  61. package/bin/pool/cache-sweep.mjs +4 -2
  62. package/bin/pool/cli.mjs +125 -6
  63. package/bin/pool/disk.mjs +43 -0
  64. package/bin/pool/docker.mjs +11 -0
  65. package/bin/pool/health.mjs +95 -0
  66. package/bin/pool/mirror-seed.mjs +103 -0
  67. package/bin/pool/router.mjs +301 -27
  68. package/bin/runner.mjs +3 -1
  69. package/bin/stats/chains.mjs +101 -0
  70. package/bin/stats/chains.test.mjs +53 -0
  71. package/bin/stats/efficiency.mjs +7 -6
  72. package/bin/stats/efficiency.test.mjs +48 -7
  73. package/bin/stats/index.mjs +11 -3
  74. package/bin/stats/stats.test.mjs +9 -0
  75. package/docs/CONFIG.md +8 -1
  76. package/docs/OUTCOME-CODES.md +4 -0
  77. package/package.json +1 -1
  78. package/pool/README.md +10 -0
  79. package/pool/image/Dockerfile +2 -1
  80. package/pool/image/entrypoint.sh +25 -6
  81. package/pool/image/mirror.sh +71 -0
  82. package/pool/install/install-agent-linux.sh +57 -5
  83. package/pool/install/install-agent-macos.sh +148 -0
  84. package/pool/install/install-agent.ps1 +11 -0
  85. package/pool/install/install-agent.sh +59 -7
  86. package/pool/install/uninstall-agent-linux.sh +75 -0
  87. package/pool/install/uninstall-agent-macos.sh +60 -0
  88. package/pool/install/uninstall-agent.ps1 +1 -0
  89. package/scripts/transition-label.sh +11 -0
@@ -9,7 +9,7 @@ import { join } from "node:path";
9
9
  import { tmpDir } from "../tests/_tmp.mjs";
10
10
  import { openBatch, isLaneAlive, listBatches, SECRET_ENV, scanStats } from "./batch.mjs";
11
11
  import { killTrackedChildren, runWithInput, trackedChildCount } from "./effects.mjs";
12
- import { findUnhosted, startDaemon, scheddPaths, connectDaemon, request, unitState, SCHEDD_SCRIPT, mergeEnv, batchEnv, droppedEnv, sanitizePath, redactEnv, exitOnSignals, readInstalledVersion } from "./schedd.mjs";
12
+ import { findUnhosted, startDaemon, scheddPaths, connectDaemon, request, unitState, SCHEDD_SCRIPT, mergeEnv, batchEnv, droppedEnv, sanitizePath, redactEnv, exitOnSignals, readInstalledVersion, batchVerdicts } from "./schedd.mjs";
13
13
  import { schedDir } from "./sched.mjs";
14
14
  import { readHeartbeat } from "./schedd-health.mjs";
15
15
  import { formatTable, orchestrate } from "./orchestrate.mjs";
@@ -149,6 +149,61 @@ describe("schedd host scheduler (#4192)", () => {
149
149
  } finally { await h.cleanup(); }
150
150
  });
151
151
 
152
+ it("#5964 a hosted clear-breaker not acked within its wait answers pending, and the request is still honoured by the runner (never dropped)", async () => {
153
+ const h = host();
154
+ try {
155
+ await h.daemon();
156
+ const all = capture(() => h.inWork(() => orchestrateFromCli(["1", "2", "--parallel", "1", "--repo", "o/r", "--no-prefilter"], h.client)));
157
+ await until(() => h.launched().length === 1 && h.lanePids().length === 1);
158
+ const [id] = listBatches(h.root);
159
+ const b = openBatch(h.root, id);
160
+ // a 1 ms wait only polls the ack once, so the reply is pending unless the runner happened to ack in that instant: retry until it does not
161
+ let r = null;
162
+ for (let i = 0; i < 40 && !r?.pending; i++) r = await request(await connectDaemon({ dir: h.sched, spawnDaemon: null }), { op: "clear-breaker", id, waitMs: 1 }, undefined, { timeoutMs: 20000 });
163
+ assert.deepEqual({ hosted: r.hosted, acknowledged: r.acknowledged, pending: r.pending }, { hosted: true, acknowledged: false, pending: true });
164
+ // the old code deleted the request here and rewrote state.json, so no ack would ever follow
165
+ await until(() => b.readClearBreakerAck() && !existsSync(join(h.root, id, "clear-breaker")));
166
+ writeFileSync(h.release, "");
167
+ await all;
168
+ } finally { await h.cleanup(); }
169
+ });
170
+
171
+ it("#5964 cli prints pending message when the hosted runner has not acked within its wait", async () => {
172
+ const h = host();
173
+ try {
174
+ await h.daemon();
175
+ const all = capture(() => h.inWork(() => orchestrateFromCli(["1", "2", "--parallel", "1", "--repo", "o/r", "--no-prefilter"], h.client)));
176
+ await until(() => h.launched().length === 1 && h.lanePids().length === 1);
177
+ const [id] = listBatches(h.root);
178
+ const lines = []; let r = null;
179
+ for (let i = 0; i < 40 && !r?.pending; i++) { lines.length = 0; r = await runBatch({ argv: ["--clear-breaker", id], deps: { batchRoot: h.root, scheddDir: h.sched, pollMs: 1 }, sink: { line: (l) => lines.push(l) } }); }
180
+ assert.equal(r.pending, true);
181
+ assert.match(lines[0], /pending: the runner will clear it on its next pass/);
182
+ assert.doesNotMatch(lines[0], /did not acknowledge/);
183
+ writeFileSync(h.release, "");
184
+ await all;
185
+ } finally { await h.cleanup(); }
186
+ });
187
+
188
+ it("#5947 clear-breaker on a hosted batch reaches the live runner, which acknowledges it (no daemon restart)", async () => {
189
+ const h = host();
190
+ try {
191
+ const d = await h.daemon();
192
+ const all = capture(() => h.inWork(() => orchestrateFromCli(["1", "2", "--parallel", "1", "--repo", "o/r", "--no-prefilter"], h.client)));
193
+ await until(() => h.launched().length === 1 && h.lanePids().length === 1);
194
+ const [id] = listBatches(h.root);
195
+ const r = await request(await connectDaemon({ dir: h.sched, spawnDaemon: null }), { op: "clear-breaker", id }, undefined, { timeoutMs: 20000 });
196
+ assert.equal(r.type, "ok");
197
+ assert.equal(r.hosted, true);
198
+ assert.equal(r.acknowledged, true, "the hosted runner consumed the request and acked");
199
+ assert.equal(openBatch(h.root, id).readClearBreakerAck().cleared, false, "no breaker was tripped");
200
+ assert.equal(existsSync(join(h.root, id, "clear-breaker")), false, "the request file is consumed");
201
+ assert.equal((await request(await connectDaemon({ dir: h.sched, spawnDaemon: null }), { op: "status" })).pid, d.pid, "same daemon");
202
+ writeFileSync(h.release, "");
203
+ await all;
204
+ } finally { await h.cleanup(); }
205
+ });
206
+
152
207
  it("a client that disconnects does not stop the batch; --resume reattaches, and replays the report once done", async () => {
153
208
  const h = host(); h.enter(); // admission off: this test needs >1 concurrent local lane on any host
154
209
  try {
@@ -486,6 +541,28 @@ await orchestrateFromCli(["1", "2", "--parallel", "2", "--repo", "o/r", "--no-pr
486
541
  } finally { await d.close(); }
487
542
  });
488
543
 
544
+ it("#5938: a stored stall clears within one tick (STALL CLEARED) once the batch is at K; status shows running/K and the split; the watchdog verdict is healthy", async () => {
545
+ const dir = tmpDir("schedd-stall-clear-"), root = join(dir, "batches"), id = "b20261122-000000-5938", lines = [];
546
+ const b = openBatch(root, id);
547
+ b.writePlan({ daemon: true, repo: "o/r", created: new Date(Date.now() - 90 * 60000).toISOString() });
548
+ b.store.save({ v: 1, order: [1, 2, 3], results: {}, running: {}, pending: [1, 2, 3], parallel: 2 });
549
+ const old = new Date(Date.now() - 30 * 60000);
550
+ utimesSync(join(b.dir, "state.json"), old, old);
551
+ assert.match(batchVerdicts(root, { windowMin: 10 })[0], /stalled/);
552
+ writeFileSync(join(b.dir, "health.json"), JSON.stringify({ stall: { at: new Date().toISOString(), sig: "1,2,3", detail: "old" } }) + "\n");
553
+ b.store.save({ v: 1, order: [1, 2, 3], results: {}, running: { 1: { startedAt: 1 }, 2: { startedAt: 1, remote: true } }, pending: [1, 2, 3], parallel: 2 });
554
+ utimesSync(join(b.dir, "state.json"), old, old);
555
+ const runBatch = async ({ sink }) => { sink.batch({ id, dir: b.dir }); return await new Promise(() => {}); };
556
+ const d = await startDaemon({ dir, root, runBatch, log: (m) => lines.push(m), resumeOnStart: true, stallCheckMs: 50, stallMin: 10 });
557
+ try {
558
+ await until(() => !readFileSync(join(b.dir, "health.json"), "utf8").includes("stall\""), 8000);
559
+ assert.match(readFileSync(join(b.dir, "batch.log"), "utf8"), /STALL CLEARED/);
560
+ assert.equal(batchVerdicts(root, { windowMin: 10 })[0], `batch ${id}: healthy`);
561
+ const st = await request(await connectDaemon({ dir, spawnDaemon: null }), { op: "status" });
562
+ assert.deepEqual(st.batches.find((x) => x.id === id).lanes, { running: 2, k: 2, local: 1, remote: 1 });
563
+ } finally { await d.close(); }
564
+ });
565
+
489
566
  it("#5806: a hosted runner wedged in setup restarts the daemon once (decision logged); the same stall again alerts and never loops", async () => {
490
567
  const dir = tmpDir("schedd-stall-setup-"), root = join(dir, "batches"), id = "b20261121-000000-5806";
491
568
  const b = openBatch(root, id);
@@ -93,3 +93,48 @@ export function stackedBaseBlock({ prBase, lane, stackedBranch = null, dependenc
93
93
  if (prBase !== lane) return `merge.stacked_base: PR base ${prBase || "?"} is not the lane ${lane}`;
94
94
  return null;
95
95
  }
96
+
97
+ /** #5833 (phase 3): cascade kinds recorded on a stacked dependent's row (`cascade`, `cascades`). */
98
+ export const CASCADES = ["rebase", "reverify", "restart", "replan"];
99
+
100
+ /**
101
+ * Which cascade a stacked dependent needs now, or null (nothing moved). `depState`: open | merged | closed (closed = ended without a merge).
102
+ * merged -> rebase onto the lane; closed -> replan on the lane base; open with a moved head -> reverify (clean rebase) or restart (conflict).
103
+ * @param {{depState:string, depHeadSha?:string|null, stackedSha?:string|null, rebaseConflict?:boolean}} a
104
+ */
105
+ export function cascadeDecision({ depState, depHeadSha = null, stackedSha = null, rebaseConflict = false }) {
106
+ if (depState === "merged") return "rebase";
107
+ if (depState === "closed") return "replan";
108
+ if (depState !== "open" || !depHeadSha || !stackedSha || depHeadSha === stackedSha) return null;
109
+ return rebaseConflict ? "restart" : "reverify";
110
+ }
111
+
112
+ /**
113
+ * The checks the dependency's final diff invalidates: a command naming a path (token with `/`) is kept when a changed path equals it or
114
+ * lies under it (or it lies under the changed path); a command naming no path cannot be scoped and is always kept.
115
+ * @param {{changedPaths:string[], checks:string[]}} a
116
+ */
117
+ export function invalidatedChecks({ changedPaths = [], checks = [] }) {
118
+ const norm = (t) => t.replace(/^["']|["']$/g, "").replace(/^\.\//, "").replace(/\/+$/, "");
119
+ return checks.filter((c) => {
120
+ const toks = String(c).split(/\s+/).map(norm).filter((t) => t.includes("/") && !t.startsWith("-") && !/^[a-z]+:\/\//.test(t));
121
+ if (!toks.length) return true;
122
+ return toks.some((t) => changedPaths.some((p) => p === t || p.startsWith(`${t}/`) || t.startsWith(`${p}/`)));
123
+ });
124
+ }
125
+
126
+ /** Batch-report metric: cascades per stacked dependent and the cost of the rework (rows carry `stacked`, `cascades`, `cascade_cost_usd`, `cascade_minutes`). */
127
+ export function cascadeRate(rows = []) {
128
+ const st = rows.filter((r) => r?.stacked);
129
+ const list = st.map((r) => (Array.isArray(r.cascades) ? r.cascades : r.cascade ? [r.cascade] : []));
130
+ const cascades = list.reduce((s, l) => s + l.length, 0);
131
+ const round = (x, k) => Math.round(x * k) / k;
132
+ return { stacked: st.length, cascades, perStacked: st.length ? round(cascades / st.length, 100) : 0,
133
+ reworkCostUsd: round(st.reduce((s, r) => s + (Number(r.cascade_cost_usd) || 0), 0), 1e6), reworkMinutes: round(st.reduce((s, r) => s + (Number(r.cascade_minutes) || 0), 0), 10) };
134
+ }
135
+
136
+ /** One report line, or null when nothing was stacked. */
137
+ export function formatCascadeSummary(rows) {
138
+ const m = cascadeRate(rows);
139
+ return m.stacked ? `stacked lanes: ${m.stacked} dependent(s), ${m.cascades} cascade(s) (${m.perStacked}/dependent), rework $${m.reworkCostUsd.toFixed(2)} / ${m.reworkMinutes} min` : null;
140
+ }
@@ -3,7 +3,7 @@
3
3
  // #5831: stacked lanes phase 1 — the pure helpers.
4
4
  import { describe, it } from "node:test";
5
5
  import assert from "node:assert/strict";
6
- import { normalizeStacking, planAdmissible, formatPlanned, parsePlanned, planStale, stackAdmissible, formatStackedOn, parseStackedOn, validStackedOn, stackedBaseBlock } from "./stacking.mjs";
6
+ import { normalizeStacking, planAdmissible, formatPlanned, parsePlanned, planStale, stackAdmissible, formatStackedOn, parseStackedOn, validStackedOn, stackedBaseBlock, cascadeDecision, invalidatedChecks, cascadeRate, formatCascadeSummary, CASCADES } from "./stacking.mjs";
7
7
 
8
8
  const SAT = new Set(["merged", "invalid"]);
9
9
  const base = { n: 2, edges: [1], results: new Map(), pending: [1, 2], running: new Map(), planTried: new Set(), satisfied: SAT };
@@ -72,3 +72,27 @@ describe("stacked builds, phase 2 (#5832)", () => {
72
72
  assert.equal(stackedBaseBlock({ prBase: "staging", lane: "staging", dependencyMerged: false }), null, "not stacked");
73
73
  });
74
74
  });
75
+
76
+ describe("cascades (#5833)", () => {
77
+ it("cascadeDecision: merged -> rebase, closed -> replan, moved head -> reverify or restart on a conflict, nothing moved -> null", () => {
78
+ assert.equal(cascadeDecision({ depState: "merged" }), "rebase");
79
+ assert.equal(cascadeDecision({ depState: "closed" }), "replan");
80
+ assert.equal(cascadeDecision({ depState: "open", depHeadSha: "b", stackedSha: "a" }), "reverify");
81
+ assert.equal(cascadeDecision({ depState: "open", depHeadSha: "b", stackedSha: "a", rebaseConflict: true }), "restart");
82
+ assert.equal(cascadeDecision({ depState: "open", depHeadSha: "a", stackedSha: "a" }), null);
83
+ assert.equal(cascadeDecision({ depState: "unknown", depHeadSha: "b", stackedSha: "a" }), null);
84
+ assert.deepEqual(CASCADES, ["rebase", "reverify", "restart", "replan"]);
85
+ });
86
+ it("invalidatedChecks keeps path-scoped checks the diff touches and every unscoped check", () => {
87
+ const checks = ["node --test bin/lean/stacking.test.mjs", "node --test docs/x.test.mjs", "pnpm lint", "eslint src/"];
88
+ assert.deepEqual(invalidatedChecks({ changedPaths: ["bin/lean/stacking.mjs", "src/a.ts"], checks }), ["pnpm lint", "eslint src/"]);
89
+ assert.deepEqual(invalidatedChecks({ changedPaths: ["bin/lean/stacking.test.mjs"], checks }), ["node --test bin/lean/stacking.test.mjs", "pnpm lint", "eslint src/"]);
90
+ assert.deepEqual(invalidatedChecks({ changedPaths: [], checks }), ["pnpm lint", "eslint src/"]);
91
+ });
92
+ it("cascadeRate: cascades per stacked dependent and the rework cost; non-stacked rows are ignored", () => {
93
+ const rows = [{ issue: 1, outcome: "merged" }, { issue: 2, stacked: true, cascades: ["reverify", "rebase"], cascade_cost_usd: 0.5, cascade_minutes: 3 }, { issue: 3, stacked: true }];
94
+ assert.deepEqual(cascadeRate(rows), { stacked: 2, cascades: 2, perStacked: 1, reworkCostUsd: 0.5, reworkMinutes: 3 });
95
+ assert.equal(formatCascadeSummary([{ issue: 1 }]), null);
96
+ assert.match(formatCascadeSummary(rows), /2 dependent\(s\), 2 cascade\(s\)/);
97
+ });
98
+ });
@@ -155,14 +155,20 @@ export const isPipelineLabel = (name) => { const n = String(name ?? ""); return
155
155
  export const pipelineLabels = (labels) => (labels ?? []).map((l) => (typeof l === "string" ? l : l?.name)).filter(isPipelineLabel);
156
156
 
157
157
  /**
158
- * Remove the pipeline labels from an issue. `labels` is what the caller already read (names or `{name}`); null re-reads them.
159
- * Best effort, returns the removed names ([] when none or on failure).
158
+ * Remove the pipeline labels from an issue, one call per label so one failing removal leaves the others removed (#5759).
159
+ * `labels` is what the caller already read (names or `{name}`); null re-reads them. Returns the removed names; `onFail(names, err)`
160
+ * receives the labels whose removal (or the re-read, names []) failed.
160
161
  */
161
- export async function clearPipelineLabels({ gh, repo, issue, labels = null }) {
162
+ export async function clearPipelineLabels({ gh, repo, issue, labels = null, onFail = null }) {
163
+ const removed = [], failed = [];
164
+ let names;
162
165
  try {
163
- const names = pipelineLabels(labels ?? JSON.parse(String(await gh(["issue", "view", String(issue), "-R", repo, "--json", "labels"])))?.labels);
164
- if (!names.length) return [];
165
- await gh(["issue", "edit", String(issue), "-R", repo, "--remove-label", names.join(",")]);
166
- return names;
167
- } catch { return []; }
166
+ names = pipelineLabels(labels ?? JSON.parse(String(await gh(["issue", "view", String(issue), "-R", repo, "--json", "labels"])))?.labels);
167
+ } catch (e) { try { onFail?.([], e); } catch { /* reporting is best effort */ } return []; }
168
+ let last = null;
169
+ for (const name of names) {
170
+ try { await gh(["issue", "edit", String(issue), "-R", repo, "--remove-label", name]); removed.push(name); } catch (e) { failed.push(name); last = e; }
171
+ }
172
+ if (failed.length) { try { onFail?.(failed, last); } catch { /* reporting is best effort */ } }
173
+ return removed;
168
174
  }
@@ -124,10 +124,27 @@ describe("#5592 gh helpers", () => {
124
124
  assert.deepEqual(pipelineLabels([{ name: "bug" }, "needs-human", { name: "parked:x" }]), ["needs-human", "parked:x"]);
125
125
  const log = [];
126
126
  assert.deepEqual(await clearPipelineLabels({ gh: ghWith([], log), repo: "o/r", issue: 7 }), ["parked:ci.red", "needs-human"]);
127
- assert.deepEqual(log.at(-1), ["issue", "edit", "7", "-R", "o/r", "--remove-label", "parked:ci.red,needs-human"]);
127
+ assert.deepEqual(log.slice(-2), [["issue", "edit", "7", "-R", "o/r", "--remove-label", "parked:ci.red"], ["issue", "edit", "7", "-R", "o/r", "--remove-label", "needs-human"]]);
128
128
  const log2 = [];
129
129
  assert.deepEqual(await clearPipelineLabels({ gh: ghWith([], log2), repo: "o/r", issue: 7, labels: [{ name: "bug" }] }), []);
130
130
  assert.equal(log2.length, 0, "nothing to remove: no gh call");
131
131
  assert.deepEqual(await clearPipelineLabels({ gh: async () => { throw new Error("boom"); }, repo: "o/r", issue: 7, labels: ["needs-human"] }), [], "best effort");
132
132
  });
133
+ it("clearPipelineLabels removes the rest when one removal fails and reports it", async () => {
134
+ const edits = [];
135
+ const gh = async (a) => { if (a[1] === "edit") { if (a.at(-1) === "remediation-queue") throw new Error("not found"); edits.push(a.at(-1)); } return ""; };
136
+ const reported = [];
137
+ const out = await clearPipelineLabels({ gh, repo: "o/r", issue: 7, labels: ["needs-human:external", "remediation-queue", "parked:x"], onFail: (n) => reported.push(...n) });
138
+ assert.deepEqual(out, ["needs-human:external", "parked:x"]);
139
+ assert.deepEqual(edits, ["needs-human:external", "parked:x"]);
140
+ assert.deepEqual(reported, ["remediation-queue"]);
141
+ });
142
+ it("clearPipelineLabels reports failed removals to the reporter", async () => {
143
+ const seen = [];
144
+ await clearPipelineLabels({ gh: async () => { throw new Error("boom"); }, repo: "o/r", issue: 7, labels: ["needs-human"], onFail: (n, e) => seen.push([n, e.message]) });
145
+ assert.deepEqual(seen, [[["needs-human"], "boom"]]);
146
+ const read = [];
147
+ await clearPipelineLabels({ gh: async () => { throw new Error("read"); }, repo: "o/r", issue: 7, onFail: (n) => read.push(n) });
148
+ assert.deepEqual(read, [[]]);
149
+ });
133
150
  });
@@ -91,7 +91,7 @@ export function equivalentRuns(frozen, sub) {
91
91
  return a.size > 0 && a.size === b.size && [...a].every(([id, ok]) => ok && b.get(id) === true);
92
92
  }
93
93
 
94
- const DRIFT_RE = /(?:generated|artifact|snapshot)s?\b[^\n]*\b(?:out of date|out-of-date|stale|differ|drift|not up to date)|\b(?:out of date|stale)\b[^\n]*\b(?:generated|regenerate)|run [`'"]?[^\n]*\bgenerate[\w:-]*[`'"]? to (?:update|regenerate)/i;
94
+ const DRIFT_RE = /(?:generated|artifact|snapshot)s?\b[^\n]*\b(?:out of date|out-of-date|stale|differ|drift|not up to date)|\b(?:out of date|stale)\b[^\n]*\b(?:generated|regenerate)|run [`'"]?[^\n]*\bgenerate[\w:-]*[`'"]? to (?:update|regenerate)|\bmissing or out[ -]of[ -]date\b|\brun [`'"]?[^\n)]*--(?:render|write|update)\b/i; // #5730: "missing or out of date (run --render-agent-md)"
95
95
  /** True when a validate failure's output reads as a stale generated artifact (a regenerate case), not a failing test. */
96
96
  export const isDriftFailure = (output) => DRIFT_RE.test(String(output ?? ""));
97
97
 
@@ -38,6 +38,9 @@ describe("#5653 validate catalogue", () => {
38
38
  it("classifies a stale generated artifact, not a test failure", () => {
39
39
  assert.equal(isDriftFailure("error: generated tools file is out of date"), true);
40
40
  assert.equal(isDriftFailure("AssertionError: 1 != 2"), false);
41
+ // 5730: the AlterLab #40841 line
42
+ assert.equal(isDriftFailure("listings/official/maps/agent.md: missing or out of date (run --render-agent-md --render-page)"), true);
43
+ assert.equal(isDriftFailure("AssertionError: expected 3, got 4"), false);
41
44
  });
42
45
  });
43
46
 
@@ -39,6 +39,11 @@ export function sparsePatterns(excludes) {
39
39
  return ["/*", ...excludes.map((p) => `!/${esc(p)}`)];
40
40
  }
41
41
 
42
+ /** forge#5890: a git spawn failure (missing cwd/binary, no exit status), as opposed to a git exit failure. */
43
+ export const isSpawnError = (e) => (e?.code === "ENOENT" || e?.code === "EACCES") && String(e?.syscall ?? "").startsWith("spawn") && typeof e?.status !== "number";
44
+ /** forge#5890: tag a spawn error with the typed deferral (sandbox.repo_missing, requeued); returns the same error. */
45
+ export const repoMissing = (e) => Object.assign(e, { deferCode: "sandbox.repo_missing", deferDetail: `lane repo directory is missing or git cannot run there (${e.code} ${e.syscall}); the lane is requeued`, retryInSeconds: 120 });
46
+
42
47
  /**
43
48
  * Add a lane worktree, sparse when the plan is non-empty. `git(args, {cwd})` is the injected io.git; `write(path, text)`
44
49
  * writes the pattern file (argv-safe for any number of patterns). `addArgs` is the plain `["worktree","add",...]` argv.
@@ -47,13 +52,13 @@ export function sparsePatterns(excludes) {
47
52
  export async function addLaneWorktree(git, write, { cwd, wt, addArgs, ref, maxBlobBytes = DEFAULT_SPARSE_MAX_KB * 1024 }) {
48
53
  let plan = { excludes: [], bytes: 0 };
49
54
  if (maxBlobBytes > 0 && typeof write === "function") {
50
- try { plan = sparsePlan(await git(["ls-tree", "-r", "-l", "-z", ref], { cwd }), { maxBlobBytes }); } catch { /* no plan: full checkout */ }
55
+ try { plan = sparsePlan(await git(["ls-tree", "-r", "-l", "-z", ref], { cwd }), { maxBlobBytes }); } catch (e) { if (isSpawnError(e)) throw repoMissing(e); /* no plan: full checkout */ }
51
56
  }
52
57
  if (!plan.excludes.length) {
53
- await git(addArgs, { cwd });
58
+ try { await git(addArgs, { cwd }); } catch (e) { throw isSpawnError(e) ? repoMissing(e) : e; }
54
59
  return { sparse: false, excluded: 0, bytes: 0 };
55
60
  }
56
- await git([...addArgs.slice(0, 2), "--no-checkout", ...addArgs.slice(2)], { cwd });
61
+ try { await git([...addArgs.slice(0, 2), "--no-checkout", ...addArgs.slice(2)], { cwd }); } catch (e) { throw isSpawnError(e) ? repoMissing(e) : e; }
57
62
  const g = (a) => git(a, { cwd: wt });
58
63
  try {
59
64
  await g(["sparse-checkout", "set", "--no-cone", "/*"]);
@@ -149,4 +149,22 @@ describe("sparse pattern file path on Windows (#5825)", () => {
149
149
  assert.equal(r.sparse, true);
150
150
  assert.deepEqual(wrote, ["C:/r/.git/worktrees/lean-5/info/sparse-checkout"]);
151
151
  });
152
+
153
+ // forge#5890
154
+ it("5890: a spawn ENOENT on ls-tree raises the typed sandbox.repo_missing error and never reaches worktree add", async () => {
155
+ const calls = [];
156
+ const fake = async (a) => { calls.push(a[0]); throw Object.assign(new Error("spawn git ENOENT"), { code: "ENOENT", syscall: "spawn git" }); };
157
+ await assert.rejects(addLaneWorktree(fake, async () => {}, { cwd: "/gone", wt: "/gone/wt", addArgs: ["worktree", "add", "/gone/wt", "main"], ref: "main" }),
158
+ (e) => e.deferCode === "sandbox.repo_missing" && e.retryInSeconds === 120 && !!e.deferDetail);
159
+ assert.deepEqual(calls, ["ls-tree"]);
160
+ });
161
+ it("5890: a non-spawn ls-tree failure still falls back to a full checkout; a spawn error from worktree add is typed", async () => {
162
+ const calls = [];
163
+ const fake = async (a) => { calls.push(a[0]); if (a[0] === "ls-tree") throw Object.assign(new Error("fatal"), { status: 128 }); return ""; };
164
+ const r = await addLaneWorktree(fake, async () => {}, { cwd: "/r", wt: "/r/wt", addArgs: ["worktree", "add", "/r/wt", "main"], ref: "main" });
165
+ assert.equal(r.sparse, false);
166
+ assert.deepEqual(calls, ["ls-tree", "worktree"]);
167
+ const bad = async () => { throw Object.assign(new Error("spawn git EACCES"), { code: "EACCES", syscall: "spawn git" }); };
168
+ await assert.rejects(addLaneWorktree(bad, null, { cwd: "/r", wt: "/r/wt", addArgs: ["worktree", "add", "/r/wt", "main"], ref: "main" }), (e) => e.deferCode === "sandbox.repo_missing");
169
+ });
152
170
  });