forgedock 1.52.0 → 1.54.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 (233) hide show
  1. package/.claude-plugin/marketplace.json +51 -0
  2. package/README.md +8 -2
  3. package/bin/auth/app-manifest.mjs +89 -0
  4. package/bin/auth/app-manifest.test.mjs +75 -0
  5. package/bin/auth/app-token.mjs +256 -0
  6. package/bin/auth/app-token.test.mjs +232 -0
  7. package/bin/brand.mjs +7 -0
  8. package/bin/config-history.mjs +151 -0
  9. package/bin/config-schema.mjs +115 -0
  10. package/bin/demo.mjs +65 -11
  11. package/bin/engine/outcome-codes.mjs +9 -3
  12. package/bin/engine/telemetry-seam.mjs +11 -3
  13. package/bin/engine/telemetry-seam.test.mjs +17 -0
  14. package/bin/engine-cli.mjs +110 -36
  15. package/bin/experiment.mjs +58 -6
  16. package/bin/first-run.mjs +122 -0
  17. package/bin/forge-utils.mjs +6 -2
  18. package/bin/forgedock.mjs +138 -142
  19. package/bin/help-text.mjs +144 -0
  20. package/bin/hooks/pre-tool-use.mjs +7 -0
  21. package/bin/journey.mjs +82 -83
  22. package/bin/lean/acceptance.mjs +313 -0
  23. package/bin/lean/acceptance.test.mjs +215 -0
  24. package/bin/lean/account-watch.mjs +28 -0
  25. package/bin/lean/account-watch.test.mjs +30 -0
  26. package/bin/lean/activation.mjs +38 -0
  27. package/bin/lean/activation.test.mjs +36 -1
  28. package/bin/lean/basered.mjs +115 -0
  29. package/bin/lean/basered.test.mjs +66 -0
  30. package/bin/lean/batch-health.mjs +114 -7
  31. package/bin/lean/batch-health.test.mjs +87 -1
  32. package/bin/lean/batch.mjs +41 -2
  33. package/bin/lean/batch.test.mjs +115 -11
  34. package/bin/lean/branchlock.mjs +54 -0
  35. package/bin/lean/branchlock.test.mjs +49 -0
  36. package/bin/lean/ceiling.mjs +72 -0
  37. package/bin/lean/ceiling.test.mjs +54 -0
  38. package/bin/lean/checkpoint-reconcile.mjs +43 -0
  39. package/bin/lean/checkpoint-reconcile.test.mjs +95 -0
  40. package/bin/lean/ci-budget.mjs +366 -0
  41. package/bin/lean/ci-budget.test.mjs +167 -0
  42. package/bin/lean/conformance.e2e.test.mjs +8 -1
  43. package/bin/lean/conformance.mjs +269 -38
  44. package/bin/lean/conformance.test.mjs +280 -7
  45. package/bin/lean/context.mjs +35 -6
  46. package/bin/lean/context.test.mjs +27 -1
  47. package/bin/lean/depcache.mjs +25 -1
  48. package/bin/lean/depcache.test.mjs +26 -0
  49. package/bin/lean/e2e.mjs +18 -2
  50. package/bin/lean/e2e.test.mjs +26 -1
  51. package/bin/lean/effects.mjs +47 -14
  52. package/bin/lean/execution.mjs +19 -3
  53. package/bin/lean/execution.test.mjs +63 -0
  54. package/bin/lean/facts.mjs +3 -3
  55. package/bin/lean/facts.test.mjs +5 -0
  56. package/bin/lean/findinglabel.mjs +16 -0
  57. package/bin/lean/findinglabel.test.mjs +39 -0
  58. package/bin/lean/fixround.mjs +14 -0
  59. package/bin/lean/fixround.test.mjs +25 -2
  60. package/bin/lean/gh-assoc.test.mjs +2 -1
  61. package/bin/lean/integration.mjs +100 -9
  62. package/bin/lean/integration.test.mjs +98 -0
  63. package/bin/lean/issuewatch-parity.mjs +64 -0
  64. package/bin/lean/issuewatch-parity.test.mjs +127 -0
  65. package/bin/lean/issuewatch-release.mjs +6 -2
  66. package/bin/lean/issuewatch-release.test.mjs +17 -1
  67. package/bin/lean/issuewatch.mjs +45 -6
  68. package/bin/lean/issuewatch.test.mjs +3 -2
  69. package/bin/lean/lanelock.mjs +14 -0
  70. package/bin/lean/lean.mjs +473 -100
  71. package/bin/lean/lean.test.mjs +686 -33
  72. package/bin/lean/light.mjs +48 -7
  73. package/bin/lean/light.test.mjs +37 -3
  74. package/bin/lean/limits.test.mjs +142 -9
  75. package/bin/lean/mechfix.mjs +124 -0
  76. package/bin/lean/mechfix.test.mjs +75 -0
  77. package/bin/lean/orchestrate-cancel.test.mjs +143 -0
  78. package/bin/lean/orchestrate.mjs +116 -28
  79. package/bin/lean/phaseledger.mjs +47 -5
  80. package/bin/lean/phaseledger.test.mjs +30 -1
  81. package/bin/lean/postdeploy-check.test.mjs +39 -0
  82. package/bin/lean/precheck.mjs +23 -4
  83. package/bin/lean/precheck.test.mjs +14 -1
  84. package/bin/lean/prereq.mjs +28 -0
  85. package/bin/lean/prereq.test.mjs +20 -0
  86. package/bin/lean/probe.mjs +4 -2
  87. package/bin/lean/prodparity.mjs +52 -0
  88. package/bin/lean/prodparity.test.mjs +67 -0
  89. package/bin/lean/prompts.mjs +77 -19
  90. package/bin/lean/quota.mjs +39 -0
  91. package/bin/lean/recovery.test.mjs +11 -1
  92. package/bin/lean/relaxation.mjs +73 -0
  93. package/bin/lean/relaxation.test.mjs +54 -0
  94. package/bin/lean/release-io.test.mjs +42 -0
  95. package/bin/lean/release-postmerge.mjs +125 -0
  96. package/bin/lean/release-preflight.mjs +58 -0
  97. package/bin/lean/release-preflight.test.mjs +114 -0
  98. package/bin/lean/release-rehearsal.mjs +64 -0
  99. package/bin/lean/release-rehearsal.test.mjs +93 -0
  100. package/bin/lean/release-review.e2e.test.mjs +77 -0
  101. package/bin/lean/release-review.mjs +254 -0
  102. package/bin/lean/release-review.test.mjs +307 -0
  103. package/bin/lean/release-snapshot.mjs +188 -0
  104. package/bin/lean/release-snapshot.test.mjs +190 -0
  105. package/bin/lean/release.mjs +296 -0
  106. package/bin/lean/release.test.mjs +387 -0
  107. package/bin/lean/render.mjs +1 -1
  108. package/bin/lean/replan.mjs +184 -0
  109. package/bin/lean/replan.test.mjs +110 -0
  110. package/bin/lean/resume.mjs +9 -7
  111. package/bin/lean/resume.test.mjs +16 -0
  112. package/bin/lean/rotator.mjs +150 -31
  113. package/bin/lean/rotator.test.mjs +105 -2
  114. package/bin/lean/sandbox-remote.mjs +9 -2
  115. package/bin/lean/schedd.mjs +83 -5
  116. package/bin/lean/schedd.test.mjs +108 -7
  117. package/bin/lean/selfreview.mjs +94 -0
  118. package/bin/lean/selfreview.test.mjs +58 -1
  119. package/bin/lean/selftest-gate.mjs +22 -0
  120. package/bin/lean/selftest-gate.test.mjs +18 -1
  121. package/bin/lean/selftest-journey.mjs +234 -0
  122. package/bin/lean/selftest-journey.test.mjs +130 -0
  123. package/bin/lean/selftest-live.mjs +2 -1
  124. package/bin/lean/seqlease.mjs +35 -1
  125. package/bin/lean/seqlease.test.mjs +15 -0
  126. package/bin/lean/seqreserve.e2e.test.mjs +135 -0
  127. package/bin/lean/seqreserve.mjs +73 -0
  128. package/bin/lean/seqreserve.test.mjs +134 -0
  129. package/bin/lean/sequence.mjs +35 -6
  130. package/bin/lean/seqversioned.mjs +147 -0
  131. package/bin/lean/stagestamp.mjs +28 -0
  132. package/bin/lean/stagestamp.test.mjs +32 -0
  133. package/bin/lean/surfaces.mjs +75 -0
  134. package/bin/lean/surfaces.test.mjs +59 -0
  135. package/bin/lean/toolplace.mjs +28 -0
  136. package/bin/lean/toolplace.test.mjs +24 -0
  137. package/bin/lean/toolstats.mjs +3 -1
  138. package/bin/lean/toolstats.test.mjs +11 -0
  139. package/bin/lean/validatebest.mjs +28 -0
  140. package/bin/lean/validatebest.test.mjs +27 -0
  141. package/bin/lean/verifier.mjs +3 -2
  142. package/bin/lean/verify.mjs +2 -1
  143. package/bin/lean/verify.test.mjs +6 -0
  144. package/bin/pool/agent.mjs +27 -4
  145. package/bin/pool/docker.mjs +5 -0
  146. package/bin/pool/router.mjs +74 -28
  147. package/bin/prereqs.mjs +111 -0
  148. package/bin/replay-timelapse.mjs +149 -0
  149. package/bin/review-staging.mjs +123 -16
  150. package/bin/review-staging.test.mjs +18 -0
  151. package/bin/runner.mjs +43 -6
  152. package/bin/splash-install.mjs +157 -0
  153. package/bin/stats/aggregate.mjs +8 -1
  154. package/bin/stats/conformance-outcomes.mjs +289 -0
  155. package/bin/stats/conformance-outcomes.test.mjs +274 -0
  156. package/bin/stats/depth.mjs +275 -0
  157. package/bin/stats/depth.test.mjs +158 -0
  158. package/bin/stats/efficiency.mjs +26 -5
  159. package/bin/stats/efficiency.test.mjs +45 -1
  160. package/bin/stats/experiment.mjs +7 -5
  161. package/bin/stats/first-review.mjs +77 -0
  162. package/bin/stats/first-review.test.mjs +36 -0
  163. package/bin/stats/firstmerge.mjs +40 -0
  164. package/bin/stats/firstmerge.test.mjs +41 -0
  165. package/bin/stats/github-source.mjs +53 -15
  166. package/bin/stats/index.mjs +147 -9
  167. package/bin/stats/local-source.mjs +12 -0
  168. package/bin/stats/origin.mjs +80 -0
  169. package/bin/stats/origin.test.mjs +58 -0
  170. package/bin/stats/query.mjs +69 -0
  171. package/bin/stats/render.mjs +3 -1
  172. package/bin/stats/scoreboard.mjs +137 -0
  173. package/bin/stats/scoreboard.test.mjs +87 -0
  174. package/bin/stats/selffiled.mjs +52 -0
  175. package/bin/stats/selffiled.test.mjs +71 -0
  176. package/bin/stats/stats.test.mjs +80 -0
  177. package/bin/tui.mjs +3 -2
  178. package/commands/bootstrap.md +15 -14
  179. package/commands/deploy-pr.md +18 -3
  180. package/commands/forge-stats.md +1 -1
  181. package/commands/forgedock-ci-setup.md +28 -0
  182. package/commands/forgedock-init.md +4 -5
  183. package/commands/issue.md +2 -0
  184. package/commands/milestone.md +9 -1
  185. package/commands/orchestrate.md +1 -1
  186. package/commands/replay.md +2 -0
  187. package/commands/review-pr-agents/security.md +4 -0
  188. package/commands/review-pr-staging.md +6 -1
  189. package/commands/work-on/build.md +4 -6
  190. package/commands/work-on/close.md +8 -0
  191. package/docs/CONFIG.md +170 -18
  192. package/docs/ISSUE-WATCH.md +25 -0
  193. package/docs/OUTCOME-CODES.md +4 -0
  194. package/docs/REPLAY.md +9 -0
  195. package/docs/SELFTEST.md +11 -0
  196. package/docs/STATS.md +61 -0
  197. package/docs/TELEMETRY.md +1 -1
  198. package/docs/eval/README.md +6 -0
  199. package/docs/eval/adversarial-bench.md +68 -0
  200. package/docs/eval/corpus/adversarial-v1.json +285 -0
  201. package/docs/eval/feature-bench.md +42 -0
  202. package/docs/eval/feature-specs/crud-auth/journeys/notes-crud-isolated.mjs +21 -0
  203. package/docs/eval/feature-specs/crud-auth/journeys/register-login.mjs +12 -0
  204. package/docs/eval/feature-specs/crud-auth/spec.md +15 -0
  205. package/docs/site/start-a-new-project.md +2 -1
  206. package/package.json +5 -2
  207. package/plugins/forgedock-splash/.claude-plugin/plugin.json +10 -0
  208. package/plugins/forgedock-splash/README.md +27 -0
  209. package/plugins/forgedock-splash/hooks/hooks.json +1 -0
  210. package/plugins/forgedock-splash/hooks/register.tsx +74 -0
  211. package/plugins/forgedock-splash/hooks/scene.ts +222 -0
  212. package/plugins/forgedock-splash/types/index.d.ts +10 -0
  213. package/pool/README.md +1 -1
  214. package/pool/image/cs-cred +14 -1
  215. package/scripts/backfill-finding-labels.mjs +50 -0
  216. package/scripts/backfill-finding-labels.test.mjs +36 -0
  217. package/scripts/bench-adversarial.mjs +216 -0
  218. package/scripts/bench-feature.mjs +170 -0
  219. package/scripts/bench-lightlane.mjs +2 -2
  220. package/scripts/bootstrap-create.mjs +2 -2
  221. package/scripts/bootstrap-validate.mjs +35 -2
  222. package/scripts/check-spec-size.sh +4 -3
  223. package/scripts/check-spec-size.test.sh +3 -0
  224. package/scripts/doctor-pipeline-state.sh +21 -6
  225. package/scripts/file-deferred-followups.sh +59 -251
  226. package/scripts/file-deferred-followups.test.sh +85 -206
  227. package/scripts/followup-route.mjs +12 -0
  228. package/scripts/owner-route-parity.test.sh +17 -1
  229. package/scripts/plan-validate-live.mjs +40 -6
  230. package/scripts/review-pr-side-effects.test.sh +40 -0
  231. package/scripts/review-pr-staging-scope.test.sh +1 -1
  232. package/scripts/review-staging-post.sh +23 -0
  233. package/scripts/review-staging-post.test.sh +8 -0
@@ -0,0 +1,125 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ /**
4
+ * Post-merge step of `forgedock release` (#5213, part 3 of #5208): confirm or dispatch the publish run for the merge commit,
5
+ * wait for the published artifact (`release.artifact_check`), then open and merge the version-sync PR (`release.version_sync`).
6
+ * Every wait is bounded (`ctx.config.postMerge` overrides the bounds) and ends in `{blocked}`, never a throw, so a resume
7
+ * retries the step; each sub-step is idempotent (an existing run, PR or merged PR is reused). Rationale:
8
+ * devdocs/decisions/5208-release-postmerge.md.
9
+ */
10
+
11
+ import { cleanupSnapshot } from "./release-snapshot.mjs";
12
+
13
+ const BOUNDS = {
14
+ publishPolls: 6, publishPollMs: 10_000, // wait for a run to appear (bot merges never trigger one)
15
+ runPolls: 90, runPollMs: 20_000, // wait for the run to finish
16
+ artifactTries: 8, artifactBaseMs: 5_000, artifactMaxMs: 120_000, // npm propagation: exponential backoff
17
+ branchPolls: 6, branchPollMs: 10_000, // wait for the sync branch to be pushed
18
+ checkPolls: 30, checkPollMs: 20_000, // wait for the sync PR's checks
19
+ };
20
+ const json = (s) => JSON.parse(String(s || "null"));
21
+ const blocked = (reason) => ({ blocked: true, reason });
22
+ const GREEN = new Set(["SUCCESS", "NEUTRAL", "SKIPPED"]);
23
+
24
+ async function findRun({ io, repo, workflow, sha }) {
25
+ const runs = json(await io.gh(["run", "list", "--repo", repo, "--workflow", workflow, "--commit", sha, "--json", "databaseId,status,conclusion", "--limit", "5"])) ?? [];
26
+ return runs[0] ?? null;
27
+ }
28
+
29
+ /** Poll `fn` until it returns a truthy value, at most `polls` times, sleeping `ms` between tries. */
30
+ async function poll(io, polls, ms, fn) {
31
+ for (let i = 0; i < polls; i++) {
32
+ const v = await fn();
33
+ if (v) return v;
34
+ if (i < polls - 1) await io.sleep(ms);
35
+ }
36
+ return null;
37
+ }
38
+
39
+ async function publishRun(ctx, sha, b) {
40
+ const { io, repo, config } = ctx;
41
+ const workflow = config.publishWorkflow || "publish.yml";
42
+ const look = () => findRun({ io, repo, workflow, sha });
43
+ let run = await poll(io, b.publishPolls, b.publishPollMs, look);
44
+ let dispatched = false;
45
+ if (!run) {
46
+ await io.gh(["workflow", "run", workflow, "--repo", repo, "--ref", ctx.def]);
47
+ dispatched = true;
48
+ run = await poll(io, b.publishPolls, b.publishPollMs, look);
49
+ if (!run) return { err: `no ${workflow} run for ${sha.slice(0, 8)} after a dispatch on ${ctx.def}; check the Actions tab, then resume` };
50
+ }
51
+ const done = await poll(io, b.runPolls, b.runPollMs, async () => { const r = await look(); return r?.status === "completed" ? r : null; });
52
+ if (!done) return { err: `${workflow} run ${run.databaseId} did not finish in time; resume to keep waiting` };
53
+ if (done.conclusion !== "success") return { err: `${workflow} run ${done.databaseId} concluded ${done.conclusion}` };
54
+ return { run: done.databaseId, dispatched };
55
+ }
56
+
57
+ async function artifact(ctx, b) {
58
+ const { io, config } = ctx;
59
+ let wait = b.artifactBaseMs;
60
+ for (let i = 0; i < b.artifactTries; i++) {
61
+ if ((await io.run(config.artifactCheck)).ok) return { ok: true, tries: i + 1 };
62
+ if (i < b.artifactTries - 1) { await io.sleep(wait); wait = Math.min(wait * 2, b.artifactMaxMs); }
63
+ }
64
+ return { err: `release.artifact_check still failing after ${b.artifactTries} tries: ${config.artifactCheck}` };
65
+ }
66
+
67
+ async function versionSync(ctx, sha, b) {
68
+ const { io, repo, staging } = ctx;
69
+ const pkg = JSON.parse(Buffer.from(String(await io.gh(["api", `repos/${repo}/contents/package.json?ref=${sha}`, "--jq", ".content"])).replace(/\s/g, ""), "base64").toString("utf8"));
70
+ const branch = `chore/sync-version-${pkg.version}`;
71
+ const find = async () => json(await io.gh(["pr", "list", "--repo", repo, "--base", staging, "--head", branch, "--state", "all", "--json", "number,state", "--limit", "1"]))?.[0] ?? null;
72
+ let pr = await find();
73
+ if (pr?.state === "MERGED") return { pr: pr.number, merged: true, reused: true };
74
+ if (!pr) {
75
+ const has = await poll(io, b.branchPolls, b.branchPollMs, async () => { try { await io.gh(["api", `repos/${repo}/branches/${branch}`, "--jq", ".name"]); return true; } catch { return false; } });
76
+ if (!has) return { err: `version-sync branch ${branch} did not appear; publish.yml may have skipped the sync, open it by hand` };
77
+ const url = String(await io.gh(["pr", "create", "--repo", repo, "--base", staging, "--head", branch, "--title", `chore: sync version ${pkg.version} to ${staging}`, "--body", `Version-only sync of the ${pkg.version} release back to ${staging} (forgedock release).`])).trim();
78
+ const n = Number(/\/pull\/(\d+)/.exec(url)?.[1]);
79
+ if (!Number.isSafeInteger(n)) return { err: `gh pr create returned no PR url: ${url}` };
80
+ pr = { number: n };
81
+ }
82
+ let red = null;
83
+ const green = await poll(io, b.checkPolls, b.checkPollMs, async () => {
84
+ const v = json(await io.gh(["pr", "view", String(pr.number), "--repo", repo, "--json", "state,headRefOid,statusCheckRollup"]));
85
+ if (v?.state === "MERGED") return { head: null, already: true };
86
+ const res = (v?.statusCheckRollup ?? []).map((c) => String(c.conclusion || c.state || "").toUpperCase());
87
+ if (res.some((r) => r && !GREEN.has(r) && !["PENDING", "IN_PROGRESS", "QUEUED", "EXPECTED"].includes(r))) { red = res.find((r) => r && !GREEN.has(r) && !["PENDING", "IN_PROGRESS", "QUEUED", "EXPECTED"].includes(r)); return { red: true }; }
88
+ return res.length && res.every((r) => GREEN.has(r)) ? { head: v.headRefOid } : null;
89
+ });
90
+ if (green?.already) return { pr: pr.number, merged: true };
91
+ if (green?.red) return { err: `version-sync PR #${pr.number} has a failing check (${red}); fix and merge it by hand` };
92
+ // GITHUB_TOKEN PRs get no CI, so "no checks" is a stop, not a green light.
93
+ if (!green) return { err: `version-sync PR #${pr.number} has no passing checks yet (a PR opened by GITHUB_TOKEN gets no CI: close and reopen it); resume once green` };
94
+ await io.gh(["pr", "merge", String(pr.number), "--repo", repo, "--merge", "--match-head-commit", green.head]);
95
+ return { pr: pr.number, merged: true };
96
+ }
97
+
98
+ /** @returns {Promise<{published, run, artifact, sync}|{blocked: true, reason: string}|{stopped: true, why: string}>} */
99
+ export async function postMergeStep(ctx) {
100
+ const { io, repo, state, config = {} } = ctx;
101
+ const b = { ...BOUNDS, ...(config.postMerge ?? {}) };
102
+ const pr = state.steps["release-pr"].result.pr;
103
+ const view = json(await io.gh(["pr", "view", String(pr), "--repo", repo, "--json", "state,mergeCommit"]));
104
+ const sha = view?.mergeCommit?.oid;
105
+ if (view?.state !== "MERGED" || !sha) return { stopped: true, why: `release PR #${pr} is not merged (${view?.state ?? "unknown"}); nothing to publish yet` };
106
+
107
+ const pub = await publishRun(ctx, sha, b);
108
+ if (pub.err) return blocked(pub.err);
109
+ let art = null;
110
+ if (config.artifactCheck) {
111
+ art = await artifact(ctx, b);
112
+ if (art.err) return blocked(art.err);
113
+ }
114
+ let sync = null;
115
+ if (config.versionSync) {
116
+ sync = await versionSync(ctx, sha, b);
117
+ if (sync.err) return blocked(sync.err);
118
+ }
119
+ if (state.release?.branch) {
120
+ const gone = cleanupSnapshot({ git: io.git, branch: state.release.branch });
121
+ if (!gone.deleted) io.print(`release: could not delete ${state.release.branch} (${gone.why}); delete it by hand`);
122
+ }
123
+ io.print(`release: published (run ${pub.run}${pub.dispatched ? ", dispatched" : ""})${art ? ", artifact confirmed" : ""}${sync ? `, version-sync PR #${sync.pr} merged` : ""}`);
124
+ return { published: true, merge: sha, run: pub.run, dispatched: pub.dispatched, artifact: art?.ok ?? null, sync };
125
+ }
@@ -0,0 +1,58 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ /**
4
+ * Host preflight of `forgedock release` (#5277): forge.yaml `release.preflight_command` runs the repo's own suites on the host
5
+ * (not as Actions minutes) before the release PR is opened, again after each fix round, and once more on the final head before
6
+ * the draft PR is marked ready. A failing blocking preflight files one `release-blocker` issue per head and stops the job; `--resume`
7
+ * retries. With no command set every function here is a no-op. No model call. Effects go through `ctx.io`.
8
+ */
9
+ import { fileBlocker, tail } from "./release-rehearsal.mjs";
10
+
11
+ export const PREFLIGHT_TIMEOUT_MS = 20 * 60_000;
12
+ const json = (s) => JSON.parse(String(s || "null"));
13
+ const off = (v) => ["false", "off", "no", "0"].includes(String(v ?? "").trim().toLowerCase());
14
+
15
+ /** `release.preflight_command` / `_timeout` (seconds) / `_blocking` -> `{command, timeoutMs, blocking}`, or null when no command is set. */
16
+ export function parsePreflightConfig(r) {
17
+ const command = typeof r?.preflight_command === "string" ? r.preflight_command.trim() : "";
18
+ if (!command) return null;
19
+ const secs = Number(r.preflight_timeout);
20
+ return { command, timeoutMs: Number.isFinite(secs) && secs > 0 ? secs * 1000 : PREFLIGHT_TIMEOUT_MS, blocking: !off(r.preflight_blocking) };
21
+ }
22
+
23
+ /**
24
+ * Run the preflight at `head`; on failure file/comment the release-blocker issue.
25
+ * @returns {{ok, head, command, blocking, code, timedOut, issue?}}
26
+ */
27
+ export async function runHostPreflight(ctx, { head, pr }) {
28
+ const { io, repo, config } = ctx;
29
+ const cfg = config.preflight;
30
+ const run = await io.rehearse(cfg.command, { timeout: cfg.timeoutMs });
31
+ const res = { ok: !!run.ok, head, command: cfg.command, blocking: cfg.blocking, code: run.code ?? null, timedOut: !!run.timedOut, output: run.ok ? "" : tail(run.output) };
32
+ if (!res.ok) res.issue = await fileBlocker({ io, repo, pr, kind: "preflight" }, res);
33
+ const { output, ...kept } = res;
34
+ return kept;
35
+ }
36
+
37
+ const stopOf = (r) => ({ stopped: true, why: `release preflight failed at ${r.head} (release-blocker #${r.issue}); fix it, then resume`, ...r });
38
+
39
+ /** Step before `release-pr`: preflight on the staging head, so no release PR is opened on a failing head. */
40
+ export async function hostPreflightStep(ctx) {
41
+ const cfg = ctx.config.preflight;
42
+ if (!cfg) return { skipped: true };
43
+ const head = String(await ctx.io.gh(["api", `repos/${ctx.repo}/commits/${ctx.staging}`, "--jq", ".sha"])).trim();
44
+ const r = await runHostPreflight(ctx, { head });
45
+ return !r.ok && r.blocking ? stopOf(r) : r;
46
+ }
47
+
48
+ /** Step after `fixes`: preflight on the final head, then mark the draft release PR ready so Actions CI runs once on it. */
49
+ export async function markReadyStep(ctx) {
50
+ if (!ctx.config.preflight) return { skipped: true };
51
+ const { io, repo } = ctx;
52
+ const { pr } = ctx.state.steps["release-pr"].result;
53
+ const view = json(await io.gh(["pr", "view", String(pr), "--repo", repo, "--json", "headRefOid,isDraft"]));
54
+ const r = await runHostPreflight(ctx, { head: view?.headRefOid, pr });
55
+ if (!r.ok && r.blocking) return stopOf(r);
56
+ if (view?.isDraft) await io.gh(["pr", "ready", String(pr), "--repo", repo]);
57
+ return { ...r, ready: true, wasDraft: !!view?.isDraft };
58
+ }
@@ -0,0 +1,114 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ import { describe, it } from "node:test";
4
+ import assert from "node:assert/strict";
5
+ import { tmpDir } from "../tests/_tmp.mjs";
6
+ import { runRelease, withStubs, readReleaseConfig, newReleaseId } from "./release.mjs";
7
+ import { parsePreflightConfig, markReadyStep } from "./release-preflight.mjs";
8
+ import { fixStep } from "./release-review.mjs";
9
+
10
+ const DISK = [{ mount: "/", type: "ext4" }];
11
+ const REPO = "o/r", HEAD = "a".repeat(40);
12
+ const ok = async () => ({ ok: true });
13
+
14
+ /** io fake: `preflightOk(n)` decides the n-th host command run; gh answers just what the preflight steps ask. */
15
+ function fakeIo({ preflightOk = () => true, draft = true } = {}) {
16
+ const calls = [], ran = [];
17
+ return {
18
+ calls, ran, now: () => 1_700_000_000_000, print() {}, sleep: async () => {},
19
+ runningLanes: async () => [], batches: async () => [], setParallel: async () => {},
20
+ rehearse: async (cmd) => { ran.push(cmd); return preflightOk(ran.length) ? { ok: true, code: 0, output: "" } : { ok: false, code: 1, output: "suite red" }; },
21
+ gh: async (a) => {
22
+ calls.push(a);
23
+ const j = a.join(" ");
24
+ if (a[0] === "api") return `${HEAD}\n`;
25
+ if (a[0] === "pr" && a[1] === "list" && a.includes("open") && a.includes("--head")) return "[]";
26
+ if (a[0] === "pr" && a[1] === "list") return "[]";
27
+ if (a[0] === "pr" && a[1] === "create") return "https://github.com/o/r/pull/9";
28
+ if (a[0] === "pr" && a[1] === "view") return JSON.stringify({ headRefOid: HEAD, isDraft: draft, state: "OPEN" });
29
+ if (a[0] === "pr" && a[1] === "ready") return "";
30
+ if (a[0] === "issue" && a[1] === "list") return "[]";
31
+ if (a[0] === "issue" && a[1] === "create") return "https://github.com/o/r/issues/50";
32
+ throw new Error(`unexpected gh ${j}`);
33
+ },
34
+ };
35
+ }
36
+ const run = (io, config, over = {}) => runRelease({ io, repo: REPO, root: tmpDir("rel-pf-"), mounts: DISK, id: newReleaseId(), opts: {}, config, branches: { staging: "staging", default: "main" }, steps: withStubs({ review: ok, fixes: ok, promotion: ok, "post-merge": ok, ...over }) });
37
+ const CFG = readReleaseConfig("release:\n preflight_command: npm test\n");
38
+
39
+ describe("release host preflight (#5277)", () => {
40
+ it("parses the flat keys and is null when unset", () => {
41
+ assert.equal(parsePreflightConfig({}), null);
42
+ assert.deepEqual(parsePreflightConfig({ preflight_command: " make t ", preflight_timeout: "30", preflight_blocking: "false" }), { command: "make t", timeoutMs: 30000, blocking: false });
43
+ assert.equal(CFG.preflight.command, "npm test");
44
+ assert.equal("preflight" in readReleaseConfig(""), false);
45
+ });
46
+
47
+ it("R6: a failing preflight opens no PR, files one release-blocker and stops the release", async () => {
48
+ const io = fakeIo({ preflightOk: () => false });
49
+ const out = await run(io, CFG);
50
+ assert.equal(out.status, "stopped");
51
+ assert.equal(out.step, "host-preflight");
52
+ assert.ok(!io.calls.some((a) => a[0] === "pr" && a[1] === "create"));
53
+ const create = io.calls.find((a) => a[0] === "issue" && a[1] === "create");
54
+ assert.ok(create.includes("release-blocker") && create.some((x) => x.includes("kind=preflight")));
55
+ });
56
+
57
+ it("R2/R6: a passing preflight opens the PR as a draft; unset opens it ready with no preflight work", async () => {
58
+ const on = fakeIo();
59
+ await run(on, CFG);
60
+ assert.ok(on.calls.find((a) => a[0] === "pr" && a[1] === "create").includes("--draft"));
61
+ const off = fakeIo();
62
+ const out = await run(off, readReleaseConfig(""));
63
+ assert.equal(out.status, "done");
64
+ assert.ok(!off.calls.find((a) => a[0] === "pr" && a[1] === "create").includes("--draft"));
65
+ assert.equal(off.ran.length, 0);
66
+ assert.ok(!off.calls.some((a) => a[0] === "pr" && a[1] === "ready"));
67
+ });
68
+
69
+ it("R4/R7: the final preflight passes, then the draft is marked ready once, after review and fixes", async () => {
70
+ const order = [];
71
+ const io = fakeIo();
72
+ const out = await run(io, CFG, { review: async () => { order.push("review"); return {}; }, fixes: async () => { order.push("fixes"); return {}; } });
73
+ assert.equal(out.status, "done");
74
+ assert.equal(io.calls.filter((a) => a[1] === "ready").length, 1);
75
+ assert.deepEqual(order, ["review", "fixes"]);
76
+ assert.ok(io.calls.findIndex((a) => a[1] === "create") < io.calls.findIndex((a) => a[1] === "ready"));
77
+ assert.equal(io.ran.length, 2); // before the PR and before ready
78
+ });
79
+
80
+ it("R6: a head whose final preflight fails is not marked ready", async () => {
81
+ const io = fakeIo({ preflightOk: (n) => n < 2 });
82
+ const out = await run(io, CFG);
83
+ assert.equal(out.step, "mark-ready");
84
+ assert.equal(out.status, "stopped");
85
+ assert.ok(!io.calls.some((a) => a[1] === "ready"));
86
+ });
87
+
88
+ it("an already-ready PR is not re-marked; non-blocking failures do not stop", async () => {
89
+ const io = fakeIo({ draft: false });
90
+ const r = await markReadyStep({ io, repo: REPO, config: CFG, state: { steps: { "release-pr": { result: { pr: 9 } } } } });
91
+ assert.equal(r.ready, true);
92
+ assert.ok(!io.calls.some((a) => a[1] === "ready"));
93
+ const nb = fakeIo({ preflightOk: () => false });
94
+ const r2 = await markReadyStep({ io: nb, repo: REPO, config: { preflight: { ...CFG.preflight, blocking: false } }, state: { steps: { "release-pr": { result: { pr: 9 } } } } });
95
+ assert.equal(r2.stopped, undefined);
96
+ assert.ok(nb.calls.some((a) => a[1] === "ready"));
97
+ });
98
+
99
+ it("R3: fixStep re-runs the preflight on the new head before the delta review, and a red one blocks", async () => {
100
+ const mk = (pfOk) => {
101
+ const io = fakeIo({ preflightOk: () => pfOk });
102
+ const seam = {
103
+ headOf: async () => HEAD, runLane: async () => ({ terminalReason: "merged" }), fileCiIssue: async () => 3,
104
+ calls: [],
105
+ };
106
+ return { io, seam, ctx: { io: Object.assign(io, { review: seam }), repo: REPO, def: "main", staging: "staging", config: CFG, save() {}, state: { steps: { review: { result: { pr: 9, marker: "FORGE:GATE_FAILURE", verdict: "X", head: "b".repeat(40), blocking: [11], ciFailing: 0 } } } } } };
107
+ };
108
+ const red = mk(false);
109
+ const out = await fixStep(red.ctx);
110
+ assert.equal(out.blocked, true);
111
+ assert.match(out.reason, /host preflight failed/);
112
+ assert.equal(red.io.ran.length, 1);
113
+ });
114
+ });
@@ -0,0 +1,64 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ /**
4
+ * Rehearsal step of `forgedock release` (#5253): runs the project's own deploy dry-run (forge.yaml `release.rehearsal`) on the
5
+ * host against the release-PR head, after review and before promotion. A failing blocking rehearsal files (or updates) one
6
+ * `release-blocker` issue per head and stops the job like a GATE_FAILURE; `--resume` re-runs it. The result is recorded in the
7
+ * release state and in a FORGE:REHEARSAL section of the release PR body. No model call. Effects go through `ctx.io`.
8
+ */
9
+ export const REHEARSAL_TIMEOUT_MS = 20 * 60_000;
10
+ export const OUTPUT_TAIL_CHARS = 6000;
11
+ export const BLOCKER_LABEL = "release-blocker";
12
+ const PR_START = "<!-- FORGE:REHEARSAL -->", PR_END = "<!-- /FORGE:REHEARSAL -->";
13
+ const json = (s) => JSON.parse(String(s || "null"));
14
+ const off = (v) => ["false", "off", "no", "0"].includes(String(v ?? "").trim().toLowerCase());
15
+
16
+ /**
17
+ * The rehearsal keys of forge.yaml's `release` map -> `{command, timeoutMs, blocking}`, or null when no command is set. The
18
+ * forge.yaml parser reads two levels, so the block is the flat keys `rehearsal_command`, `rehearsal_timeout` (seconds) and
19
+ * `rehearsal_blocking`.
20
+ */
21
+ export function parseRehearsalConfig(r) {
22
+ const command = typeof r?.rehearsal_command === "string" ? r.rehearsal_command.trim() : "";
23
+ if (!command) return null;
24
+ const secs = Number(r.rehearsal_timeout);
25
+ return { command, timeoutMs: Number.isFinite(secs) && secs > 0 ? secs * 1000 : REHEARSAL_TIMEOUT_MS, blocking: !off(r.rehearsal_blocking) };
26
+ }
27
+
28
+ export const tail = (s) => { const t = String(s ?? ""); return t.length > OUTPUT_TAIL_CHARS ? `…${t.slice(-OUTPUT_TAIL_CHARS)}` : t; };
29
+ // The rehearsal marker keeps its original form; other kinds (preflight, #5277) get their own so one head can hold both blockers.
30
+ const marker = (head, kind = "rehearsal") => `<!-- FORGE:RELEASE_BLOCKER head=${head}${kind === "rehearsal" ? "" : ` kind=${kind}`} -->`;
31
+
32
+ const prSection = (res) => `${PR_START}\n**Rehearsal**: ${res.ok ? "PASS" : res.blocking ? "FAIL (promotion held)" : "FAIL (non-blocking)"} at \`${res.head}\` — \`${res.command}\`${res.issue ? ` (#${res.issue})` : ""}\n${PR_END}`;
33
+
34
+ async function recordInPr({ io, repo, pr }, res) {
35
+ const body = String(json(await io.gh(["pr", "view", String(pr), "--repo", repo, "--json", "body"]))?.body ?? "");
36
+ const a = body.indexOf(PR_START), b = body.indexOf(PR_END);
37
+ const base = a >= 0 && b > a ? (body.slice(0, a) + body.slice(b + PR_END.length)).trimEnd() : body.trimEnd();
38
+ await io.gh(["pr", "edit", String(pr), "--repo", repo, "--body", `${base}\n\n${prSection(res)}\n`]);
39
+ }
40
+
41
+ /** One open release-blocker issue per head and kind: comment on it when it exists, else create it. @returns the issue number. */
42
+ export async function fileBlocker({ io, repo, pr, kind = "rehearsal" }, res) {
43
+ const text = `Release ${kind} failed${pr ? ` on PR #${pr}` : ""} at head \`${res.head}\`.\n\nCommand: \`${res.command}\` (exit ${res.code ?? "?"}${res.timedOut ? ", timed out" : ""})\n\n\`\`\`\n${tail(res.output)}\n\`\`\`\n`;
44
+ const open = json(await io.gh(["issue", "list", "--repo", repo, "--label", BLOCKER_LABEL, "--state", "open", "--limit", "100", "--json", "number,body"])) ?? [];
45
+ const found = open.find((i) => String(i.body ?? "").includes(marker(res.head, kind)));
46
+ if (found) { await io.gh(["issue", "comment", String(found.number), "--repo", repo, "--body", text]); return found.number; }
47
+ const url = String(await io.gh(["issue", "create", "--repo", repo, "--label", BLOCKER_LABEL, "--title", `release-blocker: ${kind} failed at ${res.head.slice(0, 12)}`, "--body", `${marker(res.head, kind)}\n${text}`])).trim();
48
+ return Number(/\/issues\/(\d+)/.exec(url)?.[1]) || null;
49
+ }
50
+
51
+ export async function rehearsalStep(ctx) {
52
+ const { io, repo, config } = ctx;
53
+ const cfg = config.rehearsal;
54
+ if (!cfg) return { skipped: true };
55
+ const { pr } = ctx.state.steps["release-pr"].result;
56
+ const head = json(await io.gh(["pr", "view", String(pr), "--repo", repo, "--json", "headRefOid"]))?.headRefOid;
57
+ const run = await io.rehearse(cfg.command, { timeout: cfg.timeoutMs });
58
+ const res = { ok: !!run.ok, head, command: cfg.command, blocking: cfg.blocking, code: run.code ?? null, timedOut: !!run.timedOut, output: run.ok ? "" : tail(run.output), at: new Date(io.now()).toISOString() };
59
+ if (!res.ok) res.issue = await fileBlocker({ io, repo, pr }, res);
60
+ await recordInPr({ io, repo, pr }, res);
61
+ const { output, ...kept } = res;
62
+ if (!res.ok && res.blocking) return { stopped: true, why: `release rehearsal failed at ${head} (release-blocker #${res.issue}); fix it, then resume`, ...kept };
63
+ return kept;
64
+ }
@@ -0,0 +1,93 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ import { describe, it } from "node:test";
4
+ import assert from "node:assert/strict";
5
+ import { tmpDir } from "../tests/_tmp.mjs";
6
+ import { runRelease, withStubs, newReleaseId, readReleaseConfig, openRelease } from "./release.mjs";
7
+ import { parseRehearsalConfig } from "./release-rehearsal.mjs";
8
+
9
+ const DISK = [{ mount: "/", type: "ext4" }];
10
+ const REPO = "o/r", HEAD = "b".repeat(40);
11
+ const ok = async () => ({ ok: true });
12
+
13
+ function fakeIo({ run = { ok: true }, issues = [], body = "Bundle" } = {}) {
14
+ const calls = [], rehearsed = [];
15
+ const st = { issues: [...issues], body };
16
+ const io = {
17
+ calls, rehearsed, st, now: () => 1_700_000_000_000, print: () => {},
18
+ runningLanes: async () => [], batches: async () => [], setParallel: async () => {},
19
+ rehearse: async (cmd, o) => { rehearsed.push([cmd, o]); return run; },
20
+ gh: async (a) => {
21
+ calls.push(a); const j = a.join(" ");
22
+ if (a[0] === "pr" && a[1] === "list" && a.includes("open")) return JSON.stringify(a.includes("--head") ? [{ number: 7, headRefOid: HEAD, url: "u" }] : []);
23
+ if (j.includes("headRefOid")) return JSON.stringify({ headRefOid: HEAD });
24
+ if (j.includes("--json comments")) return JSON.stringify({ comments: [{ body: "FORGE:GATE_PASS" }] });
25
+ if (a[0] === "api") return JSON.stringify([{ name: "forge/deploy-gate", conclusion: "success" }]);
26
+ if (j.includes("--json body")) return JSON.stringify({ body: st.body });
27
+ if (a[0] === "pr" && a[1] === "edit") { st.body = a[a.indexOf("--body") + 1]; return ""; }
28
+ if (a[0] === "pr" && a[1] === "merge") return "";
29
+ if (a[0] === "issue" && a[1] === "list") return JSON.stringify(st.issues);
30
+ if (a[0] === "issue" && a[1] === "create") { st.issues.push({ number: 42, body: a[a.indexOf("--body") + 1] }); return "https://github.com/o/r/issues/42"; }
31
+ if (a[0] === "issue" && a[1] === "comment") return "";
32
+ throw new Error(`unexpected gh ${j}`);
33
+ },
34
+ };
35
+ return io;
36
+ }
37
+ const go = async (io, config, root = tmpDir("rehearsal-"), id = newReleaseId()) => ({
38
+ out: await runRelease({ io, repo: REPO, root, mounts: DISK, id, opts: { merge: true }, config, branches: { staging: "staging", default: "main" }, steps: withStubs({ review: ok, fixes: ok, "post-merge": ok }) }),
39
+ root, id,
40
+ });
41
+ const cfg = (o = {}) => ({ rehearsal: parseRehearsalConfig({ rehearsal_command: "./dry-run.sh", ...o }) });
42
+
43
+ describe("release rehearsal (#5253)", () => {
44
+ it("unconfigured: no rehearse, no issue/PR-body calls, promotion merges", async () => {
45
+ const io = fakeIo();
46
+ const { out } = await go(io, {});
47
+ assert.equal(out.status, "done");
48
+ assert.equal(io.rehearsed.length, 0);
49
+ assert.ok(!io.calls.some((a) => a[0] === "issue" || (a[0] === "pr" && a[1] === "edit")));
50
+ assert.ok(io.calls.some((a) => a[0] === "pr" && a[1] === "merge"));
51
+ });
52
+
53
+ it("failing rehearsal holds promotion and files one blocker with output and head; a rerun comments", async () => {
54
+ const io = fakeIo({ run: { ok: false, code: 2, output: "bundle missing incident files" } });
55
+ const { out, root, id } = await go(io, cfg());
56
+ assert.equal(out.status, "stopped"); assert.equal(out.step, "rehearsal");
57
+ assert.ok(!io.calls.some((a) => a[0] === "pr" && a[1] === "merge"));
58
+ const creates = io.calls.filter((a) => a[0] === "issue" && a[1] === "create");
59
+ assert.equal(creates.length, 1);
60
+ const body = creates[0][creates[0].indexOf("--body") + 1];
61
+ assert.ok(body.includes("bundle missing incident files") && body.includes(HEAD));
62
+ assert.ok(creates[0].includes("release-blocker"));
63
+ assert.match(io.st.body, /Rehearsal\*\*: FAIL/);
64
+ assert.equal(openRelease(root, id).load().steps.rehearsal.result.head, HEAD);
65
+ await go(io, cfg(), root, id);
66
+ assert.equal(io.calls.filter((a) => a[0] === "issue" && a[1] === "create").length, 1);
67
+ assert.equal(io.calls.filter((a) => a[0] === "issue" && a[1] === "comment").length, 1);
68
+ assert.equal((io.st.body.match(/<!-- FORGE:REHEARSAL -->/g) ?? []).length, 1);
69
+ });
70
+
71
+ it("blocking:false records the failure and still promotes", async () => {
72
+ const io = fakeIo({ run: { ok: false, code: 1, output: "x" } });
73
+ const { out } = await go(io, cfg({ rehearsal_blocking: "false" }));
74
+ assert.equal(out.status, "done");
75
+ assert.match(io.st.body, /non-blocking/);
76
+ });
77
+
78
+ it("passing rehearsal is recorded in state and PR body, then promotes; timeout is passed in ms", async () => {
79
+ const io = fakeIo();
80
+ const { out, root, id } = await go(io, cfg({ rehearsal_timeout: "30" }));
81
+ assert.equal(out.status, "done");
82
+ assert.equal(io.rehearsed[0][1].timeout, 30_000);
83
+ const r = openRelease(root, id).load().steps.rehearsal;
84
+ assert.ok(r.done && r.result.ok && r.result.head === HEAD);
85
+ assert.match(io.st.body, /Rehearsal\*\*: PASS/);
86
+ });
87
+
88
+ it("config parsing", () => {
89
+ assert.ok(!("rehearsal" in readReleaseConfig("")));
90
+ assert.equal(parseRehearsalConfig({ rehearsal_command: " " }), null);
91
+ assert.deepEqual(readReleaseConfig("release:\n rehearsal_command: ./d.sh\n rehearsal_timeout: 60\n rehearsal_blocking: false\n").rehearsal, { command: "./d.sh", timeoutMs: 60000, blocking: false });
92
+ });
93
+ });
@@ -0,0 +1,77 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ /**
4
+ * End-to-end run of `forgedock release` through the real job (preflight, release-pr, review, fixes, promotion) against an
5
+ * in-memory GitHub (#5212, R1): the release PR exists, the panel runs, a HIGH finding is filed and blocks, a fix lane merges
6
+ * to staging, the delta review passes, and the job stops at GATE_PASS with the merge command, with no manual step. GitHub, the
7
+ * model and the lane process are in memory (as in conformance.e2e.test.mjs); the job, steps, state and resume are real.
8
+ */
9
+ import { describe, it } from "node:test";
10
+ import assert from "node:assert/strict";
11
+ import { tmpDir } from "../tests/_tmp.mjs";
12
+ import { runRelease, newReleaseId, openRelease } from "./release.mjs";
13
+
14
+ const DISK = [{ mount: "/", type: "ext4" }];
15
+ const sha = (n) => String(n).padStart(40, "a");
16
+
17
+ /** In-memory GitHub + panel: one release PR whose head is a counter; comments are the register. */
18
+ function world() {
19
+ const w = { head: 1, comments: [], issues: [], lanes: [], printed: [], fixed: false, agents: [], launched: [] };
20
+ const io = {
21
+ now: () => 1_700_000_000_000, print: (l) => w.printed.push(l),
22
+ runningLanes: async () => [], batches: async () => [], setParallel: async () => {},
23
+ gh: async (a) => {
24
+ const j = a.join(" ");
25
+ if (a[0] === "pr" && a[1] === "list") return JSON.stringify(a.includes("--head") && a[a.indexOf("--state") + 1] === "open" ? [{ number: 7, headRefOid: sha(w.head), url: "u" }] : []);
26
+ if (j.includes("headRefOid")) return JSON.stringify({ headRefOid: sha(w.head) });
27
+ if (j.includes("--json comments")) return JSON.stringify({ comments: w.comments.map((body) => ({ body })) });
28
+ if (a[0] === "api") return JSON.stringify([{ name: "forge/deploy-gate", conclusion: "success" }]);
29
+ throw new Error(`unexpected gh ${j}`);
30
+ },
31
+ };
32
+ io.review = {
33
+ pre: async ({ delta }) => ({ code: 0, lines: [], data: { pr: 7, headSha: sha(w.head), bundle: [1, 2], scopeMode: "full", contextFile: "/sd/ctx.json", launchedFile: "/sd/l", briefs: [{ domain: "security", path: "/sd/b" }], delta: delta ? { from: delta, files: ["f"] } : null } }),
34
+ headOf: async () => sha(w.head),
35
+ readFile: () => "brief",
36
+ markLaunched: (_f, domains) => { w.launched = domains; },
37
+ saveTestGate: () => "/sd/gate.txt",
38
+ runAgent: async ({ role }) => { w.agents.push(role); return { text: "FORGE:TEST_GATE:RESULT=PASS" }; },
39
+ finalize: async () => ({ code: 0, lines: [], data: { head: sha(w.head), notes: ["- nit"], toFile: w.fixed ? [] : [{ title: "leak", severity: "HIGH" }] } }),
40
+ fileIssue: async ({ item }) => { w.issues.push(item.title); return 100 + w.issues.length; },
41
+ fileCiIssue: async () => 999,
42
+ addNotes: async () => {},
43
+ summary: async ({ filed }) => {
44
+ const pass = w.fixed;
45
+ w.comments.push(pass ? "<!-- FORGE:GATE_PASS -->" : "<!-- FORGE:GATE_FAILURE -->");
46
+ return { code: pass ? 0 : 1, lines: [], data: { verdict: pass ? "APPROVE FOR DEPLOY" : "BLOCK DEPLOY", marker: pass ? "FORGE:GATE_PASS" : "FORGE:GATE_FAILURE", ciFailing: 0, filed } };
47
+ },
48
+ runLane: async ({ issue, lane }) => { w.lanes.push([issue, lane]); w.fixed = true; w.head++; return { terminalReason: "merged" }; },
49
+ };
50
+ return { w, io };
51
+ }
52
+
53
+ describe("forgedock release, review to gate (e2e on in-memory GitHub)", () => {
54
+ it("reviews, files the blocking finding, fixes it on staging, re-reviews the delta and stops at GATE_PASS with the merge command", async () => {
55
+ const { w, io } = world();
56
+ const out = await runRelease({ io, repo: "o/r", root: tmpDir("rel-e2e-"), mounts: DISK, id: newReleaseId(), opts: {}, config: {}, branches: { staging: "staging", default: "main" } });
57
+ assert.equal(out.status, "stopped");
58
+ assert.equal(out.step, "promotion");
59
+ assert.match(out.reason, /GATE_PASS/);
60
+ assert.deepEqual(w.issues, ["leak"], "the finding was filed");
61
+ assert.deepEqual(w.lanes, [[101, "staging"]], "one fix lane on the staging branch");
62
+ assert.deepEqual(w.comments, ["<!-- FORGE:GATE_FAILURE -->", "<!-- FORGE:GATE_PASS -->"], "failure at the first head, pass after the delta review");
63
+ assert.ok(w.agents.includes("release-review-security") && w.agents.includes("release-review-regression-risk") && w.agents.includes("release-test-gate"), "the full panel ran");
64
+ assert.ok(w.printed.some((l) => l.includes(`--match-head-commit ${sha(2)}`)), "merge command at the fixed head");
65
+ });
66
+
67
+ it("a killed job resumes after the review step without re-running it", async () => {
68
+ const { w, io } = world();
69
+ const root = tmpDir("rel-e2e-"), id = newReleaseId();
70
+ const args = { io, repo: "o/r", root, mounts: DISK, id, opts: {}, config: {}, branches: { staging: "staging", default: "main" } };
71
+ await runRelease(args);
72
+ const agents = w.agents.length;
73
+ assert.equal(openRelease(root, id, DISK).load().steps.fixes.done, true);
74
+ await runRelease(args);
75
+ assert.equal(w.agents.length, agents, "review and fixes are done: nothing re-dispatched");
76
+ });
77
+ });