forgedock 1.62.0 → 1.64.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 (87) hide show
  1. package/bin/config-schema.mjs +5 -0
  2. package/bin/engine/outcome-codes.mjs +5 -0
  3. package/bin/engine-cli.mjs +109 -21
  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 +9 -1
  10. package/bin/lean/batch.test.mjs +74 -7
  11. package/bin/lean/ceiling.mjs +47 -3
  12. package/bin/lean/ceiling.test.mjs +32 -1
  13. package/bin/lean/conformance.e2e.test.mjs +32 -6
  14. package/bin/lean/conformance.mjs +57 -13
  15. package/bin/lean/conformance.test.mjs +93 -1
  16. package/bin/lean/execution.mjs +24 -12
  17. package/bin/lean/execution.test.mjs +59 -9
  18. package/bin/lean/forgedock-lane-workflow.test.mjs +62 -2
  19. package/bin/lean/issuewatch-reconcile.mjs +2 -0
  20. package/bin/lean/issuewatch-reconcile.test.mjs +25 -0
  21. package/bin/lean/issuewatch.mjs +3 -0
  22. package/bin/lean/lanecheck.test.mjs +13 -1
  23. package/bin/lean/lean.mjs +214 -32
  24. package/bin/lean/lean.test.mjs +406 -21
  25. package/bin/lean/live-execution.mjs +25 -0
  26. package/bin/lean/live-execution.test.mjs +35 -1
  27. package/bin/lean/merged-park.mjs +76 -0
  28. package/bin/lean/merged-park.test.mjs +64 -0
  29. package/bin/lean/mergetrain.mjs +357 -0
  30. package/bin/lean/mergetrain.test.mjs +348 -0
  31. package/bin/lean/orchestrate-envhold.test.mjs +62 -0
  32. package/bin/lean/orchestrate-stacking.test.mjs +144 -0
  33. package/bin/lean/orchestrate-train.test.mjs +130 -0
  34. package/bin/lean/orchestrate-transient-git.test.mjs +53 -0
  35. package/bin/lean/orchestrate.mjs +234 -17
  36. package/bin/lean/prompts.mjs +4 -3
  37. package/bin/lean/release-review.mjs +8 -1
  38. package/bin/lean/release-review.test.mjs +42 -2
  39. package/bin/lean/release-status.test.mjs +53 -1
  40. package/bin/lean/release.mjs +6 -3
  41. package/bin/lean/render.mjs +6 -1
  42. package/bin/lean/run-issue-placement.test.mjs +27 -3
  43. package/bin/lean/sandbox-provider.contract.test.mjs +6 -0
  44. package/bin/lean/sandbox-remote.mjs +12 -2
  45. package/bin/lean/sched.mjs +19 -2
  46. package/bin/lean/sched.test.mjs +33 -1
  47. package/bin/lean/schedd-health.mjs +2 -1
  48. package/bin/lean/schedd-health.test.mjs +7 -0
  49. package/bin/lean/schedd.mjs +55 -7
  50. package/bin/lean/schedd.test.mjs +42 -1
  51. package/bin/lean/stacking.mjs +140 -0
  52. package/bin/lean/stacking.test.mjs +98 -0
  53. package/bin/lean/statuscomment.mjs +14 -8
  54. package/bin/lean/statuscomment.test.mjs +18 -1
  55. package/bin/lean/validate-catalog.mjs +1 -1
  56. package/bin/lean/validate-catalog.test.mjs +3 -0
  57. package/bin/lean/worktree.mjs +8 -3
  58. package/bin/lean/worktree.test.mjs +18 -0
  59. package/bin/pool/agent.mjs +325 -46
  60. package/bin/pool/cache-sweep.mjs +2 -0
  61. package/bin/pool/cli.mjs +120 -6
  62. package/bin/pool/disk.mjs +43 -0
  63. package/bin/pool/docker.mjs +21 -5
  64. package/bin/pool/health.mjs +95 -0
  65. package/bin/pool/router.mjs +274 -27
  66. package/bin/runner.mjs +3 -1
  67. package/bin/stats/chains.mjs +101 -0
  68. package/bin/stats/chains.test.mjs +53 -0
  69. package/bin/stats/efficiency.mjs +7 -6
  70. package/bin/stats/efficiency.test.mjs +48 -7
  71. package/bin/stats/index.mjs +11 -3
  72. package/bin/stats/stats.test.mjs +9 -0
  73. package/docs/CONFIG.md +23 -1
  74. package/docs/OUTCOME-CODES.md +4 -0
  75. package/package.json +1 -1
  76. package/pool/README.md +10 -0
  77. package/pool/image/Dockerfile +2 -1
  78. package/pool/image/entrypoint.sh +6 -6
  79. package/pool/image/mirror.sh +71 -0
  80. package/pool/install/install-agent-linux.sh +57 -5
  81. package/pool/install/install-agent-macos.sh +148 -0
  82. package/pool/install/install-agent.ps1 +11 -0
  83. package/pool/install/install-agent.sh +59 -7
  84. package/pool/install/uninstall-agent-linux.sh +75 -0
  85. package/pool/install/uninstall-agent-macos.sh +60 -0
  86. package/pool/install/uninstall-agent.ps1 +1 -0
  87. package/scripts/transition-label.sh +11 -0
@@ -0,0 +1,130 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ // #5836: the merge train in the batch runner: pr-ready frees the slot, dependents wait, hand-backs recover, resume continues.
4
+ import { describe, it } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { tmpDir } from "../tests/_tmp.mjs";
7
+ import { orchestrate } from "./orchestrate.mjs";
8
+ import { createMergeTrain, formatTrainSummary } from "./mergetrain.mjs";
9
+
10
+ process.env.FORGEDOCK_SCHED_DIR = tmpDir("train-sched-");
11
+ const H = "a".repeat(40);
12
+ const READY = (pr) => ({ terminalReason: "pr-ready", pr, head: H, required: ["build"], policy: "required", lane: "staging" });
13
+ /** A fake gh: `checks[pr]` is the list of rollups the PR shows poll by poll (the last repeats). */
14
+ function world(checks) {
15
+ const merged = new Set(), calls = [];
16
+ const gh = async (a) => {
17
+ calls.push(a);
18
+ if (a[0] === "pr" && a[1] === "view") {
19
+ const pr = Number(a[2]); const seq = checks[pr]; const c = seq.length > 1 ? seq.shift() : seq[0];
20
+ return JSON.stringify({ state: merged.has(pr) ? "MERGED" : "OPEN", headRefOid: H, headRefName: `b${pr}`, mergeable: "MERGEABLE", mergeStateStatus: "CLEAN", baseRefName: "staging", statusCheckRollup: [{ name: "build", status: c === "pending" ? "IN_PROGRESS" : "COMPLETED", conclusion: c === "pending" ? "" : c === "red" ? "FAILURE" : "SUCCESS", detailsUrl: `https://ci/${pr}` }] });
21
+ }
22
+ if (a[0] === "pr" && a[1] === "merge") merged.add(Number(a[2]));
23
+ return "";
24
+ };
25
+ return { gh, merged, calls };
26
+ }
27
+ const go = (extra) => orchestrate({ parallel: 1, readBody: async () => "", pollMs: 1, trainEveryMs: 0, sleep: async () => {}, ...extra });
28
+
29
+ describe("merge train in the batch runner (#5836)", () => {
30
+ it("frees the slot at pr-ready, merges via the train, and counts it in the report line", async () => {
31
+ const w = world({ 10: ["pending", "green"] }); const train = createMergeTrain({ gh: w.gh, repo: "o/r" });
32
+ const started = [];
33
+ const rows = await go({ issues: [1, 2], train, runOne: async (n) => { started.push([n, w.merged.size]); return n === 1 ? READY(10) : { terminalReason: "merged" }; } });
34
+ assert.deepEqual(started, [[1, 0], [2, 0]], "issue 2 started before the train merged PR 10");
35
+ assert.deepEqual(rows.map((r) => r.outcome), ["merged", "merged"]);
36
+ assert.ok(w.calls.some((a) => a[1] === "merge" && a.slice(-2).join() === `--match-head-commit,${H}`));
37
+ assert.match(formatTrainSummary(train.stats()), /^merge train: merged 1, handed back 0/);
38
+ });
39
+ it("a dependent waits for the train's merge", async () => {
40
+ const w = world({ 10: ["pending", "pending", "green"] }); const train = createMergeTrain({ gh: w.gh, repo: "o/r" });
41
+ const seen = [];
42
+ const rows = await go({ issues: [1, 2], train, readBody: async (n) => (n === 2 ? "Depends on #1" : ""),
43
+ runOne: async (n) => { seen.push([n, w.merged.has(10)]); return n === 1 ? READY(10) : { terminalReason: "merged" }; } });
44
+ assert.deepEqual(seen, [[1, false], [2, true]]);
45
+ assert.deepEqual(rows.map((r) => r.outcome), ["merged", "merged"]);
46
+ });
47
+ it("a red PR is handed back as ci.red and a recovery lane runs, then merges", async () => {
48
+ const w = world({ 10: ["red"] }); const train = createMergeTrain({ gh: w.gh, repo: "o/r" });
49
+ const marks = []; let k = 0;
50
+ const rows = await go({ issues: [1], train, recovery: { maxAttempts: 1 }, markRecovering: async (x) => { marks.push(x); },
51
+ runOne: async () => (k++ === 0 ? READY(10) : { terminalReason: "merged" }) });
52
+ assert.deepEqual(marks.map((m) => m.code), ["ci.red"]);
53
+ assert.equal(rows[0].outcome, "merged"); assert.equal(rows[0].recovered, "ci.red");
54
+ assert.equal(train.stats().handedBack["ci.red"], 1);
55
+ assert.equal(w.merged.size, 0, "the train never merged the red PR");
56
+ });
57
+ it("a hand-back with no recovery budget ends needs-human with the failing check URL", async () => {
58
+ const w = world({ 10: ["red"] }); const train = createMergeTrain({ gh: w.gh, repo: "o/r" });
59
+ const rows = await go({ issues: [1], train, recovery: { maxAttempts: 0 }, runOne: async () => READY(10) });
60
+ assert.equal(rows[0].outcome, "needs-human"); assert.equal(rows[0].code, "ci.red");
61
+ assert.match(rows[0].detail, /build https:\/\/ci\/10/);
62
+ });
63
+ it("a stopped batch reports the pr-ready row and --resume continues it through the train", async () => {
64
+ const w = world({ 10: ["pending"] }); let state = null;
65
+ const ac = new AbortController();
66
+ const store = { load: () => null, save: (s) => { state = JSON.parse(JSON.stringify(s)); if (s.train?.entries.length) ac.abort(); }, log: () => {} };
67
+ await go({ issues: [1], train: createMergeTrain({ gh: w.gh, repo: "o/r" }), store, signal: ac.signal, runOne: async () => READY(10) }).catch(() => {});
68
+ assert.equal(state.results[1].outcome, "pr-ready");
69
+ assert.equal(state.train.entries[0].pr, 10);
70
+ const w2 = world({ 10: ["green"] }); const train2 = createMergeTrain({ gh: w2.gh, repo: "o/r" });
71
+ const rows = await go({ issues: [1], train: train2, store: { load: () => state, save: () => {}, log: () => {} }, runOne: async () => { throw new Error("must not relaunch"); } });
72
+ assert.equal(rows[0].outcome, "merged"); assert.ok(w2.merged.has(10));
73
+ });
74
+ it("without a train nothing changes: a merged lane is a merged row", async () => {
75
+ const rows = await go({ issues: [1, 2], runOne: async () => ({ terminalReason: "merged" }) });
76
+ assert.deepEqual(rows.map((r) => r.outcome), ["merged", "merged"]);
77
+ });
78
+ });
79
+
80
+ describe("batched merge train resume (#5837)", () => {
81
+ it("a saved snapshot with a validating batch is restored by orchestrate; tick re-reads checks and does not rebuild", async () => {
82
+ const calls = []; const ac = new AbortController();
83
+ const gh = async (a) => {
84
+ calls.push(a);
85
+ const s = a.join(" ");
86
+ if (s.includes("/check-runs")) ac.abort();
87
+ if (a[0] === "pr" && a[1] === "view") return JSON.stringify({ state: "OPEN", headRefOid: H, headRefName: "b", mergeable: "MERGEABLE", mergeStateStatus: "BEHIND", baseRefName: "staging", statusCheckRollup: [{ name: "build", conclusion: "SUCCESS" }] });
88
+ if (s.includes("/check-runs")) return JSON.stringify({ check_runs: [{ name: "build", status: "in_progress", conclusion: null }] });
89
+ return "";
90
+ };
91
+ const mk = (n) => ({ issue: n, pr: 10 + n, head: H, required: ["build"], policy: "required", lane: "staging", since: 1 });
92
+ const saved = { entries: [mk(1), mk(2)], stats: { merged: 0, handedBack: {}, waits: [], syncs: 0, batches: 1, candidateRuns: 1 },
93
+ batches: [{ id: "x", base: "staging", baseSha: "c".repeat(40), prs: [1, 2].map((n) => ({ issue: n, pr: 10 + n, head: H })), candidate: "forge-train/staging/x", candSha: "d".repeat(40), state: "validating", startedAt: Date.now() }] };
94
+ const train = createMergeTrain({ gh, repo: "o/r", batchSize: 4 });
95
+ const store = { load: () => ({ order: [1, 2], results: { 1: { issue: 1, outcome: "pr-ready", pr: 11 }, 2: { issue: 2, outcome: "pr-ready", pr: 12 } }, train: saved }), save: () => {}, log: () => {} };
96
+ await go({ issues: [1, 2], train, store, signal: ac.signal, runOne: async () => { throw new Error("must not relaunch"); } }).catch(() => {});
97
+ assert.ok(calls.some((a) => a.join(" ").includes("/check-runs")), "orchestrate restored the train and ticked it");
98
+ assert.ok(calls.some((a) => a.join(" ").includes("/check-runs")));
99
+ assert.ok(!calls.some((a) => a.join(" ").includes("git/refs") && a.includes("POST")), "candidate not rebuilt");
100
+ assert.equal(train.snapshot().batches.length, 1);
101
+ });
102
+ });
103
+
104
+ describe("merge train bisection culprit in the batch runner (#5838)", () => {
105
+ it("a culprit handback reaches settleLane with a merged-tree recovery note; only the culprit is requeued", async () => {
106
+ const w = world({ 10: ["pending", "green"], 11: ["pending", "green"] }); const real = createMergeTrain({ gh: w.gh, repo: "o/r" });
107
+ const culprit = { pr: 10, check: "build", url: "https://ci/batch", batch: "b1" };
108
+ const train = { ...real, tick: async () => {
109
+ if (!real.has(1)) return real.tick();
110
+ const entry = real.snapshot().entries.find((e) => e.issue === 1); real.drop(1);
111
+ return [{ kind: "handback", issue: 1, pr: 10, code: "ci.red", detail: "PR #10 broke the merged tree of train batch b1", entry, culprit }, ...await real.tick()];
112
+ } };
113
+ const runs = [], decisions = [], marks = [];
114
+ const rows = await go({ issues: [1, 2], train, recovery: { maxAttempts: 1 }, decide: (d) => decisions.push(d), markRecovering: async (x) => { marks.push(x); },
115
+ runOne: async (n) => { runs.push(n); return runs.filter((x) => x === n).length === 1 ? READY(n === 1 ? 10 : 11) : { terminalReason: "merged" }; } });
116
+ assert.deepEqual(runs.sort(), [1, 1, 2], "only the culprit gets a fix lane");
117
+ assert.deepEqual(marks.map((m) => [m.issue, m.code]), [[1, "ci.red"]]);
118
+ const why = decisions.find((d) => d.issue === 1 && /recovery lane for ci\.red/.test(d.what))?.why ?? "";
119
+ assert.match(why, /PR #10 broke the merged tree of train batch b1 \(required check build https:\/\/ci\/batch\), not its own head/);
120
+ assert.deepEqual(rows.map((r) => r.outcome), ["merged", "merged"]);
121
+ });
122
+ it("with no recovery budget the needs-human row carries the culprit and the merged-tree note", async () => {
123
+ const w = world({ 10: ["pending"] }); const real = createMergeTrain({ gh: w.gh, repo: "o/r" });
124
+ const train = { ...real, tick: async () => { const entry = real.snapshot().entries[0]; real.drop(1); return [{ kind: "handback", issue: 1, pr: 10, code: "ci.red", detail: "d", entry, culprit: { pr: 10, check: "build", url: null, batch: "b2" } }]; } };
125
+ const rows = await go({ issues: [1], train, recovery: { maxAttempts: 0 }, runOne: async () => READY(10) });
126
+ assert.equal(rows[0].outcome, "needs-human");
127
+ assert.deepEqual(rows[0].culprit, { pr: 10, check: "build", url: null, batch: "b2" });
128
+ assert.match(rows[0].detail, /^Recovery note: PR #10 broke the merged tree of train batch b2/);
129
+ });
130
+ });
@@ -0,0 +1,53 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ // #5947: git transport failures (curl 56, early EOF, invalid index-pack output) are `net.transient` deferrals with backoff,
4
+ // never engine-errors, and never reach the circuit breaker; any other engine-error still counts. --clear-breaker reaches a live runner.
5
+ import { describe, it } from "node:test";
6
+ import assert from "node:assert/strict";
7
+ import { orchestrate, isTransientEngineError, GIT_TRANSPORT_TEXT } 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 EE = (detail) => ({ terminalReason: "engine-error", detail });
11
+ const MERGED = { terminalReason: "merged", pr: 9 };
12
+ const run = async ({ script, issues, breaker = { errors: 2, window_min: 10 }, extra = {} }) => {
13
+ let t = 1_000_000;
14
+ const store = memStore(), updates = [];
15
+ const calls = [];
16
+ const rows = await orchestrate({ issues, parallel: 1, readBody: async () => "", now: () => t, store, pollMs: 1000, breaker,
17
+ sleep: async (ms) => { t += Math.max(1, Number(ms) || 0); },
18
+ runOne: async (n) => { calls.push(n); t += 1000; const l = script[n]; return l[Math.min(calls.filter((c) => c === n).length - 1, l.length - 1)]; },
19
+ onUpdate: (r) => updates.push(r), ...extra });
20
+ return { rows, calls, updates, store };
21
+ };
22
+
23
+ describe("#5947 git transport failures", () => {
24
+ it("classifies git transport text, and not an ordinary failure (negative examples)", () => {
25
+ for (const d of ["error: RPC failed; curl 56 GnuTLS recv error", "fatal: early EOF", "fatal: invalid index-pack output", "fatal: the remote end hung up: unexpected disconnect while reading", "curl 28 Operation timed out", "'/cache/git/x.git' is not a local repository"]) assert.ok(GIT_TRANSPORT_TEXT.test(d) && isTransientEngineError(d), d);
26
+ for (const d of ["TypeError: x is not a function", "validate failed: 56 tests", "curl 5600 bytes"]) assert.equal(GIT_TRANSPORT_TEXT.test(d), false, d);
27
+ });
28
+
29
+ it("engine-errors with curl 56 / invalid index-pack output defer as net.transient; the breaker stays closed", async () => {
30
+ const r = await run({ issues: [1, 2], script: { 1: [EE("fatal: early EOF\nerror: RPC failed; curl 56 recv"), MERGED], 2: [EE("fatal: invalid index-pack output"), MERGED] } });
31
+ const d = r.updates.filter((u) => u.outcome === "deferred");
32
+ assert.equal(d.length, 2);
33
+ assert.ok(d.every((u) => u.code === "net.transient"));
34
+ assert.deepEqual(r.rows.map((x) => x.outcome).sort(), ["merged", "merged"]);
35
+ const st = r.store.peek();
36
+ assert.deepEqual(st.errorTimes, []);
37
+ assert.equal(st.breaker ?? null, null);
38
+ assert.equal(r.updates.some((u) => u.outcome === "breaker" || u.outcome === "engine-error"), false);
39
+ });
40
+
41
+ it("a non-transport engine-error still counts toward the breaker", async () => {
42
+ const r = await run({ issues: [1, 2, 3], breaker: { errors: 2, window_min: 10 }, script: { 1: [EE("boom A")], 2: [EE("boom B")], 3: [MERGED] } });
43
+ assert.ok(r.updates.some((u) => u.outcome === "breaker"), "two real engine-errors trip it");
44
+ });
45
+
46
+ it("getClearBreaker resets a tripped breaker in the running batch and acks", async () => {
47
+ let tripSeen = false; const acks = [];
48
+ const r = await run({ issues: [1, 2, 3], breaker: { errors: 2, window_min: 10 }, script: { 1: [EE("boom A")], 2: [EE("boom B")], 3: [MERGED] },
49
+ extra: { onUpdate: (u) => { if (u.outcome === "breaker") tripSeen = true; }, getClearBreaker: () => tripSeen, ackClearBreaker: (i) => acks.push(i) } });
50
+ assert.ok(acks.length >= 1 && acks[0].cleared === true, "the live runner acked a real clear");
51
+ assert.equal(r.store.peek().breaker ?? null, null);
52
+ });
53
+ });