forgedock 1.55.0 → 1.55.1

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.
@@ -6,6 +6,8 @@
6
6
  // The sections below mirror docs/CONFIG.md (bin/tests/config-schema.test.mjs fails when a documented section is missing here).
7
7
  // Nested keys are only checked where a section is listed in CLOSED; elsewhere only the top level and typed keys are.
8
8
 
9
+ import { parseForgeYaml } from "./forge-utils.mjs";
10
+
9
11
  export const TOP_LEVEL = [
10
12
  "project", "paths", "branches", "agents", "repos", "project_board", "orchestration", "orchestrate", "notify", "decisions",
11
13
  "hygiene", "pipeline", "execution", "engine", "prod_watch", "selftest", "release", "issue_watch", "followups", "rollouts",
@@ -30,6 +32,7 @@ export const TYPES = {
30
32
  "verification.ci_local.max_parallel": "number",
31
33
  "engine.path": { enum: ["core", "full", "lean", "auto"] },
32
34
  "billing.enabled": "bool",
35
+ "gate.required_checks": "list",
33
36
  };
34
37
 
35
38
  /** Keys the legacy `full` path never reads (the core path reads them: bin/engine-cli.mjs readEnvConfig, readConformanceMode). */
@@ -91,6 +94,8 @@ function typeError(spec, { kind, value }) {
91
94
  */
92
95
  export function validateForgeYaml(text, { path } = {}) {
93
96
  const keys = scanKeys(text);
97
+ let parsed = {};
98
+ try { parsed = parseForgeYaml(String(text)); } catch { /* unparseable: scan findings still apply */ }
94
99
  const active = keys.get("engine.path")?.value.replace(/^["']|["']$/g, "") ?? "";
95
100
  const engine = path ?? (active || "core");
96
101
  const side = engine === "full" ? "full" : "core";
@@ -103,6 +108,13 @@ export function validateForgeYaml(text, { path } = {}) {
103
108
  const ignored = IGNORED_ON[side].find((p) => key === p || key.startsWith(p + "."));
104
109
  if (ignored && key === ignored) add("error", "ignored-on-path", key, `"${key}" is set but the ${side} engine path (engine.path: ${engine}) never reads it`);
105
110
  if (DEPRECATED[key]) add("warn", "deprecated-alias", key, `"${key}" is a deprecated alias; use "${DEPRECATED[key]}"`);
111
+ // #5504: a list the YAML text writes (block or flow) or the schema types as a list must reach readers as an array.
112
+ // Only `key` and `section.key` are checked: deeper blocks have their own readers (e.g. issue_watch.watches.*).
113
+ const [sec, leaf, deeper] = key.split(".");
114
+ const got = leaf === undefined ? parsed[sec] : deeper === undefined ? parsed[sec]?.[leaf] : undefined;
115
+ if (deeper === undefined && (node.kind === "list" || TYPES[key] === "list") && node.kind !== "map" && got !== undefined && !Array.isArray(got)) {
116
+ add("warn", "list-not-array", key, `"${key}" is a list but parses to ${typeof got === "string" ? JSON.stringify(got) : typeof got}, not an array (readers of it will ignore it)`);
117
+ }
106
118
  if (TYPES[key]) {
107
119
  const want = typeError(TYPES[key], node);
108
120
  if (want) add("error", "wrong-type", key, `"${key}" must be ${want} (got ${node.kind === "scalar" ? JSON.stringify(node.value) : node.kind})`);
@@ -29,6 +29,20 @@
29
29
  // YAML parser
30
30
  // ---------------------------------------------------------------------------
31
31
 
32
+ /** A block-list item without its trailing comment and surrounding quotes. */
33
+ function unquoteListItem(raw) {
34
+ const q = raw.match(/^"([^"]*)"|^'([^']*)'/);
35
+ return q ? (q[1] ?? q[2]) : raw.replace(/\s+#.*$/, "").trim();
36
+ }
37
+
38
+ /** `[a, "b, c"]` -> ["a", "b, c"]; null when `value` is not a flow list (kept as the raw string). */
39
+ function flowList(value) {
40
+ const m = value.match(/^\[(.*)\]$/);
41
+ if (!m) return null;
42
+ const items = [...m[1].matchAll(/\s*(?:"([^"]*)"|'([^']*)'|([^,]*?))\s*(?:,|$)/g)].map((x) => x[1] ?? x[2] ?? x[3]);
43
+ return items.filter((x, k) => !(x === "" && k === items.length - 1 || x === undefined)).map((x) => x.trim());
44
+ }
45
+
32
46
  /**
33
47
  * Minimal YAML parser for forge.yaml files.
34
48
  *
@@ -38,23 +52,41 @@
38
52
  * - Nested scalars under a section: ` key: value`
39
53
  * - Comments (`# ...`) and blank lines are skipped
40
54
  * - Both LF and CRLF line endings (split on /\r?\n/)
55
+ * - Lists of scalars as string arrays (forge#5504): flow `key: [a, "b"]` at top level or under a section, and
56
+ * block ` key:` followed by deeper-indented `- item` lines under a section
41
57
  *
42
- * Does NOT handle: arrays, multi-line values, anchors, aliases, or other
58
+ * Does NOT handle: nested lists of maps, multi-line values, anchors, aliases, or other
43
59
  * YAML features. Intended only for the flat key-value structure of forge.yaml.
44
60
  *
45
61
  * @param {string} raw - Raw string content of a forge.yaml file.
46
62
  * @param {{dottedSections?: string[]}} [opts] - forge#5206: sections whose nested keys may also contain `.` and `-`
47
63
  * after the first character (e.g. `experiment:` arm overrides `on.lean.explore: on`); other sections are unchanged.
48
- * @returns {Record<string, string | Record<string, string>>}
64
+ * @returns {Record<string, string | string[] | Record<string, string | string[]>>}
49
65
  */
50
66
  export function parseForgeYaml(raw, { dottedSections = [] } = {}) {
51
67
  const result = {};
52
68
  let currentSection = null;
69
+ const lines = raw.split(/\r?\n/);
53
70
 
54
- for (const line of raw.split(/\r?\n/)) {
71
+ for (let i = 0; i < lines.length; i++) {
72
+ const line = lines[i];
55
73
  // Skip comments and blank lines
56
74
  if (/^\s*#/.test(line) || /^\s*$/.test(line)) continue;
57
75
 
76
+ // Nested block list under a section: ` key:` then deeper `- item` lines (forge#5504)
77
+ const listKey = currentSection && line.match(/^(\s+)([a-zA-Z_][a-zA-Z0-9_]*):\s*(?:#.*)?$/);
78
+ if (listKey && typeof result[currentSection] === "object") {
79
+ const items = [];
80
+ let j = i + 1;
81
+ for (; j < lines.length; j++) {
82
+ if (/^\s*(#.*)?$/.test(lines[j])) continue;
83
+ const it = lines[j].match(/^(\s*)-\s+(.*?)\s*$/);
84
+ if (!it || it[1].length < listKey[1].length) break;
85
+ items.push(unquoteListItem(it[2]));
86
+ }
87
+ if (items.length) { result[currentSection][listKey[2]] = items; i = j - 1; continue; }
88
+ }
89
+
58
90
  // Top-level section header: `section:` (no value on same line)
59
91
  const sectionMatch = line.match(/^([a-zA-Z_][a-zA-Z0-9_]*):\s*(?:#.*)?$/);
60
92
  if (sectionMatch) {
@@ -72,7 +104,7 @@ export function parseForgeYaml(raw, { dottedSections = [] } = {}) {
72
104
  const value = topScalarMatch[2] ?? topScalarMatch[4]?.trim();
73
105
  if (key && value !== undefined) {
74
106
  currentSection = null;
75
- result[key] = value;
107
+ result[key] = topScalarMatch[2] === undefined ? flowList(value) ?? value : value;
76
108
  }
77
109
  continue;
78
110
  }
@@ -92,7 +124,7 @@ export function parseForgeYaml(raw, { dottedSections = [] } = {}) {
92
124
  value !== undefined &&
93
125
  typeof result[currentSection] === "object"
94
126
  ) {
95
- result[currentSection][key] = value;
127
+ result[currentSection][key] = nestedMatch[2] === undefined ? flowList(value) ?? value : value;
96
128
  }
97
129
  }
98
130
  }
package/bin/gc.mjs CHANGED
@@ -154,7 +154,7 @@ const errText = (e) => String(e?.stderr || e?.message || e).trim().split("\n")[0
154
154
  */
155
155
  export async function planGc({ probes, scopes = new Set(GC_SCOPES), olderThanMs = LEDGER_TTL_MS, ttlMs = null, deleteMergedBranches = true, now = Date.now() } = {}) {
156
156
  const P = probes, fs = P.fs ?? nodeFs;
157
- const items = [], notes = [], seen = new Set(), liveIds = new Set(), ledgers = [];
157
+ const items = [], notes = [], seen = new Set(), liveIds = new Set(), ledgers = [], liveLaneIssues = new Set();
158
158
  const want = (type) => scopes.has(SCOPE_OF[type]);
159
159
  const ttl = (type) => (Number.isFinite(ttlMs?.[type]) ? ttlMs[type] : olderThanMs); // forge.yaml hygiene TTLs, else --older-than
160
160
  const add = (it) => { const k = `${it.type}:${it.id}`; if (seen.has(k)) return; seen.add(k); items.push(it); };
@@ -232,6 +232,7 @@ export async function planGc({ probes, scopes = new Set(GC_SCOPES), olderThanMs
232
232
  const sameHost = j.host === P.host;
233
233
  // A live owner on this host is a running lane, even past `expires` (long CI waits refresh it only on register).
234
234
  const stale = sameHost ? !(Number.isSafeInteger(j.pid) && P.alive(j.pid)) : Number(j.expires) < now;
235
+ if (!stale && j.issue != null) liveLaneIssues.add(String(j.issue));
235
236
  ledgers.push({ path, batch: j.batch, lane: j.lane, repo: j.repo ?? null, stale });
236
237
  for (const r of j.resources) {
237
238
  const type = TYPE_OF_KIND[r.kind];
@@ -280,9 +281,15 @@ export async function planGc({ probes, scopes = new Set(GC_SCOPES), olderThanMs
280
281
 
281
282
  // ---- 2. docker: labelled forgedock.owner=1 is owned; everything else is "not owned" ----
282
283
  if (want("container") || want("volume")) {
284
+ let psOut = null, psErr = null;
285
+ try { psOut = jsonLines(await P.docker(["ps", "-a", "--size", "--no-trunc", "--format", "{{json .}}"])); } catch (e) { psErr = e; }
286
+ // #5496: a lane compose project is live when its issue has a live ledger or any of its containers is running.
287
+ const runningLane = new Set((psOut ?? []).filter((c) => /^running$/i.test(String(c.State ?? "")) || /^up\b/i.test(String(c.Status ?? ""))).map((c) => String(parseLabels(c.Labels)["com.docker.compose.project"] ?? "")));
283
288
  const ownedBy = (labels, createdMs, type) => {
284
- const lane = LANE_COMPOSE_RE.test(String(labels["com.docker.compose.project"] ?? "")); // #5421: lane compose project by name
289
+ const project = String(labels["com.docker.compose.project"] ?? "");
290
+ const lane = LANE_COMPOSE_RE.test(project); // #5421: lane compose project by name
285
291
  if (labels["forgedock.owner"] !== "1" && !lane) return { owned: false, action: "report", reason: "not owned" };
292
+ if (labels["forgedock.owner"] !== "1" && (liveLaneIssues.has(project.match(/^forgedock-lane-(\d+)/)[1]) || runningLane.has(project))) return { owned: true, action: "report", reason: "live lane compose project" };
286
293
  let exp = Number(labels["forgedock.expires"]);
287
294
  if (Number.isFinite(exp) && exp > 0 && exp < 1e12) exp *= 1000;
288
295
  if (Number.isFinite(exp) && exp > 0 && exp < now) return { owned: true, action: "reclaim", reason: "forgedock label, expired" };
@@ -291,7 +298,8 @@ export async function planGc({ probes, scopes = new Set(GC_SCOPES), olderThanMs
291
298
  };
292
299
  if (want("container")) {
293
300
  try {
294
- for (const c of jsonLines(await P.docker(["ps", "-a", "--size", "--no-trunc", "--format", "{{json .}}"]))) {
301
+ if (psErr) throw psErr;
302
+ for (const c of psOut) {
295
303
  const name = String(c.Names ?? c.ID ?? "").split(",")[0];
296
304
  if (!name || seen.has(`container:${name}`)) continue;
297
305
  if (liveIds.has(`container:${name}`)) continue;
@@ -126,7 +126,7 @@ async function runReview({ seam, pr, def, delta = null }) {
126
126
  if ((st.notes ?? []).length) await seam.addNotes(pr, st.notes);
127
127
  const sum = await seam.summary({ pr, filed });
128
128
  if (!sum.data) return blocked(`the gate summary was not posted (exit ${sum.code}): ${(sum.lines ?? []).slice(-1).join("").slice(0, 200)}`);
129
- return { pr, head: st.head, verdict: sum.data.verdict, marker: sum.data.marker, ciFailing: sum.data.ciFailing, filed, blocking, delta: st.delta?.from ?? null };
129
+ return { pr, head: st.head, verdict: sum.data.verdict, marker: sum.data.marker, ciFailing: sum.data.ciFailing, ciCancelOnly: Boolean(sum.data.ciCancelOnly), filed, blocking, delta: st.delta?.from ?? null };
130
130
  }
131
131
 
132
132
  /** Review step. @returns {{pr, head, verdict, marker, filed, blocking}|{blocked: true, reason: string}} */
@@ -143,6 +143,17 @@ export async function fixStep(ctx) {
143
143
  const seam = seamOf(ctx);
144
144
  for (let round = 0; r.marker !== "FORGE:GATE_PASS"; round++) {
145
145
  if (round >= MAX_FIX_ROUNDS) return blocked(`still ${r.verdict} after ${MAX_FIX_ROUNDS} fix round(s)`);
146
+ // Only cancelled duplicate runs are red (#5502): nothing to fix. The summary reruns them once; re-summarise without spending the round.
147
+ if (!r.blocking?.length && r.ciFailing > 0 && r.ciCancelOnly) {
148
+ const sum = await seam.summary({ pr: r.pr, filed: r.filed ?? [] });
149
+ if (!sum.data) return blocked(`the gate summary was not posted (exit ${sum.code}) after rerunning the cancelled checks of #${r.pr}`);
150
+ r = { ...r, verdict: sum.data.verdict, marker: sum.data.marker, ciFailing: sum.data.ciFailing, ciCancelOnly: Boolean(sum.data.ciCancelOnly) };
151
+ ctx.state.steps.review = { ...ctx.state.steps.review, result: r };
152
+ ctx.save();
153
+ if (r.marker === "FORGE:GATE_PASS") break;
154
+ if (r.ciCancelOnly) return blocked(`required checks of #${r.pr} still cancelled after a rerun, with no failure to fix`);
155
+ round--; continue;
156
+ }
146
157
  // Blocking findings are already filed issues; red CI has none, so it gets one issue naming the failing checks.
147
158
  const issues = [...(r.blocking ?? [])];
148
159
  if (r.ciFailing > 0) {
@@ -192,6 +192,20 @@ describe("fixStep", () => {
192
192
  assert.deepEqual(s.log.filter((e) => e[0] === "lane").map((e) => e[1]), [101, 100]);
193
193
  });
194
194
 
195
+ it("only cancelled CI: no CI issue, no lane, no round spent; re-summarises and goes on", async () => {
196
+ const pass = { code: 0, data: { verdict: "APPROVE FOR DEPLOY", marker: "FORGE:GATE_PASS", ciFailing: 0 }, lines: [] };
197
+ const s = fakeSeam({ summary: pass });
198
+ const r = await fixStep(ctx(s, { review: { result: { ...failed, blocking: [], filed: [], ciFailing: 2, ciCancelOnly: true } } }));
199
+ assert.deepEqual(s.log, [["summary", []]]);
200
+ assert.equal(r.blocked, undefined);
201
+ assert.equal(r.verdict, "APPROVE FOR DEPLOY");
202
+ const still = { code: 0, data: { verdict: "BLOCK DEPLOY", marker: "FORGE:GATE_FAILURE", ciFailing: 1, ciCancelOnly: true }, lines: [] };
203
+ const s2 = fakeSeam({ summary: still });
204
+ const r2 = await fixStep(ctx(s2, { review: { result: { ...failed, blocking: [], filed: [], ciFailing: 1, ciCancelOnly: true } } }));
205
+ assert.match(r2.reason, /still cancelled/);
206
+ assert.ok(!s2.log.some((e) => e[0] === "ci-issue" || e[0] === "lane"));
207
+ });
208
+
195
209
  it("blocks when the verdict is not a pass but there is nothing to fix", async () => {
196
210
  assert.match((await fixStep(ctx(fakeSeam(), { review: { result: { ...failed, blocking: [], ciFailing: 0 } } }))).reason, /nothing to fix|neither/);
197
211
  });
@@ -142,7 +142,7 @@ function defaultIo() {
142
142
  };
143
143
  }
144
144
 
145
- function readConfig(io) {
145
+ export function readConfig(io) {
146
146
  const path = io.env.FORGE_CONFIG || join(io.cwd, "forge.yaml");
147
147
  let cfg = {};
148
148
  try { cfg = parseForgeYaml(io.readFile(path)) ?? {}; } catch { /* absent config: owner/repo check below fails */ }
@@ -540,11 +540,50 @@ export function requiredSet({ checks = [], unreadable = false } = {}, extra = []
540
540
  * (no protection, or a failed read: indistinguishable) keeps every red check blocking (fail closed).
541
541
  */
542
542
  export function classifyChecks(checks, required = []) {
543
- const red = checks.filter((k) => !CI_EXCLUDED_CHECKS.includes(k?.name) && isRed(k));
543
+ const { blockRows, warnings } = redChecks(checks, required);
544
+ return { blocking: blockRows.length, warnings };
545
+ }
546
+
547
+ /**
548
+ * classifyChecks' rows. A name with any `pass` on the head is green whatever cancelled duplicates it has (push-event and
549
+ * pull_request-event runs share a concurrency group, which cancels one of them: #5502).
550
+ */
551
+ function redChecks(checks, required = []) {
552
+ const passed = new Set(checks.filter((k) => k?.bucket === "pass").map((k) => k.name));
553
+ const red = checks.filter((k) => !CI_EXCLUDED_CHECKS.includes(k?.name) && isRed(k) && !(k.bucket === "cancel" && passed.has(k.name)));
544
554
  const req = new Set(required);
545
- if (!req.size) return { blocking: red.length, warnings: [] };
546
- const hit = red.filter((k) => req.has(k.name));
547
- return { blocking: hit.length, warnings: [...new Set(red.filter((k) => !req.has(k.name)).map((k) => String(k.name)))] };
555
+ if (!req.size) return { blockRows: red, warnings: [] };
556
+ return { blockRows: red.filter((k) => req.has(k.name)), warnings: [...new Set(red.filter((k) => !req.has(k.name)).map((k) => String(k.name)))] };
557
+ }
558
+
559
+ /** Blocking checks whose only results are `cancel` (no pass, no fail): infrastructure, worth one rerun. @returns [{name, link}] */
560
+ export function cancelOnlyChecks(checks, required = []) {
561
+ const { blockRows } = redChecks(checks, required);
562
+ const failed = new Set(blockRows.filter((k) => k.bucket === "fail").map((k) => k.name));
563
+ const seen = new Map();
564
+ for (const k of blockRows) if (k.bucket === "cancel" && !failed.has(k.name) && !seen.has(k.name)) seen.set(k.name, { name: k.name, link: k.link ?? "" });
565
+ return [...seen.values()];
566
+ }
567
+
568
+ const CI_POLL_MS = 20_000, CI_POLL_MAX = 45;
569
+
570
+ /** One `gh run rerun` per cancelled run of the cancel-only required checks, then wait until none of them is pending. @returns the re-read checks, or `checks` when nothing could be rerun. */
571
+ async function rerunCancelled(io, c, pr, env, checks, only) {
572
+ const ids = [...new Set(only.map((k) => /\/actions\/runs\/(\d+)/.exec(k.link)?.[1]).filter(Boolean))];
573
+ if (!ids.length) return checks;
574
+ for (const id of ids) await io.run("gh", ["run", "rerun", id, "-R", c.ghRepo], { env, cwd: io.cwd });
575
+ const sleep = io.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
576
+ const names = new Set(only.map((k) => k.name));
577
+ let cur = checks;
578
+ for (let i = 0; i < CI_POLL_MAX; i++) {
579
+ await sleep(CI_POLL_MS);
580
+ const r = await io.run("gh", ["pr", "checks", String(pr), "-R", c.ghRepo, "--json", "name,bucket,link"], { env, cwd: io.cwd });
581
+ const next = r.code === 0 ? parseChecks(r.stdout) : null;
582
+ if (!next) continue;
583
+ cur = next;
584
+ if (!cur.some((k) => names.has(k.name) && k.bucket === "pending")) break;
585
+ }
586
+ return cur;
548
587
  }
549
588
 
550
589
  /** Failing (fail/cancel) checks outside CI_EXCLUDED_CHECKS. */
@@ -591,13 +630,16 @@ async function summary(a, io) {
591
630
  // Phase 1E read: forgedock/verify is excluded; an unreadable result counts as failing (fail closed). forge/deploy-gate
592
631
  // and the gate-marker check are excluded too: they report this review's own marker, so an earlier GATE_FAILURE must not block the re-run that clears it.
593
632
  let ciFailing = 1;
594
- const ci = await io.run("gh", ["pr", "checks", String(pr), "-R", c.ghRepo, "--json", "name,bucket"], { env, cwd: io.cwd });
595
- const checks = ci.code === 0 ? parseChecks(ci.stdout) : null;
596
- let warnings = [];
633
+ const ci = await io.run("gh", ["pr", "checks", String(pr), "-R", c.ghRepo, "--json", "name,bucket,link"], { env, cwd: io.cwd });
634
+ let checks = ci.code === 0 ? parseChecks(ci.stdout) : null;
635
+ let warnings = [], ciCancelOnly = false;
597
636
  if (checks) {
598
637
  const read = await requiredChecksRead({ gh: io.gh, repo: c.ghRepo, lane: c.defaultBranch });
599
638
  const required = requiredSet(read, c.extraRequiredChecks);
639
+ const only = cancelOnlyChecks(checks, required);
640
+ if (only.length) checks = await rerunCancelled(io, c, pr, env, checks, only);
600
641
  ({ blocking: ciFailing, warnings } = classifyChecks(checks, required));
642
+ ciCancelOnly = ciFailing > 0 && redChecks(checks, required).blockRows.every((k) => k.bucket === "cancel");
601
643
  }
602
644
 
603
645
  const acceptanceBlocked = await acceptanceBlock(io, c, pr, tg);
@@ -654,7 +696,7 @@ async function summary(a, io) {
654
696
  } catch (e) {
655
697
  throw new Stop(1, [`REVIEW_RESULT: status: BLOCKED, blocker: could not post the Phase 8 summary and gate marker (${e.message})`, BLOCK_DEPLOY]);
656
698
  }
657
- if (a.json) io.out(JSON.stringify({ pr, headSha: head, verdict: v.verdict, why: v.why, marker, ciFailing, warnings, testGate: tg.verdict, filed: a.filed }));
699
+ if (a.json) io.out(JSON.stringify({ pr, headSha: head, verdict: v.verdict, why: v.why, marker, ciFailing, ciCancelOnly, warnings, testGate: tg.verdict, filed: a.filed }));
658
700
  else io.out([`VERDICT: ${v.verdict} (${v.why})`, ...(warnings.length ? [`WARNING: ${warnings.length} non-required check(s) red, non-blocking: ${warnings.join(", ")}`] : []), `GATE: ${marker} posted on PR #${pr}`, ...(pass ? [] : [BLOCK_DEPLOY])].join("\n"));
659
701
  return pass ? 0 : 1;
660
702
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forgedock",
3
- "version": "1.55.0",
3
+ "version": "1.55.1",
4
4
  "description": "An AI engineering team that ships to production",
5
5
  "bin": {
6
6
  "forgedock": "bin/forgedock.mjs"