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
@@ -111,6 +111,21 @@ export function redIssue({ slug, milestone, head, state, failures, specs, runUrl
111
111
  return { title: `integration-red(milestone/${slug}): full suite failing at ${short(head)}`, body, marker: redMarker(slug), milestone };
112
112
  }
113
113
 
114
+ export const journeyMarker = (slug) => `${STATE_MARKER}:journey:${slug}`;
115
+
116
+ /** #5337: title and body of the integration-red issue for a red epic journey; names the PR that merged last and every PR since the last green run. */
117
+ export function journeyRedIssue({ slug, milestone, head, pr, prs, repo, at }) {
118
+ const named = arr(prs).map((p) => `#${p}`).join(", ") || "none recorded";
119
+ const body = [
120
+ `The epic journey of milestone \`${milestone}\` is red on \`milestone/${slug}\` after the merge of ${pr != null ? `#${pr}` : "a lane PR"}. Admission of new lanes is held until a journey run is green.`, "",
121
+ `- Head: \`${short(head)}\` (${at})`,
122
+ `- Lane PRs merged since the last green journey run: ${named}`,
123
+ `- Result: see the latest FORGE:ACCEPTANCE comment on the epic (${repo})`, "",
124
+ `<!-- ${journeyMarker(slug)} -->`,
125
+ ].join("\n");
126
+ return { title: `integration-red(milestone/${slug}): journey red after ${pr != null ? `#${pr}` : "a merge"}`, body, marker: journeyMarker(slug), milestone };
127
+ }
128
+
114
129
  /** Open issue of the milestone carrying `marker`: its number, or null. */
115
130
  async function findRed({ gh, repo, milestone, marker }) {
116
131
  const open = JSON.parse(String(await gh(["issue", "list", "-R", repo, "--milestone", milestone, "--state", "open", "--limit", "500", "--json", "number,body"])) || "[]");
@@ -193,25 +208,87 @@ export async function runIntegration({ io, repo, cfg, pattern, only = null, ...r
193
208
  * onMerged counts the merge into the milestone state and, at `every_merges`, starts a run in the background (never in the
194
209
  * lane's slot); `settle()` waits for those. `prime()` loads the red streaks `holds` reads (synchronously) from the milestones.
195
210
  */
196
- export function makeIntegration({ repo, io, cfg, pattern = DEFAULT_FEATURE_PATTERN, nowFn = () => Date.now(), sleep, random, onEvent = () => {} }) {
197
- if (!cfg) return null;
211
+ export function makeIntegration({ repo, io, cfg, pattern = DEFAULT_FEATURE_PATTERN, nowFn = () => Date.now(), sleep, random, onEvent = () => {}, journeys = null, skeleton = false }) {
212
+ if (!cfg && !journeys && !skeleton) return null;
198
213
  const streaks = new Map(); // lane -> consecutive red runs
199
214
  const running = new Set();
215
+ const journeyRunning = new Set();
216
+ const journeyAgain = new Map(); // milestone title -> the last merge that landed during a running journey run (#5382)
217
+ const skeletons = new Map(); // lane -> number of its open skeleton issue (#5337: no sibling is admitted until it merges)
218
+ const journeyHeld = new Map(); // lane -> number of the open journey integration-red issue (#5337)
219
+ const journeyPrs = new Map(); // milestone title -> lane PRs merged since the last green journey run
200
220
  const pending = new Set();
201
221
  let chain = Promise.resolve();
202
222
  const lane = (title) => { const b = branchOf(pattern, title); return b ? b.branch : null; };
203
223
  const note = (ms, state) => { const l = lane(ms.title); if (l) streaks.set(l, state?.redStreak ?? 0); };
204
224
 
225
+ /** #5337: record the first lane merge / first green journey run in the milestone's FORGE:INTEGRATION block (read-modify-write). Resolves {before, description} or null when already set. */
226
+ async function stamp(ms, key) {
227
+ const fresh = (await readMilestone({ gh: io.gh, repo, title: ms.title })) ?? ms;
228
+ const before = parseIntegrationState(fresh.description) ?? emptyState();
229
+ if (before[key]) return null;
230
+ const description = renderState(fresh.description, { ...before, [key]: new Date(nowFn()).toISOString() });
231
+ await io.gh(["api", "-X", "PATCH", `repos/${repo}/milestones/${fresh.number}`, "-f", `description=${description}`]);
232
+ return { before, description };
233
+ }
234
+
235
+ /** #5337: a journey run result: red files/updates ONE integration-red issue naming the PRs and holds admission; green closes it. */
236
+ async function judge(issue, ms, title, res) {
237
+ const l = lane(title), b = branchOf(pattern, title);
238
+ if (!res || typeof res !== "object" || !b) return;
239
+ const at = new Date(nowFn()).toISOString();
240
+ if (res.red) {
241
+ if (skeletons.has(l)) return; // the skeleton has not merged: a red journey is expected and holds nothing yet
242
+ const prs = journeyPrs.get(title) ?? [];
243
+ const filed = await fileOrUpdateRed({ gh: io.gh, repo, issue: journeyRedIssue({ slug: b.slug, milestone: title, head: res.head, pr: prs[prs.length - 1] ?? null, prs, repo, at }) });
244
+ if (filed.number) journeyHeld.set(l, filed.number);
245
+ onEvent({ issue, detail: `journey red on ${l}: filed #${filed.number}, admission held` });
246
+ } else if (res.ran) {
247
+ await closeRed({ gh: io.gh, repo, milestone: title, slug: `journey:${b.slug}`, head: res.head });
248
+ journeyHeld.delete(l);
249
+ journeyPrs.delete(title);
250
+ const done = await stamp(ms, "firstJourneyGreenAt");
251
+ if (done) {
252
+ const first = done.before.firstMergeAt ? Date.parse(done.before.firstMergeAt) : NaN;
253
+ onEvent({ issue, detail: `first green journey on ${l}${Number.isFinite(first) ? ` ${Math.round((nowFn() - first) / 60000)} min after the first lane merge` : ""}` });
254
+ }
255
+ }
256
+ }
257
+
258
+ /** #5336: run the epic's journeys once; when a merge arrived meanwhile (#5382), run once more so a red hold can clear. */
259
+ function startJourneys(issue, full, title, number) {
260
+ journeyRunning.add(title);
261
+ const jp = Promise.resolve().then(() => journeys({ title, branch: lane(title), number }))
262
+ .then(async (r) => { onEvent({ issue, detail: `journeys: ${title} ${r?.summary ?? r ?? "done"}` }); await judge(issue, full, title, r); })
263
+ .catch((e) => onEvent({ issue, detail: `journey run failed: ${String(e?.message ?? e).slice(0, 200)}` }))
264
+ .finally(() => {
265
+ journeyRunning.delete(title); pending.delete(jp);
266
+ const again = journeyAgain.get(title);
267
+ if (again) { journeyAgain.delete(title); startJourneys(again.issue, again.full, title, number); }
268
+ });
269
+ pending.add(jp);
270
+ }
271
+
205
272
  async function count(issue, result) {
206
273
  const title = result?.milestone;
207
274
  if (!title) return;
208
275
  const ms = await readMilestone({ gh: io.gh, repo, title });
209
276
  if (!ms) return;
210
- const full = { ...ms, title };
211
- const s = parseIntegrationState(ms.description) ?? emptyState();
277
+ let full = { ...ms, title };
278
+ if (skeletons.get(lane(title)) === Number(issue)) skeletons.delete(lane(title)); // the skeleton merged: siblings are admitted
279
+ if (result.pr != null) journeyPrs.set(title, [...(journeyPrs.get(title) ?? []), result.pr].slice(-MAX_PRS));
280
+ if (journeys || skeleton) { const st = await stamp(full, "firstMergeAt"); if (st) full = { ...full, description: st.description }; }
281
+ // #5336: after each child merge, run the epic's journeys on the milestone branch (the runner skips milestones with no journey yet).
282
+ // #5382: a merge that lands while a run is in flight queues one rerun (the run may have started before that merge).
283
+ if (journeys) {
284
+ if (journeyRunning.has(title)) journeyAgain.set(title, { issue, full });
285
+ else startJourneys(issue, full, title, ms.number);
286
+ }
287
+ if (!cfg) return;
288
+ const s = parseIntegrationState(full.description) ?? emptyState();
212
289
  const pr = result.pr ?? null;
213
290
  const next = { ...s, mergesSince: (s.mergesSince ?? 0) + 1, mergedPrs: pr != null && !s.mergedPrs.includes(pr) ? [...s.mergedPrs, pr].slice(-MAX_PRS) : s.mergedPrs };
214
- const desc = renderState(ms.description, next);
291
+ const desc = renderState(full.description, next);
215
292
  await io.gh(["api", "-X", "PATCH", `repos/${repo}/milestones/${ms.number}`, "-f", `description=${desc}`]);
216
293
  note(full, next);
217
294
  if (!cfg.everyMerges || next.mergesSince < cfg.everyMerges || running.has(title)) return;
@@ -230,12 +307,24 @@ export function makeIntegration({ repo, io, cfg, pattern = DEFAULT_FEATURE_PATTE
230
307
  return p;
231
308
  },
232
309
  holds(issue, { lane: l } = {}) {
233
- if (!cfg.blockAdmissionAfter) return null;
234
- const n = streaks.get(String(l ?? ""));
310
+ const key = String(l ?? "");
311
+ const sk = skeletons.get(key);
312
+ if (sk && Number(issue) !== sk) return `skeleton issue #${sk} of ${key} has not merged`;
313
+ const red = journeyHeld.get(key);
314
+ // #5382: the integration-red issue is the fix for the hold: admitting it is the only exit, its merge reruns the journeys.
315
+ if (red && Number(issue) !== red) return `epic journey red on ${key} (integration-red #${red})`;
316
+ if (!cfg?.blockAdmissionAfter) return null;
317
+ const n = streaks.get(key);
235
318
  return n >= cfg.blockAdmissionAfter ? `${n} consecutive red integration runs on ${l}` : null;
236
319
  },
237
320
  async prime() {
238
- for (const ms of await listOpenMilestones({ gh: io.gh, repo })) note(ms, parseIntegrationState(ms.description));
321
+ const open = await listOpenMilestones({ gh: io.gh, repo });
322
+ for (const ms of open) note(ms, parseIntegrationState(ms.description));
323
+ // #5337: reload the holds from GitHub (the register): open skeleton issues and open journey integration-red issues.
324
+ const list = async (label) => { try { return arr(JSON.parse(String(await io.gh(["issue", "list", "-R", repo, "--label", label, "--state", "open", "--limit", "500", "--json", "number,body,milestone"])) || "[]")); } catch { return []; } };
325
+ const laneOf = (x) => { const t = x?.milestone?.title; return t && open.some((m) => m.title === t) ? lane(t) : null; };
326
+ if (skeleton) for (const x of await list("skeleton")) { const l = laneOf(x); if (l && !skeletons.has(l)) skeletons.set(l, Number(x.number)); }
327
+ if (journeys) for (const x of await list(RED_LABEL)) { const l = laneOf(x); if (l && String(x.body ?? "").includes(`<!-- ${STATE_MARKER}:journey:`)) journeyHeld.set(l, Number(x.number)); }
239
328
  },
240
329
  async settle() { await chain; while (pending.size) await Promise.allSettled([...pending]); },
241
330
  };
@@ -256,7 +345,9 @@ export async function runIntegrationCli(argv, deps = {}) {
256
345
  const on = deps.cfg !== undefined ? !!deps.cfg : !!readIntegrationConfig(deps.cwd ?? process.cwd());
257
346
  for (const ms of await listOpenMilestones({ gh: io.gh, repo })) {
258
347
  const s = parseIntegrationState(ms.description);
259
- if (s || on) (deps.print ?? ((t) => console.log(t)))(` integration: ${ms.title}: last green full-suite run ${s?.lastGreen?.at ?? "never"} (red streak ${s?.redStreak ?? 0})`);
348
+ // #5337: the metric: first lane merge to first green journey run, per milestone.
349
+ const first = s?.firstMergeAt ? `; first merge ${s.firstMergeAt}, first green journey ${s.firstJourneyGreenAt ?? "never"}` : "";
350
+ if (s || on) (deps.print ?? ((t) => console.log(t)))(` integration: ${ms.title}: last green full-suite run ${s?.lastGreen?.at ?? "never"} (red streak ${s?.redStreak ?? 0})${first}`);
260
351
  }
261
352
  return 0;
262
353
  }
@@ -120,6 +120,95 @@ describe("runIntegration", () => {
120
120
  });
121
121
  });
122
122
 
123
+ describe("walking skeleton and journey gate (#5337)", () => {
124
+ const LANE = "milestone/m-one";
125
+ const withSkeleton = (io, open = [{ number: 7, body: "", milestone: { title: "M One" } }]) => ({ ...io, gh: async (a) => (a[0] === "issue" && a[1] === "list" && a.includes("skeleton") ? JSON.stringify(open) : io.gh(a)) });
126
+
127
+ it("admits no sibling until the skeleton issue merges", async () => {
128
+ const { st, io } = fake({});
129
+ const seam = makeIntegration({ repo: "o/r", io: withSkeleton(io), cfg: null, skeleton: true, nowFn: () => NOW });
130
+ await seam.prime();
131
+ assert.match(seam.holds(8, { lane: LANE }), /skeleton issue #7 of milestone\/m-one has not merged/);
132
+ assert.equal(seam.holds(7, { lane: LANE }), null, "the skeleton itself is admitted");
133
+ assert.equal(seam.holds(8, { lane: "staging" }), null, "other lanes are untouched");
134
+ await seam.onMerged(7, {}, { milestone: "M One", pr: 20 });
135
+ assert.equal(seam.holds(8, { lane: LANE }), null);
136
+ assert.equal(parseIntegrationState(st.description).firstMergeAt, new Date(NOW).toISOString());
137
+ });
138
+ it("is off without the skeleton option", () => assert.equal(makeIntegration({ repo: "o/r", io: fake({}).io, cfg: null }), null));
139
+
140
+ it("a red journey files ONE integration-red issue naming the PR, holds admission, and a green run closes it", async () => {
141
+ const { st, io } = fake({});
142
+ let result = { summary: "#5 fail", red: true, ran: true, head: SHA };
143
+ const events = [];
144
+ const seam = makeIntegration({ repo: "o/r", io: withSkeleton(io, []), cfg: null, skeleton: true, journeys: async () => result, nowFn: () => NOW, onEvent: (e) => events.push(e.detail) });
145
+ await seam.prime();
146
+ await seam.onMerged(1, {}, { milestone: "M One", pr: 11 });
147
+ await seam.settle();
148
+ assert.equal(st.created.length, 1);
149
+ assert.match(st.created[0].title, /journey red after #11/);
150
+ assert.match(st.created[0].body, /<!-- FORGE:INTEGRATION:journey:m-one -->/);
151
+ assert.match(seam.holds(2, { lane: LANE }), /epic journey red on milestone\/m-one \(integration-red #900\)/);
152
+ await seam.onMerged(2, {}, { milestone: "M One", pr: 12 });
153
+ await seam.settle();
154
+ assert.equal(st.created.length, 1, "still one issue");
155
+ assert.match(st.edited.at(-1).body, /#11, #12/);
156
+ result = { summary: "#5 pass", red: false, ran: true, head: SHA2 };
157
+ await seam.onMerged(3, {}, { milestone: "M One", pr: 13 });
158
+ await seam.settle();
159
+ assert.deepEqual(st.closed, ["900"]);
160
+ assert.equal(seam.holds(4, { lane: LANE }), null);
161
+ const state = parseIntegrationState(st.description);
162
+ assert.ok(state.firstMergeAt && state.firstJourneyGreenAt);
163
+ assert.ok(events.some((d) => /first green journey on milestone\/m-one/.test(d)));
164
+ });
165
+ it("#5382: the integration-red issue itself is admitted, and a merge during a running journey run queues a rerun that clears the hold", async () => {
166
+ const { st, io } = fake({});
167
+ let release, runs = 0;
168
+ const gate = new Promise((r) => { release = r; });
169
+ const results = [{ summary: "fail", red: true, ran: true, head: SHA }, { summary: "pass", red: false, ran: true, head: SHA2 }];
170
+ const seam = makeIntegration({ repo: "o/r", io: withSkeleton(io, []), cfg: null, skeleton: true, nowFn: () => NOW,
171
+ journeys: async () => { const r = results[Math.min(runs++, 1)]; if (runs === 1) await gate; return r; } });
172
+ await seam.prime();
173
+ const first = seam.onMerged(1, {}, { milestone: "M One", pr: 11 });
174
+ await first;
175
+ await seam.onMerged(2, {}, { milestone: "M One", pr: 12 }); // lands while run 1 is in flight
176
+ assert.equal(runs, 1, "no concurrent run");
177
+ release();
178
+ await seam.settle();
179
+ assert.equal(runs, 2, "the merge that landed mid-run got its own run");
180
+ assert.equal(seam.holds(3, { lane: LANE }), null, "the rerun was green: hold cleared");
181
+ assert.deepEqual(st.closed, ["900"]);
182
+ // and while red, only the red issue is admitted
183
+ const red = fake({});
184
+ const seam2 = makeIntegration({ repo: "o/r", io: withSkeleton(red.io, []), cfg: null, skeleton: true, nowFn: () => NOW, journeys: async () => ({ summary: "fail", red: true, ran: true, head: SHA }) });
185
+ await seam2.prime();
186
+ await seam2.onMerged(1, {}, { milestone: "M One", pr: 11 });
187
+ await seam2.settle();
188
+ assert.match(seam2.holds(2, { lane: LANE }), /integration-red #900/);
189
+ assert.equal(seam2.holds(900, { lane: LANE }), null, "the red issue is the exit");
190
+ });
191
+ it("a red journey before the skeleton merged files nothing and holds nothing extra", async () => {
192
+ const { st, io } = fake({});
193
+ const seam = makeIntegration({ repo: "o/r", io: withSkeleton(io), cfg: null, skeleton: true, journeys: async () => ({ summary: "fail", red: true, ran: true, head: SHA }), nowFn: () => NOW });
194
+ await seam.prime();
195
+ await seam.onMerged(8, {}, { milestone: "M One", pr: 11 });
196
+ await seam.settle();
197
+ assert.equal(st.created.length, 0);
198
+ });
199
+ it("reloads an open journey red issue on prime and `integration status` shows the metric", async () => {
200
+ const body = "x\n<!-- FORGE:INTEGRATION:journey:m-one -->";
201
+ const { io } = fake({ description: renderState("", { ...emptyState(), firstMergeAt: "2026-10-27T09:00:00.000Z" }) });
202
+ const gh = async (a) => (a[0] === "issue" && a[1] === "list" && a.includes("integration-red") ? JSON.stringify([{ number: 31, body, milestone: { title: "M One" } }]) : io.gh(a));
203
+ const seam = makeIntegration({ repo: "o/r", io: { ...io, gh }, cfg: null, journeys: async () => "no journey declared" });
204
+ await seam.prime();
205
+ assert.match(seam.holds(2, { lane: LANE }), /integration-red #31/);
206
+ const lines = [];
207
+ await runIntegrationCli(["status", "--repo", "o/r"], { io, cfg: null, print: (t) => lines.push(t) });
208
+ assert.match(lines.join("\n"), /first merge 2026-10-27T09:00:00.000Z, first green journey never/);
209
+ });
210
+ });
211
+
123
212
  describe("makeIntegration seam", () => {
124
213
  it("is null when off", () => assert.equal(makeIntegration({ repo: "o/r", io: {}, cfg: null }), null));
125
214
  it("holds a lane after N consecutive red runs and releases it on green", async () => {
@@ -147,6 +236,15 @@ describe("makeIntegration seam", () => {
147
236
  assert.equal(st.created.length, 1);
148
237
  assert.match(st.created[0].body, /#11, #12/);
149
238
  });
239
+ it("runs the journeys after a child merge even with no integration cfg (#5336)", async () => {
240
+ const { io } = fake({});
241
+ const calls = [];
242
+ const seam = makeIntegration({ repo: "o/r", io, cfg: null, journeys: async (m) => { calls.push(m.title); } });
243
+ await seam.onMerged(1, {}, { milestone: "M One", pr: 11 });
244
+ await seam.settle();
245
+ assert.deepEqual(calls, ["M One"]);
246
+ assert.equal(seam.holds(1, { lane: "milestone/m-one" }), null);
247
+ });
150
248
  it("orchestrate ends a held lane `held` and starts nothing while the streak is red", async () => {
151
249
  const started = [];
152
250
  const integration = { holds: (n, { lane }) => (lane === "milestone/m-one" ? "2 consecutive red integration runs on milestone/m-one" : null) };
@@ -0,0 +1,64 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ /**
4
+ * Pure helpers of `forgedock issue-watch` for parity with the retired bash intake watcher (#5313): issues only (never a PR),
5
+ * the default skip labels, issues with an open closing PR, release awareness (pause while a `forgedock release` job runs)
6
+ * and the heartbeat liveness read by `issue-watch status` and doctor. No LLM calls; gh and the clock are injected.
7
+ */
8
+ import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
9
+ import { join } from "node:path";
10
+ import { RELEASE_STEPS } from "./release.mjs";
11
+
12
+ export const DEFAULT_SKIP_LABELS = ["epic", "needs-human", "post-deploy", "workflow:merged", "awaiting-promotion", "host-task"];
13
+ /** A release job that has not written its end `status` for this long is taken as dead, not in flight. */
14
+ export const RELEASE_STALE_MS = 6 * 3600 * 1000;
15
+ /** A heartbeat older than this many passes is reported stale. */
16
+ export const HEARTBEAT_PASSES = 3;
17
+
18
+ /** True when a listed item is a pull request (GitHub shares the number space; the bash watcher claimed PRs). */
19
+ export const isPullRequest = (item) => !!(item?.pullRequest || item?.isPullRequest || item?.__typename === "PullRequest" || /\/pull\/\d+/.test(String(item?.url ?? "")));
20
+
21
+ /** True when a `search` query asks for pull requests (`is:pr`, `type:pr`). */
22
+ export const searchesPullRequests = (search) => /(^|\s)-?(is|type):pr\b/i.test(String(search ?? "")) && !/(^|\s)-(is|type):pr\b/i.test(String(search ?? ""));
23
+
24
+ /** The first of `skip` the issue carries (label names or `{name}`), else null. */
25
+ export const skipLabelHit = (issue, skip = []) => (issue.labels ?? []).map((l) => (typeof l === "string" ? l : l?.name)).find((n) => n && skip.includes(n)) ?? null;
26
+
27
+ /** `Map<issue number, PR number>` of issues an open PR closes (`closingIssuesReferences`). A failed gh call throws: nothing is claimed blind. */
28
+ export async function closingPrIssues(gh, repo) {
29
+ const out = new Map();
30
+ for (const pr of JSON.parse(String(await gh(["pr", "list", "-R", repo, "--state", "open", "--limit", "200", "--json", "number,closingIssuesReferences"]))) ?? [])
31
+ for (const r of pr.closingIssuesReferences ?? []) if (!out.has(r.number)) out.set(r.number, pr.number);
32
+ return out;
33
+ }
34
+
35
+ /**
36
+ * The release job in flight for `repo` from `<root>/<id>/state.json`: the job writes `status` only when it ends (release.mjs
37
+ * runRelease), so a state without one and a recent mtime is running. @returns {{id, step: string|null, ageMs}|null}
38
+ */
39
+ export function releaseInFlight({ root, repo = null, now = Date.now(), staleMs = RELEASE_STALE_MS, readdir = readdirSync, stat = statSync, read = (f) => readFileSync(f, "utf8"), exists = existsSync } = {}) {
40
+ let ids = [];
41
+ try { ids = readdir(root); } catch { return null; }
42
+ let best = null;
43
+ for (const id of ids) {
44
+ const f = join(root, id, "state.json");
45
+ if (!exists(f)) continue;
46
+ let st; try { st = JSON.parse(read(f)); } catch { continue; }
47
+ if (!st || st.status || (repo && st.repo && st.repo !== repo)) continue;
48
+ let age; try { age = now - stat(f).mtimeMs; } catch { continue; }
49
+ if (age > staleMs) continue;
50
+ if (!best || age < best.ageMs) best = { id, step: RELEASE_STEPS.find((x) => !st.steps?.[x]?.done) ?? null, ageMs: age };
51
+ }
52
+ return best;
53
+ }
54
+
55
+ /** `{state: "running"|"paused"|"stale"|"done"|"unknown", reason, ageMs}` from a watch's status.json: never a process grep. */
56
+ export function watchLiveness(status, now = Date.now()) {
57
+ if (!status) return { state: "unknown", reason: "no status yet", ageMs: null };
58
+ const beat = Date.parse(status.heartbeat ?? "");
59
+ if (status.phase === "done") return { state: "done", reason: "watch finished", ageMs: Number.isFinite(beat) ? now - beat : null };
60
+ if (!Number.isFinite(beat)) return { state: "unknown", reason: "no heartbeat recorded", ageMs: null };
61
+ const ageMs = Math.max(0, now - beat), limit = HEARTBEAT_PASSES * (status.heartbeatEveryMs || 300000) + 60000;
62
+ if (ageMs > limit) return { state: "stale", reason: `last heartbeat ${Math.round(ageMs / 60000)}m ago, over ${Math.round(limit / 60000)}m: the watch is not running`, ageMs };
63
+ return status.paused ? { state: "paused", reason: status.paused.reason, ageMs } : { state: "running", reason: "heartbeat fresh", ageMs };
64
+ }
@@ -0,0 +1,127 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ import { test } from "node:test";
4
+ import assert from "node:assert/strict";
5
+ import { mkdirSync, writeFileSync, readFileSync, utimesSync } from "node:fs";
6
+ import { join } from "node:path";
7
+ import { tmpDir } from "../tests/_tmp.mjs";
8
+ import { loadWatches, validateWatch, planClaims, tick, runWatch, formatStatus, formatClaimPlan } from "./issuewatch.mjs";
9
+ import { isPullRequest, closingPrIssues, releaseInFlight, watchLiveness, DEFAULT_SKIP_LABELS } from "./issuewatch-parity.mjs";
10
+
11
+ const NOW = Date.parse("2026-11-10T12:00:00Z");
12
+ const iss = (n, o = {}) => ({ number: n, title: `t${n}`, body: "", labels: [], milestone: null, author: { login: "me" }, createdAt: "2026-11-09T00:00:00Z", ...o });
13
+ const lbl = (...n) => n.map((name) => ({ name }));
14
+ const state = () => ({ name: "w", repo: "o/r", phase: "running", claimed: [], inflight: [], merged: [], verified: [], unverified: [], closed: [], failed: [], folded: [], retries: {}, lanes: {}, batch: null, laneFor: {} });
15
+
16
+ function fakeIo(env, issues, { openPrs = [] } = {}) {
17
+ const batchOps = [], reported = new Set(); let nb = 0;
18
+ return { env: { FORGEDOCK_WATCH_DIR: env, FORGEDOCK_RELEASE_DIR: join(env, "releases") }, batchOps, reported, now: () => NOW, sleep: async () => {}, issues,
19
+ gh: async function (a) {
20
+ if (a[0] === "api") return this.issues.map((i) => `${i.number}\tOWNER`).join("\n");
21
+ if (a[0] === "pr" && a[1] === "list") return JSON.stringify(openPrs);
22
+ if (a[0] === "issue" && a[1] === "list") return JSON.stringify(this.issues);
23
+ if (a[1] === "view") return JSON.stringify({ state: "OPEN", body: "" });
24
+ return "";
25
+ },
26
+ batch: { add: (id, nums) => batchOps.push(["add", id, nums]), start: async (nums) => { batchOps.push(["start", nums]); return `b${++nb}`; }, reported: (id) => reported.has(id) } };
27
+ }
28
+ const bind = (io) => { const g = io.gh; io.gh = (a) => g.call(io, a); return io; };
29
+
30
+ test("#5313 a PR is never a claim: a PR-shaped item and an is:pr search are both refused", async () => {
31
+ assert.ok(isPullRequest({ url: "https://github.com/o/r/pull/9" }) && isPullRequest({ pullRequest: {} }) && !isPullRequest({ url: "https://github.com/o/r/issues/9" }));
32
+ assert.throws(() => validateWatch("w", { search: "is:pr label:x" }), /issues only/);
33
+ assert.doesNotThrow(() => validateWatch("w", { search: "-is:pr label:x" }));
34
+ const io = bind(fakeIo(tmpDir("iwp-"), [iss(1), iss(2, { url: "https://github.com/o/r/pull/2" })]));
35
+ const plan = await planClaims({ watch: validateWatch("w", { mode: "batch" }), repo: "o/r", io, state: state() });
36
+ assert.deepEqual(plan.claim.map((c) => c.number), [1]);
37
+ assert.match(formatClaimPlan(plan), /skip #2: pull request/);
38
+ });
39
+
40
+ test("#5313 an issue with an open closing PR is skipped, and default skip labels apply to batch watches", async () => {
41
+ const io = bind(fakeIo(tmpDir("iwp-"), [iss(1), iss(2), ...DEFAULT_SKIP_LABELS.map((l, k) => iss(10 + k, { labels: lbl(l) }))], { openPrs: [{ number: 77, closingIssuesReferences: [{ number: 2 }] }] }));
42
+ assert.deepEqual([...(await closingPrIssues(io.gh, "o/r"))], [[2, 77]]);
43
+ const plan = await planClaims({ watch: validateWatch("w", { mode: "batch" }), repo: "o/r", io, state: state() });
44
+ assert.deepEqual(plan.claim.map((c) => c.number), [1]);
45
+ assert.ok(plan.skip.some((s) => s.number === 2 && s.reason === "open closing PR #77"));
46
+ assert.equal(plan.skip.filter((s) => /^skip label /.test(s.reason)).length, DEFAULT_SKIP_LABELS.length);
47
+ const per = await planClaims({ watch: validateWatch("w", {}), repo: "o/r", io, state: state() }); // per-issue: no default list
48
+ assert.ok(per.claim.some((c) => c.number === 10));
49
+ const off = await planClaims({ watch: validateWatch("w", { mode: "batch", skip_labels: [] }), repo: "o/r", io, state: state() });
50
+ assert.ok(off.claim.some((c) => c.number === 10));
51
+ });
52
+
53
+ test("#5313 an AlterLab-equivalent config (two windows, skip labels) plans the claims the script would", async () => {
54
+ const w = loadWatches(`issue_watch:\n watches:\n nomilestone:\n milestone: none\n since: 2026-11-08T00:00:00Z\n include_followups: defer-only\n mode: batch\n milestoned:\n milestone: "1.5"\n since: 2026-11-01T00:00:00Z\n mode: batch\n`);
55
+ const ms = { title: "1.5" };
56
+ const issues = [iss(1), iss(2, { createdAt: "2026-11-01T00:00:00Z" }), iss(3, { milestone: ms }), iss(4, { milestone: ms, labels: lbl("host-task") }), iss(5, { url: "https://github.com/o/r/pull/5" }), iss(6, { milestone: ms, createdAt: "2026-10-01T00:00:00Z" })];
57
+ const io = bind(fakeIo(tmpDir("iwp-"), issues));
58
+ const claims = async (n) => (await planClaims({ watch: w[n], repo: "o/r", io, state: state() })).claim.map((c) => c.number);
59
+ assert.deepEqual(await claims("nomilestone"), [1]);
60
+ assert.deepEqual(await claims("milestoned"), [3]);
61
+ });
62
+
63
+ const relDir = (env, id, st, ageMs) => { const d = join(env, "releases", id); mkdirSync(d, { recursive: true }); const f = join(d, "state.json"); writeFileSync(f, JSON.stringify(st)); const t = (NOW - ageMs) / 1000; utimesSync(f, t, t); };
64
+
65
+ test("#5313 releaseInFlight: a running job counts; ended, stale, other-repo and missing roots do not", () => {
66
+ const env = tmpDir("iwp-"), root = join(env, "releases");
67
+ relDir(env, "r20261110-100000-1", { repo: "o/r", steps: { preflight: { done: true } } }, 60000);
68
+ const r = releaseInFlight({ root, repo: "o/r", now: NOW });
69
+ assert.equal(r.id, "r20261110-100000-1"); assert.equal(r.step, "host-preflight");
70
+ assert.equal(releaseInFlight({ root, repo: "x/y", now: NOW }), null);
71
+ const e2 = tmpDir("iwp-"); relDir(e2, "r20261110-100000-2", { repo: "o/r", status: "stopped", steps: {} }, 1000); relDir(e2, "r20261110-100000-3", { repo: "o/r", steps: {} }, 7 * 3600 * 1000);
72
+ assert.equal(releaseInFlight({ root: join(e2, "releases"), repo: "o/r", now: NOW }), null);
73
+ assert.equal(releaseInFlight({ root: join(e2, "nope"), now: NOW }), null);
74
+ });
75
+
76
+ test("#5313 a release in flight pauses the watch (no claims), the next pass resumes by itself, status shows it", async () => {
77
+ const env = tmpDir("iwp-"), dir = join(env, "w"); mkdirSync(dir, { recursive: true });
78
+ const io = bind(fakeIo(env, [iss(1)])), watch = validateWatch("w", { mode: "batch" });
79
+ relDir(env, "r20261110-110000-9", { repo: "o/r", steps: {} }, 30000);
80
+ const pass = () => runWatch({ watch, repo: "o/r", io, dir, once: true, intervalMs: 300000, cwd: env });
81
+ let s = await pass();
82
+ assert.equal(io.batchOps.length, 0); assert.match(s.paused.reason, /release r20261110-110000-9 in flight/);
83
+ const text = formatStatus(s, watch, io.now());
84
+ assert.match(text, /state: paused \(release r20261110-110000-9 in flight/); assert.match(text, /last heartbeat: 2026-11-10T12:00:00.000Z/);
85
+ assert.equal(JSON.parse(readFileSync(join(dir, "status.json"), "utf8")).paused.release, "r20261110-110000-9");
86
+ writeFileSync(join(env, "releases", "r20261110-110000-9", "state.json"), JSON.stringify({ repo: "o/r", status: "done", steps: {} })); // the job ends
87
+ s = await pass();
88
+ assert.equal(s.paused, null); assert.deepEqual(io.batchOps[0], ["start", [1]]);
89
+ assert.match(formatStatus(s, watch, io.now()), /state: running/);
90
+ });
91
+
92
+ test("#5313 watchLiveness: a fresh heartbeat runs, an old one is stale, a finished watch is done", () => {
93
+ const beat = (ms) => new Date(NOW - ms).toISOString();
94
+ assert.equal(watchLiveness({ phase: "running", heartbeat: beat(1000), heartbeatEveryMs: 300000 }, NOW).state, "running");
95
+ assert.equal(watchLiveness({ phase: "running", heartbeat: beat(3600000), heartbeatEveryMs: 300000 }, NOW).state, "stale");
96
+ assert.equal(watchLiveness({ phase: "running", heartbeat: beat(1000), paused: { reason: "release r1 in flight" } }, NOW).state, "paused");
97
+ assert.equal(watchLiveness({ phase: "done", heartbeat: beat(9e9) }, NOW).state, "done");
98
+ assert.equal(watchLiveness(null, NOW).state, "unknown");
99
+ assert.match(formatStatus({ ...state(), heartbeat: beat(3600000), heartbeatEveryMs: 300000 }, validateWatch("w", {}), NOW), /state: stale/);
100
+ });
101
+
102
+ test("#5313 a batch that reported between the settle check and the add is never added to: a new batch starts", async () => {
103
+ const io = bind(fakeIo(tmpDir("iwp-"), [iss(1)])), watch = validateWatch("w", { mode: "batch" }), st = state();
104
+ await tick({ watch, repo: "o/r", io, state: st, dir: tmpDir("iwp-") });
105
+ assert.deepEqual(io.batchOps, [["start", [1]]]);
106
+ let checks = 0; io.batch.reported = (id) => id === "b1" && ++checks > 1; // not reported at the settle check, reported at the re-check
107
+ io.issues = [iss(3)];
108
+ await tick({ watch, repo: "o/r", io, state: st, dir: tmpDir("iwp-") });
109
+ assert.deepEqual(io.batchOps.at(-1), ["start", [3]]);
110
+ assert.ok(!io.batchOps.some((o) => o[0] === "add"));
111
+ });
112
+
113
+ test("#5313 the follow-up rules and skip reasons show in the --dry-run plan: defer-only claims, post-deploy-only folds, PR and skip label skipped", async () => {
114
+ const bot = { author: { login: "forgedock[bot]" } };
115
+ const deferBody = "- [ ] fix it — defer: later\n";
116
+ const pdBody = "- [ ] `check it` — post-deploy: live\n";
117
+ const issues = [iss(1, { ...bot, title: "Follow-up: a", body: deferBody }), iss(2, { ...bot, title: "Follow-up: b", body: pdBody }), iss(3, { labels: lbl("epic") }), iss(4, { url: "https://github.com/o/r/pull/4" }), iss(5)];
118
+ const io = bind(fakeIo(tmpDir("iwp-"), issues));
119
+ const watch = validateWatch("w", { mode: "batch", include_followups: "defer-only", postdeploy_rollup: 100 });
120
+ const plan = await planClaims({ watch, repo: "o/r", io, state: state() });
121
+ const out = formatClaimPlan(plan);
122
+ assert.deepEqual(plan.claim.map((c) => c.number), [1, 5]);
123
+ assert.deepEqual(plan.fold, [2]);
124
+ assert.match(out, /would fold #2/);
125
+ assert.match(out, /skip #3: skip label epic/);
126
+ assert.match(out, /skip #4: pull request/);
127
+ });
@@ -176,7 +176,7 @@ export function releasePlanComment({ theme, tag, decision, policy, now }) {
176
176
  `**Included:** ${r.set.map((i) => `#${i.number}`).join(" ")}`,
177
177
  ...(r.pulled.length ? [`**Pulled prerequisites:** ${r.pulled.map((p) => `#${p.number} (${p.theme}, for #${p.for})`).join(", ")}`] : []),
178
178
  `**Excluded (stay pooled):** ${r.excluded.map((e) => `#${e.number} (${e.reason})`).join(", ") || "none"}`,
179
- "Promotion to the default branch stays human-only; the watch opens the deploy PR and never merges it."].join("\n");
179
+ "Promotion to the default branch stays opt-in (`release.auto_merge`); the watch opens the deploy PR, starts `forgedock release` for it and never merges it itself."].join("\n");
180
180
  }
181
181
 
182
182
  // ── the tick ─────────────────────────────────────────────────────────────────────────────────────────────────
@@ -200,7 +200,11 @@ export async function releaseTick({ watch, repo, io, state, defaults = [], listO
200
200
  if (!base) throw new Error("no default branch known; cannot open the deploy PR");
201
201
  const open = JSON.parse(await gh(["pr", "list", "-R", repo, "--head", rel.lane, "--base", base, "--state", "open", "--json", "number"]));
202
202
  rel.deployPr = open[0]?.number ?? (+(/(\d+)\s*$/.exec(await gh(["pr", "create", "-R", repo, "--base", base, "--head", rel.lane, "--title", `release(${rel.theme}): ${rel.tag}`,
203
- "--body", `Themed release **${rel.theme}** (${rel.tag}).\n\nIssues: ${rel.issues.map((n) => `#${n}`).join(" ")}\nMerged: ${state.merged.filter((n) => rel.issues.includes(n)).map((n) => `#${n}`).join(" ") || "none"}\nFailed: ${state.failed.filter((n) => rel.issues.includes(n)).map((n) => `#${n}`).join(" ") || "none"}\n\nPromotion is human-only: the issue watch opened this PR and never merges it.`]))?.[1]) || true);
203
+ "--body", `Themed release **${rel.theme}** (${rel.tag}).\n\nIssues: ${rel.issues.map((n) => `#${n}`).join(" ")}\nMerged: ${state.merged.filter((n) => rel.issues.includes(n)).map((n) => `#${n}`).join(" ") || "none"}\nFailed: ${state.failed.filter((n) => rel.issues.includes(n)).map((n) => `#${n}`).join(" ") || "none"}\n\nThe issue watch opened this PR and starts forgedock release for it; it never merges (promotion is opt-in via release.auto_merge).`]))?.[1]) || true);
204
+ }
205
+ // Hand the deploy PR to the release job (#5214); a failed start is recorded, never thrown (claims must not strand). Promotion stays opt-in.
206
+ if (io.release?.start && !rel.job) {
207
+ try { rel.job = (await io.release.start({ repo, pr: rel.deployPr, tag: rel.tag })) || "started"; } catch (e) { rel.jobError = String(e?.message ?? e); }
204
208
  }
205
209
  (state.releases ??= []).push(rel); state.release = null;
206
210
  }
@@ -161,7 +161,7 @@ test("claims nothing below the threshold; at the threshold posts a plan, tags wi
161
161
  assert.ok(io.calls.some((a) => a[0] === "label" && a[1] === "create" && a.includes("release:billing-2026-10-30")));
162
162
  assert.equal(io.calls.filter((a) => a[1] === "edit" && a.includes("--add-label")).length, 3);
163
163
  await step(io, w, st); // batch not reported: one batch per release, nothing new
164
- assert.equal(io.batches.length, 1); assert.equal(io.calls.filter((a) => a[0] === "pr").length, 0);
164
+ assert.equal(io.batches.length, 1); assert.equal(io.calls.filter((a) => a[0] === "pr" && !a.join(" ").includes("closingIssuesReferences")).length, 0);
165
165
  io.reported.add("b1"); io.closed.add(1);
166
166
  await step(io, w, st);
167
167
  const creates = io.calls.filter((a) => a[0] === "pr" && a[1] === "create");
@@ -244,3 +244,19 @@ test("CLI: --dry-run prints the cut without writing; refuses a non-release watch
244
244
  const w = loadWatches(`issue_watch:\n watches:\n sr:\n mode: release\n threshold: { min_issues: 2 }\n`).sr;
245
245
  assert.match(formatStatus({ name: "sr", repo: "o/r", phase: "running", claimed: [1], inflight: [1], merged: [], verified: [], failed: [], pool: [2, 3], llm: 2, releases: [], release: { theme: "billing", issues: [1], batch: "b1" } }, w), /pool: 2.*active: billing.*llm-classified: 2/);
246
246
  });
247
+
248
+ test("#5214: the deploy PR is handed to the release job once, without merge; a failed start is recorded", async () => {
249
+ for (const [prs, fail] of [[[], false], [[{ number: 9 }], false], [[], true]]) {
250
+ const issues = [1, 2, 3].map((n) => iss(n, { labels: lbl("billing") }));
251
+ const io = world(issues, { prs }), started = [];
252
+ io.release = { start: async (a) => { started.push(a); if (fail) throw new Error("spawn failed"); return "r1"; } };
253
+ const w = W(), st = fresh();
254
+ await step(io, w, st);
255
+ io.reported.add("b1"); io.closed.add(1);
256
+ await step(io, w, st);
257
+ assert.deepEqual(started, [{ repo: "o/r", pr: prs[0]?.number ?? 77, tag: "billing-2026-10-30" }]);
258
+ assert.equal(st.releases[0].job, fail ? undefined : "r1"); assert.equal(st.releases[0].jobError, fail ? "spawn failed" : undefined);
259
+ assert.equal(io.calls.some((a) => a[0] === "pr" && a[1] === "merge"), false);
260
+ await step(io, w, st); assert.equal(started.length, 1);
261
+ }
262
+ });