forgedock 1.54.1 → 1.55.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.
- package/bin/engine/events.mjs +1 -0
- package/bin/engine/events.test.mjs +5 -1
- package/bin/engine/outcome-codes.mjs +3 -0
- package/bin/engine-cli.mjs +126 -34
- package/bin/forgedock.mjs +54 -2
- package/bin/gc-schedule.mjs +83 -0
- package/bin/gc.mjs +56 -8
- package/bin/help-text.mjs +1 -1
- package/bin/hooks/pre-tool-use.mjs +1 -0
- package/bin/init-detect.mjs +73 -2
- package/bin/labels.json +5 -0
- package/bin/lean/admission.mjs +21 -1
- package/bin/lean/baselines.mjs +43 -0
- package/bin/lean/baselines.test.mjs +33 -0
- package/bin/lean/batch-health.mjs +43 -6
- package/bin/lean/batch-health.test.mjs +41 -1
- package/bin/lean/batch.mjs +41 -4
- package/bin/lean/batch.test.mjs +106 -3
- package/bin/lean/conformance.mjs +131 -12
- package/bin/lean/conformance.test.mjs +172 -3
- package/bin/lean/depcache.mjs +23 -2
- package/bin/lean/depcache.test.mjs +22 -0
- package/bin/lean/docsgate.mjs +137 -0
- package/bin/lean/docsgate.test.mjs +78 -0
- package/bin/lean/effects.mjs +31 -2
- package/bin/lean/enumerating.mjs +39 -13
- package/bin/lean/enumerating.test.mjs +20 -0
- package/bin/lean/execution.test.mjs +3 -3
- package/bin/lean/fastforward.mjs +93 -0
- package/bin/lean/fastforward.test.mjs +73 -0
- package/bin/lean/guardgate.mjs +38 -7
- package/bin/lean/guardgate.test.mjs +39 -0
- package/bin/lean/issuewatch-install.mjs +92 -0
- package/bin/lean/issuewatch-install.test.mjs +31 -0
- package/bin/lean/issuewatch-parity.mjs +33 -3
- package/bin/lean/issuewatch-parity.test.mjs +30 -5
- package/bin/lean/issuewatch-reconcile.mjs +123 -0
- package/bin/lean/issuewatch-reconcile.test.mjs +30 -0
- package/bin/lean/issuewatch-verify.mjs +51 -9
- package/bin/lean/issuewatch.mjs +153 -33
- package/bin/lean/issuewatch.test.mjs +243 -22
- package/bin/lean/lean.mjs +381 -75
- package/bin/lean/lean.test.mjs +437 -20
- package/bin/lean/light.mjs +11 -3
- package/bin/lean/light.test.mjs +27 -0
- package/bin/lean/lightlane.mjs +8 -3
- package/bin/lean/lightlane.test.mjs +20 -0
- package/bin/lean/mechfix.mjs +21 -2
- package/bin/lean/mechfix.test.mjs +28 -1
- package/bin/lean/orchestrate-children.test.mjs +10 -0
- package/bin/lean/orchestrate-owned.test.mjs +73 -0
- package/bin/lean/orchestrate.mjs +28 -4
- package/bin/lean/overlap.mjs +20 -0
- package/bin/lean/overlap.test.mjs +49 -0
- package/bin/lean/pagegate.mjs +152 -0
- package/bin/lean/pagegate.test.mjs +77 -0
- package/bin/lean/parked-relabel.mjs +32 -0
- package/bin/lean/parked-relabel.test.mjs +45 -0
- package/bin/lean/phaseledger.mjs +17 -2
- package/bin/lean/postdeploy-check.mjs +27 -0
- package/bin/lean/postdeploy-check.test.mjs +13 -1
- package/bin/lean/postrun.mjs +32 -0
- package/bin/lean/postrun.test.mjs +41 -0
- package/bin/lean/preflight.mjs +46 -0
- package/bin/lean/preflight.test.mjs +30 -1
- package/bin/lean/prompts.mjs +36 -6
- package/bin/lean/recovery.test.mjs +16 -0
- package/bin/lean/release.mjs +23 -2
- package/bin/lean/release.test.mjs +28 -1
- package/bin/lean/render.mjs +17 -6
- package/bin/lean/reproquality.mjs +116 -0
- package/bin/lean/reproquality.test.mjs +85 -0
- package/bin/lean/review-trigger.mjs +8 -3
- package/bin/lean/sandbox-budget.test.mjs +27 -0
- package/bin/lean/schedd.mjs +40 -11
- package/bin/lean/schedd.test.mjs +12 -1
- package/bin/lean/testadequacy.mjs +97 -0
- package/bin/lean/testadequacy.test.mjs +92 -0
- package/bin/lean/testsandbox.mjs +202 -0
- package/bin/lean/testsandbox.test.mjs +157 -0
- package/bin/lean/toolplace.mjs +5 -2
- package/bin/lean/toolplace.test.mjs +6 -0
- package/bin/lean/verify.mjs +6 -1
- package/bin/lean/verify.test.mjs +18 -2
- package/bin/lean/warmtree.mjs +77 -0
- package/bin/lean/warmtree.test.mjs +81 -0
- package/bin/stats/conformance-outcomes.mjs +12 -2
- package/bin/stats/depth.mjs +24 -1
- package/bin/stats/depth.test.mjs +21 -1
- package/bin/stats/index.mjs +5 -2
- package/bin/stats/query.mjs +2 -1
- package/commands/cleanup.md +18 -0
- package/commands/fd-introspect.md +19 -0
- package/commands/milestone.md +5 -1
- package/commands/pipeline-health/phase-2-metrics.md +4 -0
- package/commands/recover-orphans.md +31 -1
- package/commands/review-pr-staging.md +9 -0
- package/commands/review-pr.md +2 -0
- package/docs/CONFIG.md +26 -1
- package/docs/EVENTS.md +1 -0
- package/docs/ISSUE-WATCH.md +12 -3
- package/docs/eval/adversarial-bench.md +1 -1
- package/docs/eval/published/adversarial-2026-11-11.md +58 -0
- package/package.json +1 -1
- package/scripts/bench-lightlane.mjs +3 -2
- package/scripts/hotspots.sh +7 -4
- package/scripts/hotspots.test.sh +12 -0
- package/scripts/recover-orphans-stateless.test.sh +79 -0
- package/scripts/transition-label.sh +2 -0
- package/templates/workflows/forgedock-reopen-clean.yml +33 -0
|
@@ -8,7 +8,7 @@ import { tmpDir } from "../tests/_tmp.mjs";
|
|
|
8
8
|
import { openBatch } from "./batch.mjs";
|
|
9
9
|
import { DEFAULT_HEALTH, parseHealthConfig, rootsOf, evaluateHealth, formatAlert, runCheck, scheduleChecks, scheduleLine, runNotify, deliverAlert,
|
|
10
10
|
resolvedOnGithub, recordRefusal, readRefusals, statusLines, REFUSAL_KEEP,
|
|
11
|
-
evaluateDispatchStall, firstHourReport, writeFirstHour, readFirstHour, recordStallAlert, summaryLines } from "./batch-health.mjs";
|
|
11
|
+
evaluateDispatchStall, firstHourReport, writeFirstHour, readFirstHour, recordStallAlert, summaryLines, statelessNeedsHuman, statelessOnGithub } from "./batch-health.mjs";
|
|
12
12
|
|
|
13
13
|
// #1 and #3 are roots; #2 depends on #1, #4 on #3.
|
|
14
14
|
const base = (results, extra = {}) => ({ order: [1, 2, 3, 4], deps: { 2: [1], 4: [3] }, results, running: {}, pending: [], ...extra });
|
|
@@ -240,3 +240,43 @@ describe("#5314 dispatch stall and first-hour report", () => {
|
|
|
240
240
|
assert.ok(summaryLines(root, { now: Date.parse(new Date(NOW).toISOString()) }).some((l) => /DISPATCH STALLED/.test(l)));
|
|
241
241
|
});
|
|
242
242
|
});
|
|
243
|
+
|
|
244
|
+
describe("#5466 statelessNeedsHuman", () => {
|
|
245
|
+
const nh = ["<!-- FORGE:NEEDS_HUMAN -->\nx"];
|
|
246
|
+
it("flags an open issue with a NEEDS_HUMAN comment and no state label", () => {
|
|
247
|
+
assert.deepEqual(statelessNeedsHuman([
|
|
248
|
+
{ number: 1, state: "OPEN", labels: ["bug"], comments: nh },
|
|
249
|
+
{ number: 2, state: "OPEN", labels: ["parked:ci.red"], comments: nh },
|
|
250
|
+
{ number: 3, state: "OPEN", labels: ["needs-human"], comments: nh },
|
|
251
|
+
{ number: 4, state: "CLOSED", labels: [], comments: nh },
|
|
252
|
+
{ number: 5, state: "OPEN", labels: [], comments: ["hello"] },
|
|
253
|
+
]), [1]);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
describe("#5466 stateless issues surface in the batch health check", () => {
|
|
258
|
+
it("evaluateHealth reports a stateless cause; statelessOnGithub reads labels and comments", async () => {
|
|
259
|
+
const h = evaluateHealth(base({ 1: { outcome: "merged" } }), { stateless: [2] });
|
|
260
|
+
assert.equal(h.healthy, false);
|
|
261
|
+
assert.equal(h.causes[0].code, "stateless");
|
|
262
|
+
const gh = async (a) => JSON.stringify(a[2] === "1" ? { state: "OPEN", labels: [], comments: [{ body: "<!-- FORGE:NEEDS_HUMAN -->" }] } : { state: "OPEN", labels: [{ name: "needs-human" }], comments: [{ body: "<!-- FORGE:NEEDS_HUMAN -->" }] });
|
|
263
|
+
assert.deepEqual(await statelessOnGithub({ order: [1, 2] }, gh, "o/r"), [1]);
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
describe("#5469: holds in health and the first-hour report", () => {
|
|
268
|
+
const since = (h) => new Date(Date.now() - h * 3600000).toISOString();
|
|
269
|
+
it("#5469: a hold older than holdHours is a stale-hold cause; a recent or legacy hold is not", () => {
|
|
270
|
+
const st = base({ 1: { outcome: "merged" } }, { pending: [3], running: { 4: {} } });
|
|
271
|
+
const stale = evaluateHealth(st, { held: [3], holdInfo: { 3: { owner: "op@h", since: since(5) } }, batchId: "b1" });
|
|
272
|
+
assert.equal(stale.healthy, false);
|
|
273
|
+
assert.deepEqual(stale.causes.map((c) => c.code), ["stale-hold"]);
|
|
274
|
+
assert.match(stale.causes[0].detail, /#3 \(op@h, since /);
|
|
275
|
+
assert.equal(evaluateHealth(st, { held: [3], holdInfo: { 3: { owner: "op@h", since: since(1) } } }).healthy, true);
|
|
276
|
+
assert.equal(evaluateHealth(st, { held: [3] }).healthy, true, "a legacy hold has no age");
|
|
277
|
+
});
|
|
278
|
+
it("the first-hour report lists a held issue as held (owner, since)", () => {
|
|
279
|
+
const rep = firstHourReport(base({}, { pending: [3] }), { batchId: "b1", held: [3], holdInfo: { 3: { owner: "op@h", since: "2026-11-11T00:00:00.000Z" } } });
|
|
280
|
+
assert.match(rep.summary, /#3 held \(op@h, since 2026-11-11T00:00:00.000Z\)/);
|
|
281
|
+
});
|
|
282
|
+
});
|
package/bin/lean/batch.mjs
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { appendFileSync, chmodSync, closeSync, existsSync, fchmodSync, fsyncSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeSync } from "node:fs";
|
|
19
19
|
import { spawn } from "node:child_process";
|
|
20
|
-
import { homedir } from "node:os";
|
|
20
|
+
import { homedir, hostname } from "node:os";
|
|
21
21
|
import { dirname, join, resolve, sep } from "node:path";
|
|
22
22
|
import { sanitizeOverride, validateExecutionPatch } from "./live-execution.mjs";
|
|
23
23
|
|
|
@@ -97,6 +97,13 @@ const readRequeueFile = (file) => {
|
|
|
97
97
|
};
|
|
98
98
|
|
|
99
99
|
/** The positive integers among `list` (numbers, `7`, `#7`). */
|
|
100
|
+
/** #5469: the `hold-info` file as an object; {} when missing or invalid. */
|
|
101
|
+
const readHoldInfo = (file) => { try { const v = JSON.parse(readFileSync(file, "utf8")); return v && typeof v === "object" && !Array.isArray(v) ? v : {}; } catch { return {}; } };
|
|
102
|
+
/** #5469: the hold owner's session pid is known, on this host, and no longer alive. */
|
|
103
|
+
const ownerGone = (e) => {
|
|
104
|
+
if (!Number.isSafeInteger(e?.ownerPid) || e.ownerPid < 1 || (e.ownerHost && e.ownerHost !== hostname())) return false;
|
|
105
|
+
try { process.kill(e.ownerPid, 0); return false; } catch (err) { return err?.code === "ESRCH"; }
|
|
106
|
+
};
|
|
100
107
|
const ints = (list) => (Array.isArray(list) ? list : []).map((x) => (typeof x === "number" ? x : typeof x === "string" && /^#?\d+$/.test(x.trim()) ? parseInt(x.trim().replace("#", ""), 10) : NaN)).filter((n) => Number.isSafeInteger(n) && n > 0);
|
|
101
108
|
|
|
102
109
|
export function newBatchId(now = Date.now(), pid = process.pid) {
|
|
@@ -131,7 +138,7 @@ export function batchesOwning(root, repo, issue, { exceptId = null, now = Date.n
|
|
|
131
138
|
if (b.readCancel()) { out.push({ id, cancelled: true, running }); continue; }
|
|
132
139
|
const last = b.lastProgressMs();
|
|
133
140
|
const live = !b.readReport() && last !== null && now - last <= staleMs;
|
|
134
|
-
if (live && (running || (Array.isArray(st.pending) && st.pending.includes(issue)))) out.push({ id, cancelled: false, running });
|
|
141
|
+
if (live && (running || (Array.isArray(st.pending) && st.pending.includes(issue)) || b.readHeld().includes(issue))) out.push({ id, cancelled: false, running });
|
|
135
142
|
}
|
|
136
143
|
return out;
|
|
137
144
|
}
|
|
@@ -143,6 +150,14 @@ export const cancelledOwners = (root, repo, issue, exceptId = null, opts = {}) =
|
|
|
143
150
|
/** #5241: the id of an active (uncancelled) batch of `repo` already holding `issue`, else null. */
|
|
144
151
|
export const activeBatchOf = (root, repo, issue, opts = {}) => batchesOwning(root, repo, issue, opts).find((o) => !o.cancelled)?.id ?? null;
|
|
145
152
|
|
|
153
|
+
/** #5471: the id of another live batch of `repo` that has `issue` pending, running or held (`exceptId` = the asking batch), else null. */
|
|
154
|
+
export const ownerOf = (root, repo, issue, exceptId = null, opts = {}) => activeBatchOf(root, repo, issue, { ...opts, exceptId });
|
|
155
|
+
/** #5471: the batch that wins `issue` at dispatch: one running it, else one holding it pending/held with a lower id (so two batches never both defer). */
|
|
156
|
+
export const dispatchOwner = (root, repo, issue, exceptId, opts = {}) => {
|
|
157
|
+
const live = batchesOwning(root, repo, issue, { ...opts, exceptId }).filter((o) => !o.cancelled);
|
|
158
|
+
return (live.find((o) => o.running) ?? live.find((o) => o.id < exceptId))?.id ?? null;
|
|
159
|
+
};
|
|
160
|
+
|
|
146
161
|
/** Handle on one batch directory. */
|
|
147
162
|
export function openBatch(root, id) {
|
|
148
163
|
if (!ID_RE.test(String(id ?? ""))) throw new Error(`invalid batch id ${JSON.stringify(id)}`);
|
|
@@ -249,18 +264,40 @@ export function openBatch(root, id) {
|
|
|
249
264
|
readHeld: () => readAdded(f("hold")),
|
|
250
265
|
/** #4656: gates waiting on issues (`gates` file: [{ name, waitsOn: [n...], since? }], written by the ship/settle pre-flight); [] when missing or invalid. */
|
|
251
266
|
readGates: () => { const v = readJson(f("gates")); return Array.isArray(v) ? v.filter((g) => g && typeof g.name === "string" && Array.isArray(g.waitsOn)) : []; },
|
|
252
|
-
/**
|
|
253
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Merge the positive integers of `list` into the `hold` file. #5469: `meta` ({owner, ownerPid, ownerHost, forMs, reason}) is
|
|
269
|
+
* recorded per newly held issue in the `hold-info` file as {owner, since, expiresAt|null, reason, ownerPid, ownerHost}.
|
|
270
|
+
* @returns {number[]} the issues newly held
|
|
271
|
+
*/
|
|
272
|
+
holdIssues: (list, meta = null) => {
|
|
254
273
|
const have = new Set(readAdded(f("hold")));
|
|
255
274
|
const added = [...new Set(ints(list))].filter((n) => !have.has(n)).sort((a, b) => a - b);
|
|
256
275
|
if (added.length) put(f("hold"), JSON.stringify([...have, ...added].sort((a, b) => a - b)) + "\n");
|
|
276
|
+
if (added.length && meta) {
|
|
277
|
+
const now = Date.now(), info = readHoldInfo(f("hold-info"));
|
|
278
|
+
for (const n of added) info[n] = { owner: String(meta.owner ?? "operator"), since: new Date(now).toISOString(), expiresAt: Number(meta.forMs) > 0 ? new Date(now + Number(meta.forMs)).toISOString() : null, reason: meta.reason ? String(meta.reason) : null, ownerPid: Number.isSafeInteger(meta.ownerPid) ? meta.ownerPid : null, ownerHost: meta.ownerHost ?? null };
|
|
279
|
+
put(f("hold-info"), JSON.stringify(info) + "\n");
|
|
280
|
+
}
|
|
257
281
|
return added;
|
|
258
282
|
},
|
|
283
|
+
/** #5469: `{issue: {owner, since, expiresAt, reason, ownerPid, ownerHost}}` for held issues; {} when missing, invalid or a legacy hold. */
|
|
284
|
+
readHoldInfo: () => { const held = new Set(readAdded(f("hold"))), info = readHoldInfo(f("hold-info")); return Object.fromEntries(Object.entries(info).filter(([n]) => held.has(Number(n)))); },
|
|
285
|
+
/** #5469: release every hold whose `expiresAt` has passed. @returns {Array<{issue, owner, since, reason, ownerGone}>} (`ownerGone`: the owner's session pid is dead on this host) */
|
|
286
|
+
expireHolds: (now = Date.now()) => {
|
|
287
|
+
const info = readHoldInfo(f("hold-info")), held = new Set(readAdded(f("hold")));
|
|
288
|
+
const due = Object.entries(info).filter(([n, e]) => held.has(Number(n)) && e.expiresAt && Date.parse(e.expiresAt) <= now).map(([n, e]) => ({ issue: Number(n), ...e }));
|
|
289
|
+
if (!due.length) return [];
|
|
290
|
+
const out = due.map((e) => ({ issue: e.issue, owner: e.owner, since: e.since, reason: e.reason ?? null, ownerGone: ownerGone(e) }));
|
|
291
|
+
self.releaseIssues(due.map((e) => e.issue));
|
|
292
|
+
return out;
|
|
293
|
+
},
|
|
259
294
|
/** Remove `list` from the `hold` file. @returns {number[]} the issues that were held */
|
|
260
295
|
releaseIssues: (list) => {
|
|
261
296
|
const have = new Set(readAdded(f("hold")));
|
|
262
297
|
const freed = [...new Set(ints(list))].filter((n) => have.has(n)).sort((a, b) => a - b);
|
|
263
298
|
if (freed.length) put(f("hold"), JSON.stringify([...have].filter((n) => !freed.includes(n)).sort((a, b) => a - b)) + "\n");
|
|
299
|
+
const info = readHoldInfo(f("hold-info"));
|
|
300
|
+
if (freed.some((n) => info[n])) { for (const n of freed) delete info[n]; put(f("hold-info"), JSON.stringify(info) + "\n"); }
|
|
264
301
|
return freed;
|
|
265
302
|
},
|
|
266
303
|
/** `--cancel` (#4376): `{at, reason, stopRemote?}` in the `cancel` file; the runner re-reads it every pass. `stopRemote` (#4612) also asks remote lanes to stop at their checkpoint. */
|
package/bin/lean/batch.test.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
6
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, utimesSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
9
9
|
import { resolveLane, makeLaneCache } from "./lane.mjs";
|
|
@@ -357,9 +357,9 @@ describe("#4318: the batch dispatcher's signal relabel and the needs-human relab
|
|
|
357
357
|
});
|
|
358
358
|
it("#4736: a mechanical park creates its parked:<code> label before the edit", async () => {
|
|
359
359
|
const calls = [];
|
|
360
|
-
const gh = async (a) => { calls.push(a.slice(0, 3).join(" ")); return a[1] === "view" ? JSON.stringify({ state: "OPEN", body: "" }) : ""; };
|
|
360
|
+
const gh = async (a) => { calls.push(a.slice(0, 3).join(" ")); return a[1] === "view" ? JSON.stringify({ state: "OPEN", body: "", labels: [{ name: "parked:ci.red" }, { name: "remediation-queue" }] }) : ""; };
|
|
361
361
|
assert.equal(await makeRelabelNeedsHuman({ gh, repo: "o/r", now: () => 1000 })({ issue: 7, evidence: "e", parked: { code: "ci.red", pr: 3 } }), true);
|
|
362
|
-
assert.deepEqual(calls.slice(0, 3), ["issue view 7", "label create parked:ci.red", "
|
|
362
|
+
assert.deepEqual(calls.slice(0, 3), ["issue view 7", "label create parked:ci.red", "label create remediation-queue"]);
|
|
363
363
|
});
|
|
364
364
|
});
|
|
365
365
|
|
|
@@ -376,6 +376,20 @@ describe("#4318: the batch dispatcher's signal relabel and the needs-human relab
|
|
|
376
376
|
} finally { console.log = l; }
|
|
377
377
|
assert.doesNotMatch(out.join("\n"), /remediation queue/);
|
|
378
378
|
});
|
|
379
|
+
it("#5466: a failed parked relabel is reported as a batch event", async () => {
|
|
380
|
+
const evs = [];
|
|
381
|
+
const leanIo = { gh: async (a) => (a.includes("milestone") ? JSON.stringify({ milestone: null }) : JSON.stringify({ body: "" })), git: async (a) => (a[0] === "ls-remote" ? "abc\trefs/heads/staging\n" : "") };
|
|
382
|
+
const l = console.log;
|
|
383
|
+
console.log = (...x) => evs.push(x.join(" "));
|
|
384
|
+
try {
|
|
385
|
+
await orchestrateFromCli(["1", "--parallel", "1", "--repo", "o/r", "--no-prefilter"], { dir: tmpDir("pf-"), batchRoot: tmpDir("pf-batch-"), allowTmpfs: true,
|
|
386
|
+
emitTelemetry: async () => {}, io: { gh: async () => "o/r\n" }, leanIo, sched: null, decide: () => {},
|
|
387
|
+
orchestration: { breaker: null, maxDeferrals: 3, globalParallel: null, recovery: { maxAttempts: 1 } },
|
|
388
|
+
relabelNeedsHuman: async (x) => (x.parked ? "failed" : true),
|
|
389
|
+
leanModule: { runCore: async () => ({ terminalReason: "needs-human", code: "ci.red", detail: "x", pr: 5 }) } });
|
|
390
|
+
} finally { console.log = l; }
|
|
391
|
+
assert.match(evs.join("\n"), /relabel\.failed|parked relabel failed/);
|
|
392
|
+
});
|
|
379
393
|
});
|
|
380
394
|
|
|
381
395
|
describe("#4354: the batch report ends with the fail-soft alerts of the batch's repo", () => {
|
|
@@ -1745,3 +1759,92 @@ describe("#5168: --requeue accepts engine-error; a claude login failure is held,
|
|
|
1745
1759
|
});
|
|
1746
1760
|
|
|
1747
1761
|
function readdirSyncSafe(d) { try { return readdirSync(d).filter((n) => !n.endsWith(".json")); } catch { return []; } }
|
|
1762
|
+
|
|
1763
|
+
describe("#5469: holds carry an owner and an expiry", () => {
|
|
1764
|
+
it("#5469: an expired hold is re-admitted", async () => {
|
|
1765
|
+
let saved = null, held = [2], free, expired = false;
|
|
1766
|
+
const gate = new Promise((r) => { free = r; });
|
|
1767
|
+
const store = { load: () => saved, save: (s) => { saved = s; }, log: () => {} };
|
|
1768
|
+
const started = [], log = [];
|
|
1769
|
+
const done = orchestrate({ issues: [1, 2], parallel: 2, pollMs: 5, readBody: async () => "", store, getHeld: () => held, onUpdate: (r) => log.push(r),
|
|
1770
|
+
expireHolds: () => { if (!expired) return []; expired = false; held = []; return [{ issue: 2, owner: "op@h", since: "2026-11-11T00:00:00.000Z", reason: "hand-build", ownerGone: true }]; },
|
|
1771
|
+
runOne: async (n) => { started.push(n); if (n === 1) await gate; return { terminalReason: "merged" }; } });
|
|
1772
|
+
await until(() => started.includes(1));
|
|
1773
|
+
await new Promise((r) => setTimeout(r, 30));
|
|
1774
|
+
assert.deepEqual(started, [1], "held until it expires");
|
|
1775
|
+
expired = true;
|
|
1776
|
+
try { await until(() => started.includes(2), 3000); } finally { free(); } // a failure frees the gate so the run ends instead of hanging
|
|
1777
|
+
assert.deepEqual((await done).map((r) => [r.issue, r.outcome]), [[1, "merged"], [2, "merged"]]);
|
|
1778
|
+
assert.ok(log.some((r) => r.outcome === "hold-expired" && /#2 \(op@h/.test(r.detail)));
|
|
1779
|
+
assert.ok(log.some((r) => r.outcome === "hold-alert" && /owner session \(op@h\) is gone/.test(r.detail)), "a dead owner session raises an alert row");
|
|
1780
|
+
});
|
|
1781
|
+
|
|
1782
|
+
it("#5469: a finished batch with only a held issue waits for the expiry, re-admits it, and alerts when the owner is gone", async () => {
|
|
1783
|
+
let saved = null, held = [2], due = false;
|
|
1784
|
+
const store = { load: () => saved, save: (st) => { saved = st; }, log: () => {} };
|
|
1785
|
+
const started = [], log = [];
|
|
1786
|
+
const info = { 2: { owner: "op@h", since: "2026-11-11T00:00:00.000Z", expiresAt: "2026-11-11T04:00:00.000Z" } };
|
|
1787
|
+
const done = orchestrate({ issues: [1, 2], parallel: 2, pollMs: 5, readBody: async () => "", store, getHeld: () => held, getHoldInfo: () => (held.length ? info : {}), onUpdate: (r) => log.push(r),
|
|
1788
|
+
expireHolds: () => { if (!due) return []; due = false; held = []; return [{ issue: 2, owner: "op@h", since: info[2].since, reason: null, ownerGone: true }]; },
|
|
1789
|
+
runOne: async (n) => { started.push(n); return { terminalReason: "merged" }; } });
|
|
1790
|
+
try {
|
|
1791
|
+
await until(() => started.includes(1), 3000);
|
|
1792
|
+
await new Promise((r) => setTimeout(r, 60));
|
|
1793
|
+
assert.deepEqual(started, [1], "the batch stays open while the hold has not expired");
|
|
1794
|
+
due = true;
|
|
1795
|
+
await until(() => started.includes(2), 3000);
|
|
1796
|
+
} finally { due = true; held = []; }
|
|
1797
|
+
assert.deepEqual((await done).map((r) => [r.issue, r.outcome]), [[1, "merged"], [2, "merged"]]);
|
|
1798
|
+
assert.ok(log.some((r) => r.outcome === "hold-alert"));
|
|
1799
|
+
});
|
|
1800
|
+
|
|
1801
|
+
it("a batch that ends with a held issue names its owner and since; a legacy hold keeps the plain detail", async () => {
|
|
1802
|
+
let saved = null;
|
|
1803
|
+
const store = { load: () => saved, save: (s) => { saved = s; }, log: () => {} };
|
|
1804
|
+
const run = (info) => orchestrate({ issues: [1, 2], parallel: 2, pollMs: 5, readBody: async () => "", store: { ...store, load: () => null }, getHeld: () => [2], getHoldInfo: () => info,
|
|
1805
|
+
runOne: async () => ({ terminalReason: "merged" }) });
|
|
1806
|
+
const rows = await run({ 2: { owner: "op@h", since: "2026-11-11T00:00:00.000Z" } });
|
|
1807
|
+
assert.equal(rows.find((r) => r.issue === 2).detail, "held by operator (op@h, since 2026-11-11T00:00:00.000Z)");
|
|
1808
|
+
assert.equal((await run({})).find((r) => r.issue === 2).detail, "held by operator");
|
|
1809
|
+
});
|
|
1810
|
+
|
|
1811
|
+
it("the batch API: hold metadata, expireHolds releases only the due ones, release drops the metadata", () => {
|
|
1812
|
+
const b = openBatch(tmpDir("batch-hold5469-"), "b1");
|
|
1813
|
+
b.writePlan({ argv: ["1"], repo: "o/r" });
|
|
1814
|
+
b.holdIssues([2, 3], { owner: "op@h", forMs: 3600000, reason: "hand-build", ownerPid: 2147483646, ownerHost: null });
|
|
1815
|
+
b.holdIssues([4]);
|
|
1816
|
+
const info = b.readHoldInfo();
|
|
1817
|
+
assert.deepEqual(Object.keys(info), ["2", "3"]);
|
|
1818
|
+
assert.equal(info[2].reason, "hand-build");
|
|
1819
|
+
assert.deepEqual(b.expireHolds(Date.now()), []);
|
|
1820
|
+
const due = b.expireHolds(Date.now() + 2 * 3600000);
|
|
1821
|
+
assert.deepEqual(due.map((d) => [d.issue, d.owner, d.ownerGone]), [[2, "op@h", true], [3, "op@h", true]], "a pid that does not exist is a gone owner");
|
|
1822
|
+
assert.deepEqual(b.readHeld(), [4], "a legacy hold has no expiry");
|
|
1823
|
+
b.holdIssues([5], { owner: "x", forMs: 0 });
|
|
1824
|
+
b.releaseIssues([5]);
|
|
1825
|
+
assert.deepEqual(b.readHoldInfo(), {});
|
|
1826
|
+
});
|
|
1827
|
+
|
|
1828
|
+
it("through the CLI: --hold --for --reason records owner and expiry; a malformed --for rejects", async () => {
|
|
1829
|
+
const root = tmpDir("batch-hold5469-cli-");
|
|
1830
|
+
const b = openBatch(root, "b1");
|
|
1831
|
+
b.writePlan({ argv: [], repo: "o/r" });
|
|
1832
|
+
b.store.save({ order: [1, 2] });
|
|
1833
|
+
const io = { gh: async () => JSON.stringify({ state: "OPEN" }) };
|
|
1834
|
+
const res = await quiet(() => orchestrateFromCli(["--hold", "b1", "1", "--for", "4h", "--reason", "hand build"], { batchRoot: root, io }));
|
|
1835
|
+
assert.deepEqual(res.changed, [1]);
|
|
1836
|
+
const e = b.readHoldInfo()[1];
|
|
1837
|
+
assert.equal(e.reason, "hand build");
|
|
1838
|
+
assert.ok(Date.parse(e.expiresAt) - Date.parse(e.since) === 4 * 3600000);
|
|
1839
|
+
await assert.rejects(orchestrateFromCli(["--hold", "b1", "2", "--for", "soon"], { batchRoot: root, io }), /--for expects/);
|
|
1840
|
+
});
|
|
1841
|
+
|
|
1842
|
+
it("--gc-orphans cancels unhosted batches idle past the threshold and leaves recent ones", async () => {
|
|
1843
|
+
const root = tmpDir("batch-gc5469-");
|
|
1844
|
+
const mk = (id, ageMs) => { const b = openBatch(root, id); b.writePlan({ argv: [], repo: "o/r" }); b.store.save({ order: [1], pending: [1], results: {} }); const t = new Date(Date.now() - ageMs); utimesSync(join(b.dir, "state.json"), t, t); return b; };
|
|
1845
|
+
const old = mk("old", 9 * 86400000), fresh = mk("fresh", 60000);
|
|
1846
|
+
const res = await quiet(() => orchestrateFromCli(["--gc-orphans"], { batchRoot: root, io: { gh: async () => "" } }));
|
|
1847
|
+
assert.deepEqual(res.cancelled, ["old"]);
|
|
1848
|
+
assert.ok(old.readCancel()); assert.equal(fresh.readCancel(), null);
|
|
1849
|
+
});
|
|
1850
|
+
});
|
package/bin/lean/conformance.mjs
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { spawnSync } from "node:child_process";
|
|
11
11
|
import { OUTCOME_CODES, ENV_VALIDATE_TIMEOUT } from "../engine/outcome-codes.mjs";
|
|
12
12
|
import { noComments } from "./context.mjs";
|
|
13
|
+
import { seqNumber } from "./sequence.mjs";
|
|
13
14
|
import { activationFailures } from "./activation.mjs";
|
|
14
15
|
import * as nodeFs from "node:fs";
|
|
15
16
|
import { tmpdir } from "node:os";
|
|
@@ -31,8 +32,10 @@ const INCIDENTAL_RE = /(^|\/)(CHANGELOG|CHANGES|HISTORY)(\.[a-z]+)?$|(^|\/)(pack
|
|
|
31
32
|
export const MIN_QUOTE_CHARS = 12;
|
|
32
33
|
/** A contract larger than this cannot be posted whole in one comment (the comment cap is 60k). */
|
|
33
34
|
export const MAX_CONTRACT_CHARS = 40000;
|
|
34
|
-
import { CHECK_ID_RE } from "./postdeploy-check.mjs";
|
|
35
|
+
import { CHECK_ID_RE, e2eCheckFor } from "./postdeploy-check.mjs";
|
|
35
36
|
import { normaliseDecision, deadAnchors, anchorMatches } from "./decisions.mjs";
|
|
37
|
+
import { globToRegex } from "../../scripts/ci-local/lib.mjs";
|
|
38
|
+
import { contractBriefProblems } from "./pagegate.mjs"; // #5428
|
|
36
39
|
const C = OUTCOME_CODES;
|
|
37
40
|
|
|
38
41
|
/** #4789: folds what a builder retyping a quote changes: unicode punctuation, markdown links/markup, escapes, invisible chars. */
|
|
@@ -180,13 +183,28 @@ export const isTestPath = (p) => TEST_RE.test(String(p));
|
|
|
180
183
|
export const isIncidentalPath = (p) => INCIDENTAL_RE.test(String(p));
|
|
181
184
|
const cleanPath = (p) => String(p ?? "").trim().replace(/^\.\//, "");
|
|
182
185
|
const globRe = (g) => new RegExp(`^${g.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\/?/g, "\u0000").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(/\u0000/g, ".*")}$`);
|
|
183
|
-
|
|
186
|
+
const dirOf = (p) => p.slice(0, p.lastIndexOf("/") + 1);
|
|
187
|
+
/**
|
|
188
|
+
* #5440: `file` with its sequence number replaced by the one in deliverable `p`, when both sit in one directory and both
|
|
189
|
+
* names start with a (different) sequence number: an in-lane renumber (0637_x -> 0639_x) is an add from the base, so git
|
|
190
|
+
* rename detection cannot see it. null otherwise.
|
|
191
|
+
*/
|
|
192
|
+
function renumberedAs(p, file) {
|
|
193
|
+
const was = seqNumber(p.slice(dirOf(p).length)), now = seqNumber(file.slice(dirOf(file).length));
|
|
194
|
+
if (!was || !now || was === now || dirOf(p) !== dirOf(file)) return null;
|
|
195
|
+
return `${dirOf(file)}${was}${file.slice(dirOf(file).length + now.length)}`;
|
|
196
|
+
}
|
|
197
|
+
/** True when deliverable `d` (a file, a directory with or without a trailing "/", or a glob) covers changed file `f`. */
|
|
184
198
|
export function pathCovers(d, f) {
|
|
185
199
|
const p = cleanPath(d), file = cleanPath(f);
|
|
186
200
|
if (!p) return false;
|
|
187
201
|
if (p.endsWith("/")) return file.startsWith(p);
|
|
188
|
-
|
|
189
|
-
|
|
202
|
+
const hit = (x) => (/[*?]/.test(p) ? globRe(p).test(x) : p === x);
|
|
203
|
+
// a file and a directory cannot share a path, so a slash-less deliverable that prefixes `file/` is a directory
|
|
204
|
+
if (!/[*?]/.test(p) && file.startsWith(`${p}/`)) return true;
|
|
205
|
+
if (hit(file)) return true;
|
|
206
|
+
const as = renumberedAs(p, file);
|
|
207
|
+
return as !== null && hit(as);
|
|
190
208
|
}
|
|
191
209
|
/** #5365: explicit coupling map: editing `when` (a deliverable) also puts `also` in scope (a test asserts parity between them). */
|
|
192
210
|
const COUPLED_PATHS = [{ when: "bin/engine/outcome-codes.mjs", also: ["docs/OUTCOME-CODES.md"] }];
|
|
@@ -453,7 +471,49 @@ export function weakenedE2eDecisions(c) {
|
|
|
453
471
|
}).map((k) => k.id).filter(Boolean);
|
|
454
472
|
}
|
|
455
473
|
|
|
456
|
-
|
|
474
|
+
const TEST_LEVELS = ["unit", "integration", "e2e", "live"];
|
|
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;
|
|
477
|
+
/** #5445: a proof whose words are (almost) all in the deliverable text of its requirement only restates the fix. Pure. */
|
|
478
|
+
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; });
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* #5445: problems with the frozen test plan `test_plan: [{requirement, proof, level, level_reason, repro, reason, regression, env, command}]`.
|
|
485
|
+
* Shape is checked whenever present; `required` (a bug lane with repro on) also needs one row per deliver requirement.
|
|
486
|
+
*/
|
|
487
|
+
export function testPlanProblems(c, { required = false } = {}) {
|
|
488
|
+
const plan = c?.test_plan, problems = [];
|
|
489
|
+
if (plan == null) { if (!required) return problems; }
|
|
490
|
+
else if (!Array.isArray(plan)) return ["test_plan must be an array of rows"];
|
|
491
|
+
const rows = Array.isArray(plan) ? plan : [], dels = Array.isArray(c?.deliverables) ? c.deliverables : [];
|
|
492
|
+
if (required) for (const r of (Array.isArray(c?.requirements) ? c.requirements : []).filter((x) => x?.disposition === "deliver")) if (!rows.some((t) => t?.requirement === r.id)) problems.push(`${r.id}: test_plan needs a row for this bug requirement (proof, level, level_reason, repro or no-repro with reason, command)`);
|
|
493
|
+
for (const t of rows) {
|
|
494
|
+
const id = t?.requirement ?? "test_plan row";
|
|
495
|
+
if (!t || typeof t !== "object" || !t.requirement) { problems.push("test_plan row without a requirement id"); continue; }
|
|
496
|
+
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`);
|
|
498
|
+
if (!TEST_LEVELS.includes(t.level)) problems.push(`${id}: test_plan level must be one of ${TEST_LEVELS.join("|")}`);
|
|
499
|
+
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`);
|
|
502
|
+
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
|
+
if (blank(t.command)) problems.push(`${id}: test_plan needs the exact command validate runs`);
|
|
504
|
+
else {
|
|
505
|
+
for (const p of tmpdirInputs(t.command)) problems.push(tmpInputProblem(id, p));
|
|
506
|
+
if (vitestQuietFlag(t.command)) problems.push(`${id}: test_plan command: vitest 3 rejects -q/--quiet; use --reporter=dot`);
|
|
507
|
+
const syn = shellSyntaxError(t.command);
|
|
508
|
+
if (syn) problems.push(`${id}: test_plan command is not valid shell (bash -n: ${syn})`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return problems;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/** #5448: a requirement that starts as an imperative build verb is development work, not a prod-only measurement. */
|
|
515
|
+
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 } = {}) {
|
|
457
517
|
const problems = [];
|
|
458
518
|
if (!c || typeof c !== "object" || Array.isArray(c)) return { ok: false, problems: ["contract.json is missing or not a JSON object"] };
|
|
459
519
|
const reqs = Array.isArray(c.requirements) ? c.requirements : [];
|
|
@@ -467,6 +527,8 @@ export function validateContract(c, issueText, { repro = false } = {}) {
|
|
|
467
527
|
if (!inIssue(r?.quote, issueText)) problems.push(quoteMiss(id, r?.quote, issueText));
|
|
468
528
|
if (TRACKED.includes(r?.disposition) && blank(r?.why)) problems.push(`${id}: ${r.disposition} needs a why`);
|
|
469
529
|
if (r?.disposition === "post-deploy" && !CHECK_ID_RE.test(String(r?.check ?? ""))) problems.push(`${id}: post-deploy needs a check id (\`check\`, e.g. "login-smoke") naming an entry of .forge/post-deploy-checks.json on the default branch`);
|
|
530
|
+
if (r?.disposition === "post-deploy" && blank(r?.local_infeasible_why)) problems.push(`${id}: post-deploy needs local_infeasible_why: why a fixture or recorded response cannot check this locally (#5448)`);
|
|
531
|
+
if (r?.disposition === "post-deploy" && (inLaneDeferral(r) || (bucketKind(r?.bucket) !== "owner" && bucketKind(r?.bucket) !== "host" && DEV_WORK_RE.test(String(r?.quote ?? ""))))) problems.push(`${id}: development work (finding or fixing the signal) is delivered in-lane, never deferred as prod-only; deliver it and keep only the measurement post-deploy (#5448)`);
|
|
470
532
|
if (r?.disposition === "not-applicable" && blank(r?.evidence)) problems.push(`${id}: not-applicable needs file:line evidence`);
|
|
471
533
|
for (const m of bucketProblems(r)) problems.push(`${id}: ${m}`);
|
|
472
534
|
if (r?.class != null && !FOLLOWUP_CLASSES.includes(r.class)) problems.push(`${id}: class must be one of ${FOLLOWUP_CLASSES.join("|")}`);
|
|
@@ -474,6 +536,13 @@ export function validateContract(c, issueText, { repro = false } = {}) {
|
|
|
474
536
|
if (isOutOfBand(r) && r?.disposition !== "deliver") problems.push(`${id}: verify out_of_band applies only to a deliver requirement`);
|
|
475
537
|
else if (isOutOfBand(r) && blank(r?.evidence)) problems.push(`${id}: verify out_of_band needs evidence naming the job or workflow that measures it (or set verify "in_lane" if this change can check it)`);
|
|
476
538
|
}
|
|
539
|
+
if (c.regression != null && !Array.isArray(c.regression)) problems.push("regression must be an array of {id, command, covers}");
|
|
540
|
+
for (const g of Array.isArray(c.regression) ? c.regression : []) {
|
|
541
|
+
if (!g?.id || blank(g?.command)) { problems.push(`regression entry without id or command: ${JSON.stringify(g ?? null).slice(0, 80)}`); continue; }
|
|
542
|
+
for (const p of tmpdirInputs(g.command)) problems.push(tmpInputProblem(g.id, p));
|
|
543
|
+
const syn = shellSyntaxError(g.command);
|
|
544
|
+
if (syn) problems.push(`${g.id}: the command is not valid shell (bash -n: ${syn})`);
|
|
545
|
+
}
|
|
477
546
|
const dels = Array.isArray(c.deliverables) ? c.deliverables : [];
|
|
478
547
|
if (reqs.some((r) => r?.disposition === "deliver") && !dels.length) problems.push("deliver requirements but no deliverables");
|
|
479
548
|
for (const d of dels) if (!d?.id || !d?.path) problems.push(`deliverable without id or path: ${JSON.stringify(d).slice(0, 80)}`);
|
|
@@ -512,7 +581,9 @@ export function validateContract(c, issueText, { repro = false } = {}) {
|
|
|
512
581
|
if (syn) problems.push(`repro_test: the command is not valid shell (bash -n: ${syn})`);
|
|
513
582
|
}
|
|
514
583
|
}
|
|
584
|
+
problems.push(...testPlanProblems(c, { required: testPlan }));
|
|
515
585
|
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
|
|
516
587
|
return { ok: problems.length === 0, problems };
|
|
517
588
|
}
|
|
518
589
|
|
|
@@ -769,6 +840,8 @@ export function deferChecklessPostDeploy(contract) {
|
|
|
769
840
|
const converted = [];
|
|
770
841
|
const requirements = (Array.isArray(contract?.requirements) ? contract.requirements : []).map((r) => {
|
|
771
842
|
if (r?.disposition !== "post-deploy" || CHECK_ID_RE.test(String(r?.check ?? ""))) return r;
|
|
843
|
+
// #5448: only a row that truly needs an owner or read-only prod data is converted; any other check-less prod-only claim stays post-deploy so freeze rejects it
|
|
844
|
+
if (!EXTERNAL_NEED_RE.test(`${r.bucket ?? ""} ${r.why ?? ""}`) && !READONLY_PROD_RE.test(`${r.bucket ?? ""} ${r.why ?? ""}`)) return r;
|
|
772
845
|
converted.push(r.id);
|
|
773
846
|
return { ...r, disposition: "defer", bucket: String(r.bucket ?? "").startsWith("owner:") ? r.bucket : ORCHESTRATOR_BUCKET, why: r.why ?? "post-deploy action with no registered check: deferred to the orchestrator" };
|
|
774
847
|
});
|
|
@@ -791,6 +864,7 @@ export function applyValidateRecipes(contract, recipes) {
|
|
|
791
864
|
if (Array.isArray(contract.validate)) out.validate = contract.validate.map((v) => (v && typeof v === "object" ? { ...v, command: rewrite(v.id, v.command) } : v));
|
|
792
865
|
const t = contract.repro_test;
|
|
793
866
|
if (t && typeof t === "object" && !Array.isArray(t)) out.repro_test = { ...t, command: rewrite("repro_test", t.command) };
|
|
867
|
+
if (Array.isArray(contract.test_plan)) out.test_plan = contract.test_plan.map((r) => (r && typeof r === "object" ? { ...r, command: rewrite(`test_plan ${r.requirement}`, r.command) } : r)); // #5445
|
|
794
868
|
return { contract: applied.length ? out : contract, applied };
|
|
795
869
|
}
|
|
796
870
|
/** #5020: the env.* verdict for a repro command that failed on head because a tool is missing (e.g. an uninstalled Poetry env); null when the failure is the test's own. */
|
|
@@ -958,7 +1032,7 @@ export function repoTracks(paths) {
|
|
|
958
1032
|
* `ciCovered` (#4527): the validate ids accepted only because the head is CI-verified (no local result, or a missing host
|
|
959
1033
|
* tool), for the trajectory; always an array.
|
|
960
1034
|
*/
|
|
961
|
-
export function precheck({ contract, result, changedFiles, ignore = [], ciVerified = false, hotspots = null, repro = null, validateRuns = null, repoHas = () => false, frozen = null, checkIds = null, guardFailures = null, coupledFailures = null, relaxationFailures = null, routeFailures = null, prodParityFailures = null, newOffKeys = null, substitutedRuns = null, removedPaths = [], baseFiles = [], uiBrowser = null }) {
|
|
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 }) {
|
|
962
1036
|
const failures = [], superseded = [], ciCovered = [];
|
|
963
1037
|
// #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)
|
|
964
1038
|
if (checkIds) for (const r of contract.requirements ?? []) {
|
|
@@ -968,7 +1042,7 @@ export function precheck({ contract, result, changedFiles, ignore = [], ciVerifi
|
|
|
968
1042
|
if (newOffKeys?.length) for (const f of activationFailures(contract, newOffKeys)) failures.push({ code: C.CONFORMANCE_UNIMPLEMENTED, ...f });
|
|
969
1043
|
// #5285: interactive UI changed on a high-risk surface with no real-browser check configured: a recorded skip that blocks
|
|
970
1044
|
if (uiBrowser?.files?.length && uiBrowser.highRisk && !uiBrowser.ran) failures.push({ code: C.CONFORMANCE_E2E_UNVERIFIED, kind: "ui_browser_unverified", detail: `interactive UI changed (${uiBrowser.files.slice(0, 5).join(", ")}) on a high-risk surface but no real-browser check runs (${uiBrowser.reason}); configure verify.e2e_label/e2e_workflow or add a Playwright spec` });
|
|
971
|
-
const outside = (k) => changedFiles.filter((f) => !ignore.some((p) => f.startsWith(p)) && !authorizationOf(k, f));
|
|
1045
|
+
const outside = (k) => changedFiles.filter((f) => !ignore.some((p) => f.startsWith(p)) && !authorizationOf(k, f) && !(docsPaths?.length && docsPaths.some((g) => globToRegex(g).test(f)))); // #5419: configured docs.paths/registries are authorized
|
|
972
1046
|
const creep = outside(contract);
|
|
973
1047
|
const amendedOnly = frozenAmendedFiles(frozen, contract, outside, creep);
|
|
974
1048
|
if (creep.length) failures.push({ code: C.CONFORMANCE_SCOPE_CREEP, kind: "scope_creep", detail: `changed outside the contract's deliverables: ${creep.join(", ")}` });
|
|
@@ -1004,7 +1078,7 @@ export function precheck({ contract, result, changedFiles, ignore = [], ciVerifi
|
|
|
1004
1078
|
continue;
|
|
1005
1079
|
}
|
|
1006
1080
|
const miss = rerun ? missingTool(rerun, { repoHas, command: v.command }) : null;
|
|
1007
|
-
|
|
1081
|
+
// #5447: CI may not run this test, so a missing tool on the rerun is never covered by a CI-verified head
|
|
1008
1082
|
if (miss) failures.push({ code: C.ENV_TOOL_MISSING, kind: "validate_env", tool: miss.tool, detail: `validate ${v.id} (\`${v.command}\`) could not run: the host is missing ${KIND_NAME[miss.kind]} '${miss.tool}' (environment, not the change)${outputTail(rerun.output)}` });
|
|
1009
1083
|
else if (amendedOnly && isScopeCheck(v.command)) superseded.push({ id: v.id, files: amendedOnly });
|
|
1010
1084
|
else failures.push({ code: C.CONFORMANCE_UNIMPLEMENTED, kind: "validate_failed", detail: `validate ${v.id} (\`${v.command}\`) failed (exit ${r.exit})${outputTail(rerun?.output)}` });
|
|
@@ -1023,8 +1097,9 @@ export function precheck({ contract, result, changedFiles, ignore = [], ciVerifi
|
|
|
1023
1097
|
else if (s !== "implemented") failures.push({ code: C.CONFORMANCE_UNIMPLEMENTED, kind: "requirement_unimplemented", detail: `${r.id} reported "${s ?? "no status"}"` });
|
|
1024
1098
|
}
|
|
1025
1099
|
}
|
|
1100
|
+
for (const f of baselineFailures ?? []) failures.push({ code: C.CONFORMANCE_REGRESSION, ...f }); // #5448
|
|
1026
1101
|
failures.push(...hotspotGrowth({ contract, result, hotspots, changedFiles }));
|
|
1027
|
-
if (repro) failures.push(...reproFailures(contract, repro));
|
|
1102
|
+
if (repro) failures.push(...reproFailures(contract, repro), ...reproQualityFailures(repro));
|
|
1028
1103
|
failures.push(...sourceDeliverableFailures(contract, changedFiles, ignore));
|
|
1029
1104
|
// #4693: a broken guard fails unless the contract carries a supersedes amendment for it
|
|
1030
1105
|
const retired = new Set((contract.supersedes ?? []).map((s) => s.guard));
|
|
@@ -1032,6 +1107,8 @@ export function precheck({ contract, result, changedFiles, ignore = [], ciVerifi
|
|
|
1032
1107
|
for (const f of coupledFailures ?? []) failures.push(f); // #5079
|
|
1033
1108
|
for (const f of relaxationFailures ?? []) failures.push(f); // #5237
|
|
1034
1109
|
failures.push(...(routeFailures ?? [])); // #5087: topology.route_reachability, blocking when declared
|
|
1110
|
+
failures.push(...(docsFailures ?? [])); // #5419: forge.yaml docs
|
|
1111
|
+
failures.push(...(pageFailures ?? [])); // #5428: forge.yaml pages
|
|
1035
1112
|
failures.push(...(prodParityFailures ?? [])); // #5284: topology.prod_parity
|
|
1036
1113
|
return { ok: failures.length === 0, failures, superseded, ciCovered };
|
|
1037
1114
|
}
|
|
@@ -1071,6 +1148,13 @@ export function reproFailures(contract, { base, head } = {}) {
|
|
|
1071
1148
|
detail: `repro test ${name} (\`${t.command ?? ""}\`) must fail on the base and pass on head; got BASE=${base ?? "UNRUNNABLE"} HEAD=${head}${skipped}` }];
|
|
1072
1149
|
}
|
|
1073
1150
|
|
|
1151
|
+
/** #5446: a repro_test every targeted mutation of the fix survived. Only under lean.repro_quality: enforce; patch_echo is the reviewer's call. */
|
|
1152
|
+
export function reproQualityFailures({ quality, enforce } = {}) {
|
|
1153
|
+
if (!enforce || quality !== "mutation_survivor") return [];
|
|
1154
|
+
return [{ code: MUTATION_SURVIVED, kind: "repro_mutation_survivor",
|
|
1155
|
+
detail: "repro_test still passes with the fix's changed lines mutated (flipped condition, early return, dropped call): it does not exercise the fix" }];
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1074
1158
|
const DOC_ONLY_RE = /\.(?:md|mdx|txt|rst|adoc)$/i;
|
|
1075
1159
|
const SOURCE_EXT_RE = /\.(?:m?[jt]sx?|cjs|py|go|rs|rb|java|kt|swift|php|cs|c|cc|cpp|h|hpp|sh)$/i;
|
|
1076
1160
|
/**
|
|
@@ -1285,7 +1369,8 @@ export function checkCompleteness(rv, { contract, changedFiles, issueText, pathE
|
|
|
1285
1369
|
/** #4726, #5339: a requirement quote that carries a `[type:e2e]` or `[type:manual]` criterion. */
|
|
1286
1370
|
const wantsE2e = (r) => /\[type:(?:e2e|manual)\]/i.test(String(r?.quote ?? ""));
|
|
1287
1371
|
/** #5339: failure kinds enforced without an `engine.conformance_kinds` entry (the entry still overrides). */
|
|
1288
|
-
|
|
1372
|
+
// #5449: test_missing/test_weak are only generated for bug lanes (testadequacy.mjs), so enforcing the kinds is bug-only.
|
|
1373
|
+
const DEFAULT_ENFORCED_KINDS = ["e2e_row", "test_missing", "test_weak"];
|
|
1289
1374
|
const E2E_CMD_RE = /\b(?:playwright|cypress|e2e|live[- ]stack|wdio)\b/i;
|
|
1290
1375
|
/**
|
|
1291
1376
|
* #4726: whether a validate command runs a real end-to-end check: an entry of `verify.e2e_checks`, a file of the e2e spec set
|
|
@@ -1298,11 +1383,45 @@ export function isE2eCommand(command, e2e = null) {
|
|
|
1298
1383
|
if (typeof e2e?.isSpec === "function" && cmd.split(/\s+/).some((t) => t && e2e.isSpec(t.replace(/^["']+|["']+$/g, "")))) return true;
|
|
1299
1384
|
return E2E_CMD_RE.test(cmd);
|
|
1300
1385
|
}
|
|
1386
|
+
/** #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
|
+
export function prodOnlyE2e(quote) {
|
|
1388
|
+
const q = String(quote ?? "");
|
|
1389
|
+
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);
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* #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.
|
|
1395
|
+
*/
|
|
1396
|
+
export function autoPostDeployE2e(contract, only = null) {
|
|
1397
|
+
const converted = [];
|
|
1398
|
+
const requirements = (Array.isArray(contract?.requirements) ? contract.requirements : []).map((r) => {
|
|
1399
|
+
if (!["deliver", "defer"].includes(r?.disposition) || !wantsE2e(r) || (only && !only.includes(r.id)) || isOutOfBand(r) || !prodOnlyE2e(r.quote)) return r;
|
|
1400
|
+
const g = e2eCheckFor(r.id, r.quote);
|
|
1401
|
+
if (!g) return r;
|
|
1402
|
+
converted.push({ id: r.id, check: g.id, entry: g.entry });
|
|
1403
|
+
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
|
+
});
|
|
1405
|
+
return { contract: converted.length ? { ...contract, requirements } : contract, converted };
|
|
1406
|
+
}
|
|
1407
|
+
/** #5468: the row ids named by `e2e_row` failures when every failure is one; null otherwise (anything else blocks as before). */
|
|
1408
|
+
export function loneE2eRows(failures) {
|
|
1409
|
+
const fs = failures ?? [];
|
|
1410
|
+
if (!fs.length || !fs.every((f) => f?.code === C.CONFORMANCE_E2E_UNVERIFIED && f.kind === "e2e_row")) return null;
|
|
1411
|
+
const ids = fs.map((f) => /^(\S+) is a /.exec(String(f.detail ?? ""))?.[1]);
|
|
1412
|
+
return ids.every(Boolean) ? [...new Set(ids)] : null;
|
|
1413
|
+
}
|
|
1414
|
+
/** #5468 (#5450): a validate that declares `env` names of configured test sandboxes (forge.yaml `sandboxes`) runs against a provisioned live service: the route for an e2e check that can run pre-merge. */
|
|
1415
|
+
export function sandboxedRun(v, e2e = null) {
|
|
1416
|
+
const known = e2e?.sandboxes ?? [];
|
|
1417
|
+
const names = Array.isArray(v?.env) ? v.env : typeof v?.env === "string" ? v.env.split(",") : [];
|
|
1418
|
+
return names.some((n) => known.includes(String(n).trim()));
|
|
1419
|
+
}
|
|
1301
1420
|
/** #4726: true when a V-ref named in the row's `validated_by` resolves to a contract validate command that is a real e2e check. */
|
|
1302
1421
|
export function e2eVerified(row, contract, e2e = null) {
|
|
1303
1422
|
const by = String(row?.validated_by ?? "");
|
|
1304
1423
|
const refs = (contract?.validate ?? []).filter((v) => v?.id && new RegExp(`(?:^|[^A-Za-z0-9_])${v.id}(?![A-Za-z0-9_])`).test(by));
|
|
1305
|
-
return refs.some((v) => isE2eCommand(v.command, e2e)) || (!refs.length && isE2eCommand(by, e2e));
|
|
1424
|
+
return refs.some((v) => isE2eCommand(v.command, e2e) || sandboxedRun(v, e2e)) || (!refs.length && isE2eCommand(by, e2e));
|
|
1306
1425
|
}
|
|
1307
1426
|
/**
|
|
1308
1427
|
* The engine's decision from the reviewer's rows. state: conforms | nonconforming | review.unparseable | review.incomplete
|
|
@@ -1327,7 +1446,7 @@ export function decide(raw, ctx) {
|
|
|
1327
1446
|
f.push({ code: ["deferred", "post-deploy"].includes(row.status) ? C.CONFORMANCE_UNTRACKED_DEFERRAL : C.CONFORMANCE_UNIMPLEMENTED, detail: `${r.amendment?.text ? `${r.id} amendment not accepted (amended to "${String(r.amendment.text).slice(0, 200)}"): ` : `${r.id} `}${row.status}${row.note ? `: ${row.note}` : ""}${row.evidence ? ` (${row.evidence})` : ""}` });
|
|
1328
1447
|
} else if (r.disposition === "deliver" && wantsE2e(r) && !e2eVerified(row, ctx.contract, ctx.e2e)) {
|
|
1329
1448
|
const faked = (ctx.e2e?.faked ?? []).length ? `; faked or mocked components in ${ctx.e2e.faked.slice(0, 3).join(", ")}` : "";
|
|
1330
|
-
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` });
|
|
1449
|
+
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` : ""}` });
|
|
1331
1450
|
} else if (r.disposition === "defer" && wantsE2e(r)) {
|
|
1332
1451
|
// #5339: a deferred e2e/manual requirement is not met; only a post-deploy one is transferred to the epic (the lane closes partial)
|
|
1333
1452
|
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` });
|