forgedock 1.67.0 → 1.69.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 (156) hide show
  1. package/bin/config-schema.mjs +1 -0
  2. package/bin/engine/outcome-codes.mjs +1 -0
  3. package/bin/engine-cli.mjs +103 -21
  4. package/bin/engine.mjs +10 -0
  5. package/bin/forgedock.mjs +17 -1
  6. package/bin/help-text.mjs +1 -0
  7. package/bin/lean/admission.mjs +21 -0
  8. package/bin/lean/admission.test.mjs +30 -0
  9. package/bin/lean/advisory.test.mjs +39 -15
  10. package/bin/lean/amendment-schema.mjs +3 -4
  11. package/bin/lean/attempts.mjs +34 -31
  12. package/bin/lean/attempts.test.mjs +33 -19
  13. package/bin/lean/basered.mjs +26 -0
  14. package/bin/lean/batch-health.mjs +17 -12
  15. package/bin/lean/batch-health.test.mjs +39 -11
  16. package/bin/lean/batch.mjs +11 -1
  17. package/bin/lean/batch.test.mjs +51 -2
  18. package/bin/lean/capsample.mjs +25 -0
  19. package/bin/lean/ci-gate.mjs +2 -90
  20. package/bin/lean/ci-gate.test.mjs +1 -127
  21. package/bin/lean/ci-precheck.mjs +25 -8
  22. package/bin/lean/ci-precheck.test.mjs +24 -0
  23. package/bin/lean/clear-breaker.test.mjs +4 -3
  24. package/bin/lean/commentstate.mjs +10 -5
  25. package/bin/lean/commentstate.test.mjs +12 -1
  26. package/bin/lean/conformance.e2e.test.mjs +9 -6
  27. package/bin/lean/conformance.mjs +62 -197
  28. package/bin/lean/conformance.test.mjs +46 -376
  29. package/bin/lean/depcache.mjs +102 -10
  30. package/bin/lean/depcache.test.mjs +105 -0
  31. package/bin/lean/docsgate.mjs +0 -32
  32. package/bin/lean/docsgate.test.mjs +2 -23
  33. package/bin/lean/effects-cap.test.mjs +9 -1
  34. package/bin/lean/effects-killtree.test.mjs +35 -0
  35. package/bin/lean/effects.mjs +57 -25
  36. package/bin/lean/engine-readmit.test.mjs +35 -0
  37. package/bin/lean/envgap.mjs +111 -0
  38. package/bin/lean/envgap.test.mjs +64 -0
  39. package/bin/lean/execution.mjs +13 -4
  40. package/bin/lean/execution.test.mjs +33 -0
  41. package/bin/lean/failure-census.mjs +170 -0
  42. package/bin/lean/failure-census.test.mjs +59 -0
  43. package/bin/lean/failure-stop.mjs +12 -1
  44. package/bin/lean/failure-stop.test.mjs +14 -1
  45. package/bin/lean/guardgate.test.mjs +2 -3
  46. package/bin/lean/heavy.mjs +33 -4
  47. package/bin/lean/heavy.test.mjs +38 -6
  48. package/bin/lean/hostconfig.mjs +54 -0
  49. package/bin/lean/hostconfig.test.mjs +67 -0
  50. package/bin/lean/hotarea.mjs +0 -36
  51. package/bin/lean/hotarea.test.mjs +1 -22
  52. package/bin/lean/issuewatch-verify.mjs +19 -4
  53. package/bin/lean/issuewatch.mjs +21 -4
  54. package/bin/lean/issuewatch.test.mjs +48 -1
  55. package/bin/lean/lane-audit-gap.mjs +66 -0
  56. package/bin/lean/lane-audit-gap.test.mjs +59 -0
  57. package/bin/lean/lane-audit-llm.mjs +52 -0
  58. package/bin/lean/lane-audit-llm.test.mjs +57 -0
  59. package/bin/lean/lane-audit-query.mjs +47 -0
  60. package/bin/lean/lane-audit-query.test.mjs +44 -0
  61. package/bin/lean/lane-audit-signatures.mjs +33 -0
  62. package/bin/lean/lane-audit.mjs +110 -0
  63. package/bin/lean/lane-audit.test.mjs +97 -0
  64. package/bin/lean/lane-recovery.test.mjs +33 -0
  65. package/bin/lean/lanecheck.mjs +5 -3
  66. package/bin/lean/lanecheck.test.mjs +6 -0
  67. package/bin/lean/lean.mjs +247 -152
  68. package/bin/lean/lean.test.mjs +502 -206
  69. package/bin/lean/limits.mjs +17 -0
  70. package/bin/lean/limits.test.mjs +15 -1
  71. package/bin/lean/live-execution.mjs +24 -2
  72. package/bin/lean/live-execution.test.mjs +62 -0
  73. package/bin/lean/orchestrate-attempts.test.mjs +17 -9
  74. package/bin/lean/orchestrate-dispatch-placement.test.mjs +81 -0
  75. package/bin/lean/orchestrate-envhold.test.mjs +62 -1
  76. package/bin/lean/orchestrate-heldroot.test.mjs +72 -0
  77. package/bin/lean/orchestrate-hostfallback.test.mjs +59 -1
  78. package/bin/lean/orchestrate-overload-recovery.test.mjs +37 -0
  79. package/bin/lean/orchestrate-pause.test.mjs +53 -1
  80. package/bin/lean/orchestrate-reconcile.test.mjs +17 -0
  81. package/bin/lean/orchestrate-relaunch-gates.test.mjs +57 -0
  82. package/bin/lean/orchestrate-stacking.test.mjs +10 -0
  83. package/bin/lean/orchestrate.mjs +215 -42
  84. package/bin/lean/postdeploy-check.test.mjs +1 -3
  85. package/bin/lean/precheck.mjs +20 -0
  86. package/bin/lean/preflight.mjs +110 -14
  87. package/bin/lean/preflight.test.mjs +64 -4
  88. package/bin/lean/prompts.mjs +11 -21
  89. package/bin/lean/recurrence.mjs +6 -148
  90. package/bin/lean/recurrence.test.mjs +11 -147
  91. package/bin/lean/release-deploy.mjs +35 -5
  92. package/bin/lean/release-deploy.test.mjs +50 -3
  93. package/bin/lean/release-flakes.mjs +48 -2
  94. package/bin/lean/release-flakes.test.mjs +45 -1
  95. package/bin/lean/release-ledger.mjs +19 -1
  96. package/bin/lean/release-ledger.test.mjs +23 -0
  97. package/bin/lean/release-preflight.mjs +28 -0
  98. package/bin/lean/release-preflight.test.mjs +42 -1
  99. package/bin/lean/release-review.mjs +40 -5
  100. package/bin/lean/release-review.test.mjs +43 -2
  101. package/bin/lean/release.mjs +45 -15
  102. package/bin/lean/release.test.mjs +32 -0
  103. package/bin/lean/retry.mjs +1 -1
  104. package/bin/lean/retry.test.mjs +6 -1
  105. package/bin/lean/rotator.mjs +9 -0
  106. package/bin/lean/rotator.test.mjs +11 -1
  107. package/bin/lean/sandbox-remote.mjs +51 -13
  108. package/bin/lean/schedd.mjs +13 -8
  109. package/bin/lean/schedd.test.mjs +65 -5
  110. package/bin/lean/selfreview.mjs +1 -1
  111. package/bin/lean/statuscomment.mjs +4 -1
  112. package/bin/lean/validate-catalog.mjs +108 -0
  113. package/bin/lean/validate-catalog.test.mjs +46 -1
  114. package/bin/lean/verify.mjs +1 -1
  115. package/bin/pool/affinity.test.mjs +91 -0
  116. package/bin/pool/agent.mjs +247 -23
  117. package/bin/pool/cache-sweep.mjs +31 -10
  118. package/bin/pool/ci-autoscale.mjs +160 -0
  119. package/bin/pool/cli.mjs +56 -9
  120. package/bin/pool/docker.mjs +5 -0
  121. package/bin/pool/engine-placement.test.mjs +94 -0
  122. package/bin/pool/image-manifest.mjs +24 -0
  123. package/bin/pool/image-manifest.test.mjs +20 -0
  124. package/bin/pool/lane-target.mjs +41 -0
  125. package/bin/pool/lane-tools.mjs +29 -5
  126. package/bin/pool/lane-tools.test.mjs +36 -7
  127. package/bin/pool/mirror-seed.mjs +15 -11
  128. package/bin/pool/project-layer.mjs +142 -0
  129. package/bin/pool/project-layer.test.mjs +73 -0
  130. package/bin/pool/router.mjs +106 -36
  131. package/bin/pool/version.mjs +72 -2
  132. package/bin/review-staging.mjs +11 -3
  133. package/bin/runner.mjs +59 -11
  134. package/bin/stats/release.mjs +7 -0
  135. package/bin/stats/release.test.mjs +20 -0
  136. package/bin/stats/scorecard.mjs +187 -0
  137. package/bin/stats/scorecard.test.mjs +89 -0
  138. package/bin/stats/tool-parks.mjs +29 -0
  139. package/bin/stats/tool-parks.test.mjs +21 -0
  140. package/docs/CONFIG.md +41 -0
  141. package/docs/OUTCOME-CODES.md +1 -0
  142. package/docs/STATS.md +17 -0
  143. package/package.json +1 -1
  144. package/pool/image/Dockerfile +15 -3
  145. package/pool/image/manifest.json +25 -0
  146. package/pool/image/mirror.sh +11 -2
  147. package/pool/install/install-agent.ps1 +11 -4
  148. package/scripts/ci-local/adapters/github-actions.mjs +8 -0
  149. package/scripts/ci-local/cli.mjs +1 -1
  150. package/scripts/ci-local/plan.mjs +3 -2
  151. package/scripts/ci-local.test.sh +14 -2
  152. package/scripts/failure-census.mjs +67 -0
  153. package/scripts/review-finalize.sh +5 -5
  154. package/scripts/review-finalize.test.sh +8 -1
  155. package/scripts/verify-phase-trail.sh +11 -0
  156. package/scripts/verify-phase-trail.test.sh +9 -0
@@ -1,24 +1,17 @@
1
1
  // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
2
  // SPDX-License-Identifier: AGPL-3.0-or-later
3
3
  /**
4
- * #5760: CI budget gate. A lane that adds a workflow file, a job, or a CI step running one test file must fold it into the
5
- * forge.yaml `ci.budget.shared_regression_job` or carry a `# FORGE:CI_BUDGET trigger=<scope> minutes=<N>/month why=<text>`
6
- * comment in the workflow YAML; a new workflow or job needs concurrency, timeout-minutes, path scoping and (issue/comment
7
- * events) a job-level `if:`; `max_workflows`/`max_ci_jobs` cap the counts unless the same diff removes as many. Deterministic,
8
- * 0 LLM calls, no YAML dependency (an indentation scan like bin/forge-utils.mjs). The one-level forge.yaml parser flattens
4
+ * #5760: CI budget reporting (the lane gate that parked on a missing `# FORGE:CI_BUDGET` annotation was cut in #6083; only the
5
+ * `CI_NET` report of the net workflow/job/minutes change remains). Deterministic, 0 LLM calls, no YAML dependency (an indentation scan like bin/forge-utils.mjs). The one-level forge.yaml parser flattens
9
6
  * `ci.budget.*` into `ci`, so `ci.budget.monthly_minutes` is the same key as #5278's `ci.monthly_minutes`.
10
7
  */
11
8
  import { execFileSync } from "node:child_process";
12
9
  import { readFileSync } from "node:fs";
13
10
  import { join } from "node:path";
14
11
  import { fileURLToPath } from "node:url";
15
- import { OUTCOME_CODES } from "../engine/outcome-codes.mjs";
16
12
  import { parseForgeYaml } from "../forge-utils.mjs";
17
13
 
18
- const C = OUTCOME_CODES.CONFORMANCE_UNIMPLEMENTED;
19
14
  export const WORKFLOW_RE = /^\.github\/workflows\/[^/]+\.ya?ml$/;
20
- const COMMENT_EVENTS = ["issues", "issue_comment", "pull_request_review_comment", "discussion_comment"];
21
- const PATH_EVENTS = ["push", "pull_request", "pull_request_target"];
22
15
  // A runner at command position: segment start, after env assignments and a launcher, never inside a path or extension (#5787).
23
16
  const RUNNER_RE = /^(?:\w+=\S*\s+)*(?:(?:npx|bunx|pnpm(?:\s+exec)?|yarn|uv\s+run|poetry\s+run|python3?\s+-m)\s+)?(?:[^\s;&|]*\/)?(?:node\s+(?:[^\s]+\s+)*--test|vitest|jest|pytest|go\s+test|playwright\s+test|mocha|bash|sh)(?=\s|$)/;
24
17
  const YAML_KEY_RE = /^["']?[A-Za-z_][\w-]*["']?\s*:(?:\s|$)/;
@@ -107,15 +100,6 @@ export function scanWorkflow(text) {
107
100
  return { lines, triggers, pathsExempt, concurrency: top.some((t) => t.key === "concurrency"), jobs, annotations };
108
101
  }
109
102
 
110
- /** Lines of `head` not matched by a line of `base` (multiset on trimmed text), as indexes into head. */
111
- function addedLineIdx(base, head) {
112
- const left = new Map();
113
- for (const l of String(base ?? "").split(/\r?\n/)) left.set(l.trim(), (left.get(l.trim()) ?? 0) + 1);
114
- const out = [];
115
- String(head ?? "").split(/\r?\n/).forEach((l, i) => { const k = l.trim(); if (left.get(k) > 0) left.set(k, left.get(k) - 1); else out.push(i); });
116
- return out;
117
- }
118
-
119
103
  /** The single test file a run line invokes, or null (a test runner with exactly one test-file argument). */
120
104
  export function singleTestFile(line) {
121
105
  const cmd = String(line ?? "").replace(/^\s*-?\s*(?:run\s*:\s*[|>]?)?/, "").trim();
@@ -130,70 +114,6 @@ export function singleTestFileSteps(addedLines) {
130
114
  return (addedLines ?? []).map((l, i) => ({ line: i, file: singleTestFile(l) })).filter((x) => x.file);
131
115
  }
132
116
 
133
- const fail = (kind, detail) => ({ code: C, kind, detail });
134
- const FIX = (shared) => `${shared ? `fold it into the shared job \`${shared}\` (forge.yaml ci.budget.shared_regression_job) or ` : ""}add \`# FORGE:CI_BUDGET trigger=<scope> minutes=<N>/month why=<why a shared job cannot hold it>\` in the workflow YAML`;
135
-
136
- /** Annotation verdict over the scan's annotations inside [from, to]: "ok" | {invalid: missing[]} | null (none). */
137
- function annotated(scan, from, to) {
138
- const inScope = scan.annotations.filter((a) => a.line >= from && a.line <= to);
139
- if (inScope.some((a) => !a.missing.length)) return "ok";
140
- return inScope.length ? { invalid: inScope[0].missing } : null;
141
- }
142
- function annotationFailure(where, verdict, shared) {
143
- if (verdict === "ok") return [];
144
- if (verdict?.invalid) return [fail("ci_budget_annotation_invalid", `${where}: the FORGE:CI_BUDGET annotation is missing ${verdict.invalid.join(", ")} (needs trigger=, minutes= and why=)`)];
145
- return [fail("ci_budget_unannotated", `${where} adds CI with no cost statement: ${FIX(shared)}`)];
146
- }
147
-
148
- function hygiene(file, scan, job, { wholeFile }) {
149
- const gaps = [];
150
- if (!scan.concurrency && !job.concurrency) gaps.push("concurrency");
151
- if (!job.timeout) gaps.push("timeout-minutes");
152
- const pathTriggers = PATH_EVENTS.filter((e) => scan.triggers[e] && !scan.triggers[e].paths && !(e === "push" && scan.triggers[e].tagOnly) && !scan.pathsExempt);
153
- if (pathTriggers.length && (wholeFile || !job.if)) gaps.push(`path scoping (paths/paths-ignore on ${pathTriggers.join(", ")}; tag-only push is exempt, or add \`# FORGE:CI_PATHS_EXEMPT why=<text>\`)`);
154
- if (COMMENT_EVENTS.some((e) => scan.triggers[e]) && !job.if) gaps.push("a job-level if: filter for issue/comment events");
155
- return gaps.length ? [fail("ci_hygiene", `${file} job \`${job.id}\` is new but has no ${gaps.join(", no ")}`)] : [];
156
- }
157
-
158
- const countJobs = (scans) => Object.values(scans).reduce((n, s) => n + s.jobs.length, 0);
159
-
160
- /**
161
- * The gate over base and head workflow maps ({path: text}, only `.github/workflows/*.yml|yaml` are read).
162
- * @returns {{code, kind, detail}[]} kinds: ci_budget_unannotated, ci_budget_annotation_invalid, ci_budget_exceeded, ci_hygiene
163
- */
164
- export function ciGateFindings({ cfg = parseCiBudget(null), base = {}, head = {} } = {}) {
165
- const wf = (m) => Object.fromEntries(Object.entries(m ?? {}).filter(([p]) => WORKFLOW_RE.test(p)).map(([p, t]) => [p, scanWorkflow(t)]));
166
- const b = wf(base), h = wf(head), out = [];
167
- const shared = cfg?.sharedJob ?? null;
168
- const sharedDir = shared && shared.includes("/") ? shared.replace(/\/+$/, "") + "/" : null;
169
- for (const [file, scan] of Object.entries(h)) {
170
- if (!b[file]) {
171
- out.push(...annotationFailure(`new workflow ${file}`, annotated(scan, 0, scan.lines.length), shared));
172
- for (const j of scan.jobs) out.push(...hygiene(file, scan, j, { wholeFile: true }));
173
- continue;
174
- }
175
- const baseIds = new Set(b[file].jobs.map((j) => j.id));
176
- const added = new Set(addedLineIdx(base[file], head[file]));
177
- for (const j of scan.jobs) {
178
- if (baseIds.has(j.id)) continue;
179
- out.push(...annotationFailure(`${file} new job \`${j.id}\``, annotated(scan, j.start, j.end), shared));
180
- out.push(...hygiene(file, scan, j, { wholeFile: false }));
181
- }
182
- for (const i of added) {
183
- const test = singleTestFile(scan.lines[i]);
184
- if (!test) continue;
185
- const j = scan.jobs.find((x) => i >= x.start && i <= x.end);
186
- if (!j || !baseIds.has(j.id)) continue; // outside a job, or inside a new job (judged above)
187
- if (shared && (j.id === shared || (sharedDir && test.replace(/^\.\//, "").startsWith(sharedDir)))) continue;
188
- out.push(...annotationFailure(`${file} job \`${j.id}\` step running only ${test}`, annotated(scan, j.start, j.end), shared));
189
- }
190
- }
191
- const [wb, wh, jbn, jhn] = [Object.keys(b).length, Object.keys(h).length, countJobs(b), countJobs(h)];
192
- if (cfg?.maxWorkflows != null && wh > cfg.maxWorkflows && wh > wb) out.push(fail("ci_budget_exceeded", `${wh} workflow files exceed ci.budget.max_workflows ${cfg.maxWorkflows} (+${wh - wb} in this diff): remove or fold as many workflows as you add`));
193
- if (cfg?.maxCiJobs != null && jhn > cfg.maxCiJobs && jhn > jbn) out.push(fail("ci_budget_exceeded", `${jhn} CI jobs exceed ci.budget.max_ci_jobs ${cfg.maxCiJobs} (+${jhn - jbn} in this diff): fold the new job(s) into an existing job or remove as many`));
194
- return out;
195
- }
196
-
197
117
  /** Net CI change between two workflow maps: {workflows, jobs, minutes, line}. */
198
118
  export function netCiChange({ base = {}, head = {}, cfg = null } = {}) {
199
119
  const wf = (m) => Object.entries(m ?? {}).filter(([p]) => WORKFLOW_RE.test(p)).map(([, t]) => scanWorkflow(t));
@@ -213,14 +133,6 @@ async function workflowsAt(git, ref) {
213
133
  return out;
214
134
  }
215
135
 
216
- /** Lane wiring: [] after one `git diff` when the diff touches no workflow file; else the gate over merge-base vs HEAD. */
217
- export async function ciBudgetFailures({ cfg = null, base, git }) {
218
- const changed = String(await git(["diff", "--name-only", `${base}...HEAD`, "--", ".github/workflows"])).split("\n").map((x) => x.trim()).filter((p) => WORKFLOW_RE.test(p));
219
- if (!changed.length) return [];
220
- const mb = String(await git(["merge-base", base, "HEAD"])).trim() || base;
221
- return ciGateFindings({ cfg: cfg ?? parseCiBudget(null), base: await workflowsAt(git, mb), head: await workflowsAt(git, "HEAD") });
222
- }
223
-
224
136
  /** `node bin/lean/ci-gate.mjs net --base REF --head REF [--cwd DIR]`: prints the CI_NET line; exit 0, `CI_NET: unknown (<why>)` on failure. */
225
137
  export async function ciGateCli(argv, { print = (s) => process.stdout.write(s + "\n"), cwd: cwdIn = process.cwd() } = {}) {
226
138
  const arg = (k) => { const i = argv.indexOf(k); return i >= 0 ? argv[i + 1] : null; };
@@ -4,7 +4,7 @@
4
4
  import { describe, it } from "node:test";
5
5
  import assert from "node:assert/strict";
6
6
  import { tmpDir } from "../tests/_tmp.mjs";
7
- import { parseCiBudget, parseAnnotation, scanWorkflow, singleTestFile, singleTestFileSteps, ciGateFindings, netCiChange, ciBudgetFailures, ciGateCli } from "./ci-gate.mjs";
7
+ import { parseCiBudget, parseAnnotation, scanWorkflow, singleTestFile, singleTestFileSteps, netCiChange, ciGateCli } from "./ci-gate.mjs";
8
8
  import { parseForgeYaml } from "../forge-utils.mjs";
9
9
 
10
10
  const kinds = (f) => f.map((x) => x.kind).sort();
@@ -50,44 +50,12 @@ const GOOD = [
50
50
  "",
51
51
  ].join("\n");
52
52
 
53
- describe("lane check (#5760 R10)", () => {
54
- it("a lane adding a bare workflow fails (unannotated + hygiene)", () => {
55
- const f = ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: BASE_CI, ".github/workflows/one.yml": BARE } });
56
- assert.deepEqual(kinds(f), ["ci_budget_unannotated", "ci_hygiene"]);
57
- assert.match(f.find((x) => x.kind === "ci_hygiene").detail, /concurrency.*timeout-minutes.*path scoping/);
58
- assert.equal(f[0].code, "conformance.unimplemented");
59
- assert.match(f.find((x) => x.kind === "ci_budget_unannotated").detail, /shared job `regression`/);
60
- });
61
- it("a lane folding a one-file check into the shared job passes", () => {
62
- const head = BASE_CI.replace(" - run: node --test tests/a.test.mjs tests/b.test.mjs", " - run: node --test tests/a.test.mjs tests/b.test.mjs\n - run: node --test tests/new.test.mjs");
63
- assert.deepEqual(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: head } }), []);
64
- });
65
- it("an annotated, scoped workflow passes", () => {
66
- assert.deepEqual(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: BASE_CI, ".github/workflows/gpu.yaml": GOOD } }), []);
67
- });
68
- });
69
-
70
53
  describe("annotation and single-file steps", () => {
71
- it("an annotation missing minutes is invalid", () => {
72
- const f = ciGateFindings({ cfg, base: {}, head: { ".github/workflows/gpu.yml": GOOD.replace("minutes=120/month ", "") } });
73
- assert.deepEqual(kinds(f), ["ci_budget_annotation_invalid"]);
74
- assert.match(f[0].detail, /missing minutes/);
75
- });
76
54
  it("parseAnnotation reads the three fields", () => {
77
55
  assert.deepEqual(parseAnnotation(" # FORGE:CI_BUDGET trigger=push:main minutes=30 why=deploy smoke, not a test"), { trigger: "push:main", minutes: 30, why: "deploy smoke, not a test", missing: [] });
78
56
  assert.deepEqual(parseAnnotation("# FORGE:CI_BUDGET why=x").missing, ["trigger", "minutes"]);
79
57
  assert.equal(parseAnnotation("# a comment"), null);
80
58
  });
81
- it("a single-file step added to another job fails unless annotated", () => {
82
- const head = BASE_CI.replace(" - run: npm run lint", " - run: npm run lint\n - run: npx vitest run src/a.spec.ts");
83
- assert.deepEqual(kinds(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: head } })), ["ci_budget_unannotated"]);
84
- const ann = head.replace(" lint:\n", " # FORGE:CI_BUDGET trigger=pull_request minutes=5 why=lint-coupled spec\n lint:\n");
85
- assert.deepEqual(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: ann } }), []);
86
- });
87
- it("a shared dir folds a step whose file lives under it", () => {
88
- const head = BASE_CI.replace(" - run: npm run lint", " - run: npm run lint\n - run: pytest tests/regression/test_x.py");
89
- assert.deepEqual(ciGateFindings({ cfg: parseCiBudget({ shared_regression_job: "tests/regression" }), base: { [CI]: BASE_CI }, head: { [CI]: head } }), []);
90
- });
91
59
  it("singleTestFile needs a runner and exactly one test file", () => {
92
60
  assert.equal(singleTestFile(" - run: node --test bin/x.test.mjs"), "bin/x.test.mjs");
93
61
  assert.equal(singleTestFile("run: bash scripts/foo.test.sh"), "scripts/foo.test.sh");
@@ -101,87 +69,10 @@ describe("annotation and single-file steps", () => {
101
69
  for (const l of [" - run: echo scripts/foo.test.sh", " - name: check scripts/foo.test.sh", " - scripts/foo.test.sh", "run: cat x.test.sh", " - name: Run vitest on a.test.ts", "run: cat lib/bash/x.test.mjs"]) assert.equal(singleTestFile(l), null, l);
102
70
  assert.equal(singleTestFile("run: npm ci && bash scripts/foo.test.sh"), "scripts/foo.test.sh");
103
71
  assert.equal(singleTestFile(" npx vitest run src/a.test.ts"), "src/a.test.ts");
104
- const head = BASE_CI.replace(" - run: npm run lint", " - run: npm run lint\n - name: check scripts/foo.test.sh\n - run: echo scripts/foo.test.sh");
105
- assert.deepEqual(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: head } }), []);
106
72
  });
107
73
  it("singleTestFile still flags real runner steps (#5787 over-narrowing guard)", () => {
108
74
  assert.equal(singleTestFile("run: cd x && pytest tests/test_a.py"), "tests/test_a.py");
109
75
  assert.equal(singleTestFile("run: sh scripts/foo.test.sh"), "scripts/foo.test.sh");
110
- const head = BASE_CI.replace(" - run: npm run lint", " - run: npm run lint\n - run: bash scripts/foo.test.sh");
111
- assert.deepEqual(kinds(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: head } })), ["ci_budget_unannotated"]);
112
- });
113
- });
114
-
115
- describe("push path scoping exemptions (#5792)", () => {
116
- const rel = (on, pre = "") => `${pre}# FORGE:CI_BUDGET trigger=push minutes=5 why=release\nname: rel\non:\n${on}\nconcurrency: rel\njobs:\n rel:\n runs-on: ubuntu-latest\n timeout-minutes: 10\n steps:\n - run: make release\n`;
117
- const run = (text) => ciGateFindings({ cfg, base: {}, head: { ".github/workflows/rel.yml": text } });
118
- it("a tag-only push trigger needs no paths", () => {
119
- assert.deepEqual(run(rel(" push:\n tags: ['v*']")), []);
120
- });
121
- it("a push with branches (or tags and branches) still needs paths", () => {
122
- assert.match(run(rel(" push:\n branches: [main]"))[0].detail, /path scoping/);
123
- assert.match(run(rel(" push:\n tags: ['v*']\n branches: [main]"))[0].detail, /path scoping/);
124
- });
125
- it("a FORGE:CI_PATHS_EXEMPT annotation with why exempts a deploy-on-main push; without why it does not", () => {
126
- const on = " push:\n branches: [main]";
127
- assert.deepEqual(run(rel(on, "# FORGE:CI_PATHS_EXEMPT why=deploys on every merge\n")), []);
128
- assert.match(run(rel(on, "# FORGE:CI_PATHS_EXEMPT\n"))[0].detail, /path scoping/);
129
- });
130
- });
131
-
132
- describe("new jobs and hygiene", () => {
133
- const withJob = (job) => BASE_CI + job;
134
- it("a job added to an existing workflow needs an annotation above or inside it", () => {
135
- const job = " e2e:\n runs-on: ubuntu-latest\n timeout-minutes: 15\n steps:\n - run: npm run e2e\n";
136
- assert.deepEqual(kinds(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: withJob(job) } })), ["ci_budget_unannotated"]);
137
- const ann = " # FORGE:CI_BUDGET trigger=pull_request:src/** minutes=200 why=browser stack\n" + job;
138
- assert.deepEqual(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: withJob(ann) } }), []);
139
- });
140
- it("a new job without timeout-minutes is a hygiene failure", () => {
141
- const job = " # FORGE:CI_BUDGET trigger=pr minutes=5 why=x\n e2e:\n runs-on: ubuntu-latest\n steps:\n - run: npm run e2e\n";
142
- const f = ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: withJob(job) } });
143
- assert.deepEqual(kinds(f), ["ci_hygiene"]);
144
- assert.match(f[0].detail, /`e2e`.*timeout-minutes/);
145
- });
146
- it("an issue_comment job without a job-level if: fails ci_hygiene", () => {
147
- const wf = "# FORGE:CI_BUDGET trigger=issue_comment minutes=10 why=bot command\non:\n issue_comment:\n types: [created]\nconcurrency: bot\njobs:\n bot:\n timeout-minutes: 5\n runs-on: ubuntu-latest\n steps:\n - run: echo hi\n";
148
- const f = ciGateFindings({ cfg, base: {}, head: { ".github/workflows/bot.yml": wf } });
149
- assert.deepEqual(kinds(f), ["ci_hygiene"]);
150
- assert.match(f[0].detail, /job-level if:/);
151
- const ok = wf.replace(" bot:\n", " bot:\n if: startsWith(github.event.comment.body, '/bot')\n");
152
- assert.deepEqual(ciGateFindings({ cfg, base: {}, head: { ".github/workflows/bot.yml": ok } }), []);
153
- });
154
- it("a schedule-only workflow needs no path scoping", () => {
155
- const wf = "# FORGE:CI_BUDGET trigger=nightly minutes=300 why=full suite\non:\n schedule:\n - cron: '0 3 * * *'\n workflow_dispatch:\nconcurrency: nightly\njobs:\n full:\n timeout-minutes: 60\n runs-on: ubuntu-latest\n steps:\n - run: npm test\n";
156
- assert.deepEqual(ciGateFindings({ cfg, base: {}, head: { ".github/workflows/nightly.yml": wf } }), []);
157
- });
158
- it("scanWorkflow reads triggers, concurrency and job children", () => {
159
- const s = scanWorkflow(BASE_CI);
160
- assert.deepEqual(s.triggers, { pull_request: { paths: true, tagOnly: false } });
161
- assert.equal(s.concurrency, true);
162
- assert.deepEqual(s.jobs.map((j) => [j.id, j.timeout, j.if]), [["lint", true, false], ["regression", true, false]]);
163
- assert.deepEqual(Object.keys(scanWorkflow("on: [push, pull_request]\njobs: {}\n").triggers), ["push", "pull_request"]);
164
- });
165
- });
166
-
167
- describe("max_workflows / max_ci_jobs (#5760 R8)", () => {
168
- const two = { [CI]: BASE_CI, ".github/workflows/old.yml": GOOD };
169
- it("exceeding max_workflows fails, and passes when the same diff removes one", () => {
170
- const c = parseCiBudget({ max_workflows: "2" });
171
- const head = { ...two, ".github/workflows/gpu.yml": GOOD };
172
- assert.deepEqual(kinds(ciGateFindings({ cfg: c, base: two, head })), ["ci_budget_exceeded"]);
173
- const swapped = { [CI]: BASE_CI, ".github/workflows/gpu.yml": GOOD };
174
- assert.deepEqual(ciGateFindings({ cfg: c, base: two, head: swapped }), []);
175
- });
176
- it("exceeding max_ci_jobs fails unless a job is folded away", () => {
177
- const c = parseCiBudget({ max_ci_jobs: "2" });
178
- const job = " # FORGE:CI_BUDGET trigger=pr minutes=5 why=x\n e2e:\n runs-on: ubuntu-latest\n timeout-minutes: 5\n steps:\n - run: npm run e2e\n";
179
- assert.deepEqual(kinds(ciGateFindings({ cfg: c, base: { [CI]: BASE_CI }, head: { [CI]: BASE_CI + job } })), ["ci_budget_exceeded"]);
180
- const folded = BASE_CI.replace(/ lint:\n(?: .*\n)*?(?= regression:)/, "") + job;
181
- // the fold removes exactly the lint job (regression guard for the unambiguous, non-backtracking pattern)
182
- assert.ok(!folded.includes("lint:") && !folded.includes("npm run lint"));
183
- assert.ok(folded.includes(" regression:\n") && folded.endsWith(job));
184
- assert.deepEqual(ciGateFindings({ cfg: c, base: { [CI]: BASE_CI }, head: { [CI]: folded } }), []);
185
76
  });
186
77
  });
187
78
 
@@ -200,23 +91,6 @@ describe("config, net change and wiring", () => {
200
91
  assert.equal(r.line, "CI_NET: workflows +2, jobs +2, est. minutes/month +120 of 3000 budget");
201
92
  assert.match(netCiChange({ base: head, head: { [CI]: BASE_CI } }).line, /workflows -2, jobs -2, est\. minutes\/month -120$/);
202
93
  });
203
- it("ciBudgetFailures makes one git call when no workflow changed", async () => {
204
- const calls = [];
205
- const git = async (a) => { calls.push(a); return "src/a.js\n"; };
206
- assert.deepEqual(await ciBudgetFailures({ cfg, base: "origin/staging", git }), []);
207
- assert.equal(calls.length, 1);
208
- });
209
- it("ciBudgetFailures reads merge-base and HEAD workflows when a workflow changed", async () => {
210
- const files = { mb: { [CI]: BASE_CI }, HEAD: { [CI]: BASE_CI, ".github/workflows/one.yml": BARE } };
211
- const git = async (a) => {
212
- if (a[0] === "diff") return ".github/workflows/one.yml\n";
213
- if (a[0] === "merge-base") return "mb\n";
214
- if (a[0] === "ls-tree") return Object.keys(files[a[3]]).join("\n");
215
- const [ref, p] = a[1].split(/:(.*)/s);
216
- return files[ref][p];
217
- };
218
- assert.deepEqual(kinds(await ciBudgetFailures({ cfg, base: "origin/staging", git })), ["ci_budget_unannotated", "ci_hygiene"]);
219
- });
220
94
  it("the CLI prints CI_NET unknown on a bad ref and usage on bad args", async () => {
221
95
  const out = [];
222
96
  const cwd = tmpDir("ci-gate-");
@@ -34,7 +34,8 @@ const HEAVY = [
34
34
  ];
35
35
  const CHEAP = [
36
36
  ["typecheck", /type-?check|\btsc\b|\bmypy\b|pyright|\btypes\b/i],
37
- ["lint", /lint|eslint|ruff|prettier|\bformat|clippy|shellcheck|golangci|\bvet\b|stylelint|biome/i],
37
+ ["lint", /lint|eslint|ruff|prettier|\bformat|\bfmt\b|\bblack\b|gofmt|rustfmt|clippy|shellcheck|golangci|\bvet\b|stylelint|biome/i],
38
+ ["wiring", /wiring|registered|\bmanifest\b|\bcoverage[-_ ]map\b/i],
38
39
  ["test", /test|vitest|jest|pytest|\bspec\b|mocha|\bbats\b/i],
39
40
  ];
40
41
  export const HEAVY_KINDS = HEAVY.map(([k]) => k);
@@ -93,13 +94,21 @@ export function requiredFor(job, required) {
93
94
  * @returns {{source:"required"|"fallback", run:object[], skipped:{job,name,reason}[], unrunnable:{job,name,reason}[], note:string}}
94
95
  * run: [{job, name, workflow, kind, why, steps: string[], plan: object}] (plan: a one-job ci-local plan)
95
96
  */
96
- export function selectCiPrecheck({ plan, required = null, cfg = parseCiPrecheckConfig(null) }) {
97
+ export function selectCiPrecheck({ plan, required = null, releaseRequired = null, cfg = parseCiPrecheckConfig(null) }) {
97
98
  const jobs = (Array.isArray(plan?.jobs) ? plan.jobs : []).filter((j) => j && CI_SOURCES.has(j.source) && !/:variants$/.test(str(j.id)));
98
99
  const byId = new Map(jobs.map((j) => [j.id, j]));
99
100
  const req = (Array.isArray(required) ? required : []).map(str).filter(Boolean);
100
101
  // required jobs, then (transitively) the jobs an aggregator required job needs
101
102
  const why = new Map();
102
103
  for (const j of jobs) { const hit = requiredFor(j, req); if (hit.length) why.set(j.id, `required check ${hit.map((h) => `"${h}"`).join(", ")}`); }
104
+ // #6049: required checks of the release branch, run in the lane too (a release-only formatter or wiring job)
105
+ const relReq = (Array.isArray(releaseRequired) ? releaseRequired : []).map(str).filter(Boolean);
106
+ const relHit = new Set();
107
+ for (const j of jobs) {
108
+ const hit = requiredFor(j, relReq);
109
+ for (const h of hit) relHit.add(h);
110
+ if (hit.length && !why.has(j.id)) why.set(j.id, `required check ${hit.map((h) => `"${h}"`).join(", ")} on release branch`);
111
+ }
103
112
  const queue = [...why.keys()];
104
113
  while (queue.length) {
105
114
  const id = queue.shift();
@@ -126,7 +135,15 @@ export function selectCiPrecheck({ plan, required = null, cfg = parseCiPrecheckC
126
135
  }
127
136
  const cap = Number.isInteger(cfg.maxJobs) ? cfg.maxJobs : DEFAULT_MAX_JOBS;
128
137
  for (const r of run.splice(cap)) skipped.push({ job: r.job, name: r.name, reason: `over lean.ci_precheck_max_jobs (${cap}): left to CI` });
129
- return { source, run, skipped, unrunnable, note };
138
+ // #6049: release-required contexts with no job the lane runs (no job maps, or the job is skipped / unrunnable here)
139
+ const covered = new Set(run.flatMap((r) => requiredFor(jobs.find((j) => j.id === r.job), relReq)));
140
+ const parity = relReq.filter((c) => !covered.has(c)).map((context) => {
141
+ const j = jobs.find((x) => requiredFor(x, [context]).length);
142
+ if (!j) return { context, reason: "no CI job maps to this required release check" };
143
+ const s = [...skipped, ...unrunnable].find((x) => x.job === j.id);
144
+ return { context, job: j.id, reason: s?.reason ?? "job not run in the lane" };
145
+ });
146
+ return { source, run, skipped, unrunnable, note, parity };
130
147
  }
131
148
 
132
149
  const slug = (id) => str(id).replace(/[^A-Za-z0-9_.-]+/g, "_").slice(0, 120) || "job";
@@ -144,19 +161,19 @@ export function ciPrecheckCommand(sel, { perCommandMs = 300000, script = CI_LOCA
144
161
  * skipJobs: job ids an earlier round found unrunnable (not rerun)
145
162
  * @returns {Promise<{source, note, commands:{job,name,workflow,kind,why,steps,command}[], skipped, unrunnable}>}
146
163
  */
147
- export async function deriveCiPrecheck({ buildPlan, required = null, cfg, wt, base, lane, files = [], perCommandMs, writeFile, skipJobs = new Set() }) {
164
+ export async function deriveCiPrecheck({ buildPlan, required = null, releaseRequired = null, releaseBranch = "", cfg, wt, base, lane, files = [], perCommandMs, writeFile, skipJobs = new Set() }) {
148
165
  let plan;
149
- try { plan = await buildPlan({ repo: wt, base, baseBranch: lane, files }); } catch (e) {
150
- return { source: "none", note: "", commands: [], skipped: [], unrunnable: [{ job: "*", name: "ci-local plan", reason: `CI check plan unavailable: ${str(e?.message ?? e).split("\n")[0].slice(0, 200)}` }] };
166
+ try { plan = await buildPlan({ repo: wt, base, baseBranch: lane, ...(releaseBranch ? { releaseBranch } : {}), files }); } catch (e) {
167
+ return { source: "none", note: "", commands: [], skipped: [], unrunnable: [{ job: "*", name: "ci-local plan", reason: `CI check plan unavailable: ${str(e?.message ?? e).split("\n")[0].slice(0, 200)}` }], parity: [] };
151
168
  }
152
- const sel = selectCiPrecheck({ plan, required, cfg });
169
+ const sel = selectCiPrecheck({ plan, required, releaseRequired, cfg });
153
170
  const commands = [], unrunnable = [...sel.unrunnable], skipped = [...sel.skipped];
154
171
  for (const r of sel.run) {
155
172
  if (skipJobs.has(r.job)) { skipped.push({ job: r.job, name: r.name, reason: "unrunnable in an earlier round: left to CI" }); continue; }
156
173
  try { await writeFile(`${CI_PRECHECK_DIR}/${slug(r.job)}.json`, `${JSON.stringify(r.plan)}\n`); } catch (e) { unrunnable.push({ job: r.job, name: r.name, reason: `plan file not written: ${str(e?.message ?? e).slice(0, 120)}` }); continue; }
157
174
  commands.push({ job: r.job, name: r.name, workflow: r.workflow, kind: r.kind, why: r.why, steps: r.steps, command: ciPrecheckCommand(r, { perCommandMs }) });
158
175
  }
159
- return { source: sel.source, note: sel.note, commands, skipped, unrunnable };
176
+ return { source: sel.source, note: sel.note, commands, skipped, unrunnable, parity: sel.parity };
160
177
  }
161
178
 
162
179
  /** The first line of `output` starting with `prefix`, without it; "" when none. */
@@ -94,6 +94,30 @@ describe("#5820 selection", () => {
94
94
  });
95
95
  });
96
96
 
97
+ describe("#6049 release-branch required checks", () => {
98
+ const plan = { ...PLAN, jobs: [...PLAN.jobs, job("fmt", "Format check", ["black --check ."]), job("wiring", "Suite wiring", ["bash scripts/check-test-wiring.sh"])] };
99
+ it("a release-only required formatter and a wiring job are selected with a release-branch why", () => {
100
+ const s = selectCiPrecheck({ plan, required: ["Lint"], releaseRequired: ["Format check", "Suite wiring"] });
101
+ assert.deepEqual(s.run.map((r) => [r.job, r.why]), [["gha:ci:lint", 'required check "Lint"'], ["gha:ci:fmt", 'required check "Format check" on release branch'], ["gha:ci:wiring", 'required check "Suite wiring" on release branch']]);
102
+ assert.deepEqual(s.parity, []);
103
+ });
104
+ it("a required release context with no job (or a heavy one) is a parity gap", () => {
105
+ const s = selectCiPrecheck({ plan, required: ["Lint"], releaseRequired: ["Format check", "Release signing", "E2E"] });
106
+ assert.deepEqual(s.parity.map((g) => g.context), ["Release signing", "E2E"]);
107
+ assert.match(s.parity[0].reason, /no CI job/);
108
+ assert.match(s.parity[1].reason, /heavy \(e2e\)/);
109
+ });
110
+ it("no gaps and an unchanged selection when releaseRequired is empty; ci_precheck exclude still applies", () => {
111
+ const a = selectCiPrecheck({ plan, required: ["Lint"] }), b = selectCiPrecheck({ plan, required: ["Lint"], releaseRequired: [] });
112
+ assert.deepEqual(b.run.map((r) => r.job), a.run.map((r) => r.job)); assert.deepEqual(b.parity, []);
113
+ const x = selectCiPrecheck({ plan, required: ["Lint"], releaseRequired: ["Format check"], cfg: parseCiPrecheckConfig({ ci_precheck_exclude: "gha:ci:fmt" }) });
114
+ assert.deepEqual(x.parity.map((g) => g.context), ["Format check"]);
115
+ });
116
+ it("classifier negatives: a deploy or docs job is not treated as wiring or formatting", () => {
117
+ assert.equal(classifyJob(job("deploy", "Deploy docs", ["bash deploy.sh"])).kind, "other");
118
+ });
119
+ });
120
+
97
121
  describe("#5820 derive + outcome", () => {
98
122
  it("writes one plan file per job and returns bounded ci-local commands", async () => {
99
123
  const written = new Map();
@@ -17,13 +17,14 @@ const MERGED = { terminalReason: "merged", pr: 9 };
17
17
 
18
18
  /** A runner whose every pass costs 12 s of injected time; `req` is the pending request `at` (or null), made `reqAfterMs` after the trip. */
19
19
  const slowRun = async ({ reqAfterMs }) => {
20
- let t = 1_000_000, tripAt = null, req = null, consumed = 0; const acks = [], calls = [];
20
+ let t = 1_000_000, tripAt = null, req = null, consumed = 0; const acks = [], calls = [], ac = new AbortController();
21
21
  const script = { 1: [EE("boom A")], 2: [EE("boom B")], 3: [MERGED] };
22
- const rows = await orchestrate({ issues: [1, 2, 3], parallel: 1, readBody: async () => "", now: () => t, store: memStore(), pollMs: 12000, breaker: { errors: 2, window_min: 10 },
22
+ const rows = await orchestrate({ issues: [1, 2, 3], parallel: 1, readBody: async () => "", now: () => t, store: memStore(), pollMs: 12000, breaker: { errors: 2, window_min: 10 }, signal: ac.signal,
23
23
  sleep: async (ms) => { t += Math.max(12000, Number(ms) || 0); },
24
24
  runOne: async (n) => { calls.push(n); t += 12000; return script[n][0]; },
25
25
  onUpdate: (u) => { if (u.outcome === "breaker" && tripAt === null) { tripAt = t; req = tripAt + reqAfterMs; } },
26
- getClearBreaker: () => req, consumeClearBreaker: () => { req = null; consumed++; }, ackClearBreaker: (i) => acks.push(i) });
26
+ getClearBreaker: () => req, consumeClearBreaker: () => { req = null; consumed++; if (reqAfterMs < 0) ac.abort(); }, // #6042: a trip kept closed by a stale request waits for an operator; the test ends it
27
+ ackClearBreaker: (i) => acks.push(i) });
27
28
  return { rows, acks, calls, consumed };
28
29
  };
29
30
 
@@ -5,7 +5,7 @@
5
5
  * NEEDS_HUMAN text posts nothing; a changed FACTS or DEPENDENCY is edited in place; a changed NEEDS_HUMAN is a new comment
6
6
  * (statuscomment.mjs header: a new comment notifies a person, an edit does not, and issuewatch keys on the newest one). Pure.
7
7
  */
8
- import { IN_PLACE_MARKERS } from "./statuscomment.mjs";
8
+ import { IN_PLACE_MARKERS, contractKeyOf } from "./statuscomment.mjs";
9
9
 
10
10
  /** Markers whose changed state is PATCHed rather than posted again. */
11
11
  export const PATCH_MARKERS = Object.freeze(IN_PLACE_MARKERS.filter((m) => m !== "FORGE:NEEDS_HUMAN"));
@@ -32,10 +32,15 @@ export function findLast(comments, marker, trusted = () => true) {
32
32
  return null;
33
33
  }
34
34
 
35
- /** `{action: "skip"|"patch"|"create", prior}` for posting `body` under `marker` given the issue's comments. */
36
- export function decidePost({ marker, body, comments, trusted }) {
37
- const prior = findLast(comments, marker, trusted);
35
+ /**
36
+ * `{action: "skip"|"patch"|"create", prior}` for posting `body` under `marker` given the issue's comments. #5931: with a `contractHash`
37
+ * the prior is the newest comment keyed to that hash and every in-place marker (NEEDS_HUMAN too) is edited in place; a changed hash is a new comment.
38
+ */
39
+ export function decidePost({ marker, body, comments, trusted, contractHash = null }) {
40
+ const keyed = !!contractHash && IN_PLACE_MARKERS.includes(marker);
41
+ const list = Array.isArray(comments) ? comments : [];
42
+ const prior = keyed ? findLast(list.filter((c) => contractKeyOf(c?.body) === String(contractHash).replace(/[^\w]/g, "")), marker, trusted) : findLast(comments, marker, trusted);
38
43
  if (!prior) return { action: "create", prior: null };
39
44
  if (normalizeState(prior.body) === normalizeState(body)) return { action: "skip", prior };
40
- return { action: PATCH_MARKERS.includes(marker) ? "patch" : "create", prior };
45
+ return { action: keyed || PATCH_MARKERS.includes(marker) ? "patch" : "create", prior };
41
46
  }
@@ -3,7 +3,7 @@
3
3
  import { describe, it } from "node:test";
4
4
  import assert from "node:assert/strict";
5
5
  import { normalizeState, findLast, decidePost } from "./commentstate.mjs";
6
- import { IN_PLACE_MARKERS } from "./statuscomment.mjs";
6
+ import { IN_PLACE_MARKERS, contractKey } from "./statuscomment.mjs";
7
7
 
8
8
  const body = (m, text, cost = "0.10") => `<!-- ${m} -->\n${text}\n\n_cost $${cost}, tokens 1 in / 2 out_`;
9
9
  const url = "https://github.com/o/r/issues/1#issuecomment-5";
@@ -30,3 +30,14 @@ describe("post only on a state change (#5979)", () => {
30
30
  assert.equal(normalizeState(body("M", "a b 1e0c3e45")), normalizeState(body("M", "a b", "5")));
31
31
  });
32
32
  });
33
+
34
+ describe("#5931 in-place per contract hash", () => {
35
+ for (const m of ["FORGE:NEEDS_HUMAN", "FORGE:FACTS", "FORGE:AMENDMENT-STATE"]) {
36
+ it(`${m}: edited in place at the same contract hash, a new comment when the hash changes`, () => {
37
+ assert.ok(IN_PLACE_MARKERS.includes(m));
38
+ const comments = [{ body: `${body(m, "old")}\n${contractKey("c1")}`, url }];
39
+ assert.equal(decidePost({ marker: m, body: body(m, "new"), comments, contractHash: "c1" }).action, "patch");
40
+ assert.equal(decidePost({ marker: m, body: body(m, "new"), comments, contractHash: "c2" }).action, "create");
41
+ });
42
+ }
43
+ });
@@ -166,6 +166,9 @@ function oracle(c, quotes = Q) {
166
166
  const bad = rv.issue_coverage.some((x) => x.status !== "covered") || rows.some((r) => ["missing", "partial"].includes(r.status)) || rv.scope.some((s) => s.authorized_by === "none") || billing;
167
167
  return "```json\n" + JSON.stringify({ ...rv, verdict: bad ? "NONCONFORMING" : "CONFORMS", summary: "oracle" }) + "\n```";
168
168
  }
169
+ // #6083: these gates are advisory by default; the tests of their blocking path re-promote them with engine.conformance_kinds enforce
170
+ const ENFORCED = Object.fromEntries(["conformance.unimplemented", "conformance.untracked_deferral", "conformance.preserve_violated"].map((c) => [c, "enforce"]));
171
+ const runCaseEnf = (cs, conformance = "enforce", extra = {}) => runCase(cs, conformance, { ...extra, opts: { ...(extra.opts ?? {}), conformanceKinds: ENFORCED } });
169
172
  const generic = () => "```json\n" + JSON.stringify({ verdict: "PASS", fixes_issue: true, regression: false, reason: "looks good" }) + "\n```";
170
173
 
171
174
  async function runCase(cs, conformance = "enforce", extra = {}) {
@@ -205,18 +208,18 @@ describe("conformance gate end-to-end (real git, disposable repo)", { skip: !HAV
205
208
  merged(o); assert.ok(o.staging.export); assert.ok(o.markers.includes("FORGE:AMENDMENT"));
206
209
  });
207
210
  it("3 scope creep: an unauthorized billing change is caught by the review's preserve check and reverted before it can reach staging", async () => {
208
- const o = await runCase({ contract: FULL, impl: (t) => { fix(t, ["scrape", "search", "export"]); t.write({ "src/billing.js": "export function price(units) { return Math.round(units) * 0.01; }\n" }); },
211
+ const o = await runCaseEnf({ contract: FULL, impl: (t) => { fix(t, ["scrape", "search", "export"]); t.write({ "src/billing.js": "export function price(units) { return Math.round(units) * 0.01; }\n" }); },
209
212
  resume: (t) => t.restore("src/billing.js") });
210
213
  // unclog: file scope alone is advisory (no precheck stop); the violated preserve row (P1) blocks and the resume reverts it
211
214
  merged(o); assert.equal(o.staging.billingChanged, false); assert.deepEqual([o.counts.builder, o.counts.reviewer], [3, 2]);
212
215
  assert.ok(o.log.some((e) => e.event === "ADVISORY" && e.rows.includes("scope_creep")), "scope creep is recorded as advisory");
213
216
  });
214
217
  it("4 a claimed follow-up without a tracking issue blocks merge before any review", async () => {
215
- const o = await runCase({ contract: FULL, impl: (t) => fix(t, ["scrape", "search"]), claims: (k) => claimAll(k).map((r) => (r.id === "R3" ? { id: "R3", status: "deferred", note: "follow-up" } : r)) });
218
+ const o = await runCaseEnf({ contract: FULL, impl: (t) => fix(t, ["scrape", "search"]), claims: (k) => claimAll(k).map((r) => (r.id === "R3" ? { id: "R3", status: "deferred", note: "follow-up" } : r)) });
216
219
  blocked(o, "conformance.untracked_deferral"); assert.equal(o.counts.reviewer, 0); assert.equal(o.followups.length, 0);
217
220
  });
218
221
  it("4b the deferral made typed on the resume is tracked, linked, and the issue closes", async () => {
219
- const o = await runCase({ contract: FULL, impl: (t) => fix(t, ["scrape", "search"]), claims: (k) => claimAll(k).map((r) => (r.id === "R3" ? { id: "R3", status: "deferred" } : r)),
222
+ const o = await runCaseEnf({ contract: FULL, impl: (t) => fix(t, ["scrape", "search"]), claims: (k) => claimAll(k).map((r) => (r.id === "R3" ? { id: "R3", status: "deferred" } : r)),
220
223
  resume: (t, res) => { res.amendments = [{ kind: "defer", requirement: "R3", why: "export ships on its own release train" }]; } });
221
224
  merged(o); assert.equal(o.followups.length, 1); assert.equal(o.followups[0].state, "OPEN");
222
225
  assert.match(o.pr.body, new RegExp(`Remaining work tracked\\n- #${o.followups[0].number}`)); assert.ok(o.markers.includes("FORGE:TRACKED"));
@@ -266,14 +269,14 @@ describe("conformance gate end-to-end (real git, disposable repo)", { skip: !HAV
266
269
  it("#5087 a declared topology.route_reachability that rejects the new route blocks before merge (#38241 fixture)", async () => {
267
270
  const ingress = path.join(tmpDir("ingress-"), "check-ingress.sh");
268
271
  fs.writeFileSync(ingress, "for p in \"$@\"; do case \"$p\" in /api/v1/batch*) ;; /api/v1/*) echo \"unreachable: $p -> api\" >&2; exit 1 ;; esac; done\n");
269
- const o = await runCase({ contract: ROUTED, impl: addRoute }, "enforce", { runCommand: runCheckCommand, opts: { routeReachability: `bash ${ingress.replace(/\\/g, "/")}`, verify: { maxRounds: 0 } } });
272
+ const o = await runCaseEnf({ contract: ROUTED, impl: addRoute }, "enforce", { runCommand: runCheckCommand, opts: { routeReachability: `bash ${ingress.replace(/\\/g, "/")}`, verify: { maxRounds: 0 } } });
270
273
  assert.equal(o.staging.search, false, "staging untouched");
271
274
  assert.equal(o.ret.terminalReason, "needs-human"); assert.equal(o.pr, undefined, "no PR");
272
275
  assert.ok(o.log.some((e) => e.event === "PRECHECK" && e.failures.includes("conformance.unimplemented")));
273
276
  assert.match(o.ret.detail, /topology\.route_reachability[\s\S]*\/api\/v1\/agent\/signup\/pending[\s\S]*unreachable: \/api\/v1\/agent\/signup\/pending -> api/);
274
277
  });
275
278
  it("#5284 a declared topology.prod_parity surface touched without a check result or justification blocks before merge", async () => {
276
- const o = await runCase({ contract: ROUTED, impl: addRoute }, "enforce", { runCommand: runCheckCommand, opts: { prodParity: { "web/src/app/**": "note: exercise the page under the production runtime" }, verify: { maxRounds: 0 } } });
279
+ const o = await runCaseEnf({ contract: ROUTED, impl: addRoute }, "enforce", { runCommand: runCheckCommand, opts: { prodParity: { "web/src/app/**": "note: exercise the page under the production runtime" }, verify: { maxRounds: 0 } } });
277
280
  assert.equal(o.staging.search, false, "staging untouched");
278
281
  assert.equal(o.ret.terminalReason, "needs-human"); assert.equal(o.pr, undefined, "no PR");
279
282
  assert.ok(o.log.some((e) => e.event === "PRECHECK" && e.failures.includes("conformance.unimplemented")));
@@ -299,7 +302,7 @@ describe("conformance gate end-to-end (real git, disposable repo)", { skip: !HAV
299
302
  assert.ok(review.includes("**Issue coverage:** 2/2 "), "the guidance row is not counted as an issue requirement");
300
303
  });
301
304
  it("#5750 a lane following the prescription but missing the outcome fails", async () => {
302
- const o = await runCase({ issue: GISSUE, quotes: GQ, contract: GUIDED, impl: (t) => t.write({ "src/routes/scrape.js": prescribed, "test/leak.test.js": leakTest([]) }) });
305
+ const o = await runCaseEnf({ issue: GISSUE, quotes: GQ, contract: GUIDED, impl: (t) => t.write({ "src/routes/scrape.js": prescribed, "test/leak.test.js": leakTest([]) }) });
303
306
  assert.equal(o.ret.terminalReason, "needs-human"); assert.equal(o.pr, undefined, "no PR"); assert.equal(o.issue.state, "OPEN");
304
307
  assert.equal(o.ret.code, "conformance.unimplemented");
305
308
  });