forgedock 1.66.0 → 1.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/bin/config-schema.mjs +3 -0
  2. package/bin/engine/outcome-codes.mjs +2 -0
  3. package/bin/engine-cli.mjs +193 -27
  4. package/bin/engine.mjs +10 -0
  5. package/bin/forgedock.mjs +24 -1
  6. package/bin/help-text.mjs +4 -3
  7. package/bin/introspect-schedule.mjs +98 -0
  8. package/bin/introspect-schedule.test.mjs +67 -0
  9. package/bin/lean/admission.mjs +21 -0
  10. package/bin/lean/admission.test.mjs +30 -0
  11. package/bin/lean/advisory.test.mjs +64 -0
  12. package/bin/lean/amendment-schema.mjs +30 -0
  13. package/bin/lean/attempts.mjs +162 -0
  14. package/bin/lean/attempts.test.mjs +141 -0
  15. package/bin/lean/basered.mjs +81 -0
  16. package/bin/lean/basered.test.mjs +68 -1
  17. package/bin/lean/batch-health.mjs +20 -12
  18. package/bin/lean/batch-health.test.mjs +55 -11
  19. package/bin/lean/batch.mjs +45 -0
  20. package/bin/lean/batch.test.mjs +105 -5
  21. package/bin/lean/capwait.mjs +14 -3
  22. package/bin/lean/capwait.test.mjs +20 -0
  23. package/bin/lean/ci-gate.mjs +2 -90
  24. package/bin/lean/ci-gate.test.mjs +1 -127
  25. package/bin/lean/ci-precheck.mjs +25 -8
  26. package/bin/lean/ci-precheck.test.mjs +24 -0
  27. package/bin/lean/clear-breaker.mjs +14 -0
  28. package/bin/lean/clear-breaker.test.mjs +4 -3
  29. package/bin/lean/commentstate.mjs +46 -0
  30. package/bin/lean/commentstate.test.mjs +43 -0
  31. package/bin/lean/concurrency.mjs +89 -0
  32. package/bin/lean/concurrency.test.mjs +113 -0
  33. package/bin/lean/conformance.e2e.test.mjs +13 -8
  34. package/bin/lean/conformance.mjs +73 -181
  35. package/bin/lean/conformance.test.mjs +61 -345
  36. package/bin/lean/depcache.mjs +100 -10
  37. package/bin/lean/depcache.test.mjs +105 -0
  38. package/bin/lean/docsgate.mjs +0 -32
  39. package/bin/lean/docsgate.test.mjs +2 -23
  40. package/bin/lean/effects-cap.test.mjs +9 -1
  41. package/bin/lean/effects-killtree.test.mjs +35 -0
  42. package/bin/lean/effects.mjs +42 -24
  43. package/bin/lean/efficiency.mjs +162 -0
  44. package/bin/lean/efficiency.test.mjs +79 -0
  45. package/bin/lean/engine-readmit.test.mjs +35 -0
  46. package/bin/lean/envgap.mjs +93 -0
  47. package/bin/lean/envgap.test.mjs +53 -0
  48. package/bin/lean/execution.mjs +41 -17
  49. package/bin/lean/execution.test.mjs +58 -0
  50. package/bin/lean/failure-census.mjs +170 -0
  51. package/bin/lean/failure-census.test.mjs +59 -0
  52. package/bin/lean/failure-stop.mjs +46 -0
  53. package/bin/lean/failure-stop.test.mjs +45 -0
  54. package/bin/lean/fixtures/capacity-storm.json +609 -0
  55. package/bin/lean/guardgate.test.mjs +2 -3
  56. package/bin/lean/heavy.mjs +33 -4
  57. package/bin/lean/heavy.test.mjs +38 -6
  58. package/bin/lean/hotarea.mjs +0 -36
  59. package/bin/lean/hotarea.test.mjs +1 -22
  60. package/bin/lean/issuewatch-verify.mjs +19 -4
  61. package/bin/lean/issuewatch.mjs +21 -4
  62. package/bin/lean/issuewatch.test.mjs +48 -1
  63. package/bin/lean/lane-audit-gap.mjs +66 -0
  64. package/bin/lean/lane-audit-gap.test.mjs +59 -0
  65. package/bin/lean/lane-audit-llm.mjs +5 -0
  66. package/bin/lean/lane-audit-query.mjs +47 -0
  67. package/bin/lean/lane-audit-query.test.mjs +44 -0
  68. package/bin/lean/lane-audit-signatures.mjs +33 -0
  69. package/bin/lean/lane-audit.mjs +110 -0
  70. package/bin/lean/lane-audit.test.mjs +97 -0
  71. package/bin/lean/lane-recovery.test.mjs +33 -0
  72. package/bin/lean/lanecheck.mjs +5 -3
  73. package/bin/lean/lanecheck.test.mjs +6 -0
  74. package/bin/lean/lean.mjs +311 -154
  75. package/bin/lean/lean.test.mjs +530 -223
  76. package/bin/lean/limits.mjs +17 -0
  77. package/bin/lean/limits.test.mjs +15 -1
  78. package/bin/lean/live-execution.mjs +21 -2
  79. package/bin/lean/live-execution.test.mjs +39 -0
  80. package/bin/lean/liveness.mjs +37 -0
  81. package/bin/lean/liveness.test.mjs +33 -0
  82. package/bin/lean/orchestrate-attempts.test.mjs +82 -0
  83. package/bin/lean/orchestrate-envhold.test.mjs +47 -0
  84. package/bin/lean/orchestrate-heldroot.test.mjs +72 -0
  85. package/bin/lean/orchestrate-hostfallback.test.mjs +59 -1
  86. package/bin/lean/orchestrate-overload-recovery.test.mjs +37 -0
  87. package/bin/lean/orchestrate-pause.test.mjs +76 -1
  88. package/bin/lean/orchestrate-reconcile.test.mjs +164 -0
  89. package/bin/lean/orchestrate-relaunch-gates.test.mjs +57 -0
  90. package/bin/lean/orchestrate-stacking.test.mjs +10 -0
  91. package/bin/lean/orchestrate.mjs +344 -45
  92. package/bin/lean/phaseledger.mjs +6 -0
  93. package/bin/lean/phaseledger.test.mjs +13 -1
  94. package/bin/lean/postdeploy-check.test.mjs +1 -3
  95. package/bin/lean/precheck.mjs +20 -0
  96. package/bin/lean/preflight.mjs +100 -11
  97. package/bin/lean/preflight.test.mjs +44 -4
  98. package/bin/lean/prompts.mjs +13 -28
  99. package/bin/lean/reconcile.mjs +90 -0
  100. package/bin/lean/recurrence.mjs +6 -112
  101. package/bin/lean/recurrence.test.mjs +11 -92
  102. package/bin/lean/release-flakes.mjs +14 -2
  103. package/bin/lean/release-flakes.test.mjs +17 -1
  104. package/bin/lean/release-ledger.mjs +19 -1
  105. package/bin/lean/release-ledger.test.mjs +23 -0
  106. package/bin/lean/release-preflight.mjs +28 -0
  107. package/bin/lean/release-preflight.test.mjs +42 -1
  108. package/bin/lean/release-review.mjs +40 -5
  109. package/bin/lean/release-review.test.mjs +43 -2
  110. package/bin/lean/release.mjs +43 -14
  111. package/bin/lean/release.test.mjs +32 -0
  112. package/bin/lean/retry.mjs +1 -1
  113. package/bin/lean/retry.test.mjs +6 -1
  114. package/bin/lean/rotator.mjs +9 -0
  115. package/bin/lean/rotator.test.mjs +11 -1
  116. package/bin/lean/sandbox-remote.mjs +49 -11
  117. package/bin/lean/sched.mjs +19 -0
  118. package/bin/lean/sched.test.mjs +11 -1
  119. package/bin/lean/schedd-health.mjs +4 -4
  120. package/bin/lean/schedd-health.test.mjs +8 -4
  121. package/bin/lean/schedd.mjs +45 -8
  122. package/bin/lean/schedd.test.mjs +120 -7
  123. package/bin/lean/selfreview.mjs +1 -1
  124. package/bin/lean/slo.mjs +126 -0
  125. package/bin/lean/slo.test.mjs +112 -0
  126. package/bin/lean/statuscomment.mjs +40 -0
  127. package/bin/lean/statuscomment.test.mjs +48 -1
  128. package/bin/lean/validate-catalog.mjs +108 -0
  129. package/bin/lean/validate-catalog.test.mjs +46 -1
  130. package/bin/lean/verify.mjs +3 -2
  131. package/bin/pool/affinity.test.mjs +91 -0
  132. package/bin/pool/agent.mjs +144 -10
  133. package/bin/pool/cache-sweep.mjs +31 -10
  134. package/bin/pool/ci-autoscale.mjs +160 -0
  135. package/bin/pool/cli.mjs +53 -9
  136. package/bin/pool/docker.mjs +3 -0
  137. package/bin/pool/engine-placement.test.mjs +94 -0
  138. package/bin/pool/lane-target.mjs +41 -0
  139. package/bin/pool/lane-tools.mjs +26 -0
  140. package/bin/pool/lane-tools.test.mjs +9 -0
  141. package/bin/pool/mirror-seed.mjs +15 -11
  142. package/bin/pool/router.mjs +88 -32
  143. package/bin/pool/version.mjs +29 -2
  144. package/bin/review-staging.mjs +11 -3
  145. package/bin/runner.mjs +59 -11
  146. package/bin/stats/attempts.mjs +54 -0
  147. package/bin/stats/attempts.test.mjs +30 -0
  148. package/bin/stats/churn.mjs +49 -0
  149. package/bin/stats/churn.test.mjs +31 -0
  150. package/bin/stats/index.mjs +11 -3
  151. package/bin/stats/release.mjs +7 -0
  152. package/bin/stats/release.test.mjs +20 -0
  153. package/bin/stats/scorecard.mjs +187 -0
  154. package/bin/stats/scorecard.test.mjs +89 -0
  155. package/commands/orchestrate.md +21 -18
  156. package/docs/CONFIG.md +41 -0
  157. package/docs/OUTCOME-CODES.md +2 -0
  158. package/docs/STATS.md +17 -0
  159. package/package.json +1 -1
  160. package/pool/image/Dockerfile +14 -2
  161. package/pool/image/manifest.json +25 -0
  162. package/pool/image/mirror.sh +11 -2
  163. package/pool/install/install-agent.ps1 +11 -4
  164. package/scripts/check-devdocs-freshness.sh +1 -1
  165. package/scripts/ci-local/adapters/github-actions.mjs +8 -0
  166. package/scripts/ci-local/cli.mjs +1 -1
  167. package/scripts/ci-local/plan.mjs +3 -2
  168. package/scripts/ci-local.test.sh +11 -0
  169. package/scripts/failure-census.mjs +67 -0
  170. package/scripts/review-finalize.sh +5 -5
  171. package/scripts/review-finalize.test.sh +8 -1
  172. package/scripts/verify-phase-trail.sh +11 -0
  173. package/scripts/verify-phase-trail.test.sh +9 -0
@@ -0,0 +1,49 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ /**
4
+ * #5979: comment churn per issue. Counts the engine's own comments (a `<!-- FORGE:... -->` marker) on each issue and the
5
+ * repeated failures (the same `sig=<hash>` on more than one NEEDS_HUMAN/PARKED comment), so a noisy issue is visible. Pure,
6
+ * except `readChurn`, which is read-only and best effort.
7
+ */
8
+ const FORGE_RE = /<!--\s*FORGE:[A-Z_:-]+/;
9
+ const FAIL_RE = /<!--\s*FORGE:(?:NEEDS_HUMAN|PARKED)(?![A-Za-z0-9_])/;
10
+ const SIG_RE = /\bsig=([0-9a-f]{12})\b/;
11
+
12
+ const median = (xs) => { const s = [...xs].sort((a, b) => a - b); return s.length ? (s.length % 2 ? s[(s.length - 1) / 2] : (s[s.length / 2 - 1] + s[s.length / 2]) / 2) : 0; };
13
+
14
+ /** @param {{issue:number, comments:{body:string}[]}[]} issues @returns {{perIssue:{issue:number, comments:number, repeats:number}[], max:number, median:number, repeated:number}} */
15
+ export function churnStats(issues) {
16
+ const perIssue = [];
17
+ for (const it of Array.isArray(issues) ? issues : []) {
18
+ const sigs = new Map();
19
+ let comments = 0;
20
+ for (const c of Array.isArray(it?.comments) ? it.comments : []) {
21
+ const body = String(c?.body ?? "");
22
+ if (!FORGE_RE.test(body)) continue;
23
+ comments++;
24
+ const sig = FAIL_RE.test(body) ? SIG_RE.exec(body)?.[1] : null;
25
+ if (sig) sigs.set(sig, (sigs.get(sig) ?? 0) + 1);
26
+ }
27
+ perIssue.push({ issue: it?.issue, comments, repeats: [...sigs.values()].filter((n) => n > 1).length });
28
+ }
29
+ const counts = perIssue.map((p) => p.comments);
30
+ return { perIssue, max: Math.max(0, ...counts), median: median(counts), repeated: perIssue.reduce((a, p) => a + p.repeats, 0) };
31
+ }
32
+
33
+ /** Report lines; none when there is nothing to count. */
34
+ export function formatChurnLines(stats) {
35
+ if (!stats?.perIssue?.length) return [];
36
+ const top = [...stats.perIssue].sort((a, b) => b.comments - a.comments).slice(0, 3).filter((p) => p.comments > 0);
37
+ return [`comments per issue: max ${stats.max}, median ${stats.median}${top.length ? ` (${top.map((p) => `#${p.issue}: ${p.comments}`).join(", ")})` : ""}; repeated failures: ${stats.repeated}`];
38
+ }
39
+
40
+ /** Read the comments of `issues` through `gh` and return the report lines; never throws. */
41
+ export async function readChurn({ gh, repo, issues }) {
42
+ try {
43
+ const out = [];
44
+ for (const n of (issues ?? []).slice(0, 50)) {
45
+ try { out.push({ issue: n, comments: JSON.parse(String(await gh(["issue", "view", String(n), "-R", repo, "--json", "comments"])))?.comments ?? [] }); } catch { /* skip an unreadable issue */ }
46
+ }
47
+ return formatChurnLines(churnStats(out));
48
+ } catch { return []; }
49
+ }
@@ -0,0 +1,31 @@
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 { churnStats, formatChurnLines, readChurn } from "./churn.mjs";
6
+
7
+ const c = (marker, extra = "") => ({ body: `<!-- FORGE:${marker} -->\n${extra}` });
8
+ describe("comment churn (#5979)", () => {
9
+ const issues = [
10
+ { issue: 1, comments: [c("NEEDS_HUMAN", "sig=aaaaaaaaaaaa"), c("PARKED", "sig=aaaaaaaaaaaa"), c("DEPENDENCY"), { body: "a person wrote this" }] },
11
+ { issue: 2, comments: [c("STATUS")] },
12
+ ];
13
+ it("counts FORGE comments per issue and repeated failures", () => {
14
+ const s = churnStats(issues);
15
+ assert.deepEqual(s.perIssue, [{ issue: 1, comments: 3, repeats: 1 }, { issue: 2, comments: 1, repeats: 0 }]);
16
+ assert.equal(s.max, 3);
17
+ assert.equal(s.median, 2);
18
+ assert.equal(s.repeated, 1);
19
+ });
20
+ it("different signatures are not a repeat", () => {
21
+ assert.equal(churnStats([{ issue: 3, comments: [c("NEEDS_HUMAN", "sig=aaaaaaaaaaaa"), c("NEEDS_HUMAN", "sig=bbbbbbbbbbbb")] }]).repeated, 0);
22
+ });
23
+ it("formats lines, and none for no issues", () => {
24
+ assert.match(formatChurnLines(churnStats(issues))[0], /comments per issue: max 3, median 2 \(#1: 3, #2: 1\); repeated failures: 1/);
25
+ assert.deepEqual(formatChurnLines(churnStats([])), []);
26
+ });
27
+ it("readChurn never throws", async () => {
28
+ assert.deepEqual(await readChurn({ gh: async () => { throw new Error("x"); }, repo: "o/r", issues: [1] }), []);
29
+ assert.deepEqual(await readChurn({ gh: null, repo: "o/r", issues: null }), []);
30
+ });
31
+ });
@@ -23,6 +23,7 @@ import { readExperiment } from "../experiment.mjs";
23
23
  import { compoundingReport, gatherCompounding, renderCompounding, DEFAULT_BUCKETS, DEFAULT_WINDOW_MS } from "./compounding.mjs";
24
24
  import { poolUtilisation, formatPoolLines } from "./pool.mjs";
25
25
  import { chainsReport, formatChainLines } from "./chains.mjs";
26
+ import { attemptsReport, formatAttemptLines } from "./attempts.mjs";
26
27
  import { ciAwarenessReport, readCiLogs, renderCiAwareness } from "./ci-awareness.mjs";
27
28
  import { gatherIssues, selfFiledReport, renderSelfFiled } from "./selffiled.mjs";
28
29
  import { firstReviewReport, renderFirstReview } from "./first-review.mjs";
@@ -43,6 +44,7 @@ export const HELP = `Usage: forgedock stats [--since <version|date>] [--repo <ow
43
44
  forgedock stats --by version [--post-metrics <pr>] [--min-n N] [--repo <owner/repo>] [--json]
44
45
  forgedock stats --pool [--window 7d,30d] [--repo <owner/repo>] [--json]
45
46
  forgedock stats --chains [--window 7d,30d] [--repo <owner/repo>] [--json]
47
+ forgedock stats --attempts [--window 7d,30d] [--repo <owner/repo>] [--json]
46
48
  forgedock stats --ci-awareness [--repo <owner/repo>] [--since <date>] [--json]
47
49
  forgedock stats --first-review [--repo <owner/repo>] [--since <date>] [--min-n 20] [--json]
48
50
  forgedock stats --first-merge [--repo <owner/repo>[,<owner/repo>...]] [--json]
@@ -105,6 +107,7 @@ Pool (forge#4549; local batch reports, no gh):
105
107
  --ci-awareness median/p90 CI awareness latency, CI rounds per PR and wall per round, per engine version, from local run logs (#5692);
106
108
  --since <date> keeps only the lanes started on/after that date
107
109
  --pool remote lane minutes, lanes and share per pool agent over --window (default 7d,30d)
110
+ --attempts lanes per merged issue (failed lanes in the attempts ledger + the merging one) and engine comments per issue, from local batch files (#5986)
108
111
  --chains stacked-lane chains from local batch reports: wall time p50 by depth, per-link overlap, cascade rework rate (#5834)
109
112
 
110
113
  Efficiency (forge#4402; local batch dirs and run logs, gh only for merged issues' bodies, labels and probes):
@@ -174,7 +177,7 @@ Lane profile baseline (forge#4436; local run logs only, every run of each issue,
174
177
  export function experimentExit(opts, report) { return opts.requireMet && report.targets_met !== true ? 1 : 0; }
175
178
 
176
179
  export function parseArgs(argv) {
177
- const o = { card: false, week: false, month: false, includeRepoNames: false, publicRepo: false, out: null, depth: false, conformanceOutcomes: false, windowDays: null, since: null, repo: null, edge: null, milestone: null, contextAb: false, exploreAb: false, tiers: false, compounding: false, selfFiled: false, origin: false, firstMerge: false, bucket: null, laneProfile: false, issues: null, efficiency: false, pool: false, chains: false, ciAwareness: false, batch: null, windows: null, compare: null, by: null, experiment: null, emitEvent: false, requireMet: false, postMetrics: null, offline: false, json: false, refresh: false, compact: false, local: true, cache: true, minN: DEFAULT_MIN_N, releaseTimes: null, help: false };
180
+ const o = { card: false, week: false, month: false, includeRepoNames: false, publicRepo: false, out: null, depth: false, conformanceOutcomes: false, windowDays: null, since: null, repo: null, edge: null, milestone: null, contextAb: false, exploreAb: false, tiers: false, compounding: false, selfFiled: false, origin: false, firstMerge: false, bucket: null, laneProfile: false, issues: null, efficiency: false, pool: false, chains: false, attempts: false, ciAwareness: false, batch: null, windows: null, compare: null, by: null, experiment: null, emitEvent: false, requireMet: false, postMetrics: null, offline: false, json: false, refresh: false, compact: false, local: true, cache: true, minN: DEFAULT_MIN_N, releaseTimes: null, help: false };
178
181
  const val = (i, name) => {
179
182
  const v = argv[i + 1];
180
183
  if (v == null || v.startsWith("--")) throw new Error(`${name} needs a value`);
@@ -210,6 +213,7 @@ export function parseArgs(argv) {
210
213
  else if (name === "--depth") o.depth = true;
211
214
  else if (name === "--pool") o.pool = true;
212
215
  else if (name === "--chains") o.chains = true;
216
+ else if (name === "--attempts") o.attempts = true;
213
217
  else if (name === "--release-ledger") o.releaseLedger = true;
214
218
  else if (name === "--baseline") { const v = take(); if (v !== "save" && v !== "compare") throw new Error("--baseline must be save or compare"); o.baseline = v; }
215
219
  else if (name === "--baseline-file") o.baselineFile = take();
@@ -246,10 +250,10 @@ export function parseArgs(argv) {
246
250
  }
247
251
  if ((o.week || o.month || o.includeRepoNames || o.publicRepo || o.out) && !o.card) throw new Error("--week, --month, --include-repo-names, --public-repo and --out need --card");
248
252
  if (o.week && o.month) throw new Error("--week and --month are mutually exclusive");
249
- if (o.card && (o.depth || o.pool || o.chains || o.ciAwareness || o.efficiency || o.compounding || o.selfFiled || o.conformanceOutcomes || o.contextAb || o.exploreAb || o.tiers || o.laneProfile || o.edge || o.milestone || o.experiment || o.by)) throw new Error("--card cannot be combined with another query mode");
253
+ if (o.card && (o.depth || o.pool || o.chains || o.attempts || o.ciAwareness || o.efficiency || o.compounding || o.selfFiled || o.conformanceOutcomes || o.contextAb || o.exploreAb || o.tiers || o.laneProfile || o.edge || o.milestone || o.experiment || o.by)) throw new Error("--card cannot be combined with another query mode");
250
254
  if (o.card && (o.week || o.month) && o.since) throw new Error("--week/--month and --since are mutually exclusive");
251
255
  if (o.batch && !o.efficiency) throw new Error("--batch and --window need --efficiency");
252
- if (o.windows && !o.efficiency && !o.pool && !o.chains && !o.compounding) throw new Error("--batch and --window need --efficiency");
256
+ if (o.windows && !o.efficiency && !o.pool && !o.chains && !o.attempts && !o.compounding) throw new Error("--batch and --window need --efficiency");
253
257
  if (o.bucket && !o.compounding) throw new Error("--bucket needs --compounding");
254
258
  if (o.compare && !o.efficiency) throw new Error("--compare and --offline need --efficiency");
255
259
  if (o.offline && !o.efficiency && !o.depth) throw new Error("--compare and --offline need --efficiency (--offline also works with --depth)");
@@ -429,6 +433,9 @@ export async function buildReport(opts, deps = {}) {
429
433
  const pool = poolUtilisation({ batchRoot: deps.batchRoot ?? batchRoot(env), repo, windows: opts.windows ?? parseWindows("7d,30d"), now: deps.now?.() ?? Date.now() });
430
434
  return { repo, query: { pool } };
431
435
  }
436
+ if (opts.attempts) { // #5986: local batch files only
437
+ return { repo, query: { attempts: attemptsReport({ batchRoot: deps.batchRoot ?? batchRoot(env), repo, windows: opts.windows ?? parseWindows("7d,30d"), now: deps.now?.() ?? Date.now() }) } };
438
+ }
432
439
  if (opts.chains) { // #5834: local batch reports only
433
440
  return { repo, query: { chains: chainsReport({ batchRoot: deps.batchRoot ?? batchRoot(env), repo, windows: opts.windows ?? parseWindows("7d,30d"), now: deps.now?.() ?? Date.now() }) } };
434
441
  }
@@ -583,6 +590,7 @@ export async function runStats(argv, deps = {}) {
583
590
  if (report.query?.self_filed && !opts.json) { process.stdout.write(`${renderSelfFiled(report.query.self_filed)}\n`); return 0; }
584
591
  if (report.query?.depth && !opts.json) { process.stdout.write(`${renderDepth(report.query.depth, { repo: report.repo, since: opts.since })}\n`); return 0; }
585
592
  if (report.query?.ci_awareness && !opts.json) { process.stdout.write(`${renderCiAwareness(report.query.ci_awareness)}\n`); return 0; }
593
+ if (report.query?.attempts && !opts.json) { process.stdout.write(`${formatAttemptLines(report.query.attempts).join("\n")}\n`); return 0; }
586
594
  if (report.query?.chains && !opts.json) { process.stdout.write(`${formatChainLines(report.query.chains).join("\n")}\n`); return 0; }
587
595
  if (report.query?.pool && !opts.json) { process.stdout.write(`${formatPoolLines(report.query.pool).join("\n")}\n`); return 0; }
588
596
  if (report.query?.efficiency && !opts.json) {
@@ -108,6 +108,7 @@ export const LEDGER_METRICS = Object.freeze([
108
108
  { key: "queue_s_p90", label: "Queue time (p90)", unit: "s", phase1: 30, end: 30 },
109
109
  { key: "failed_minute_share", label: "CI minutes in failed jobs", unit: "pct" },
110
110
  { key: "cancelled_minute_share", label: "CI minutes in cancelled jobs", unit: "pct" },
111
+ { key: "snapshot_rounds_per_release_p50", label: "Snapshot rounds per release (p50)", unit: "n", phase1: 3, end: 2 },
111
112
  { key: "ci_round_fail_rate", label: "CI rounds that fail", unit: "pct" },
112
113
  { key: "deploy_live_rate", label: "Deploy attempts that reached live", unit: "pct", higherBetter: true },
113
114
  ]);
@@ -209,6 +210,12 @@ export function computeReleaseLedger(data, cfg = {}) {
209
210
  m.ci_round_job_min_p50 = round1(p50(judged.map((r) => r.jobMin)));
210
211
  m.ci_round_fail_rate = judged.length ? round1(judged.filter((r) => r.outcome === "fail").length / judged.length, 3) : null;
211
212
  n.rounds = judged.length;
213
+ // ledger rounds (#6013): snapshots per release, wall time and cause of each round
214
+ const led = (data.ledger ?? []).filter((l) => l.snapshots > 0);
215
+ m.snapshot_rounds_per_release_p50 = round1(p50(led.map((l) => l.snapshots)));
216
+ m.snapshot_rounds_per_release_max = led.length ? Math.max(...led.map((l) => l.snapshots)) : null;
217
+ m.snapshot_wall_min_total = round1(led.reduce((a, l) => a + (l.wallMin || 0), 0));
218
+ for (const c of ["regression", "flake", "runner"]) m[`snapshot_rounds_${c}`] = led.reduce((a, l) => a + (l.causes?.[c] || 0), 0);
212
219
  m.pushes_per_release_pr_p50 = round1(p50(pushes.map((x) => x.pushes))); m.pushes_per_release_pr_max = pushes.length ? Math.max(...pushes.map((x) => x.pushes)) : null;
213
220
  n.release_prs = plan.releases.length; n.release_prs_with_ci = pushes.length;
214
221
 
@@ -66,3 +66,23 @@ describe("--by / --post-metrics parsing (#4628)", () => {
66
66
  assert.throws(() => parseArgs(["--by", "version", "--post-metrics", "x"]), /PR number/);
67
67
  });
68
68
  });
69
+
70
+ describe("ledger snapshot rounds (#6013)", () => {
71
+ it("reports rounds per release, wall time and cause counts, and trends rounds", async () => {
72
+ const { computeReleaseLedger, LEDGER_METRICS, ledgerTable } = await import("./release.mjs");
73
+ const ledger = [
74
+ { pr: 1, snapshots: 3, wallMin: 90, causes: { regression: 2, flake: 1, runner: 0 } },
75
+ { pr: 2, snapshots: 1, wallMin: 30, causes: { regression: 0, flake: 0, runner: 1 } },
76
+ { pr: 3, snapshots: 0, wallMin: 0, causes: { regression: 0, flake: 0, runner: 0 } },
77
+ ];
78
+ const r = computeReleaseLedger({ repo: "o/r", sinceMs: 0, untilMs: 1, base: "main", prs: [], runs: [], jobs: {}, ledger }, {});
79
+ assert.equal(r.metrics.snapshot_rounds_per_release_p50, 2);
80
+ assert.equal(r.metrics.snapshot_rounds_per_release_max, 3);
81
+ assert.equal(r.metrics.snapshot_wall_min_total, 120);
82
+ assert.deepEqual([r.metrics.snapshot_rounds_regression, r.metrics.snapshot_rounds_flake, r.metrics.snapshot_rounds_runner], [2, 1, 1]);
83
+ assert.ok(LEDGER_METRICS.some((d) => d.key === "snapshot_rounds_per_release_p50" && d.end === 2), "trended against a target");
84
+ const row = ledgerTable(r.metrics).find((x) => x.key === "snapshot_rounds_per_release_p50");
85
+ assert.equal(row.today, 2);
86
+ assert.equal(row.status, "end-met");
87
+ });
88
+ });
@@ -0,0 +1,187 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ /**
4
+ * `forgedock scorecard --repo R --release vX [--json]` (#6084): a per-release scorecard computed from the register
5
+ * (GitHub telemetry records, optional batch rows and LANE_AUDIT annotations), compared to the previous release. No LLM
6
+ * and no network beyond the injected `gh`. Each metric is null (n/a) when its source is absent or below min n; a verdict
7
+ * is null when either side is null. Verdict rule and tolerances match bin/stats/release.mjs (#4628).
8
+ */
9
+ import { DEFAULT_MIN_N, UNKNOWN, compareVersions, percentile } from "./aggregate.mjs";
10
+ import { existsSync, readFileSync } from "node:fs";
11
+ import { join } from "node:path";
12
+ import { batchRoot, listBatches } from "../lean/batch.mjs";
13
+ import { defaultGh, fetchGithubRecords, isTrusted, isValidRepo, parsePages, toModel } from "./github-source.mjs";
14
+
15
+ export const SCORECARD_MARKER = "<!-- FORGE:SCORECARD v1 -->";
16
+ const isNum = (x) => typeof x === "number" && Number.isFinite(x);
17
+ // kind: rate (absolute tolerance) | rel (relative tolerance)
18
+ export const SCORECARD_METRICS = [
19
+ { key: "first_pass_rate", label: "first-pass merge rate", lowerBetter: false, flat: 0.02, kind: "rate" },
20
+ { key: "interventions_per_batch", label: "operator interventions/batch", lowerBetter: true, flat: 0.05, kind: "rel" },
21
+ { key: "needs_human_genuine", label: "needs-human (genuine)", lowerBetter: true, flat: 0.05, kind: "rel" },
22
+ { key: "needs_human_pipeline", label: "needs-human (pipeline)", lowerBetter: true, flat: 0.05, kind: "rel" },
23
+ { key: "queue_min", label: "queue min/lane", lowerBetter: true, flat: 0.05, kind: "rel" },
24
+ { key: "active_min", label: "active min/lane", lowerBetter: true, flat: 0.05, kind: "rel" },
25
+ { key: "wait_min", label: "wait min/lane", lowerBetter: true, flat: 0.05, kind: "rel" },
26
+ { key: "minutes_per_merge", label: "minutes/merge", lowerBetter: true, flat: 0.05, kind: "rel" },
27
+ { key: "usd_per_merge", label: "$/merge", lowerBetter: true, flat: 0.05, kind: "rel" },
28
+ { key: "revert_rate", label: "revert rate", lowerBetter: true, flat: 0.02, kind: "rate" },
29
+ { key: "rework_rate", label: "rework rate", lowerBetter: true, flat: 0.02, kind: "rate" },
30
+ { key: "tested_requirements_rate", label: "requirements covered by tests", lowerBetter: false, flat: 0.02, kind: "rate" },
31
+ { key: "stuck_issues", label: "stuck issues (>1 attempt)", lowerBetter: true, flat: 0.05, kind: "rel" },
32
+ ];
33
+
34
+ const ratio = (a, b, minN) => (b >= minN && b > 0 ? a / b : null);
35
+ const sum = (xs) => xs.reduce((a, b) => a + b, 0);
36
+ const median = (xs, minN) => (xs.length >= minN ? percentile(xs, 50) : null);
37
+ const phaseSum = (r, k) => { const v = Object.values(r.phases ?? {}).map((p) => p?.[k]).filter(isNum); return v.length ? sum(v) : null; };
38
+
39
+ /** The metric values of one release; every one null when its source is absent or its own sample is below minN. */
40
+ export function scorecardValues({ records = [], batchRows = [], laneAudits = [] } = {}, release, minN = DEFAULT_MIN_N) {
41
+ const runs = records.filter((r) => r?.version === release && r.finished);
42
+ const merged = runs.filter((r) => r.reason === "merged");
43
+ const rows = batchRows.filter((b) => b && (b.release == null || b.release === release) && isNum(b.interventions));
44
+ const audits = laneAudits.filter((a) => a && (a.release == null || a.release === release) && (a.class === "genuine" || a.class === "pipeline"));
45
+ const nh = (c) => (audits.length >= minN ? audits.filter((a) => a.class === c).length : null);
46
+ const wall = merged.map((r) => r.wallMs).filter(isNum);
47
+ const usd = merged.map((r) => phaseSum(r, "usd")).filter(isNum);
48
+ const field = (k) => median(merged.map((r) => r[k]).filter(isNum), minN);
49
+ const active = merged.map((r) => phaseSum(r, "ms")).filter(isNum);
50
+ const revFlagged = merged.filter((r) => typeof r.reverted === "boolean");
51
+ const verifiable = merged.filter((r) => r.verified != null);
52
+ const attempts = (r) => r.builderAttempts?.length ?? 0;
53
+ return {
54
+ n: runs.length,
55
+ first_pass_rate: ratio(merged.filter((r) => !r.remediated && attempts(r) <= 1).length, merged.length, minN),
56
+ interventions_per_batch: rows.length >= minN ? sum(rows.map((b) => b.interventions)) / rows.length : null,
57
+ needs_human_genuine: nh("genuine"),
58
+ needs_human_pipeline: nh("pipeline"),
59
+ queue_min: field("queueMin"),
60
+ active_min: active.length >= minN ? percentile(active, 50) / 60000 : null,
61
+ wait_min: field("waitMin"),
62
+ minutes_per_merge: wall.length >= minN ? percentile(wall, 50) / 60000 : null,
63
+ usd_per_merge: usd.length >= minN ? sum(usd) / usd.length : null,
64
+ revert_rate: ratio(revFlagged.filter((r) => r.reverted).length, revFlagged.length, minN),
65
+ rework_rate: ratio(merged.filter((r) => r.remediated).length, merged.length, minN),
66
+ tested_requirements_rate: ratio(verifiable.filter((r) => r.verified).length, verifiable.length, minN),
67
+ stuck_issues: runs.length >= minN ? runs.filter((r) => attempts(r) > 1).length : null,
68
+ };
69
+ }
70
+
71
+ function verdict(m, cur, prev) {
72
+ if (!isNum(cur) || !isNum(prev)) return null;
73
+ const d = m.kind === "rate" ? cur - prev : prev === 0 ? (cur === 0 ? 0 : Infinity) : (cur - prev) / prev;
74
+ if (Math.abs(d) <= m.flat) return "flat";
75
+ return (d < 0) === m.lowerBetter ? "improved" : "regressed";
76
+ }
77
+
78
+ /** Never throws: a malformed input yields an all-null scorecard. */
79
+ export function buildScorecard({ records = [], batchRows = [], laneAudits = [], release, prev = null, minN = DEFAULT_MIN_N } = {}) {
80
+ try {
81
+ const known = [...new Set((records ?? []).map((r) => r?.version).filter((v) => v && v !== UNKNOWN))].sort(compareVersions);
82
+ const prevVersion = prev ?? (known.includes(release) ? known[known.indexOf(release) - 1] ?? null : null);
83
+ const src = { records: records ?? [], batchRows: batchRows ?? [], laneAudits: laneAudits ?? [] };
84
+ const values = scorecardValues(src, release, minN);
85
+ const before = prevVersion ? scorecardValues(src, prevVersion, minN) : null;
86
+ const verdicts = Object.fromEntries(SCORECARD_METRICS.map((m) => [m.key, before ? verdict(m, values[m.key], before[m.key]) : null]));
87
+ const regressions = SCORECARD_METRICS.filter((m) => verdicts[m.key] === "regressed").map((m) => m.key);
88
+ return { release, against: prevVersion, minN, values, previous: before, verdicts, regressions };
89
+ } catch {
90
+ const values = Object.fromEntries(SCORECARD_METRICS.map((m) => [m.key, null]));
91
+ return { release, against: null, minN, values, previous: null, verdicts: Object.fromEntries(SCORECARD_METRICS.map((m) => [m.key, null])), regressions: [] };
92
+ }
93
+ }
94
+
95
+ const fmt = (m, v) => (v == null ? "n/a" : m.kind === "rate" ? `${(v * 100).toFixed(0)}%` : m.key === "usd_per_merge" ? `$${v.toFixed(2)}` : String(Math.round(v * 100) / 100));
96
+
97
+ export function renderScorecard(sc) {
98
+ const line = (r) => `| ${r.join(" | ")} |`;
99
+ const head = ["metric", sc.release, sc.against ?? "previous", "verdict"];
100
+ const rows = SCORECARD_METRICS.map((m) => [m.label, fmt(m, sc.values[m.key]), sc.previous ? fmt(m, sc.previous[m.key]) : "n/a", sc.verdicts[m.key] ?? "n/a"]);
101
+ const reg = sc.regressions.length ? `Regressions vs ${sc.against}: ${SCORECARD_METRICS.filter((m) => sc.regressions.includes(m.key)).map((m) => m.label).join(", ")}` : `Regressions: none${sc.against ? ` vs ${sc.against}` : ""}`;
102
+ return [`Release scorecard ${sc.release} (min n ${sc.minN}; n/a when the source is absent or below it)`, line(head), line(head.map(() => "---")), ...rows.map(line), "", reg].join("\n");
103
+ }
104
+
105
+ /** The FORGE:SCORECARD section: marker, table and snapshot as fenced JSON. */
106
+ export function scorecardComment(sc) {
107
+ return `${SCORECARD_MARKER}\n${renderScorecard(sc)}\n\n\`\`\`json\n${JSON.stringify(sc)}\n\`\`\`\n`;
108
+ }
109
+
110
+ export const SCORECARD_HELP = `forgedock scorecard --repo <owner/repo> --release <vX> [--json] [--min-n N]
111
+ Per-release scorecard from the GitHub register, compared to the previous release. No LLM calls.
112
+ `;
113
+
114
+ export function parseScorecardArgs(argv) {
115
+ const o = { repo: null, release: null, json: false, help: false, minN: DEFAULT_MIN_N, error: null };
116
+ for (let i = 0; i < argv.length; i++) {
117
+ const a = argv[i];
118
+ if (a === "--help" || a === "-h") o.help = true;
119
+ else if (a === "--json") o.json = true;
120
+ else if (a === "--repo" || a === "--release" || a === "--min-n") {
121
+ const v = argv[++i];
122
+ if (v == null || v.startsWith("--")) { o.error = `${a} needs a value`; break; }
123
+ if (a === "--min-n") { const n = Number(v); if (!Number.isInteger(n) || n < 1) { o.error = "--min-n must be a positive integer"; break; } o.minN = n; }
124
+ else o[a.slice(2)] = v;
125
+ } else { o.error = `unknown argument ${a}`; break; }
126
+ }
127
+ return o;
128
+ }
129
+
130
+ /** Batch logs of `repo` on disk: one row per batch, interventions = operator requeues applied (state.json `requeueApplied`). */
131
+ export function batchRowsFromDisk(repo, root = batchRoot()) {
132
+ const read = (f) => { try { return JSON.parse(readFileSync(f, "utf8")); } catch { return null; } };
133
+ return listBatches(root).flatMap((id) => {
134
+ const plan = read(join(root, id, "plan.json")), st = existsSync(join(root, id, "state.json")) ? read(join(root, id, "state.json")) : null;
135
+ if (!plan || plan.repo !== repo || !st) return [];
136
+ return [{ batch: id, interventions: Array.isArray(st.requeueApplied) ? st.requeueApplied.length : 0 }];
137
+ });
138
+ }
139
+
140
+ export const LANE_AUDIT_RE = /^<!-- FORGE:LANE_AUDIT v1 -->/;
141
+ export const FAILURE_CENSUS_RE = /^<!-- FORGE:FAILURE_CENSUS v1 -->/;
142
+
143
+ /**
144
+ * Trusted LANE_AUDIT and failure-census comments -> entries. Each comment starts with its marker and carries a fenced
145
+ * json block holding one object or an array: LANE_AUDIT `{issue, release?, class: "genuine"|"pipeline"}`, failure-census
146
+ * `{issue, release?, class?, reverted?}` (a census `class` counts as a needs-human audit when no LANE_AUDIT covers the issue).
147
+ */
148
+ export function parseRegisterComments(comments, env = process.env) {
149
+ const out = { laneAudits: [], census: [] };
150
+ for (const c of comments ?? []) {
151
+ const body = String(c?.body ?? "");
152
+ const kind = LANE_AUDIT_RE.test(body) ? "laneAudits" : FAILURE_CENSUS_RE.test(body) ? "census" : null;
153
+ if (!kind || !isTrusted(c, env)) continue;
154
+ const block = /```json\n([\s\S]*?)(?:\n```|$)/.exec(body);
155
+ if (!block) continue;
156
+ let v; try { v = JSON.parse(block[1]); } catch { continue; }
157
+ for (const e of Array.isArray(v) ? v : [v]) if (e && typeof e === "object") out[kind].push(e);
158
+ }
159
+ const audited = new Set(out.laneAudits.map((a) => a.issue));
160
+ out.laneAudits.push(...out.census.filter((e) => e.class && !audited.has(e.issue)).map((e) => ({ issue: e.issue, release: e.release, class: e.class })));
161
+ return out;
162
+ }
163
+
164
+ /** Fetch the register and build the scorecard. `deps.gh`/`deps.fetch` are injectable. */
165
+ export async function gatherScorecard({ repo, release, minN = DEFAULT_MIN_N }, deps = {}) {
166
+ const result = await (deps.fetch ?? fetchGithubRecords)({ repo, gh: deps.gh ?? defaultGh, useCache: deps.useCache ?? true });
167
+ const model = toModel(repo, result);
168
+ let reg = { laneAudits: [], census: [] };
169
+ try { reg = deps.register ?? parseRegisterComments(parsePages(await (deps.gh ?? defaultGh)(["api", "--paginate", `repos/${repo}/issues/comments`]))); } catch { /* no register comments: those metrics stay n/a */ }
170
+ const reverted = new Set(reg.census.filter((e) => e.reverted === true).map((e) => e.issue)), tracked = new Set(reg.census.filter((e) => typeof e.reverted === "boolean").map((e) => e.issue));
171
+ const runs = model.runs.map((r) => (tracked.has(r.issue) ? { ...r, reverted: reverted.has(r.issue) } : r));
172
+ return buildScorecard({ records: runs, laneAudits: [...(deps.laneAudits ?? []), ...reg.laneAudits], batchRows: deps.batchRows ?? (() => { try { return batchRowsFromDisk(repo); } catch { return []; } })(), release, minN });
173
+ }
174
+
175
+ export async function runScorecard(argv, deps = {}) {
176
+ const o = parseScorecardArgs(argv);
177
+ if (o.help) { process.stdout.write(SCORECARD_HELP); return 0; }
178
+ const fail = (msg) => { process.stderr.write(`forgedock scorecard: ${msg}\n`); return 2; };
179
+ if (o.error) return fail(o.error);
180
+ if (!o.release) return fail("--release is required");
181
+ if (!isValidRepo(o.repo)) return fail("--repo owner/repo is required");
182
+ try {
183
+ const sc = await gatherScorecard(o, deps);
184
+ process.stdout.write(`${o.json ? JSON.stringify(sc) : renderScorecard(sc)}\n`);
185
+ return 0;
186
+ } catch (err) { process.stderr.write(`forgedock scorecard: ${err.message}\n`); return 1; }
187
+ }
@@ -0,0 +1,89 @@
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 { mkdirSync, writeFileSync } from "node:fs";
6
+ import { join } from "node:path";
7
+ import { tmpDir } from "../tests/_tmp.mjs";
8
+ import { parseRegisterComments, batchRowsFromDisk, buildScorecard, renderScorecard, scorecardComment, parseScorecardArgs, runScorecard, gatherScorecard, SCORECARD_MARKER } from "./scorecard.mjs";
9
+
10
+ const run = (version, i, o = {}) => ({ version, issue: i, finished: true, reason: "merged", remediated: false, wallMs: 600000, verified: true,
11
+ phases: { implement: { usd: 2, ms: 300000 } }, builderAttempts: [{ attempt: 1 }], ...o });
12
+ const many = (v, n, f) => Array.from({ length: n }, (_, i) => run(v, i, f?.(i)));
13
+
14
+ describe("scorecard", () => {
15
+ it("computes metrics from fixtures; sources that are absent are null", () => {
16
+ const sc = buildScorecard({ records: many("1.0.0", 10), release: "1.0.0", minN: 5 });
17
+ assert.equal(sc.values.first_pass_rate, 1);
18
+ assert.equal(sc.values.minutes_per_merge, 10);
19
+ assert.equal(sc.values.usd_per_merge, 2);
20
+ assert.equal(sc.values.active_min, 5);
21
+ assert.equal(sc.values.stuck_issues, 0);
22
+ assert.equal(sc.values.interventions_per_batch, null);
23
+ assert.equal(sc.values.needs_human_genuine, null); // no LANE_AUDIT
24
+ assert.equal(sc.values.revert_rate, null);
25
+ });
26
+ it("splits needs-human by LANE_AUDIT class and averages interventions per batch", () => {
27
+ const laneAudits = [...Array(3).fill({ class: "genuine" }), ...Array(2).fill({ class: "pipeline" })];
28
+ const batchRows = [{ interventions: 2 }, { interventions: 4 }];
29
+ const sc = buildScorecard({ records: many("1.0.0", 5), laneAudits, batchRows, release: "1.0.0", minN: 2 });
30
+ assert.equal(sc.values.needs_human_genuine, 3);
31
+ assert.equal(sc.values.needs_human_pipeline, 2);
32
+ assert.equal(sc.values.interventions_per_batch, 3);
33
+ });
34
+ it("is null below min-n", () => {
35
+ assert.equal(buildScorecard({ records: many("1.0.0", 3), release: "1.0.0" }).values.first_pass_rate, null);
36
+ });
37
+ it("flags a regression against the previous release", () => {
38
+ const records = [...many("1.0.0", 10), ...many("1.1.0", 10, (i) => (i < 5 ? { remediated: true } : {}))];
39
+ const sc = buildScorecard({ records, release: "1.1.0" });
40
+ assert.equal(sc.against, "1.0.0");
41
+ assert.equal(sc.verdicts.first_pass_rate, "regressed");
42
+ assert.ok(sc.regressions.includes("rework_rate"));
43
+ assert.equal(sc.verdicts.minutes_per_merge, "flat");
44
+ });
45
+ it("never throws on bad input and renders with the marker", () => {
46
+ const sc = buildScorecard({ records: [null, 5], release: "x" });
47
+ assert.deepEqual(sc.regressions, []);
48
+ const recs = [...many("1.0.0", 10), ...many("1.1.0", 10, () => ({ remediated: true }))];
49
+ const out = scorecardComment(buildScorecard({ records: recs, release: "1.1.0" }));
50
+ assert.ok(out.startsWith(SCORECARD_MARKER));
51
+ assert.match(renderScorecard(buildScorecard({ records: recs, release: "1.1.0" })), /Regressions vs 1\.0\.0: .*first-pass merge rate/);
52
+ assert.match(renderScorecard(sc), /n\/a/);
53
+ });
54
+ it("parses CLI args; --release is required", async () => {
55
+ assert.deepEqual(parseScorecardArgs(["--repo", "o/r", "--release", "v1", "--json"]).release, "v1");
56
+ assert.match(parseScorecardArgs(["--bogus"]).error, /unknown/);
57
+ assert.match(parseScorecardArgs(["--release"]).error, /needs a value/);
58
+ assert.equal(await runScorecard(["--repo", "o/r"]), 2);
59
+ });
60
+ it("uses only the injected fetcher (no network)", async () => {
61
+ const fetch = async ({ repo }) => ({ records: [], items: [], repo });
62
+ const sc = await gatherScorecard({ repo: "o/r", release: "v1" }, { fetch, gh: async () => { throw new Error("no network"); } });
63
+ assert.equal(sc.values.n, 0);
64
+ });
65
+ it("reads batch logs from disk: interventions are applied requeues of that repo's batches", () => {
66
+ const root = tmpDir("sc-");
67
+ const mk = (id, repo, st) => { mkdirSync(join(root, id), { recursive: true }); writeFileSync(join(root, id, "plan.json"), JSON.stringify({ repo })); writeFileSync(join(root, id, "state.json"), JSON.stringify(st)); };
68
+ mk("b-1", "o/r", { requeueApplied: ["a", "b"] });
69
+ mk("b-2", "o/r", {});
70
+ mk("b-3", "x/y", { requeueApplied: ["a"] });
71
+ assert.deepEqual(batchRowsFromDisk("o/r", root), [{ batch: "b-1", interventions: 2 }, { batch: "b-2", interventions: 0 }]);
72
+ });
73
+ it("reads LANE_AUDIT and failure-census comments from the register; untrusted or malformed ones are ignored", async () => {
74
+ const c = (marker, v, assoc = "OWNER") => ({ author_association: assoc, user: { login: "u" }, body: `<!-- FORGE:${marker} v1 -->\n\`\`\`json\n${typeof v === "string" ? v : JSON.stringify(v)}\n\`\`\`` });
75
+ const reg = parseRegisterComments([
76
+ c("LANE_AUDIT", [{ issue: 1, class: "genuine" }, { issue: 2, class: "pipeline" }]),
77
+ c("FAILURE_CENSUS", { issue: 3, class: "pipeline", reverted: true }),
78
+ c("LANE_AUDIT", { issue: 9, class: "genuine" }, "NONE"),
79
+ c("LANE_AUDIT", "{not json"),
80
+ { body: "plain", author_association: "OWNER" },
81
+ ], {});
82
+ assert.deepEqual(reg.laneAudits.map((a) => `${a.issue}:${a.class}`), ["1:genuine", "2:pipeline", "3:pipeline"]);
83
+ assert.equal(reg.census.length, 1);
84
+ const fetch = async () => ({ records: [], items: [] });
85
+ const sc = await gatherScorecard({ repo: "o/r", release: "v1", minN: 1 }, { fetch, register: reg, batchRows: [] });
86
+ assert.equal(sc.values.needs_human_genuine, 1);
87
+ assert.equal(sc.values.needs_human_pipeline, 2);
88
+ });
89
+ });
@@ -58,12 +58,10 @@ Do this yourself. Spawn no sub-agents here.
58
58
  `K` = `--parallel` if given, otherwise `orchestration.max_concurrent` from the repo's `forge.yaml`
59
59
  (`yq '.orchestration.max_concurrent' forge.yaml`), otherwise 3.
60
60
 
61
- **Lanes (base branches).** Each issue has its own lane, and ForgeDock works it out: an issue with a milestone
62
- goes to forge.yaml `branches.feature_pattern` (`milestone/<slug>`, which must exist on origin), any other issue
63
- to `branches.staging`. The default (production) branch is never a lane. Do not pass `--lane`; a `--lane` that
64
- differs from the issue's lane is refused (`lane-refused`, `lane.mismatch`). A dependency edge between two lanes
65
- (for example a milestone issue waiting on a staging-lane fix) never gets that fix on its base: list it in the
66
- plan and either re-milestone the dependency or wait for a milestone sync. Never mix lanes silently.
61
+ **Lanes (base branches).** ForgeDock picks each issue's lane: a milestone issue goes to forge.yaml
62
+ `branches.feature_pattern` (`milestone/<slug>`, must exist on origin), any other to `branches.staging`, never the
63
+ default branch. Do not pass `--lane` (a mismatch is refused: `lane-refused`, `lane.mismatch`). A cross-lane dependency
64
+ never gets the fix on its base: list it, then re-milestone the dependency or wait for a milestone sync.
67
65
 
68
66
  ## 3. Launch lanes
69
67
 
@@ -119,14 +117,11 @@ remaining maintenance once no feature is pending; otherwise the rest ends `held
119
117
  When a lane finishes (agent lanes; the batch runner applies the same rules itself):
120
118
  - `deferred` (lease held by another or a dead session): put it back in the queue and retry after the
121
119
  lease time printed in its output.
122
- - `deferred` with "host busy" (code `host.busy`: the host is short of memory, tmp space or CPU headroom;
123
- no lease was taken and nothing was posted): put the issue back in the queue and lower the effective K by
124
- 1 for the next 5 minutes, never below 1. Before raising K back, start one lane and check that it is not
125
- host busy again.
126
- - `deferred` with `rate_limited` (usage limit; the last output line carries the reset time): stop launching
127
- new lanes until that reset time, let running lanes finish, then resume the queue.
128
- - `dependency-open`: the engine or the builder found a dependency you missed (its output names it). This is a
129
- scheduling fact, not a failure: add the edge and requeue the issue behind it. Do not skip its dependents.
120
+ - `deferred` `host.busy` (host short of memory, tmp or CPU; nothing taken or posted): requeue it and lower K by 1
121
+ for 5 minutes (never below 1); before raising K, check one lane is not host busy again.
122
+ - `deferred` `rate_limited`: launch nothing until the reset time on its last line; running lanes finish.
123
+ - `dependency-open`: the engine or the builder found a dependency you missed (its output names it). A
124
+ scheduling fact, not a failure: add the edge and requeue the issue behind it. Keep its dependents.
130
125
  If the dependency is outside the set and agents can resolve it, add it to the batch and launch it.
131
126
  - `lane-refused` (codes `lane.mismatch`, `lane.default_branch`, `lane.branch_missing`, `lane.unresolved`): nothing
132
127
  ran (no lease, comment or worktree). Report the code and its detail (for example a missing `milestone/<slug>`
@@ -191,10 +186,7 @@ other lane running meanwhile.
191
186
 
192
187
  ## 3b. Settle scope (#4665)
193
188
 
194
- When settle begins, freeze the milestone's issue set (`scripts/settle-scope.mjs` `freezeScope`). Issues filed later are
195
- classified by `classifyNew`: decomposition children of a frozen issue stay in the milestone and join the measured set;
196
- deferred follow-ups go to the next milestone or the backlog; review findings and others count as growth only.
197
- `convergence` measures the frozen set plus those children; a STOP prints `formatStopReport` (growth and sources).
189
+ At settle, freeze the milestone's issue set and classify later issues with `scripts/settle-scope.mjs` (its header documents the rules).
198
190
 
199
191
  ## 4. Report
200
192
 
@@ -207,3 +199,14 @@ show `invalid (pre-filter)`). Then print:
207
199
  5. one escalation list: the human-code `needs-human` issues only, asked once.
208
200
 
209
201
  Nothing else.
202
+
203
+ ## Standing orders (`--select`)
204
+
205
+ `forgedock orchestrate --select '<query>'` (a GitHub issue search: `no:milestone`, `milestone:X`, `label:Y`) stores the selector in the batch and keeps owning it; no watcher process is needed (the schedd-hosted runner reconciles every few minutes):
206
+
207
+ - matching open issues join under the same DAG, priority and lane rules as `--add`; closed or moved ones leave.
208
+ - an issue stays scheduled until it is closed, merged, or blocked by a human code (credentials, spend, customer, promotion, product decision). Re-admission needs no operator command: `deferred` retries with exponential backoff (cap 2 h); `held` / `engine-error` re-admit on an agent or lane-image version change or after a 6 h cooldown; a conformance failure gets one more attempt after the base moves, then is listed in a single "needs decision" digest; the engine's `env.*` issue joins the order and its closure re-admits the waiters.
209
+ - the breaker resets itself after a cooldown when the failures were environmental (VM restart, mirror, network) and the pool is healthy, with a FORGE:DECISION.
210
+ - a merge into a staging lane branch closes the issue (and notes it on the post-deploy rollup when `FORGE_POSTDEPLOY_ROLLUP=<issue>` is set).
211
+
212
+ `forgedock orchestrate --status <id>` shows the coverage: matching open = running + queued + backing-off + waiting on deps + human-blocked (listed) + unscheduled. `unscheduled: 0` is the healthy state.