forgedock 1.56.0 → 1.58.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 (140) hide show
  1. package/bin/config-schema.mjs +1 -1
  2. package/bin/engine/outcome-codes.mjs +2 -1
  3. package/bin/engine/phases.mjs +4 -3
  4. package/bin/engine-cli.mjs +48 -12
  5. package/bin/forgedock.mjs +52 -3
  6. package/bin/gc.mjs +43 -6
  7. package/bin/help-text.mjs +4 -2
  8. package/bin/lean/batch-health.mjs +5 -1
  9. package/bin/lean/batch-health.test.mjs +7 -1
  10. package/bin/lean/batch.mjs +7 -2
  11. package/bin/lean/batch.test.mjs +45 -0
  12. package/bin/lean/conformance.e2e.test.mjs +3 -2
  13. package/bin/lean/conformance.mjs +118 -20
  14. package/bin/lean/conformance.test.mjs +172 -3
  15. package/bin/lean/decisions.mjs +98 -1
  16. package/bin/lean/decisions.test.mjs +30 -1
  17. package/bin/lean/depcache.mjs +124 -13
  18. package/bin/lean/depcache.test.mjs +121 -3
  19. package/bin/lean/design-gate.mjs +144 -0
  20. package/bin/lean/design-gate.test.mjs +169 -0
  21. package/bin/lean/effects-cap.test.mjs +17 -0
  22. package/bin/lean/effects.mjs +58 -13
  23. package/bin/lean/heavy.mjs +25 -8
  24. package/bin/lean/hostload.test.mjs +28 -0
  25. package/bin/lean/intake.mjs +97 -0
  26. package/bin/lean/intake.test.mjs +105 -0
  27. package/bin/lean/interfaces.mjs +181 -0
  28. package/bin/lean/interfaces.test.mjs +192 -0
  29. package/bin/lean/issuewatch-install.mjs +52 -12
  30. package/bin/lean/issuewatch-install.test.mjs +50 -0
  31. package/bin/lean/issuewatch-parity.mjs +16 -3
  32. package/bin/lean/issuewatch-parity.test.mjs +32 -0
  33. package/bin/lean/issuewatch-reconcile.mjs +29 -1
  34. package/bin/lean/issuewatch-reconcile.test.mjs +21 -0
  35. package/bin/lean/issuewatch.mjs +34 -3
  36. package/bin/lean/issuewatch.test.mjs +49 -1
  37. package/bin/lean/lanecheck.test.mjs +15 -4
  38. package/bin/lean/lean.mjs +110 -24
  39. package/bin/lean/lean.test.mjs +183 -4
  40. package/bin/lean/orchestrate-blocked.test.mjs +18 -2
  41. package/bin/lean/orchestrate-owned.test.mjs +14 -5
  42. package/bin/lean/orchestrate.mjs +26 -4
  43. package/bin/lean/orphan-pr.mjs +3 -2
  44. package/bin/lean/orphan-pr.test.mjs +8 -1
  45. package/bin/lean/pagegate.mjs +35 -12
  46. package/bin/lean/pagegate.test.mjs +39 -1
  47. package/bin/lean/preflight.mjs +35 -1
  48. package/bin/lean/preflight.test.mjs +27 -1
  49. package/bin/lean/prompts.mjs +2 -1
  50. package/bin/lean/reap.test.mjs +39 -0
  51. package/bin/lean/recovery.test.mjs +28 -3
  52. package/bin/lean/release-config.mjs +169 -0
  53. package/bin/lean/release-config.test.mjs +132 -0
  54. package/bin/lean/release-control.mjs +171 -0
  55. package/bin/lean/release-control.test.mjs +167 -0
  56. package/bin/lean/release-deploy.mjs +209 -0
  57. package/bin/lean/release-deploy.test.mjs +217 -0
  58. package/bin/lean/release-fence.mjs +50 -0
  59. package/bin/lean/release-fence.test.mjs +105 -0
  60. package/bin/lean/release-flakes.mjs +139 -0
  61. package/bin/lean/release-flakes.test.mjs +116 -0
  62. package/bin/lean/release-gates.mjs +230 -0
  63. package/bin/lean/release-gates.test.mjs +146 -0
  64. package/bin/lean/release-ledger.mjs +176 -0
  65. package/bin/lean/release-ledger.test.mjs +226 -0
  66. package/bin/lean/release-minutes.mjs +102 -0
  67. package/bin/lean/release-minutes.test.mjs +107 -0
  68. package/bin/lean/release-nightly.mjs +75 -0
  69. package/bin/lean/release-nightly.test.mjs +48 -0
  70. package/bin/lean/release-postmerge.mjs +8 -2
  71. package/bin/lean/release-review.e2e.test.mjs +1 -0
  72. package/bin/lean/release-review.mjs +54 -7
  73. package/bin/lean/release-review.test.mjs +76 -7
  74. package/bin/lean/release-status.mjs +300 -0
  75. package/bin/lean/release-status.test.mjs +220 -0
  76. package/bin/lean/release-unitmap.mjs +35 -0
  77. package/bin/lean/release-unitmap.test.mjs +41 -0
  78. package/bin/lean/release-verify.mjs +221 -0
  79. package/bin/lean/release-verify.test.mjs +176 -0
  80. package/bin/lean/release.mjs +244 -22
  81. package/bin/lean/release.test.mjs +44 -0
  82. package/bin/lean/render.mjs +3 -1
  83. package/bin/lean/run-issue-placement.test.mjs +82 -0
  84. package/bin/lean/sandbox-remote.mjs +16 -0
  85. package/bin/lean/schedd.mjs +1 -1
  86. package/bin/lean/seam.mjs +115 -0
  87. package/bin/lean/seam.test.mjs +118 -0
  88. package/bin/lean/selftest-journey.mjs +40 -2
  89. package/bin/lean/selftest-journey.test.mjs +43 -3
  90. package/bin/lean/statuscomment.mjs +168 -0
  91. package/bin/lean/statuscomment.test.mjs +133 -0
  92. package/bin/lean/ui-quality.mjs +57 -0
  93. package/bin/lean/ui-quality.test.mjs +55 -0
  94. package/bin/lean/visual-gate.test.mjs +63 -0
  95. package/bin/pool/agent.mjs +16 -2
  96. package/bin/pool/router.mjs +5 -1
  97. package/bin/review-staging.mjs +5 -3
  98. package/bin/stats/card.mjs +117 -0
  99. package/bin/stats/card.test.mjs +109 -0
  100. package/bin/stats/conformance-outcomes.test.mjs +2 -1
  101. package/bin/stats/depth.mjs +1 -1
  102. package/bin/stats/gh-retry.test.mjs +152 -0
  103. package/bin/stats/github-source.mjs +147 -14
  104. package/bin/stats/index.mjs +35 -2
  105. package/bin/stats/stats.test.mjs +31 -3
  106. package/bin/vendor/js-yaml/LICENSE +21 -0
  107. package/bin/vendor/js-yaml/PIN.md +7 -0
  108. package/bin/vendor/js-yaml/js-yaml.mjs +3851 -0
  109. package/commands/design-render-critique-loop.md +2 -0
  110. package/commands/design.md +2 -0
  111. package/commands/issue.md +1 -1
  112. package/commands/milestone.md +1 -1
  113. package/commands/review-pr-agents/frontend.md +1 -0
  114. package/commands/review-pr-staging.md +5 -0
  115. package/docs/CONFIG.md +95 -2
  116. package/docs/ISSUE-WATCH.md +7 -0
  117. package/docs/OUTCOME-CODES.md +1 -0
  118. package/docs/STATS.md +10 -0
  119. package/docs/design/visual-gate.md +25 -0
  120. package/docs/eval/adversarial-bench.md +2 -2
  121. package/docs/eval/corpus/adversarial-v1.json +3 -3
  122. package/docs/site/start-a-new-project.md +7 -0
  123. package/docs/spec/forge-protocol-v1.md +31 -0
  124. package/package.json +1 -1
  125. package/pool/README.md +2 -0
  126. package/scripts/acceptance-red-green.sh +15 -1
  127. package/scripts/acceptance-red-green.test.sh +12 -0
  128. package/scripts/bench-adversarial.mjs +4 -0
  129. package/scripts/bench-lightlane.mjs +4 -1
  130. package/scripts/bootstrap-create.mjs +8 -2
  131. package/scripts/ci-local/scoping.mjs +19 -0
  132. package/scripts/ci-local.test.sh +16 -3
  133. package/scripts/fixtures/ci-local/gha-dorny/.github/workflows/ci.yml +4 -0
  134. package/scripts/plan-validate-live.mjs +9 -6
  135. package/scripts/review-prepare.sh +7 -1
  136. package/scripts/review-roster.sh +5 -2
  137. package/scripts/review-roster.test.sh +9 -0
  138. package/scripts/visual-gate.mjs +64 -0
  139. package/templates/bootstrap/technical-spike.md +17 -0
  140. package/templates/contracts/seam-check.mjs +236 -0
@@ -33,7 +33,7 @@ export const MIN_QUOTE_CHARS = 12;
33
33
  /** A contract larger than this cannot be posted whole in one comment (the comment cap is 60k). */
34
34
  export const MAX_CONTRACT_CHARS = 40000;
35
35
  import { CHECK_ID_RE, e2eCheckFor } from "./postdeploy-check.mjs";
36
- import { normaliseDecision, deadAnchors, anchorMatches } from "./decisions.mjs";
36
+ import { normaliseDecision, deadAnchors, anchorMatches, parseRequirementDecision } from "./decisions.mjs";
37
37
  import { globToRegex } from "../../scripts/ci-local/lib.mjs";
38
38
  import { contractBriefProblems } from "./pagegate.mjs"; // #5428
39
39
  const C = OUTCOME_CODES;
@@ -473,13 +473,52 @@ export function weakenedE2eDecisions(c) {
473
473
 
474
474
  const TEST_LEVELS = ["unit", "integration", "e2e", "live"];
475
475
  const planWords = (t) => new Set(String(t ?? "").toLowerCase().match(/[a-z0-9]{3,}/g)?.map((w) => w.slice(0, 5)) ?? []);
476
- const MOCK_RE = /\b(?:mock|stub|fake)\w*/i, NEG_MOCK_PLAN_RE = /\b(?:no|not|never|without|non|avoid\w*)[ -]+(?:\w+[ -]+)?(?:mock|stub|fake)\w*/gi;
476
+ const NEG_MOCK_PLAN_RE = /\b(?:no|not|never|without|non|avoid\w*)[ -]+(?:\w+[ -]+)?(?:mock|stub|fake)\w*/gi;
477
+ const deliverableWords = (d) => planWords(`${d?.change ?? ""} ${d?.path ?? ""}`);
478
+ /** #5445: the deliverable whose words cover the largest share of the proof's, as {id, pct, ratio}, or null. Pure. */
479
+ export function proofEchoDetail(proof, deliverables) {
480
+ // #5592: code identifiers (`name`, camelCase, snake_case, name()) only name the thing under test; they never count towards an echo,
481
+ // and a proof with fewer than 3 words left says too little to be a restatement.
482
+ const pw = planWords(String(proof ?? "").replace(/`[^`]*`|\b\w+\(\)|\b[a-z]+[A-Z]\w*|\b\w+_\w+/g, " "));
483
+ if (pw.size < 3) return null;
484
+ let best = null;
485
+ for (const d of deliverables) { const dw = deliverableWords(d); let n = 0; for (const w of pw) if (dw.has(w)) n++; const ratio = n / pw.size; if (!best || ratio > best.ratio) best = { id: d?.id ?? d?.path ?? "?", pct: Math.round(ratio * 100), ratio }; }
486
+ return best;
487
+ }
477
488
  /** #5445: a proof whose words are (almost) all in the deliverable text of its requirement only restates the fix. Pure. */
478
489
  export function proofEchoesDeliverable(proof, deliverables) {
479
- const pw = planWords(proof);
480
- if (!pw.size) return false;
481
- return deliverables.some((d) => { const dw = planWords(`${d?.change ?? ""} ${d?.path ?? ""}`); let n = 0; for (const w of pw) if (dw.has(w)) n++; return n / pw.size >= 0.7; });
490
+ return (proofEchoDetail(proof, deliverables)?.ratio ?? 0) >= 0.7;
491
+ }
492
+ const MOCK_STOP = new Set(["only", "the", "and", "out", "with", "for", "its", "that", "this", "any", "all", "are", "was", "were", "been", "being", "than", "then", "also", "real"]);
493
+ /**
494
+ * #5587: the first non-negated mock/stub/fake mention in `reason` whose target (up to 4 words after the mock word, or up to 3 words
495
+ * before it, inside the same clause) shares a word stem with a deliverable path/change, as {phrase, id}; else null. Fake clocks and
496
+ * a stub aimed at something outside the deliverables (an I/O boundary) are fine. Pure.
497
+ */
498
+ export function mockedDeliverable(reason, deliverables) {
499
+ const text = String(reason ?? "").replace(NEG_MOCK_PLAN_RE, " ").replace(FAKE_CLOCK_RE, " ");
500
+ const re = /\b(?:mock|stub|fake)\w*/gi;
501
+ for (let m; (m = re.exec(text));) {
502
+ const clauseStart = Math.max(text.lastIndexOf(".", m.index), text.lastIndexOf(";", m.index), text.lastIndexOf(",", m.index), text.lastIndexOf("\n", m.index)) + 1;
503
+ const after = text.slice(m.index + m[0].length).split(/[.;,\n]/)[0].split(/\s+/).filter(Boolean).slice(0, 4);
504
+ const before = text.slice(clauseStart, m.index).split(/\s+/).filter(Boolean).slice(-3);
505
+ const words = [...before, ...after].filter((w) => !MOCK_STOP.has(w.toLowerCase().replace(/[^a-z0-9]/g, "")));
506
+ const tw = planWords(words.join(" "));
507
+ for (const d of deliverables) { const dw = deliverableWords(d); if ([...tw].some((w) => dw.has(w))) return { phrase: `${m[0]} ${after.join(" ")}`.trim(), id: d?.id ?? d?.path ?? "?" }; }
508
+ }
509
+ return null;
510
+ }
511
+ const TEST_PLAN_RULES = [["test_plan.mock", /level_reason mocks /], ["test_plan.echo", /proof restates a deliverable/], ["test_plan.proof", /test_plan proof /], ["test_plan.level", /test_plan level/], ["test_plan.repro", /test_plan (?:repro|no-repro)/], ["test_plan.command", /test_plan (?:needs the exact command|command)/], ["test_plan.row", /test_plan (?:needs a row|row |must be an array)/]];
512
+ /** #5587: the rule id of a contract problem for `contract.invalid` telemetry: a test_plan rule, else "other". Pure. */
513
+ export const contractRuleId = (problem) => TEST_PLAN_RULES.find(([, re]) => re.test(String(problem)))?.[0] ?? "other";
514
+ /** #5587: {ruleId: count} over contract problems. Pure. */
515
+ export function contractRuleCounts(problems) {
516
+ const out = {};
517
+ for (const p of problems ?? []) { const k = contractRuleId(p); out[k] = (out[k] ?? 0) + 1; }
518
+ return out;
482
519
  }
520
+ /** #5587: true when every problem is a test_plan rule (not scope or safety), so a second correction round is allowed. Pure. */
521
+ export const onlyTestPlanProblems = (problems) => (problems ?? []).length > 0 && problems.every((p) => contractRuleId(p) !== "other");
483
522
  /**
484
523
  * #5445: problems with the frozen test plan `test_plan: [{requirement, proof, level, level_reason, repro, reason, regression, env, command}]`.
485
524
  * Shape is checked whenever present; `required` (a bug lane with repro on) also needs one row per deliver requirement.
@@ -494,11 +533,17 @@ export function testPlanProblems(c, { required = false } = {}) {
494
533
  const id = t?.requirement ?? "test_plan row";
495
534
  if (!t || typeof t !== "object" || !t.requirement) { problems.push("test_plan row without a requirement id"); continue; }
496
535
  if (blank(t.proof)) problems.push(`${id}: test_plan proof must name the root-cause observable that shows the cause is fixed`);
497
- else if (proofEchoesDeliverable(t.proof, dels.filter((d) => (d?.requirements ?? []).includes(t.requirement)))) problems.push(`${id}: test_plan proof only restates a deliverable; describe the observable that was wrong (the symptom or root cause), not the presence of the fix`);
536
+ else {
537
+ const echo = proofEchoDetail(t.proof, dels.filter((d) => (d?.requirements ?? []).includes(t.requirement)));
538
+ if (echo && echo.ratio >= 0.7) problems.push(`${id}: test_plan proof restates a deliverable: ≥70% of the proof's words repeat deliverable ${echo.id} (${echo.pct}%); phrase it as the wrong behaviour observed on base (symptom observed today → assertion that fails on base and passes on head, e.g. \"www.reddit.com listing .json returns 403 today → assert the fetch returns 200 JSON\")`);
539
+ }
498
540
  if (!TEST_LEVELS.includes(t.level)) problems.push(`${id}: test_plan level must be one of ${TEST_LEVELS.join("|")}`);
499
541
  if (blank(t.level_reason)) problems.push(`${id}: test_plan level needs a level_reason (why the cheapest level that observes the cause)`);
500
- else if (MOCK_RE.test(String(t.level_reason).replace(NEG_MOCK_PLAN_RE, " "))) problems.push(`${id}: test_plan may not prove the cause fixed by mocking the component the bug lives in; pick a level that exercises it`);
501
- if (blank(t.repro)) problems.push(`${id}: test_plan repro must be a test id (red on base, green on head) or "no-repro" with a reason`);
542
+ else {
543
+ const mocked = mockedDeliverable(t.level_reason, dels.filter((d) => (d?.requirements ?? []).includes(t.requirement)));
544
+ if (mocked) problems.push(`${id}: test_plan level_reason mocks \"${mocked.phrase}\", which is in deliverable ${mocked.id}; level_reason must not contain the words mock/stub/fake unless negated or aimed outside the deliverables; describe the real component exercised and where the I/O boundary is; allowed: a real instance of ${mocked.id}'s component, with stubs only at its I/O boundary (clock, network, browser factory) and, for DB code, a real database session`);
545
+ }
546
+ if (blank(t.repro)) problems.push(`${id}: test_plan repro must be a test id (red on base, green on head) or "no-repro" with a reason; a test id is a file path plus test name, e.g. \`tests/test_scrape.py::test_listing_returns_json\` or \`test/scrape.test.js#listing returns json\`, not a sentence`);
502
547
  else if (/^no-repro$/i.test(String(t.repro).trim()) && blank(t.reason)) problems.push(`${id}: test_plan no-repro needs a reason the reviewer can reject`);
503
548
  if (blank(t.command)) problems.push(`${id}: test_plan needs the exact command validate runs`);
504
549
  else {
@@ -513,7 +558,7 @@ export function testPlanProblems(c, { required = false } = {}) {
513
558
 
514
559
  /** #5448: a requirement that starts as an imperative build verb is development work, not a prod-only measurement. */
515
560
  const DEV_WORK_RE = /^\W*(?:\w+\s+){0,2}?(?:find|fix|implement|develop|build|write|patch|add|change)\b/i;
516
- export function validateContract(c, issueText, { repro = false, pages = null, testPlan = false } = {}) {
561
+ export function validateContract(c, issueText, { repro = false, pages = null, testPlan = false, readFile = null } = {}) {
517
562
  const problems = [];
518
563
  if (!c || typeof c !== "object" || Array.isArray(c)) return { ok: false, problems: ["contract.json is missing or not a JSON object"] };
519
564
  const reqs = Array.isArray(c.requirements) ? c.requirements : [];
@@ -570,7 +615,7 @@ export function validateContract(c, issueText, { repro = false, pages = null, te
570
615
  if (repro) {
571
616
  const t = c.repro_test;
572
617
  if (t === "none") { if (blank(c.repro_test_reason)) problems.push(`repro_test "none" needs a one-line repro_test_reason`); }
573
- else if (!t || typeof t !== "object" || Array.isArray(t) || blank(t.path) || blank(t.command)) problems.push(`this is a bug: repro_test must be {"path","id","command"} (a test that fails on the base and passes after the fix) or "none" with a repro_test_reason`);
618
+ else if (!t || typeof t !== "object" || Array.isArray(t) || blank(t.path) || blank(t.command)) problems.push(`this is a bug: repro_test must be {"path","id","command"} (a test that fails on the base and passes after the fix), e.g. {"path":"tests/test_scrape.py","id":"test_listing_returns_json","command":"pytest tests/test_scrape.py::test_listing_returns_json"}, or "none" with a repro_test_reason; free text is not a test id`);
574
619
  else {
575
620
  for (const p of tmpdirInputs(t.command)) problems.push(tmpInputProblem("repro_test", p));
576
621
  if (guessedUvEnv(t.command)) problems.push(guessedUvProblem("repro_test"));
@@ -583,7 +628,7 @@ export function validateContract(c, issueText, { repro = false, pages = null, te
583
628
  }
584
629
  problems.push(...testPlanProblems(c, { required: testPlan }));
585
630
  if (JSON.stringify(c).length > MAX_CONTRACT_CHARS) problems.push(`the contract is over ${MAX_CONTRACT_CHARS} characters; keep quotes to the requirement sentence and descriptions short`);
586
- if (pages) problems.push(...contractBriefProblems(c, pages)); // #5428: page deliverables need page_gate briefs
631
+ if (pages) problems.push(...contractBriefProblems(c, pages, { readFile })); // #5428: page deliverables need page_gate briefs
587
632
  return { ok: problems.length === 0, problems };
588
633
  }
589
634
 
@@ -810,8 +855,8 @@ const ENV_SIGNATURES = [
810
855
  [/\bENOTFOUND\b|\bEAI_AGAIN\b|npm (?:ERR!|error) network|getaddrinfo (?:ENOTFOUND|EAI_AGAIN)/i, "network access for npm"],
811
856
  ];
812
857
  const envSignature = (out) => { const hit = ENV_SIGNATURES.find(([re]) => re.test(out)); return hit ? { tool: hit[1], kind: "environment" } : null; };
813
- const SECRET_PAIR_RE = /\b([A-Za-z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|API_?KEY|CREDENTIAL)[A-Za-z0-9_]*\s*[=:]\s*)\S+/gi;
814
- const SECRET_SHAPE_RE = /\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|sk-[A-Za-z0-9_-]{20,}|xox[baprs]-[A-Za-z0-9-]{10,}|AKIA[0-9A-Z]{16})\b|Bearer\s+[A-Za-z0-9._~+/=-]{12,}/g;
858
+ export const SECRET_PAIR_RE = /\b([A-Za-z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|API_?KEY|CREDENTIAL)[A-Za-z0-9_]*\s*[=:]\s*)\S+/gi;
859
+ export const SECRET_SHAPE_RE = /\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|sk-[A-Za-z0-9_-]{20,}|xox[baprs]-[A-Za-z0-9-]{10,}|AKIA[0-9A-Z]{16})\b|Bearer\s+[A-Za-z0-9._~+/=-]{12,}/g;
815
860
  /** #5371: the last `lines` lines of a command's output with secret-looking values redacted, as an indented block for a failure detail ("" when empty). */
816
861
  export function outputTail(output, lines = 40) {
817
862
  const t = String(output ?? "").replace(/\x1b\[[0-9;]*[A-Za-z]/g, "").split("\n").map((l) => l.trimEnd());
@@ -1017,6 +1062,23 @@ export function repoTracks(paths) {
1017
1062
  return (name) => segs.has(name) || segs.has(`${name}.py`);
1018
1063
  }
1019
1064
 
1065
+ /**
1066
+ * #5338: a changed file under the anchors of an active decision row (architecture choice or spike `Interfaces` row,
1067
+ * engine-authored preserve row) needs the builder's `result.preserve` row for it with status "intact"; a lane that really
1068
+ * changes the interface amends {kind:"decision", decision:{..., supersedes:"<id>"}}, which removes the row. Pure.
1069
+ */
1070
+ export function interfaceDecisionFailures(contract, result, changedFiles) {
1071
+ const out = [];
1072
+ for (const p of contract?.preserve ?? []) {
1073
+ if (p?.source !== "decision" || !Array.isArray(p.anchors)) continue;
1074
+ const hit = (changedFiles ?? []).filter((f) => p.anchors.some((a) => anchorMatches(a, f)));
1075
+ if (!hit.length) continue;
1076
+ const ack = (result?.preserve ?? []).find((x) => x?.id === p.id);
1077
+ if (ack?.status !== "intact") out.push({ code: C.CONFORMANCE_PRESERVE_VIOLATED, kind: "decision_unsuperseded", detail: `${p.id} (decision ${p.decision}): ${hit.slice(0, 3).join(", ")} changed under its anchors without a supersedes decision; report preserve ${p.id} intact, or amend {kind:"decision", decision:{choice, anchors, supersedes:"${p.decision}"}, why}` });
1078
+ }
1079
+ return out;
1080
+ }
1081
+
1020
1082
  /**
1021
1083
  * Deterministic checks before any reviewer tokens are spent: unauthorized files, failed or missing validation,
1022
1084
  * requirements not implemented, deferrals without a tracking issue, and unexempted hotspot growth. Returns {ok, failures[], superseded[]}; each failure carries a
@@ -1032,7 +1094,7 @@ export function repoTracks(paths) {
1032
1094
  * `ciCovered` (#4527): the validate ids accepted only because the head is CI-verified (no local result, or a missing host
1033
1095
  * tool), for the trajectory; always an array.
1034
1096
  */
1035
- export function precheck({ contract, result, changedFiles, ignore = [], ciVerified = false, hotspots = null, repro = null, validateRuns = null, repoHas = () => false, frozen = null, checkIds = null, baselineFailures = null, guardFailures = null, coupledFailures = null, relaxationFailures = null, routeFailures = null, docsFailures = null, pageFailures = null, docsPaths = null, prodParityFailures = null, newOffKeys = null, substitutedRuns = null, removedPaths = [], baseFiles = [], uiBrowser = null }) {
1097
+ export function precheck({ contract, result, changedFiles, ignore = [], ciVerified = false, hotspots = null, repro = null, validateRuns = null, repoHas = () => false, frozen = null, checkIds = null, baselineFailures = null, guardFailures = null, coupledFailures = null, relaxationFailures = null, routeFailures = null, docsFailures = null, pageFailures = null, docsPaths = null, prodParityFailures = null, seamFailures = null, newOffKeys = null, substitutedRuns = null, removedPaths = [], baseFiles = [], uiBrowser = null }) {
1036
1098
  const failures = [], superseded = [], ciCovered = [];
1037
1099
  // #4626: a post-deploy check id must be on the default branch or added by this PR (`checkIds`: ids of both checks files; null = not resolved)
1038
1100
  if (checkIds) for (const r of contract.requirements ?? []) {
@@ -1110,6 +1172,8 @@ export function precheck({ contract, result, changedFiles, ignore = [], ciVerifi
1110
1172
  failures.push(...(docsFailures ?? [])); // #5419: forge.yaml docs
1111
1173
  failures.push(...(pageFailures ?? [])); // #5428: forge.yaml pages
1112
1174
  failures.push(...(prodParityFailures ?? [])); // #5284: topology.prod_parity
1175
+ failures.push(...interfaceDecisionFailures(contract, result, changedFiles)); // #5338
1176
+ failures.push(...(seamFailures ?? [])); // #5338: a declared interface's provider and consumer no longer agree
1113
1177
  return { ok: failures.length === 0, failures, superseded, ciCovered };
1114
1178
  }
1115
1179
 
@@ -1132,8 +1196,10 @@ function frozenAmendedFiles(frozen, contract, outside, creep) {
1132
1196
  * #4334: HEAD=UNRUNNABLE or no words (the harness could not run the test) is env.repro_unrunnable, kind repro_env: an
1133
1197
  * environment error, never a builder resume.
1134
1198
  */
1135
- export function reproFailures(contract, { base, head } = {}) {
1199
+ export function reproFailures(contract, { base, head, pristine } = {}) {
1136
1200
  if (head === "RAN" && base === "FAILED") return [];
1201
+ // #5544: head's test passes on base source but the base's own version of it fails: a test-only fix, not already fixed
1202
+ if (head === "RAN" && base === "RAN" && pristine === "FAILED") return [];
1137
1203
  const t = contract?.repro_test ?? {};
1138
1204
  const name = [t.path, t.id].filter((x) => !blank(x)).join(" ") || "repro_test";
1139
1205
  if (!head || head === "UNRUNNABLE") {
@@ -1367,7 +1433,9 @@ export function checkCompleteness(rv, { contract, changedFiles, issueText, pathE
1367
1433
 
1368
1434
 
1369
1435
  /** #4726, #5339: a requirement quote that carries a `[type:e2e]` or `[type:manual]` criterion. */
1370
- const wantsE2e = (r) => /\[type:(?:e2e|manual)\]/i.test(String(r?.quote ?? ""));
1436
+ /** #5547: a tag inside a mid-sentence code span (`` `[type:e2e]` row whose ... ``) is a mention of the tag, not the tag; a trailing backticked tag still counts. */
1437
+ const tagText = (q) => String(q ?? "").replace(/`[^`\n]*`/g, (span, at, all) => (/[^\s.,;:)]/.test(all.slice(at + span.length).replace(/`[^`\n]*\[type:[^`\n]*`/g, "")) ? "" : span));
1438
+ const wantsE2e = (r) => /\[type:(?:e2e|manual)\]/i.test(tagText(r?.quote));
1371
1439
  /** #5339: failure kinds enforced without an `engine.conformance_kinds` entry (the entry still overrides). */
1372
1440
  // #5449: test_missing/test_weak are only generated for bug lanes (testadequacy.mjs), so enforcing the kinds is bug-only.
1373
1441
  const DEFAULT_ENFORCED_KINDS = ["e2e_row", "test_missing", "test_weak"];
@@ -1386,24 +1454,54 @@ export function isE2eCommand(command, e2e = null) {
1386
1454
  /** #5468: a `[type:e2e]`/`[type:manual]` quote whose observable only exists in production (live URL, deploy, prod probe); local stack, browser and sandbox wording is runnable pre-merge. */
1387
1455
  export function prodOnlyE2e(quote) {
1388
1456
  const q = String(quote ?? "");
1457
+ if (LIVE_INFRA_RE.test(q)) return true; // #5547
1389
1458
  if (/\b(?:localhost|127\.0\.0\.1|local stack|playwright|browser|sandbox|staging)\b/i.test(q)) return false;
1390
- return /https?:\/\//i.test(q) || /\b(?:after (?:the )?deploy|production|prod probe|live (?:domain|site)|prod)\b/i.test(q);
1459
+ return /https?:\/\//i.test(q) || /\b(?:after (?:the )?deploy|production|prod probe|live (?:domain|site)|prod)\b/i.test(q) || PROD_WINDOW_RE.test(q);
1391
1460
  }
1461
+ /** #5547: criteria whose run needs a live benchmark, a paid run, remote infra or host-level load: observable only outside the lane, by shape not by repo name. */
1462
+ const LIVE_INFRA_RE = /\b(?:live|paid|remote)\s+(?:benchmarks?|runs?|infra(?:structure)?|hosts?)\b|\bbench(?:mark)?[\w.-]*\.(?:mjs|js|py|sh)\b|\bre-?run\b[^.]{0,60}\bbench(?:mark)?\b|\b(?:sandbox pool|(?:remote|rented|cloud|gpu) (?:infra|hosts?|runners?|clusters?|boxe?s?|machines?|gpus?|pool)|on (?:a|the) (?:remote|rented|cloud|gpu) \w+)\b|\bsynthetic load\b|\b\d+\s*[×x]\s*(?:nproc|cores?|cpus?)\b|\bCPU hogs?\b|\bhost[- ]level (?:load|run)\b|\b[≤<]=?\s*[\d.]+\s*[×x]\s*(?:the\s+)?(?:control\s+)?cost\b/i;
1463
+ /** #5524: production observation windows without a URL: a metric/alert window, "at the next <weekday>", current volume, a prod host. */
1464
+ const PROD_WINDOW_RE = /\b(?:over|for|within|across)\s+(?:the\s+(?:last|next)\s+)?\d+\s*(?:h|hrs?|hours?|d|days?|w|weeks?|min|minutes?)\b|\bat the next (?:mon|tues?|wednes|thurs?|fri|sat(?:ur)?|sun)(?:day)?\b|\bat current (?:volume|traffic|load)\b|\bon (?:OVH|prod(?:uction)?)\b|\b\w*Slo\w*Burn\w*\b|\bSLO\b|\b(?:does not|doesn't|did not) fire\b/i;
1392
1465
  /**
1393
1466
  * #5468: rewrite production-only e2e/manual rows (deliver or defer; only `only` ids when given) to `post-deploy` with a generated
1394
- * check id. Pure; returns {contract, converted:[{id, check, entry}]}. A row whose quote names no probeable URL is left alone.
1467
+ * check id. Pure; returns {contract, converted:[{id, check, entry}]}. A row with no probeable URL becomes a checkless post-deploy row (check: null).
1395
1468
  */
1396
1469
  export function autoPostDeployE2e(contract, only = null) {
1397
1470
  const converted = [];
1398
1471
  const requirements = (Array.isArray(contract?.requirements) ? contract.requirements : []).map((r) => {
1399
1472
  if (!["deliver", "defer"].includes(r?.disposition) || !wantsE2e(r) || (only && !only.includes(r.id)) || isOutOfBand(r) || !prodOnlyE2e(r.quote)) return r;
1400
1473
  const g = e2eCheckFor(r.id, r.quote);
1401
- if (!g) return r;
1474
+ if (!g && LIVE_INFRA_RE.test(String(r.quote))) { // #5547: needs a paid/remote/host-level run: a checkless row for the orchestrator (its why names spend and a third-party host so deferChecklessPostDeploy routes it)
1475
+ converted.push({ id: r.id, check: null, entry: null });
1476
+ return { ...r, e2e_tracked: true, disposition: "post-deploy", bucket: "post-deploy", local_infeasible_why: "the run needs a live benchmark, paid run, remote infra or host-level load that no local fixture provides", why: "live benchmark/paid run/remote infra/host-level load: needs spend or a third-party host the lane cannot run; tracked by the orchestrator (#5547)" };
1477
+ }
1478
+ if (!g) { // #5524: no probeable URL: a checkless post-deploy row; deferChecklessPostDeploy routes it to the orchestrator
1479
+ converted.push({ id: r.id, check: null, entry: null });
1480
+ return { ...r, disposition: "post-deploy", bucket: "post-deploy", local_infeasible_why: "the observable is a production observation window with no probeable URL", why: "production observation window: read-only production telemetry, no probeable URL (#5524)" };
1481
+ }
1402
1482
  converted.push({ id: r.id, check: g.id, entry: g.entry });
1403
1483
  return { ...r, disposition: "post-deploy", bucket: "post-deploy", check: g.id, local_infeasible_why: "the observable exists only in production (live domain or deploy), so no local fixture can check it", why: "production-only e2e/manual criterion: converted by the engine to a post-deploy check (#5468)" };
1404
1484
  });
1405
1485
  return { contract: converted.length ? { ...contract, requirements } : contract, converted };
1406
1486
  }
1487
+ /**
1488
+ * #5547: apply trusted structured operator decisions (`<!-- FORGE:DECISION {"requirement":"R2","disposition":"post-deploy"} -->`) to a
1489
+ * frozen contract: a deliver/defer row becomes a checkless post-deploy row (deferChecklessPostDeploy then routes it). Only comments after
1490
+ * the last FORGE:CONTRACT comment count. Pure; returns {contract, applied:[id]}.
1491
+ */
1492
+ export function applyRequirementDecisions(contract, comments = []) {
1493
+ const list = Array.isArray(comments) ? comments : [];
1494
+ const at = list.map((c) => String(c?.body ?? "").trimStart().startsWith("<!-- FORGE:CONTRACT")).lastIndexOf(true);
1495
+ const ds = list.slice(at + 1).map((c) => parseRequirementDecision(c?.body)).filter(Boolean);
1496
+ const applied = [];
1497
+ const requirements = (Array.isArray(contract?.requirements) ? contract.requirements : []).map((r) => {
1498
+ const d = ds.find((x) => x.requirement === r?.id);
1499
+ if (!d || !["deliver", "defer"].includes(r.disposition)) return r;
1500
+ applied.push(r.id);
1501
+ return { ...r, e2e_tracked: true, disposition: "post-deploy", bucket: "post-deploy", local_infeasible_why: "operator decision: the run needs spend or a third-party host outside the lane", why: `operator FORGE:DECISION: tracked post-deploy by the orchestrator, needs spend or a third-party host${d.why ? ` (${d.why})` : ""} (#5547)` };
1502
+ });
1503
+ return { contract: applied.length ? { ...contract, requirements } : contract, applied };
1504
+ }
1407
1505
  /** #5468: the row ids named by `e2e_row` failures when every failure is one; null otherwise (anything else blocks as before). */
1408
1506
  export function loneE2eRows(failures) {
1409
1507
  const fs = failures ?? [];
@@ -1447,7 +1545,7 @@ export function decide(raw, ctx) {
1447
1545
  } else if (r.disposition === "deliver" && wantsE2e(r) && !e2eVerified(row, ctx.contract, ctx.e2e)) {
1448
1546
  const faked = (ctx.e2e?.faked ?? []).length ? `; faked or mocked components in ${ctx.e2e.faked.slice(0, 3).join(", ")}` : "";
1449
1547
  f.push({ code: C.CONFORMANCE_E2E_UNVERIFIED, kind: "e2e_row", detail: `${r.id} is a [type:e2e]/[type:manual] criterion but ${row.validated_by || "its validated_by"} is not a real end-to-end check (the repo's e2e set, Playwright/browser/live stack${faked}); run one, or mark ${r.id} post-deploy so it is transferred to the epic's acceptance${ctx.e2e?.sandboxes?.length ? `; it can run pre-merge: declare env: [${ctx.e2e.sandboxes.slice(0, 3).join(", ")}] on its validate to use the test sandbox (#5450), do not defer it` : ""}` });
1450
- } else if (r.disposition === "defer" && wantsE2e(r)) {
1548
+ } else if (r.disposition === "defer" && wantsE2e(r) && r.e2e_tracked !== true) { // #5547: an engine-tracked live-infra/operator-decided row is the transfer the gate asks for
1451
1549
  // #5339: a deferred e2e/manual requirement is not met; only a post-deploy one is transferred to the epic (the lane closes partial)
1452
1550
  f.push({ code: C.CONFORMANCE_E2E_UNVERIFIED, kind: "e2e_row", detail: `${r.id} is a [type:e2e]/[type:manual] criterion deferred without a run; run the real path, or mark ${r.id} post-deploy so it is transferred to the epic's acceptance` });
1453
1551
  }
@@ -3,7 +3,7 @@
3
3
  import { readFileSync } from "node:fs";
4
4
  import { describe, it } from "node:test";
5
5
  import assert from "node:assert/strict";
6
- import { testPlanProblems, proofEchoesDeliverable, outputTail, removedNamedPaths, removedPathsOf, shellSyntaxError, unrunnableValidate, noopCommand, substituteVerdict, describesUnrunnableCommand, vitestQuietFlag, normalizeRunnerCommand, cliUsageError, validateContract, applyAmendments, amendmentKindProblems, precheck, hotspotGrowth, reproFailures, reproQualityFailures, isBugIssue, parseReview, checkCompleteness, decide, closePlan, isInvestigation, formatShadowSummary, followupItems, inIssue, snapQuote, snapQuotes, isTestPath, normalizeEvidencePath, mergeReviewRows, reviewSkeleton, missingIds, resolveEvidencePath, movingBaseDiff, scopeText, evidencePathLine, evidencePathOnly, reaskable, matchCriterion, criterionLines, fillEngineRows, explainFailures, resolveForgedockPaths, missingTool, repoTracks, tmpdirInputs, isScopeCheck, isPureScopeCheck, dropScopeValidates, tagOutOfBand, outOfBandRequirements, isOutOfBand, followupMap, renderPendingFollowups, VERIFY_MODES, OUT_OF_BAND_RE, FOLLOWUP_CLASSES, followupClass, inLaneDeferral, pendingTracking, BUCKETS, bucketKind, bucketProblems, bucketTally, isE2eCommand, e2eVerified, impliedDocDeliverables, applyValidateRecipes, deferChecklessPostDeploy, substituteShellProblem, reproEnvMiss, ORCHESTRATOR_BUCKET, ownerRoute, weakenedE2eDecisions, guessedUvEnv, projectDirPathMiss, rewriteProjectDirCommand, convertDelivered } from "./conformance.mjs";
6
+ import { testPlanProblems, proofEchoesDeliverable, outputTail, removedNamedPaths, removedPathsOf, shellSyntaxError, unrunnableValidate, noopCommand, substituteVerdict, describesUnrunnableCommand, vitestQuietFlag, normalizeRunnerCommand, cliUsageError, validateContract, applyAmendments, amendmentKindProblems, precheck, hotspotGrowth, reproFailures, reproQualityFailures, isBugIssue, parseReview, checkCompleteness, decide, closePlan, isInvestigation, formatShadowSummary, followupItems, inIssue, snapQuote, snapQuotes, isTestPath, normalizeEvidencePath, mergeReviewRows, reviewSkeleton, missingIds, resolveEvidencePath, movingBaseDiff, scopeText, evidencePathLine, evidencePathOnly, reaskable, matchCriterion, criterionLines, fillEngineRows, explainFailures, resolveForgedockPaths, missingTool, repoTracks, tmpdirInputs, isScopeCheck, isPureScopeCheck, dropScopeValidates, tagOutOfBand, outOfBandRequirements, isOutOfBand, followupMap, renderPendingFollowups, VERIFY_MODES, OUT_OF_BAND_RE, FOLLOWUP_CLASSES, followupClass, inLaneDeferral, pendingTracking, BUCKETS, bucketKind, bucketProblems, bucketTally, isE2eCommand, e2eVerified, impliedDocDeliverables, applyValidateRecipes, deferChecklessPostDeploy, substituteShellProblem, reproEnvMiss, ORCHESTRATOR_BUCKET, ownerRoute, weakenedE2eDecisions, guessedUvEnv, projectDirPathMiss, rewriteProjectDirCommand, convertDelivered, mockedDeliverable, proofEchoDetail, contractRuleCounts, onlyTestPlanProblems } from "./conformance.mjs";
7
7
 
8
8
  const ISSUE = "## Requirements\n1. The scrape route must release the spend reservation on 429.\n2. The search route must release the spend reservation on 429.\n\n- [ ] Billing pricing is unchanged.";
9
9
  const Q1 = "The scrape route must release the spend reservation on 429.";
@@ -842,6 +842,14 @@ describe("repro_test on bug lanes (#4271)", () => {
842
842
  assert.match(reproFailures(k, { base: "SKIPPED", head: "FAILED" })[0].detail, /HEAD=FAILED \(base not run: head did not pass\)$/);
843
843
  assert.doesNotMatch(reproFailures(k, { base: "RAN", head: "RAN" })[0].detail, /base not run/);
844
844
  });
845
+ it("#5544 BASE=RAN HEAD=RAN PRISTINE=FAILED is a test-only fix: no repro_base_green, not already fixed", () => {
846
+ const k = { ...C, repro_test: RT };
847
+ const testOnly = ["test/leak.test.js"];
848
+ const pc = precheck({ contract: k, result: res, changedFiles: testOnly, repro: { base: "RAN", head: "RAN", pristine: "FAILED" } });
849
+ assert.equal(pc.failures.some((f) => f.kind === "repro_base_green"), false);
850
+ assert.equal(alreadyFixedOnBase(pc.failures, testOnly), false);
851
+ assert.deepEqual(reproFailures(k, { base: "RAN", head: "RAN", pristine: "RAN" }).map((f) => f.kind), ["repro_base_green"]);
852
+ });
845
853
  it("#5080 repro_base_green: BASE=RAN HEAD=RAN is its own kind, and a test-only diff with a source deliverable is never the fix", () => {
846
854
  const k = { ...C, repro_test: RT };
847
855
  const green = precheck({ contract: k, result: res, changedFiles: files, repro: { base: "RAN", head: "RAN" } });
@@ -1821,18 +1829,40 @@ describe("test plan frozen with the contract (#5445)", () => {
1821
1829
  assert.equal(bug(K([row("R1", { repro: "no-repro", reason: "spec-only change" }), row("R2")])), "");
1822
1830
  });
1823
1831
  it("a proof that echoes a deliverable is rejected; one about the 403 is accepted", () => {
1824
- assert.match(bug(K([row("R1", { proof: "the listing .json URL is rewritten to old.reddit.com" }), row("R2")])), /R1: test_plan proof only restates a deliverable/);
1832
+ assert.match(bug(K([row("R1", { proof: "the listing .json URL is rewritten to old.reddit.com" }), row("R2")])), /R1: test_plan proof restates a deliverable: ≥70% of the proof's words repeat deliverable D1 \(\d+%\); phrase it as the wrong behaviour observed on base/);
1825
1833
  assert.equal(proofEchoesDeliverable("the listing json URL is rewritten", D.slice(0, 1)), true);
1826
1834
  assert.equal(proofEchoesDeliverable("returns 200 JSON instead of 403", D.slice(0, 1)), false);
1835
+ assert.equal(proofEchoDetail("the listing json URL is rewritten", D.slice(0, 1)).id, "D1");
1836
+ });
1837
+ it("#5592: naming the function under test does not make a proof an echo; a blank repro gets a literal test id example", () => {
1838
+ const d = [{ id: "D1", path: "src/scrape.js", change: "fix fetchListing so the listing url uses old.reddit.com", requirements: ["R1"] }];
1839
+ assert.equal(proofEchoesDeliverable("`fetchListing` returns 403 for www.reddit.com", d), false);
1840
+ assert.equal(proofEchoesDeliverable("fetchListing() fetch_listing listing", d), false, "fewer than 3 prose words left: nothing to judge");
1841
+ assert.equal(proofEchoesDeliverable("the listing url uses old.reddit.com", d), true);
1842
+ assert.match(testPlanProblems(K([row("R1", { repro: "" })])).join(), /e\.g\. `tests\/test_scrape\.py::test_listing_returns_json`/);
1827
1843
  });
1828
1844
  it("level, its reason and the command are checked; mocking the bug's component is rejected", () => {
1829
1845
  assert.match(testPlanProblems(K([row("R1", { level: "manual" })])).join(), /level must be one of/);
1830
1846
  assert.match(testPlanProblems(K([row("R1", { level_reason: "" })])).join(), /level_reason/);
1831
- assert.match(testPlanProblems(K([row("R1", { level_reason: "mock the fetcher" })])).join(), /mocking the component/);
1847
+ assert.match(testPlanProblems(K([row("R1", { level_reason: "mock the listing URL rewrite" })])).join(), /level_reason mocks "mock the listing URL rewrite", which is in deliverable D1; level_reason must not contain the words mock\/stub\/fake unless negated/);
1848
+ for (const ok of ["real AsyncSession; stub only the Umami HTTP endpoint", "fake clock drives the expiry", "no mocks needed, real fixture"]) assert.equal(testPlanProblems(K([row("R1", { level_reason: ok })])).length, 0, ok);
1849
+ assert.equal(mockedDeliverable("stub the search handler", D.slice(0, 1)), null);
1850
+ assert.equal(mockedDeliverable("the scrape module is mocked", D.slice(0, 1)).id, "D1");
1832
1851
  assert.equal(testPlanProblems(K([row("R1", { level_reason: "no mocks needed, real fixture" })])).length, 0);
1833
1852
  assert.match(testPlanProblems(K([row("R1", { command: "" })])).join(), /exact command/);
1834
1853
  assert.match(testPlanProblems({ ...C, test_plan: "x" }).join(), /must be an array/);
1835
1854
  });
1855
+ it("#5587: rule ids are counted, the corrections carry the allowed level and the worked example, and only test-plan problems earn a second round", () => {
1856
+ const mock = testPlanProblems(K([row("R1", { level_reason: "mock the listing URL rewrite" }), row("R2", { proof: "the listing json URL is rewritten", command: "" })]));
1857
+ assert.match(mock.join("\n"), /real instance of D1's component, with stubs only at its I\/O boundary \(clock, network, browser factory\) and, for DB code, a real database session/);
1858
+ assert.deepEqual(contractRuleCounts(mock), { "test_plan.mock": 1, "test_plan.command": 1 });
1859
+ const echo = testPlanProblems(K([row("R1", { proof: "the listing json URL is rewritten to old.reddit.com" })]));
1860
+ assert.match(echo.join(), /symptom observed today → assertion that fails on base and passes on head, e\.g\./);
1861
+ assert.deepEqual(contractRuleCounts(echo), { "test_plan.echo": 1 });
1862
+ assert.equal(onlyTestPlanProblems(mock), true);
1863
+ assert.equal(onlyTestPlanProblems([...mock, "R1: quote is not verbatim"]), false);
1864
+ assert.equal(onlyTestPlanProblems([]), false);
1865
+ });
1836
1866
  it("applyValidateRecipes rewrites test_plan commands", () => {
1837
1867
  const r = applyValidateRecipes(K([row("R1")]), [{ match: "^node --test", replace: "npx node --test" }]);
1838
1868
  assert.equal(r.contract.test_plan[0].command, "npx node --test test/x.test.js");
@@ -1928,3 +1958,142 @@ describe("#5468 production-only e2e/manual criteria become post-deploy checks",
1928
1958
  assert.equal(o.a.run, "x"); assert.equal(o.b.run, "z");
1929
1959
  });
1930
1960
  });
1961
+
1962
+ import { interfaceDecisionFailures } from "./conformance.mjs";
1963
+ describe("interface decisions at precheck (#5338)", () => {
1964
+ const row = { id: "H1", what: "Interface api -> worker", source: "decision", decision: "i7-2", anchors: ["worker/refund.py", "api/"] };
1965
+ const c = { requirements: [], preserve: [row] };
1966
+ it("flags a changed anchored file without an intact preserve report", () => {
1967
+ const f = interfaceDecisionFailures(c, {}, ["worker/refund.py"]);
1968
+ assert.deepEqual(f.map((x) => x.kind), ["decision_unsuperseded"]);
1969
+ assert.match(f[0].detail, /supersedes:"i7-2"/);
1970
+ assert.equal(interfaceDecisionFailures(c, { preserve: [{ id: "H1", status: "violated" }] }, ["api/x.py"]).length, 1);
1971
+ });
1972
+ it("passes when acknowledged, superseded (row removed), or no anchored file changed", () => {
1973
+ assert.deepEqual(interfaceDecisionFailures(c, { preserve: [{ id: "H1", status: "intact" }] }, ["api/x.py"]), []);
1974
+ assert.deepEqual(interfaceDecisionFailures({ preserve: [] }, {}, ["api/x.py"]), []);
1975
+ assert.deepEqual(interfaceDecisionFailures(c, {}, ["web/a.ts"]), []);
1976
+ assert.deepEqual(interfaceDecisionFailures({ preserve: [{ ...row, anchors: ["db/"] }] }, {}, ["api/x.py"]), []);
1977
+ });
1978
+ it("precheck surfaces it and stays ok without interface rows", () => {
1979
+ const res = { requirements: [], validation: [] };
1980
+ assert.equal(precheck({ contract: { requirements: [], deliverables: [], preserve: [row] }, result: res, changedFiles: ["api/x.py"], ignore: ["api/x.py"] }).failures.some((x) => x.kind === "decision_unsuperseded"), true);
1981
+ assert.equal(precheck({ contract: { requirements: [], deliverables: [], preserve: [] }, result: res, changedFiles: [] }).failures.some((x) => x.kind === "decision_unsuperseded"), false);
1982
+ });
1983
+ });
1984
+ describe("#5524 URL-less production-only e2e/manual rows", () => {
1985
+ const Q40655 = "On OVH after deploy, a Monday report closed during the day is not re-created (verified at the next Monday) [type:manual]";
1986
+ const Q40662 = "T1 succeeded slow ratio < 0.05 over 24h, and `JobTurnaroundSloSlowBurn` does not fire at current volume for 7 days [type:manual]";
1987
+ const Q40486 = "Re-run the #38833 R3 probe after deploy [type:manual]";
1988
+ const LQ = "The signup page works against the local stack in a browser over 24h [type:e2e]";
1989
+ const mk = (quote) => ({ ...C, requirements: [{ id: "R1", quote, disposition: "deliver" }, C.requirements[1]] });
1990
+ it("#5524 prodOnlyE2e recognises observation windows", () => {
1991
+ for (const q of [Q40655, Q40662, Q40486, "ratio stays low over 24h [type:manual]", "no alert for 7 days [type:manual]", "restored at the next Tuesday [type:manual]", "holds at current volume [type:manual]", "runs on OVH [type:manual]"]) assert.equal(prodOnlyE2e(q), true, q);
1992
+ for (const q of [LQ, "works on staging for 7 days [type:e2e]", "sandbox run over 24h [type:e2e]"]) assert.equal(prodOnlyE2e(q), false, q);
1993
+ });
1994
+ it("#5524 URL-less production-only rows convert to checkless post-deploy", () => {
1995
+ for (const q of [Q40655, Q40662, Q40486]) {
1996
+ const out = autoPostDeployE2e(mk(q));
1997
+ assert.equal(out.converted.length, 1);
1998
+ assert.equal(out.converted[0].check, null);
1999
+ assert.equal(out.contract.requirements[0].disposition, "post-deploy");
2000
+ const d = deferChecklessPostDeploy(out.contract);
2001
+ assert.deepEqual(d.converted, ["R1"]);
2002
+ assert.equal(d.contract.requirements[0].disposition, "defer");
2003
+ assert.equal(d.contract.requirements[0].bucket, "owner:orchestrator");
2004
+ assert.equal(d.contract.requirements[1].disposition, "deliver");
2005
+ }
2006
+ });
2007
+ it("#5524 replay: URL rows keep a check id and a local-only quote stays deliver", () => {
2008
+ const out = autoPostDeployE2e(mk("`https://store.alterlab.io/x` returns 200 after deploy [type:e2e]"));
2009
+ assert.match(out.contract.requirements[0].check, /^e2e-r1-/);
2010
+ assert.equal(autoPostDeployE2e(mk(LQ)).converted.length, 0);
2011
+ assert.equal(autoPostDeployE2e(mk(LQ)).contract.requirements[0].disposition, "deliver");
2012
+ });
2013
+ it("#5524 review converts URL-less lone e2e_unverified", () => {
2014
+ const contract = { ...mk(Q40655), validate: [{ id: "V1", command: "pytest tests/test_x.py" }] };
2015
+ const lctx = { ...ctx, contract, issueText: `${ISSUE}\n${Q40655}` };
2016
+ const r = { ...good, issue_coverage: [{ quote: Q40655, status: "covered" }, ...good.issue_coverage.slice(1)] };
2017
+ const d = decide(r, lctx);
2018
+ assert.equal(d.state, "nonconforming");
2019
+ const ids = loneE2eRows(d.failures);
2020
+ assert.deepEqual(ids, ["R1"]);
2021
+ const cv = autoPostDeployE2e(contract, ids);
2022
+ assert.equal(cv.converted.length, ids.length);
2023
+ assert.equal(deferChecklessPostDeploy(cv.contract).contract.requirements[0].disposition, "defer");
2024
+ });
2025
+ });
2026
+ import { applyRequirementDecisions } from "./conformance.mjs";
2027
+ describe("#5547 live-infra, paid and host-load e2e rows", () => {
2028
+ const Q5541 = "re-run `bench-adversarial.mjs run … --arms full,control` on legion, ≤ 1.3× control cost [type:e2e]";
2029
+ const Q5531 = "Under a synthetic load of 4× nproc CPU hogs, `schedd status` answers in < 1 s [type:e2e]";
2030
+ const LOCAL = "The signup page works against the local stack in a browser under load [type:e2e]";
2031
+ const mk = (quote) => ({ ...C, requirements: [{ id: "R1", quote: Q1, disposition: "deliver" }, { id: "R2", quote, disposition: "deliver" }], validate: [{ id: "V1", command: "pytest tests/test_x.py" }] });
2032
+ it("#5547 prodOnlyE2e recognises live-infra shapes, not local rows", () => {
2033
+ for (const q of [Q5541, Q5531, "a paid run of the batch completes [type:manual]", "on a rented GPU box the job finishes [type:e2e]", "on the remote cluster the job finishes [type:e2e]", "a sandbox pool run passes [type:e2e]", "host-level load keeps p99 low [type:e2e]"]) assert.equal(prodOnlyE2e(q), true, q);
2034
+ for (const q of [LOCAL, "sandbox run over 24h [type:e2e]"]) assert.equal(prodOnlyE2e(q), false, q);
2035
+ });
2036
+ it("#5547 live-infra rows convert to a post-deploy defer owned by the orchestrator", () => {
2037
+ for (const q of [Q5541, Q5531]) {
2038
+ const out = autoPostDeployE2e(mk(q));
2039
+ assert.deepEqual(out.converted.map((x) => x.id), ["R2"]);
2040
+ const d = deferChecklessPostDeploy(out.contract);
2041
+ assert.deepEqual(d.converted, ["R2"]);
2042
+ assert.equal(d.contract.requirements[1].disposition, "defer");
2043
+ assert.equal(d.contract.requirements[1].bucket, "owner:orchestrator");
2044
+ assert.equal(d.contract.requirements[0].disposition, "deliver");
2045
+ }
2046
+ assert.equal(autoPostDeployE2e(mk(LOCAL)).converted.length, 0);
2047
+ });
2048
+ it("#5547 the classifier keys on shape, not on host or repo names", () => {
2049
+ for (const q of ["on myhost the job finishes [type:e2e]", "legion of users sign up locally [type:e2e]"]) assert.equal(prodOnlyE2e(q), false, q);
2050
+ });
2051
+ it("#5547 replay: #5531 R2 unchanged converts at review and the lane conforms", () => {
2052
+ const contract = mk(Q5531);
2053
+ const lctx = { ...ctx, contract, issueText: `${ISSUE}\n${Q5531}` };
2054
+ const r = { ...good, issue_coverage: [...good.issue_coverage, { quote: Q5531, status: "covered" }], requirements: [good.requirements[0], { id: "R2", status: "implemented", evidence: "src/search.js:7", validated_by: "V1" }] };
2055
+ const d = decide(r, lctx);
2056
+ assert.equal(d.state, "nonconforming");
2057
+ const ids = loneE2eRows(d.failures);
2058
+ assert.deepEqual(ids, ["R2"]);
2059
+ const eff = deferChecklessPostDeploy(autoPostDeployE2e(contract, ids).contract).contract;
2060
+ assert.equal(eff.requirements[1].disposition, "defer");
2061
+ const d2 = decide({ ...r, requirements: [good.requirements[0], { id: "R2", status: "deferred", evidence: "-", deferral_ok: true }] }, { ...lctx, contract: eff });
2062
+ assert.equal(d2.state, "conforms", JSON.stringify(d2.failures));
2063
+ });
2064
+ it("#5547 a quote that only mentions the tag in a mid-sentence code span is not an e2e row; a trailing backticked tag still is", () => {
2065
+ const R1 = "An `[type:e2e]`/`[type:manual]` row whose quote names a live benchmark, a paid run, remote infra (legion, computeshare, a sandbox pool) or host-level load is converted to a tracked `post-deploy` defer";
2066
+ assert.equal(autoPostDeployE2e(mk(R1)).converted.length, 0, "the mention is not converted to post-deploy");
2067
+ const contract = mk(R1);
2068
+ const lctx = { ...ctx, contract, issueText: `${ISSUE}\n${R1}` };
2069
+ const r = { ...good, issue_coverage: [...good.issue_coverage, { quote: R1, status: "covered" }], requirements: [good.requirements[0], { id: "R2", status: "implemented", evidence: "src/search.js:7", validated_by: "V1" }] };
2070
+ assert.ok(!decide(r, lctx).failures.some((f) => f.kind === "e2e_row"), "no e2e_unverified for a tag mention");
2071
+ assert.deepEqual(autoPostDeployE2e(mk("on a remote host the live benchmark finishes `[type:e2e]`")).converted.map((x) => x.id), ["R2"]);
2072
+ });
2073
+ it("#5547 a structured operator decision amends the frozen row; prose, untargeted and delivered-elsewhere rows are untouched", () => {
2074
+ const contract = mk(Q5531);
2075
+ const dec = (j) => ({ body: `<!-- FORGE:DECISION ${JSON.stringify(j)} -->\n## Decision` });
2076
+ const out = applyRequirementDecisions(contract, [{ body: "<!-- FORGE:CONTRACT -->\n{}" }, dec({ requirement: "R2", disposition: "post-deploy" }), { body: "FORGE:DECISION prose" }]);
2077
+ assert.deepEqual(out.applied, ["R2"]);
2078
+ assert.equal(out.contract.requirements[1].disposition, "post-deploy");
2079
+ assert.equal(deferChecklessPostDeploy(out.contract).contract.requirements[1].bucket, "owner:orchestrator");
2080
+ assert.equal(out.contract.requirements[0].disposition, "deliver");
2081
+ assert.equal(applyRequirementDecisions(contract, [dec({ requirement: "R2", disposition: "deliver" })]).applied.length, 0);
2082
+ assert.equal(applyRequirementDecisions(contract, [dec({ requirement: "R2", disposition: "post-deploy" }), { body: "<!-- FORGE:CONTRACT -->\n{}" }]).applied.length, 0, "a decision older than the contract is ignored");
2083
+ });
2084
+ });
2085
+
2086
+ describe("#5623: builder-correctable contract problems", () => {
2087
+ it("contractSelfCorrectable: shape problems are builder-correctable; a quote-only mismatch is not", async () => {
2088
+ const { contractSelfCorrectable } = await import("./lean.mjs");
2089
+ assert.equal(contractSelfCorrectable(["R7: test_plan no-repro needs a reason the reviewer can reject"]), true);
2090
+ assert.equal(contractSelfCorrectable(["R1: quote is not verbatim", "R7: test_plan no-repro needs a reason the reviewer can reject"]), true);
2091
+ assert.equal(contractSelfCorrectable(["R1: quote is not verbatim"]), false);
2092
+ assert.equal(contractSelfCorrectable([]), false);
2093
+ });
2094
+ it("classifyNeedsHuman: contract.invalid is recoverable (one fresh-plan requeue), with or without an issue edit", async () => {
2095
+ const { classifyNeedsHuman, OUTCOME_CODES } = await import("../engine/outcome-codes.mjs");
2096
+ assert.equal(classifyNeedsHuman({ outcome: "needs-human", code: OUTCOME_CODES.CONTRACT_INVALID }), "recoverable");
2097
+ assert.equal(classifyNeedsHuman({ outcome: "needs-human", code: OUTCOME_CODES.CONTRACT_INVALID, issueEdited: true }), "recoverable");
2098
+ });
2099
+ });