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
@@ -94,7 +94,7 @@ describe("post-deploy named checks (#4626)", () => {
94
94
  assert.equal(r.state, "recorded-fail"); assert.deepEqual(w.spawned, []);
95
95
  });
96
96
 
97
- it("contract: post-deploy needs a check id; amendment too; precheck rejects an unknown id; followup item names it", () => {
97
+ it("contract: post-deploy needs a check id; amendment too; followup item names it", () => {
98
98
  const Q = "The deploy-time health row must exist after promotion.";
99
99
  const c = { requirements: [{ id: "R1", quote: Q, disposition: "post-deploy", why: "w" }], deliverables: [], preserve: [], validate: [{ id: "V1", command: "true" }] };
100
100
  assert.ok(validateContract(c, Q).problems.some((p) => /needs a check id/.test(p)));
@@ -105,8 +105,6 @@ describe("post-deploy named checks (#4626)", () => {
105
105
  assert.equal(deferred.contract.requirements[0].disposition, "defer");
106
106
  const ok = applyAmendments(frozen, [{ kind: "post-deploy", requirement: "R1", why: "w", check: "smoke" }], Q);
107
107
  assert.equal(ok.contract.requirements[0].check, "smoke");
108
- const pc = precheck({ contract: { ...c, requirements: [{ ...c.requirements[0], check: "ghost" }] }, result: { requirements: [] }, changedFiles: [], checkIds: new Set(["smoke"]) });
109
- assert.ok(pc.failures.some((f) => f.kind === "check_unknown"));
110
108
  assert.match(followupItems([{ ...c.requirements[0], check: "smoke" }])[0].why, /^post-deploy: \[check:smoke\] w/);
111
109
  });
112
110
  });
@@ -234,6 +234,26 @@ export function quietFailure(output, { lines = QUIET_TAIL_LINES, maxChars = Infi
234
234
  return out.join("\n");
235
235
  }
236
236
 
237
+ /** #6107: masks credential-looking text before a check's output reaches a needs-human comment or the run log. Generic patterns only. */
238
+ export function redactSecrets(text) {
239
+ return String(text ?? "")
240
+ .replace(/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g, "[redacted private key]")
241
+ .replace(/\b(?:sk|pk|rk)-[A-Za-z0-9_-]{8,}/g, "[redacted]")
242
+ .replace(/\b(?:ghp|gho|ghu|ghs|ghr|github_pat|glpat|xox[abprs]|npm|AKIA|ASIA)[_-]?[A-Za-z0-9_-]{12,}/g, "[redacted]")
243
+ .replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._~+\/=-]{8,}/gi, "$1 [redacted]")
244
+ .replace(/\b([A-Za-z0-9_.-]*(?:token|secret|password|passwd|api[_-]?key|private[_-]?key|credential|authorization)[A-Za-z0-9_.-]*)(["']?\s*[:=]\s*["']?)[^\s"',}]{4,}/gi, "$1$2[redacted]")
245
+ .replace(/\b([a-z][a-z0-9+.-]*:\/\/[^\s:@\/]+:)[^\s@\/]+@/gi, "$1[redacted]@");
246
+ }
247
+
248
+ /**
249
+ * #6107: one failed check as park/run-log text: its name (a CI job name, else the command) and the last `lines` lines of
250
+ * its output, secrets redacted, within `maxChars`.
251
+ */
252
+ export function checkFailureTail(f, { name = null, lines = QUIET_TAIL_LINES, maxChars = 4000 } = {}) {
253
+ const label = name ? `${name} (\`${f.command}\`)` : `\`${f.command}\``;
254
+ return `\n\nFailing check ${label}, exit ${f.rc}, last ${lines} lines of its output:\n${redactSecrets(quietFailure(f.output, { lines, maxChars }))}`;
255
+ }
256
+
237
257
  /** #4364: the compact pass/fail table `forgedock check` prints; #4390: each failure quiet (`quietFailure`), within `cap` chars. */
238
258
  export function formatCheckTable(r, cap = LOG_CAP) {
239
259
  const word = (x) => (x.status === "ci" ? "CI" : x.status ? "DEFERRED" : x.rc === 0 ? "PASS" : `FAIL exit ${x.rc}`);
@@ -11,8 +11,9 @@
11
11
  */
12
12
  import { builtinModules } from "node:module";
13
13
  import { existsSync } from "node:fs";
14
- import { join, dirname, delimiter, relative } from "node:path";
14
+ import { join, dirname, delimiter, posix } from "node:path";
15
15
  import { missingTool } from "./conformance.mjs";
16
+ import { hostPoetryConfigProblem } from "./hostconfig.mjs";
16
17
 
17
18
  export const PREFLIGHT_CAP = 20;
18
19
  const KIND_NAME = { command: "command", "python-module": "Python module", "node-module": "Node package", path: "path", "env-var": "env var" };
@@ -101,7 +102,7 @@ function moduleNeeds(exe, args) {
101
102
  /**
102
103
  * The probes for `contract.validate[]`: {probes: [{ids, tool, kind, interp, needs, probe}], dropped}. `needs` is the command
103
104
  * probe (tool) a module probe depends on: skip the module probe when its interpreter is missing. A name `repoHas(name)` holds
104
- * or a deliverable's change text names (the change adds it) is not probed; paths and `$...` words are never probed.
105
+ * or a deliverable's change text names (the change adds it) is not probed; nor is a tool `provided(name)` (the image manifest, #6037); paths and `$...` words are never probed.
105
106
  */
106
107
  /** #5020: the contract's runnable commands: each validate entry plus the repro_test, which fails the same ways. */
107
108
  export function contractCommands(contract) {
@@ -109,10 +110,10 @@ export function contractCommands(contract) {
109
110
  const t = contract?.repro_test;
110
111
  return t && typeof t === "object" && typeof t.command === "string" && t.command.trim() ? [...out, { id: "repro_test", command: t.command }] : out;
111
112
  }
112
- export function preflightProbes(contract, { repoHas = () => false, cap = PREFLIGHT_CAP } = {}) {
113
+ export function preflightProbes(contract, { repoHas = () => false, provided = () => false, cap = PREFLIGHT_CAP } = {}) {
113
114
  const changes = (Array.isArray(contract?.deliverables) ? contract.deliverables : []).map((d) => String(d?.change ?? "")).join("\n");
114
115
  const named = (name) => new RegExp(`(^|[^\\w@/.-])${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![\\w/-])`).test(changes);
115
- const skip = (name) => !name || name.includes("/") && !name.startsWith("@") || name.startsWith("$") || repoHas(name) || named(name);
116
+ const skip = (name) => !name || provided(name) || name.includes("/") && !name.startsWith("@") || name.startsWith("$") || repoHas(name) || named(name);
116
117
  const byKey = new Map();
117
118
  const add = (id, kind, tool, interp = null) => {
118
119
  const key = `${kind}|${tool}|${interp ?? ""}`;
@@ -159,12 +160,32 @@ export function testRunnerProblems(contract, runners) {
159
160
  return out;
160
161
  }
161
162
 
163
+ /**
164
+ * #5749: validate/repro commands that cannot run in a lane sandbox whatever is installed: a host-only wrapper or path
165
+ * (`legion-run`, `ssh <host>`, `/home/<user>/...`) or an unbounded CPU busy loop (`while :`/`while true` with no sleep or
166
+ * read, `yes > /dev/null`, `seq $(nproc)` fan-out). One problem per command id. Pure.
167
+ */
168
+ export function hostOnlyProblems(contract) {
169
+ const out = [];
170
+ for (const v of contractCommands(contract)) {
171
+ const cmd = v.command, why = [];
172
+ const exes = shellSegments(cmd).map((seg) => { let i = 0; while (i < seg.length && (/^[A-Za-z_]\w*=/.test(seg[i]) || ["!", "time", "exec", "command", "env"].includes(seg[i]))) i++; return seg[i]; });
173
+ if (cmd.split(/[\s'"`(;&|]+/).includes("legion-run") || exes.includes("legion-run")) why.push("the host-only wrapper `legion-run`");
174
+ if (exes.includes("ssh")) why.push("`ssh <host>`");
175
+ if (/(^|[\s='"`:(])\/home\/[\w.-]+\//.test(cmd)) why.push("an absolute `/home/<user>/` path");
176
+ if (/\bwhile\s+(:|true)\s*;\s*do\s*(:\s*;\s*)?done\b/.test(cmd) || /\byes\b[^|;&]*>\s*\/dev\/null/.test(cmd) || /\bseq\s+\$\(\s*nproc\s*\)/.test(cmd)) why.push("an unbounded CPU busy loop");
177
+ if (why.length) out.push(`${v.id}: uses ${why.join(" and ")}, which no lane sandbox provides or tolerates, so the command cannot run as written; use a bounded check through the repo's own toolchain, not a host wrapper, host path or CPU stress loop`);
178
+ }
179
+ return out;
180
+ }
181
+
162
182
  const FIX_HOW = "run the check through the repo's own toolchain (its virtualenv, lockfile-pinned runner or package scripts) or use a check that does not need it, never a global install";
163
183
  /** One contract problem per miss: names the validate ids and the tool (or path, or env var), and how to fix the plan (never a global install). */
164
184
  export function preflightProblems(misses) {
165
185
  return (misses ?? []).map((m) => {
166
186
  const ids = m.ids.join(", ");
167
187
  if (m.kind === "env-var") return `${ids}: uses $${m.tool}, which is unset or empty in the lane environment, so the validate command cannot run as written; set it inside the command or ${FIX_HOW}`;
188
+ if (m.source === "collect") return `${ids}: importing its test modules on the base worktree (pytest --collect-only) failed: needs Python module '${m.tool}'${m.line ? ` (\`${m.line}\`)` : ""}, so the command does not run in the environment that has the test's dependencies; run it the way the repo's CI runs that test path (its working-directory and poetry run / uv run) or ${FIX_HOW}`; // #5753
168
189
  if (m.source === "run") return `${ids}: running it on the base worktree stopped before any test ran: needs ${KIND_NAME[m.kind] ?? m.kind} '${m.tool}'${m.line ? ` (\`${m.line}\`)` : ""}, so the validate command cannot run here; ${m.kind === "path" ? "point it at a path the repo or a deliverable has, or " : ""}${FIX_HOW}`;
169
190
  return `${ids}: needs ${KIND_NAME[m.kind] ?? m.kind} '${m.tool}'${m.interp ? ` (for ${m.interp})` : ""}, which this host lacks, so the validate command cannot run here; ${FIX_HOW}`;
170
191
  });
@@ -326,12 +347,81 @@ export function testRunSummary({ contract, failures = [], repro = null } = {}) {
326
347
  return { declared: ids.length, ran: ids.length - skipped.length, redGreen, skipped };
327
348
  }
328
349
 
329
- /** #5447: tool names the contract's test plan declares in `env` (per row of the #5445 `test_plan` array, or `test_plan.env`); strings, comma lists or {tool}; [] when absent. Pure. */
330
- export function declaredEnv(contract) {
350
+ /**
351
+ * #5447: tool names the contract's test plan declares in `env` (per row of the #5445 `test_plan` array, or `test_plan.env`);
352
+ * strings, comma lists or {tool}; [] when absent. #5753: a directory the repo tracks (`files`: tracked paths, e.g. `shared`)
353
+ * is never a host tool. Pure.
354
+ */
355
+ export function declaredEnv(contract, files = []) {
331
356
  const plan = contract?.test_plan;
332
357
  const raw = Array.isArray(plan) ? plan.map((r) => r?.env) : [plan?.env];
333
358
  const names = raw.flatMap((e) => (Array.isArray(e) ? e : typeof e === "string" ? e.split(",") : [])).map((e) => String(typeof e === "string" ? e : e?.tool ?? "").trim());
334
- return [...new Set(names.filter((t) => /^[\w.+-]+$/.test(t) && isExecutableName(t)))];
359
+ const dirs = trackedDirs(files);
360
+ return [...new Set(names.filter((t) => /^[\w.+-]+$/.test(t) && isExecutableName(t) && !dirs.has(t)))];
361
+ }
362
+ /** #5753: every directory name a tracked path runs through (`shared/detection/x.py` -> shared, detection). */
363
+ function trackedDirs(files) {
364
+ const out = new Set();
365
+ for (const f of Array.isArray(files) ? files : []) for (const seg of String(f).split("/").slice(0, -1)) if (seg) out.add(seg);
366
+ return out;
367
+ }
368
+
369
+ /** The prefix of one command segment up to its pytest invocation (bare, path/.venv, `python[3[.x]] -m pytest`, after
370
+ * `poetry|uv [flags] run [flags]` and env assignments), or null. A linear token scan: no backtracking (CodeQL js/redos). */
371
+ function pytestPrefix(segment) {
372
+ const toks = [...String(segment).matchAll(/\S+/g)].map((m) => ({ t: m[0], end: m.index + m[0].length }));
373
+ let i = 0;
374
+ while (i < toks.length && /^[A-Za-z_]\w*=/.test(toks[i].t)) i++;
375
+ const base = (t) => t.split("/").pop();
376
+ const isPy = (t) => /^python3?(?:\.\d+)?$/.test(base(t));
377
+ const isPytest = (t) => base(t) === "pytest";
378
+ if (i < toks.length && (toks[i].t === "poetry" || toks[i].t === "uv")) {
379
+ i++;
380
+ while (i < toks.length && toks[i].t.startsWith("-")) i++;
381
+ if (toks[i]?.t !== "run") return null;
382
+ i++;
383
+ while (i < toks.length && toks[i].t.startsWith("-")) {
384
+ const flag = toks[i].t; i++;
385
+ const next = toks[i]?.t;
386
+ if (!flag.includes("=") && next && !next.startsWith("-") && !isPy(next) && !isPytest(next) && toks[i + 1]) i++;
387
+ }
388
+ }
389
+ const t = toks[i]?.t;
390
+ if (!t) return null;
391
+ if (isPytest(t)) return segment.slice(0, toks[i].end);
392
+ if (isPy(t) && toks[i + 1]?.t === "-m" && toks[i + 2]?.t === "pytest") return segment.slice(0, toks[i + 2].end);
393
+ return null;
394
+ }
395
+ /**
396
+ * #5753: the contract command with `--collect-only -q` after its first pytest invocation (bare, `.venv/bin/python -m`,
397
+ * `poetry run`, `uv run`): one cheap run imports the test modules, so an import error shows at freeze, not in the builder.
398
+ * null when the command runs no pytest. Pure.
399
+ */
400
+ export function collectOnlyCommand(command) {
401
+ const parts = String(command ?? "").split(/(&&|\|\||;|\||\n)/);
402
+ for (let i = 0; i < parts.length; i += 2) {
403
+ const pre = pytestPrefix(parts[i]);
404
+ if (pre === null) continue;
405
+ if (/(?:^|\s)--collect-only\b/.test(parts[i])) return null;
406
+ parts[i] = `${pre} --collect-only -q${parts[i].slice(pre.length)}`;
407
+ return parts.slice(0, i + 1).join(""); // later segments (`| tail`, `&& echo`) would hide the collect exit
408
+ }
409
+ return null;
410
+ }
411
+ const COLLECT_IMPORT_RE = /(?:ModuleNotFoundError|ImportError): No module named '?([\w.]+)'?/;
412
+ /**
413
+ * #5753: why a collect-only run (collectOnlyCommand) shows the test module cannot import on this host: a module the repo does
414
+ * not track (`repoHas`) is {tool, kind: "python-module", line}. A passing or empty collection, a timeout, an import of a name
415
+ * the change adds (`cannot import name`) and a repo-owned module are no miss (RED on base is expected). Pure.
416
+ */
417
+ export function collectImportMiss(r, { repoHas = () => false } = {}) {
418
+ const rc = r?.rc, out = String(r?.output ?? "");
419
+ if (!Number.isInteger(rc) || rc === 0 || rc === 5 || rc === TIMEOUT_RC) return null;
420
+ const m = COLLECT_IMPORT_RE.exec(out);
421
+ if (!m) return null;
422
+ const tool = m[1].split(".")[0];
423
+ if (!tool || repoHas(tool) || repoHas(m[1])) return null;
424
+ return { tool, kind: "python-module", line: (out.split("\n").find((l) => l.includes(m[0])) ?? "").trim().slice(0, 160) };
335
425
  }
336
426
 
337
427
  /** #5590: pytest's built-in fixtures, never host executables. */
@@ -390,15 +480,15 @@ export function manifestDepOwner(name, files = [], readFile = () => "") {
390
480
  const parts = String(f).split("/"), base = parts[parts.length - 1];
391
481
  if (parts.includes("node_modules") || !(base === "package.json" || base === "pyproject.toml" || /^requirements[\w.-]*\.txt$/.test(base))) continue;
392
482
  let text = ""; try { text = String(readFile(f) ?? ""); } catch { continue; }
393
- if (manifestDeclares(base.startsWith("requirements") ? "requirements.txt" : base, text, name)) return dirname(f);
483
+ if (manifestDeclares(base.startsWith("requirements") ? "requirements.txt" : base, text, name)) return posix.dirname(f);
394
484
  }
395
485
  return null;
396
486
  }
397
487
 
398
488
  /** nearest ancestor dir (of `dir`, up to the root ".") holding a tracked Python manifest, or null. */
399
489
  function nearestPyProject(dir, files) {
400
- const have = new Set(files.filter((f) => PY_MANIFESTS.has(String(f).split("/").pop()) || /(^|\/)requirements[\w.-]*\.txt$/.test(f)).map((f) => dirname(f)));
401
- for (let d = dir; ; d = dirname(d)) { if (have.has(d)) return d; if (d === "." || d === "/") return null; }
490
+ const have = new Set(files.filter((f) => PY_MANIFESTS.has(String(f).split("/").pop()) || /(^|\/)requirements[\w.-]*\.txt$/.test(f)).map((f) => posix.dirname(f)));
491
+ for (let d = dir; ; d = posix.dirname(d)) { if (have.has(d)) return d; if (d === "." || d === "/") return null; }
402
492
  }
403
493
  const PYTEST_SEG = /^(\s*(?:[A-Za-z_]\w*=\S*\s+)*)(?:python3?(?:\.\d+)?\s+-m\s+pytest|pytest)\b/;
404
494
  /**
@@ -412,19 +502,25 @@ export function venvPythonRewrite(command, files = [], exists = () => false) {
412
502
  const out = parts.map((seg, i) => {
413
503
  if (i % 2) return seg;
414
504
  const cd = /^\s*cd\s+(?:"([^"]+)"|'([^']+)'|(\S+))\s*$/.exec(seg);
415
- if (cd) { const t = (cd[1] ?? cd[2] ?? cd[3]).replace(/^\.\//, "").replace(/\/+$/, ""); cwd = t.startsWith("/") || t.startsWith("$") || t.startsWith("..") ? "?" : join(cwd === "?" ? "." : cwd, t) || "."; return seg; }
505
+ if (cd) { const t = (cd[1] ?? cd[2] ?? cd[3]).replace(/^\.\//, "").replace(/\/+$/, ""); cwd = t.startsWith("/") || t.startsWith("$") || t.startsWith("..") ? "?" : posix.join(cwd === "?" ? "." : cwd, t) || "."; return seg; }
416
506
  const m = PYTEST_SEG.exec(seg);
417
507
  if (!m || cwd === "?") return seg;
418
508
  const rest = seg.slice(m[0].length);
419
509
  const tp = rest.split(/\s+/).map((x) => x.replace(/::.*$/, "").replace(/^\.\//, "")).find((x) => x && !x.startsWith("-") && /[\w-]\/|\.py$/.test(x) && !x.startsWith("/"));
420
- const origin = cwd !== "." ? cwd : tp ? dirname(tp) : ".";
510
+ const origin = cwd !== "." ? cwd : tp ? posix.dirname(tp) : ".";
421
511
  const proj = nearestPyProject(origin, files);
422
512
  if (proj === null) return seg;
423
- const venv = join(proj, ".venv/bin/python");
513
+ const venv = posix.join(proj, ".venv/bin/python");
424
514
  if (!exists(venv)) return seg;
425
- const rel = cwd === "." ? venv : relative(cwd, venv);
515
+ const rel = cwd === "." ? venv : posix.relative(cwd, venv);
426
516
  changed = true;
427
517
  return `${m[1]}${rel} -m pytest${rest}`;
428
518
  });
429
519
  return changed ? out.join("") : String(command ?? "");
430
520
  }
521
+
522
+ /** #5917: host config defects (not contract misses): a poisoned poetry config fails every host validate as if the change were wrong. */
523
+ export function hostEnvDefects(opts = {}) {
524
+ const p = hostPoetryConfigProblem(opts);
525
+ return p ? [p] : [];
526
+ }
@@ -3,8 +3,8 @@
3
3
  import { describe, it } from "node:test";
4
4
  import assert from "node:assert/strict";
5
5
  import { mkdirSync, writeFileSync } from "node:fs";
6
- import { join } from "node:path";
7
- import { manifestDepOwner, venvPythonRewrite, testRunnerProblems, shellSegments, pythonImports, nodeImports, preflightProbes, preflightProblems, runProbeMiss, unsetEnvVars, runPreflight, knownToContract, contractCommands, depInstallFailures, toolMissingInstalls, testRunSummary, projectBinDirs, withLocalBins } from "./preflight.mjs";
6
+ import { join, delimiter } from "node:path";
7
+ import { manifestDepOwner, venvPythonRewrite, testRunnerProblems, shellSegments, pythonImports, nodeImports, preflightProbes, preflightProblems, runProbeMiss, unsetEnvVars, runPreflight, knownToContract, contractCommands, depInstallFailures, toolMissingInstalls, testRunSummary, projectBinDirs, withLocalBins, collectOnlyCommand, collectImportMiss, declaredEnv, hostEnvDefects } from "./preflight.mjs";
8
8
  import { runCheckCommand } from "./effects.mjs";
9
9
  import { repoTracks } from "./conformance.mjs";
10
10
  import { tmpDir } from "../tests/_tmp.mjs";
@@ -54,7 +54,7 @@ describe("#4328 validate preflight: what a command needs", () => {
54
54
  assert.equal(rc["command:node"], 0); assert.equal(rc["node-module:here"], 0, "found in an ancestor node_modules");
55
55
  assert.notEqual(rc["node-module:absent-pkg-4328"], 0);
56
56
  const py = preflightProbes(C(`python3 -c "import json, no_such_mod_4328"`)).probes.filter((p) => p.kind === "python-module");
57
- if ((await runCheckCommand({ command: "command -v python3", cwd: dir })).rc === 0) {
57
+ if ((await runCheckCommand({ command: "python3 -c pass", cwd: dir })).rc === 0) { // #5753: a Windows Store python3 stub is on PATH but runs nothing
58
58
  assert.deepEqual(await Promise.all(py.map(async (p) => (await runCheckCommand({ command: p.probe, cwd: dir })).rc !== 0)), [false, true]);
59
59
  }
60
60
  });
@@ -209,7 +209,7 @@ describe("project-local executables (#5592 3d/9)", () => {
209
209
  assert.equal((await runCheckCommand({ command: probes[0].probe, cwd: wt, env: { PATH: withLocalBins(base, local) } })).rc, 0);
210
210
  });
211
211
  it("local bins go after the lane PATH, never ahead, and are not duplicated", () => {
212
- assert.equal(withLocalBins("/a:/b", ["/c", "/a"]), "/a:/b:/c");
212
+ assert.equal(withLocalBins(["/a", "/b"].join(delimiter), ["/c", "/a"]), ["/a", "/b", "/c"].join(delimiter)); // #5753: the host PATH delimiter (; on Windows)
213
213
  });
214
214
  });
215
215
 
@@ -241,3 +241,63 @@ describe("#5683 sub-project manifest deps and venv python", () => {
241
241
  assert.equal(venvPythonRewrite("cd web && pytest", files, exists), "cd web && pytest");
242
242
  });
243
243
  });
244
+
245
+ describe("#5749 host-only and busy-loop validates", () => {
246
+ const V = (...commands) => ({ deliverables: [], validate: commands.map((command, i) => ({ id: `V${i + 1}`, command })) });
247
+ it("#5749 hostOnlyProblems rejects host-only and busy-loop validates", async () => {
248
+ const { hostOnlyProblems } = await import("./preflight.mjs");
249
+ const bad = [`legion-run bash -lc 'for i in $(seq $(nproc)); do (timeout 300 sh -c "while :; do :; done") & done; npx vitest run'`, "ssh build-host make test", "bash /home/u/x/check.sh", "yes > /dev/null & npx vitest run"];
250
+ for (const c of bad) assert.equal(hostOnlyProblems(V(c)).length, 1, c);
251
+ assert.match(hostOnlyProblems(V(bad[0]))[0], /^V1: /);
252
+ assert.deepEqual(hostOnlyProblems(V("npx vitest run", "python -m pytest tests/x.py", "while read l; do echo $l; done < f", "git diff origin/staging...HEAD --stat")), []);
253
+ assert.equal(hostOnlyProblems({ ...V("npx vitest run"), repro_test: { path: "t.py", id: "t", command: "ssh h pytest t.py" } }).length, 1);
254
+ });
255
+ it("#5749 repro_test python -m pytest is probed at freeze", () => {
256
+ const c = { ...V("npx vitest run"), repro_test: { path: "tests/x.py", id: "t", command: "python -m pytest tests/x.py::t" } };
257
+ const got = preflightProbes(c).probes.map((p) => [p.kind, p.tool, p.ids.join(",")]);
258
+ assert.deepEqual(got.filter((x) => x[2] === "repro_test"), [["command", "python", "repro_test"], ["python-module", "pytest", "repro_test"]]);
259
+ });
260
+ });
261
+
262
+ describe("#5753 collect-only import preflight and tracked-dir env names", () => {
263
+ it("collectOnlyCommand adds --collect-only -q after the pytest invocation, dropping later segments", () => {
264
+ assert.equal(collectOnlyCommand("cd services/worker && poetry run pytest ../../shared/t.py -x"), "cd services/worker && poetry run pytest --collect-only -q ../../shared/t.py -x");
265
+ assert.equal(collectOnlyCommand("python3 -m pytest -q tests/t.py | tail -5"), "python3 -m pytest --collect-only -q -q tests/t.py ");
266
+ assert.equal(collectOnlyCommand(".venv/bin/python -m pytest t.py"), ".venv/bin/python -m pytest --collect-only -q t.py");
267
+ assert.equal(collectOnlyCommand("uv run --frozen pytest"), "uv run --frozen pytest --collect-only -q");
268
+ assert.equal(collectOnlyCommand("node --test x.test.mjs"), null);
269
+ });
270
+ it("a collect-only ModuleNotFoundError of a module the repo does not track is a miss; RED-on-base shapes are not", () => {
271
+ const out = "ImportError while importing test module '/w/shared/detection/test_x.py'.\nE ModuleNotFoundError: No module named 'html2text'\n";
272
+ assert.deepEqual(collectImportMiss({ rc: 2, output: out }), { tool: "html2text", kind: "python-module", line: "E ModuleNotFoundError: No module named 'html2text'" });
273
+ assert.equal(collectImportMiss({ rc: 2, output: out }, { repoHas: (n) => n === "html2text" }), null, "a repo-owned module is the change's");
274
+ assert.equal(collectImportMiss({ rc: 2, output: "ImportError: cannot import name 'new_fn' from 'shared.x'" }), null, "a name the change adds");
275
+ assert.equal(collectImportMiss({ rc: 0, output: out }), null);
276
+ assert.equal(collectImportMiss({ rc: 5, output: "no tests ran" }), null);
277
+ });
278
+ it("a tracked repo directory name (shared) in declared env is never a host tool", () => {
279
+ const c = { test_plan: [{ requirement: "R1", env: ["shared", "pytest"] }] };
280
+ assert.deepEqual(declaredEnv(c, ["shared/detection/test_x.py", "services/worker/pyproject.toml"]), ["pytest"]);
281
+ assert.deepEqual(declaredEnv(c), ["shared", "pytest"], "without tracked paths the name is unchanged");
282
+ });
283
+ });
284
+
285
+ describe("hostEnvDefects (#5917)", () => {
286
+ it("surfaces a poisoned poetry host config as an env defect, not a miss", () => {
287
+ const d = tmpDir("preflight-poetry-"); writeFileSync(join(d, "config.toml"), "[virtualenvs]\ncreate = false\n");
288
+ const r = hostEnvDefects({ env: { POETRY_CONFIG_DIR: d } });
289
+ assert.equal(r.length, 1);
290
+ assert.equal(r[0].code, "env.host_poetry_config");
291
+ assert.deepEqual(hostEnvDefects({ env: { POETRY_CONFIG_DIR: tmpDir("preflight-empty-") } }), []);
292
+ });
293
+ });
294
+
295
+ describe("#6037 provided() skips image-manifest command probes", () => {
296
+ it("skips provided tools, still probes others and modules", () => {
297
+ const c = C("shellcheck x.sh && yq . a.yml && ripgrep foo && python3 -c 'import yaml'");
298
+ const provided = (n) => ["shellcheck", "yq", "python3"].includes(n);
299
+ assert.deepEqual(needs(c, { provided }), [["command", "ripgrep", null, "V1"], ["python-module", "yaml", "python3", "V1"]]);
300
+ assert.deepEqual(needs(c), needs(c, {}));
301
+ assert.ok(needs(c).some((p) => p[1] === "shellcheck"));
302
+ });
303
+ });
@@ -322,15 +322,7 @@ export function buildOpeningNote({ paths = [], tests = [], packFiles = [] } = {}
322
322
  /** #4857: validate-command rules for the plan prompt (the implement session resumes it), kept out of the shared templates (their token caps are guarded). */
323
323
  export function unrunnableValidateNote(testRunners = null) {
324
324
  const map = testRunners && typeof testRunners === "object" ? Object.entries(testRunners).map(([k, v]) => `${k}/ -> ${v}`).join("; ") : "";
325
- return `\n\nValidate and repro commands must pass bash -n (no prose notes), select tests that exist, and run from the right cwd (never combine \`poetry -C <dir>\` or \`uv run --project <dir>\` with repo-root-relative paths: use \`cd <dir> && poetry run pytest <dir-relative paths>\`)${map ? ` (forge.yaml verification.test_runners: ${map})` : ""}. An unrunnable validate (missing tool, wrong cwd, no tests selected) is never a block or "human" product-decision: run an equivalent through the repo's toolchain and record {"kind":"substitute-validate","validate":"V#","command":"<runnable equivalent>","why":""} in ${RESULT_FILE} amendments. A post-deploy requirement needs a registered check id; one that is a manual or production-credential action with no runnable check is disposition "defer" with bucket "owner:<action>" only when it needs credentials, spend, an account, a third party or a customer; read-only prod data is "host". forge.yaml validate.recipes rewrite matching commands at freeze, and the engine rewrites an unrunnable command from the repo's CI-derived command catalogue: prefer the repo's own CI test commands over free-form paths. A substitute that runs the same test ids with the same result is recorded, not failed. A criterion only time or production can show (a 14-day metric, a corpus re-run, a published scorecard) is post-deploy or defer with a bucket: never narrow it into something the lane can observe.`;
326
- }
327
-
328
- /** #5419: the R-docs rule for the planner; "" when forge.yaml docs.required_for is unset. */
329
- export function docsPlanNote(cfg) {
330
- if (!cfg?.required_for?.length) return "";
331
- const where = cfg.paths?.length ? ` under ${cfg.paths.join(", ")}` : "";
332
- const reg = cfg.registries?.length ? ` and their registration (${cfg.registries.join(", ")})` : "";
333
- return `\n\nThis repo requires user docs for user-facing surfaces (${cfg.required_for.join(", ")}). When the issue adds or changes one (a public API endpoint, MCP tool, dashboard page or feature, CLI command or SDK method), ${CONTRACT_FILE} must carry a requirement R-docs and a deliverable for each docs page${where} to create or update${reg}. A \`/docs/...\` link the change adds must resolve to a page. If no docs apply, say why in the result file as docs: [{"surface":"<kind>","justification":"<why>"}].`;
325
+ return `\n\nValidate and repro commands must pass bash -n (no prose notes), select tests that exist, and run from the right cwd (never combine \`poetry -C <dir>\` or \`uv run --project <dir>\` with repo-root-relative paths: use \`cd <dir> && poetry run pytest <dir-relative paths>\`)${map ? ` (forge.yaml verification.test_runners: ${map})` : ""}. An unrunnable validate (missing tool, wrong cwd, no tests selected) is never a block or "human" product-decision: run an equivalent through the repo's toolchain and report its real result in ${RESULT_FILE}. A post-deploy requirement needs a registered check id; one that is a manual or production-credential action with no runnable check is disposition "defer" with bucket "owner:<action>" only when it needs credentials, spend, an account, a third party or a customer; read-only prod data is "host". forge.yaml validate.recipes rewrite matching commands at freeze, and the engine rewrites an unrunnable command from the repo's CI-derived command catalogue: prefer the repo's own CI test commands over free-form paths. A criterion only time or production can show (a 14-day metric, a corpus re-run, a published scorecard) is post-deploy or defer with a bucket: never narrow it into something the lane can observe.`;
334
326
  }
335
327
 
336
328
  /** #5428: the page_gate rule for the planner; "" when forge.yaml pages is off. */
@@ -426,17 +418,18 @@ export function contractCorrectionPrompt(problems) {
426
418
  return `Your ${CONTRACT_FILE} is not valid:\n${problems.slice(0, 20).map((p) => `- ${p}`).join("\n")}\n\nFix the contract (planning only, no code, no commit) and stop. Do not push or touch GitHub.`;
427
419
  }
428
420
 
429
- /** #5089: the builder's amendments name an unknown kind or miss a field; one correction before the conformance gate. */
430
- export function amendmentCorrectionPrompt(problems) {
431
- return `The amendments in ${RESULT_FILE} are not valid:\n${problems.slice(0, 20).map((p) => `- ${p}`).join("\n")}\n\nRewrite them with a valid kind (${AMEND_KINDS.join(", ")}). A validate-row id (G2) is never a supersedes guard: use {"kind":"substitute-validate","validate":"G2","command":"<runnable equivalent>","why":""}. A deliverable that is impossible on this platform is {"kind":"defer","requirement":"R#","why":""}, not a changed deliverable. Edit only ${RESULT_FILE} (commit nothing else) and stop. Do not push or touch GitHub.`;
432
- }
433
-
434
421
  /** The one bounded correction round, in the builder's own session. */
435
422
  export function conformanceResumePrompt(failures, mode = "local", lane = "") {
436
423
  const baseMoved = lane && failures.some((f) => f?.kind === "validate_failed")
437
424
  ? `\n\nIf a validate command fails only because origin/${lane} moved on after this branch started (the change itself is fine), bring the branch up to date with \`git merge --no-edit origin/${lane}\` (already fetched; never rebase or force), resolve any conflicts, then re-run every validate command and record the results.`
438
425
  : "";
439
- return `The change does not conform to the frozen contract and the issue:\n${failures.slice(0, 30).map((f) => `- ${f.code}: ${String(f.detail).slice(0, 900)}`).join("\n")}${baseMoved}\n\nFix each item in the code, or record a typed amendment with a why in ${RESULT_FILE}. ${rerun(mode)}, commit, and update ${IMPLEMENTATION_FILE} and ${RESULT_FILE}. Do not push or touch GitHub.`;
426
+ // #6058: a requirement with no status row was skipped, not failed: name each id with its quote and ask for the work and a row
427
+ const skipped = failures.filter((f) => f?.kind === "requirement_no_status" && f.reqId);
428
+ const rest = skipped.length ? failures.filter((f) => !skipped.includes(f)) : failures;
429
+ const targeted = skipped.length
430
+ ? `You skipped ${skipped.length === 1 ? "a requirement" : `${skipped.length} requirements`}: ${RESULT_FILE} has no status row for ${skipped.map((f) => f.reqId).join(", ")}, so ${skipped.length === 1 ? "it was" : "they were"} not addressed at all:\n${skipped.map((f) => `- ${f.reqId}: "${String(f.quote ?? "").slice(0, 400)}"`).join("\n")}\n\nFor each one, implement it now (a file it needs that no deliverable names is an \`add-deliverable\` amendment), then add its row {"id","status","evidence"} to the requirements array of ${RESULT_FILE}, keeping the rows already there.${rest.length ? "\n\nAlso:\n" : ""}`
431
+ : "The change does not conform to the frozen contract and the issue:\n";
432
+ return `${targeted}${rest.slice(0, 30).map((f) => `- ${f.code}: ${String(f.detail).slice(0, 900)}`).join("\n")}${baseMoved}\n\nFix each item in the code, or record a typed amendment with a why in ${RESULT_FILE}. ${rerun(mode)}, commit, and update ${IMPLEMENTATION_FILE} and ${RESULT_FILE}. Do not push or touch GitHub.`;
440
433
  }
441
434
 
442
435
  /** forge#4159: the one resume for package.json edges between workspace packages the contract does not name. */
@@ -444,11 +437,6 @@ export function structurePrompt(edges, mode = "local") {
444
437
  return `This change adds dependencies between workspace packages that the frozen contract does not name:\n${edges.slice(0, 30).map((e) => `- ${e.from} -> ${e.to} (${e.kind}, ${e.manifest})`).join("\n")}\n\nFor each one, add it to the contract with a reason, or remove it: either record {"kind":"add-deliverable","path":"<that package.json>","why":"<names the package and why this dependency is right>"} in ${RESULT_FILE}, or drop the dependency from the package.json and the code that needs it. ${rerun(mode)}, commit, and update ${IMPLEMENTATION_FILE} and ${RESULT_FILE}. Do not push or touch GitHub.`;
445
438
  }
446
439
 
447
- /** The repo's devdocs freshness rule failed on the committed change: add a decision record (conflict-free) and commit. */
448
- export function docsPrompt(output, mode = "local") {
449
- return `The repository's docs freshness check (scripts/check-devdocs-freshness.sh) fails on this change:\n${String(output ?? "").slice(0, 4000)}\n\nAdd a new devdocs/decisions/<issue>-<slug>.md describing the behaviour you changed in a few lines (a new file never conflicts with parallel lanes; edit a shared dossier only when the check accepts nothing else). ${rerun(mode)}, commit, and update ${IMPLEMENTATION_FILE} and ${RESULT_FILE}. Do not push or touch GitHub.`;
450
- }
451
-
452
440
  /**
453
441
  * #4363: a fix round in a fresh session (no transcript). It carries the site's task prompt (which holds the capped
454
442
  * failure output), the lane diff, the frozen contract and the issue title and summary, each capped; under FIX_PROMPT_MAX.
@@ -485,6 +473,7 @@ const BLOCK_RULES = `"blocked" needs a typed "block" in ${RESULT_FILE}, one of:
485
473
  - {"kind":"split-required","subissues":[{"title":"","body":"","depends_on":[0],"files":["<path>"]}],"size":{"files":N,"lines":N}}: too big for one change. The engine files the sub-issues (depends_on = indexes of earlier sub-issues; files = the files or dirs each will edit, also accepted as "paths") only when every sub-issue's files are disjoint from the others' or the whole change's size estimate exceeds ${SPLIT_MIN_FILES} files or ${SPLIT_MIN_LINES} lines; otherwise keep one lane: an ordered checklist in the contract with a validate per item. In an admitted split, siblings editing the same hub (barrel or index export list, union type, shared fixture, index doc) get its slots pre-staged in the earliest sub-issue, which the others depend on, or their own per-feature files; the engine serialises sub-issues still sharing a file.
486
474
  - {"kind":"design-invalidated","decision":"<what no longer holds>","why":"","epic":N}: the design is wrong; the engine files one amendment and holds open siblings.
487
475
  - {"kind":"human","why":"${HUMAN_BLOCK_REASONS.join("|")}"}: only an external action agents cannot take, or a product decision too critical for agents. Optional "remainder":[{"title","body"}]: the agent-doable rest, filed as its own issue.
476
+ Merging the base into this lane's own branch is the engine's base-sync, never "blocked" or human: say so in the summary and carry on.
488
477
  "An upstream issue must land first", "needs a split" and "needs prod data that read-only monitoring can read" are never "human".
489
478
  A check that times out (rc 124) is host load, never a block: run the narrowest targeted command for your changed files and say the full one could not finish.
490
479
  Remote sandbox lacking a host-only capability (sops, prod_monitor, ops_credentials): name it in the summary.`;
@@ -520,6 +509,7 @@ You receive the GitHub issue with its comments, the frozen contract (requirement
520
509
  - issue_coverage: one row per requirement or acceptance criterion in the issue, quoted verbatim, saying whether the contract covers it, narrows it, or misses it. The skeleton lists the contract's quotes; add a row for any issue requirement the contract does not quote.
521
510
  - guidance: a guidance requirement (pre-filled covered / not-applicable) is a proposed change, non-binding: judge whether the outcome rows are met, never whether the proposal was followed. Set misclassified: true on its issue_coverage row only when the quote is really a symptom or success criterion. A deliver row with derived_outcome is judged against derived_outcome, like amendment.text.
522
511
  - amendment: a requirement with an \`amendment\` is judged against amendment.text and its why, not the quote; its issue_coverage row is covered when the amendment follows from its why. A requirement with \`amended_from\` was contracted defer or post-deploy and flipped to deliver: compare amended_from.quote and amended_from.why with amendment.text side by side, and mark the row partial when the rewording drops the original work or only trivially restates it. If it does not hold, mark the row partial with note "amendment: <what to change>".
512
+ - frozen defer/post-deploy rows: a requirement the contract froze as defer or post-deploy is a tracked follow-up, never an omission; do not mark its issue_coverage row narrowed or missing for that. An amendment that cites a frozen decision id (D#/K#) is judged against that decision's choice and justification.
523
513
  - requirements: one row per contract requirement id: implemented|partial|missing|deferred|post-deploy|not-applicable, with evidence as a backtick-quoted repo-relative path:line copied verbatim from the changed files, including (group), [slug] and [...slug] folders (e.g. \`apps/web/app/(console)/layout.tsx:12\`, not route.ts:12) and the validate id or test that proves it (validated_by). For a defer or post-deploy requirement add deferral_ok: true only if it is genuinely separate work or only checkable after a deploy, false if it belongs in this change, including an outcome criterion (a metric, rate or log expectation) this change could ship as a test, metric or alert, or a read-only production check possible now (bucket verify-now). For a verify out_of_band row (measured by the named job, not in this lane) set instrumented: true only when its budget test or bench is committed and that job is configured, with that path:line as evidence; false otherwise. Do not judge the measured result.
524
514
  - post-deploy requirements: deferral_ok is false when the requirement has no \`check\` id, or its check is neither in .forge/post-deploy-checks.json on the default branch nor added by this change (the commands run from that file only).
525
515
  - scope: one row per changed file, pre-filled with the engine's authorization: the deliverable id that authorizes it (deliverables may be directories or globs), "test", "incidental" (changelog, lockfile), or "none" with what it changes. Change it only if the diff shows the file does something its deliverable does not cover.
@@ -602,7 +592,7 @@ export function reproFlagNote(flag) {
602
592
 
603
593
  export function reviewerPrompt({ issue, comments = [], contract, result, files = [], diff, stat = "", base = "", structure = "", ignore = [`${LEAN_DIR}/`], skeleton = null, investigationVerdict = null, domains = [], relaxations = [], reproFlag = null }) {
604
594
  const notes = comments.map((c) => String(c?.body ?? "")).filter((b) => !/^<!-- FORGE:/.test(b.trim()));
605
- const decisions = comments.filter((c) => isDecision(c?.body) && isTrustedIssueComment(c)).map((c) => String(c.body)); // #4901: operator decisions bind the review; other FORGE: records stay out
595
+ const decisions = comments.filter((c) => isDecision(c?.body) && isTrustedIssueComment(c)).map((c) => `Binding operator decision (trusted; judge the rows against it, as the builder was told):\n${String(c.body)}`); // #4901/#6051: operator decisions bind the review and the builder alike; other FORGE: records stay out
606
596
  notes.push(...decisions);
607
597
  const sk = JSON.stringify(skeleton ?? reviewSkeleton(contract ?? {}, files, ignore), null, 1);
608
598
  return `Issue #${issue.number}: ${issue.title}\n\n<issue_body>\n${cap(issue.body ?? "", 20000)}\n</issue_body>\n\n<issue_comments>\n${cap(notes.join("\n---\n"), 8000)}\n</issue_comments>\n\n<contract>\n${cap(JSON.stringify(contract ?? {}, null, 1), 12000)}\n</contract>\n\n<builder_result>\n${cap(JSON.stringify(result ?? {}, null, 1), 6000)}\n</builder_result>\n\n${investigationVerdict ? `<investigation_verdict>${investigationVerdict}</investigation_verdict>\n${VERDICT_RULE}\n\n` : ""}<changed_files>\n${files.join("\n")}\n</changed_files>\n\n<rubric>\n${REVIEW_RUBRIC}\n</rubric>\n\n<row_skeleton>\n${cap(sk, 30000)}\n</row_skeleton>\n\n<diff>\n${boundDiff(diff, { stat, base })}\n</diff>${structure ? `\n<structure>${String(structure).replace(/[\r\n]+/g, " ")}</structure>` : ""}${domainChecksBlock(domains)}${relaxationBlock(relaxations)}${reproFlagNote(reproFlag)}`;