forgedock 1.61.2 → 1.62.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/config-schema.mjs +10 -1
- package/bin/engine/outcome-codes.mjs +4 -0
- package/bin/engine-cli.mjs +159 -17
- package/bin/env/env.mjs +6 -4
- package/bin/forge-home-check.mjs +91 -0
- package/bin/forgedock.mjs +50 -7
- package/bin/gc.mjs +2 -0
- package/bin/hooks/pre-tool-use.mjs +4 -0
- package/bin/journey.mjs +55 -5
- package/bin/lean/admission.mjs +16 -5
- package/bin/lean/batch-health.mjs +55 -16
- package/bin/lean/batch-health.test.mjs +67 -1
- package/bin/lean/batch.mjs +8 -0
- package/bin/lean/batch.test.mjs +5 -0
- package/bin/lean/ceiling.mjs +20 -0
- package/bin/lean/ceiling.test.mjs +33 -2
- package/bin/lean/ci-gate.mjs +240 -0
- package/bin/lean/ci-gate.test.mjs +227 -0
- package/bin/lean/ci-precheck.mjs +178 -0
- package/bin/lean/ci-precheck.test.mjs +149 -0
- package/bin/lean/conformance.mjs +85 -9
- package/bin/lean/conformance.test.mjs +155 -3
- package/bin/lean/context.test.mjs +7 -6
- package/bin/lean/dag.mjs +128 -0
- package/bin/lean/dag.test.mjs +131 -0
- package/bin/lean/decisions.mjs +5 -4
- package/bin/lean/decisions.test.mjs +11 -0
- package/bin/lean/delguard.mjs +84 -0
- package/bin/lean/delguard.test.mjs +104 -0
- package/bin/lean/depcache.mjs +125 -17
- package/bin/lean/depcache.test.mjs +111 -0
- package/bin/lean/design-gate.mjs +5 -5
- package/bin/lean/design-gate.test.mjs +14 -0
- package/bin/lean/effects.mjs +72 -4
- package/bin/lean/execution.mjs +41 -7
- package/bin/lean/execution.test.mjs +99 -3
- package/bin/lean/forgedock-lane-workflow.test.mjs +35 -0
- package/bin/lean/guardgate.mjs +30 -7
- package/bin/lean/guardgate.test.mjs +44 -1
- package/bin/lean/guards.test.mjs +1 -1
- package/bin/lean/heavy.test.mjs +87 -0
- package/bin/lean/hotarea.mjs +73 -0
- package/bin/lean/hotarea.test.mjs +73 -0
- package/bin/lean/issuewatch-reconcile.mjs +20 -1
- package/bin/lean/issuewatch-reconcile.test.mjs +30 -0
- package/bin/lean/lanecheck.mjs +27 -3
- package/bin/lean/lanecheck.test.mjs +47 -5
- package/bin/lean/laneconfine.mjs +83 -0
- package/bin/lean/laneconfine.test.mjs +113 -0
- package/bin/lean/lean.mjs +376 -79
- package/bin/lean/lean.test.mjs +710 -22
- package/bin/lean/live-reconcile.mjs +169 -0
- package/bin/lean/live-reconcile.test.mjs +176 -0
- package/bin/lean/orchestrate-envhold.test.mjs +245 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +39 -0
- package/bin/lean/orchestrate.mjs +207 -17
- package/bin/lean/outcomeevidence.mjs +104 -0
- package/bin/lean/outcomeevidence.test.mjs +78 -0
- package/bin/lean/page-capture.mjs +68 -0
- package/bin/lean/page-capture.test.mjs +44 -0
- package/bin/lean/pagegate.mjs +46 -7
- package/bin/lean/pagegate.test.mjs +66 -1
- package/bin/lean/postdeploy-check.mjs +18 -4
- package/bin/lean/postdeploy-check.test.mjs +32 -1
- package/bin/lean/prefilter.mjs +36 -4
- package/bin/lean/prefilter.test.mjs +31 -1
- package/bin/lean/preflight.mjs +22 -0
- package/bin/lean/preflight.test.mjs +19 -1
- package/bin/lean/probe.mjs +18 -0
- package/bin/lean/probe.test.mjs +40 -0
- package/bin/lean/prompts.mjs +40 -3
- package/bin/lean/recovery.test.mjs +20 -0
- package/bin/lean/recurrence.mjs +133 -0
- package/bin/lean/recurrence.test.mjs +99 -0
- package/bin/lean/release-config.mjs +2 -1
- package/bin/lean/release-config.test.mjs +18 -0
- package/bin/lean/release-control.mjs +4 -2
- package/bin/lean/release-control.test.mjs +15 -0
- package/bin/lean/release-merge-hold.mjs +65 -0
- package/bin/lean/release-merge-hold.test.mjs +69 -0
- package/bin/lean/release-review.mjs +26 -9
- package/bin/lean/release-review.test.mjs +53 -0
- package/bin/lean/release-status.mjs +3 -1
- package/bin/lean/release-status.test.mjs +11 -0
- package/bin/lean/release.test.mjs +26 -1
- package/bin/lean/render.mjs +8 -7
- package/bin/lean/routing.mjs +49 -0
- package/bin/lean/routing.test.mjs +54 -1
- package/bin/lean/run-issue-placement.test.mjs +30 -1
- package/bin/lean/sandbox-actions.mjs +121 -0
- package/bin/lean/sandbox-actions.test.mjs +94 -0
- package/bin/lean/sandbox-provider.contract.test.mjs +22 -1
- package/bin/lean/sandbox-remote.mjs +3 -1
- package/bin/lean/schedd-health.mjs +14 -2
- package/bin/lean/schedd-health.test.mjs +13 -0
- package/bin/lean/schedd.mjs +43 -17
- package/bin/lean/schedd.test.mjs +61 -1
- package/bin/lean/toolchain.mjs +16 -6
- package/bin/lean/toolplace.mjs +12 -0
- package/bin/lean/weakguard.mjs +105 -0
- package/bin/lean/weakguard.test.mjs +59 -0
- package/bin/lean/winspawn.mjs +61 -0
- package/bin/lean/winspawn.test.mjs +45 -0
- package/bin/lean/worktree.mjs +3 -1
- package/bin/lean/worktree.test.mjs +11 -0
- package/bin/pool/agent.mjs +210 -14
- package/bin/pool/cache-sweep.mjs +74 -0
- package/bin/pool/cli.mjs +11 -3
- package/bin/pool/docker.mjs +33 -2
- package/bin/pool/health.mjs +38 -0
- package/bin/pool/lane-tools.mjs +23 -4
- package/bin/pool/lane-tools.test.mjs +12 -1
- package/bin/pool/router.mjs +21 -3
- package/bin/runner.mjs +37 -0
- package/bin/splash-scene.mjs +356 -0
- package/bin/win-hide-children.mjs +114 -0
- package/commands/orchestrate.md +18 -27
- package/commands/review-pr-agents/infra.md +1 -0
- package/commands/review-pr-staging.md +2 -2
- package/docs/CONFIG.md +60 -3
- package/docs/OUTCOME-CODES.md +3 -0
- package/package.json +1 -1
- package/plugins/forgedock-splash/.claude-plugin/plugin.json +1 -1
- package/plugins/forgedock-splash/README.md +1 -1
- package/plugins/forgedock-splash/hooks/scene.ts +142 -8
- package/pool/README.md +6 -0
- package/pool/image/entrypoint.sh +1 -0
- package/scripts/check-spec-size.sh +3 -1
- package/scripts/gen-splash-scene.mjs +24 -0
- package/scripts/review-staging-pre.sh +8 -3
- package/scripts/review-staging-pre.test.sh +2 -0
package/bin/lean/preflight.mjs
CHANGED
|
@@ -288,6 +288,28 @@ export function depInstallFailures({ results = [], changedFiles = [] } = {}) {
|
|
|
288
288
|
return { block, logged };
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
+
/**
|
|
292
|
+
* #5804: the failed installs of `results` that could not start because the host lacks a tool (depcache's ENOENT
|
|
293
|
+
* `tool not found: ...` reason, or a row coded env.tool_missing, #5651). Each is {tool, label}: the binary named in
|
|
294
|
+
* `spawn <tool> ENOENT` when present, else the ecosystem. Knowable before any session; a retry on this host cannot fix it.
|
|
295
|
+
* Scoped to what the change may need: the root (primary) install always counts; a sub-project install (`dir` other than
|
|
296
|
+
* ".") only when one of `files` (issue-named paths, frozen deliverables) is under its dir. The rest stay with the gate. Pure.
|
|
297
|
+
*/
|
|
298
|
+
export function toolMissingInstalls(results = [], { files = [] } = {}) {
|
|
299
|
+
const out = [];
|
|
300
|
+
const paths = (Array.isArray(files) ? files : []).map((f) => String(f ?? "").replace(/^\.\//, "")).filter(Boolean);
|
|
301
|
+
for (const r of Array.isArray(results) ? results : []) {
|
|
302
|
+
if (r?.status !== "failed") continue;
|
|
303
|
+
const reason = String(r.reason ?? "");
|
|
304
|
+
if (!/^tool not found\b/i.test(reason) && r.code !== "env.tool_missing") continue;
|
|
305
|
+
const sub = r.dir && r.dir !== "." ? String(r.dir).replace(/^\.\//, "").replace(/\/+$/, "") : null;
|
|
306
|
+
if (sub && !paths.some((f) => underDir(sub, f))) continue; // #5804: a sub-project the change does not place itself in
|
|
307
|
+
const tool = /\bspawn\s+(\S+)\s+ENOENT\b/.exec(reason)?.[1] ?? r.eco ?? "python";
|
|
308
|
+
out.push({ tool, label: `${r.eco ?? "dependencies"}${r.dir && r.dir !== "." ? ` in ${r.dir}` : ""}: ${reason || "tool not found"}` });
|
|
309
|
+
}
|
|
310
|
+
return out;
|
|
311
|
+
}
|
|
312
|
+
|
|
291
313
|
/**
|
|
292
314
|
* #5447: declared vs ran for the FORGE:TRAJECTORY Tests row. Declared: each validate plus the repro_test. Skipped: a
|
|
293
315
|
* declared id named by an env/missing/timeout failure of `failures` (reason = its kind). redGreen: repro BASE=FAILED HEAD=RAN.
|
|
@@ -4,7 +4,7 @@ import { describe, it } from "node:test";
|
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
|
-
import { manifestDepOwner, venvPythonRewrite, testRunnerProblems, shellSegments, pythonImports, nodeImports, preflightProbes, preflightProblems, runProbeMiss, unsetEnvVars, runPreflight, knownToContract, contractCommands, depInstallFailures, testRunSummary, projectBinDirs, withLocalBins } from "./preflight.mjs";
|
|
7
|
+
import { manifestDepOwner, venvPythonRewrite, testRunnerProblems, shellSegments, pythonImports, nodeImports, preflightProbes, preflightProblems, runProbeMiss, unsetEnvVars, runPreflight, knownToContract, contractCommands, depInstallFailures, toolMissingInstalls, testRunSummary, projectBinDirs, withLocalBins } from "./preflight.mjs";
|
|
8
8
|
import { runCheckCommand } from "./effects.mjs";
|
|
9
9
|
import { repoTracks } from "./conformance.mjs";
|
|
10
10
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
@@ -151,6 +151,24 @@ describe("#5447 unrunnable tests: install classification and the Tests summary",
|
|
|
151
151
|
assert.equal(r.block.length, 1);
|
|
152
152
|
assert.equal(r.block[0].code, "env.tool_missing");
|
|
153
153
|
});
|
|
154
|
+
it("#5804 toolMissingInstalls picks tool-not-found and env.tool_missing rows only, naming the spawned binary", () => {
|
|
155
|
+
const r = toolMissingInstalls([
|
|
156
|
+
{ status: "failed", eco: "pnpm", dir: ".", reason: "tool not found: spawn pnpm ENOENT" },
|
|
157
|
+
{ status: "failed", eco: "poetry", dir: "svc", code: "env.tool_missing", reason: "poetry is not available under python3.12" },
|
|
158
|
+
{ status: "failed", eco: "npm", dir: ".", reason: "install failed: ERESOLVE" },
|
|
159
|
+
{ status: "hit", eco: "uv", reason: "tool not found: spawn uv ENOENT" },
|
|
160
|
+
], { files: ["./svc/app/main.py"] });
|
|
161
|
+
assert.deepEqual(r.map((m) => m.tool), ["pnpm", "poetry"]);
|
|
162
|
+
assert.match(r[1].label, /^poetry in svc: /);
|
|
163
|
+
assert.deepEqual(toolMissingInstalls(null), []);
|
|
164
|
+
});
|
|
165
|
+
it("#5804 a sub-project install counts only when a named or deliverable path is under it; the root install always counts", () => {
|
|
166
|
+
const rows = [{ status: "failed", eco: "poetry", dir: "services/worker", reason: "tool not found: spawn poetry ENOENT" }];
|
|
167
|
+
assert.deepEqual(toolMissingInstalls(rows), [], "no files place the change: the gate judges it");
|
|
168
|
+
assert.deepEqual(toolMissingInstalls(rows, { files: ["web/src/a.ts", "services/workers/x.py"] }), [], "a sibling prefix is not under it");
|
|
169
|
+
assert.deepEqual(toolMissingInstalls(rows, { files: ["services/worker/app.py"] }).map((m) => m.tool), ["poetry"]);
|
|
170
|
+
assert.deepEqual(toolMissingInstalls([{ status: "failed", eco: "pnpm", reason: "tool not found: spawn pnpm ENOENT" }]).map((m) => m.tool), ["pnpm"], "no dir is the root");
|
|
171
|
+
});
|
|
154
172
|
it("testRunSummary counts declared, ran, red->green and skipped(reason)", () => {
|
|
155
173
|
const c = { validate: [{ id: "V1", command: "a" }, { id: "V2", command: "b" }], repro_test: { command: "c" } };
|
|
156
174
|
const t = testRunSummary({ contract: c, failures: [{ kind: "validate_env", detail: "validate V2 (`b`) could not run" }], repro: { base: "FAILED", head: "RAN" } });
|
package/bin/lean/probe.mjs
CHANGED
|
@@ -218,6 +218,23 @@ export function renderProbeComment({ probe, fix, defaultBranch, defaultSha, r })
|
|
|
218
218
|
].join("\n");
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
export const POST_DEPLOY_FAILED_LABEL = "post-deploy-failed";
|
|
222
|
+
const AWAITING_PROMOTION = "awaiting-promotion";
|
|
223
|
+
|
|
224
|
+
/** #5704: drop `awaiting-promotion` (the fix is live); best effort, a missing label or no rights changes nothing. */
|
|
225
|
+
export async function clearAwaitingPromotion({ io, repo, issue }) {
|
|
226
|
+
try { await io.gh(["issue", "edit", String(issue), "-R", repo, "--remove-label", AWAITING_PROMOTION]); } catch { /* not labelled or no rights */ }
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** #5704: the fix is live and its verification failed: `awaiting-promotion` -> `post-deploy-failed` (label created on first use); best effort. */
|
|
230
|
+
export async function markPostDeployFailed({ io, repo, issue }) {
|
|
231
|
+
await clearAwaitingPromotion({ io, repo, issue });
|
|
232
|
+
const add = () => io.gh(["issue", "edit", String(issue), "-R", repo, "--add-label", POST_DEPLOY_FAILED_LABEL]);
|
|
233
|
+
try { await add(); } catch {
|
|
234
|
+
try { await io.gh(["label", "create", POST_DEPLOY_FAILED_LABEL, "-R", repo, "--force", "--color", "D93F0B", "--description", "Fix is live but its post-deploy verification failed. Managed by ForgeDock."]); await add(); } catch { /* the comment still shows it */ }
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
221
238
|
/** Read the issue (REST, for author_association) and its comments. */
|
|
222
239
|
async function readIssue(issue, repo, io) {
|
|
223
240
|
const iss = JSON.parse(String(await io.gh(["api", `repos/${repo}/issues/${issue}`])));
|
|
@@ -253,6 +270,7 @@ export async function probeIssue({ issue, repo, cwd = process.cwd(), io, default
|
|
|
253
270
|
try { await io.gh(["issue", "reopen", String(issue), "-R", repo]); } catch (e) { note = `; reopen failed: ${String(e?.message ?? e).slice(0, 120)}`; }
|
|
254
271
|
}
|
|
255
272
|
await io.gh(["issue", "comment", String(issue), "-R", repo, "--body", body]);
|
|
273
|
+
await (r.result === "fail" ? markPostDeployFailed : clearAwaitingPromotion)({ io, repo, issue }); // #5704
|
|
256
274
|
return row(r.result, detail + note, { fix, defaultBranch });
|
|
257
275
|
}
|
|
258
276
|
|
package/bin/lean/probe.test.mjs
CHANGED
|
@@ -212,3 +212,43 @@ describe("probe (#4399)", () => {
|
|
|
212
212
|
assert.equal(slow.result, "fail"); assert.equal(slow.exit, null);
|
|
213
213
|
});
|
|
214
214
|
});
|
|
215
|
+
|
|
216
|
+
describe("probe labels (#5704)", () => {
|
|
217
|
+
const labelled = (w, { missingLabel = false } = {}) => {
|
|
218
|
+
const inner = w.io.gh, edits = [];
|
|
219
|
+
let created = false;
|
|
220
|
+
w.io.gh = async (a) => {
|
|
221
|
+
if (a[0] === "label" && a[1] === "create") { created = true; edits.push(["create", a[2]]); return ""; }
|
|
222
|
+
if (a[0] === "issue" && a[1] === "edit") {
|
|
223
|
+
if (missingLabel && !created && a.includes("--add-label")) throw new Error("label not found");
|
|
224
|
+
edits.push(a.slice(3).filter((x) => x !== "-R" && x !== "o/r")); return "";
|
|
225
|
+
}
|
|
226
|
+
return inner(a);
|
|
227
|
+
};
|
|
228
|
+
return edits;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
it("a fail removes awaiting-promotion and adds post-deploy-failed (created on first use)", async () => {
|
|
232
|
+
const w = world();
|
|
233
|
+
const edits = labelled(w, { missingLabel: true });
|
|
234
|
+
const r = await run(w, { code: 1, stdout: "boom" });
|
|
235
|
+
assert.equal(r.outcome, "fail");
|
|
236
|
+
assert.deepEqual(w.reopened, ["7"]);
|
|
237
|
+
assert.deepEqual(edits, [["--remove-label", "awaiting-promotion"], ["create", "post-deploy-failed"], ["--add-label", "post-deploy-failed"]]);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("a pass removes awaiting-promotion only", async () => {
|
|
241
|
+
const w = world();
|
|
242
|
+
const edits = labelled(w);
|
|
243
|
+
const r = await run(w);
|
|
244
|
+
assert.equal(r.outcome, "pass");
|
|
245
|
+
assert.deepEqual(edits, [["--remove-label", "awaiting-promotion"]]);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("a dry run touches no label", async () => {
|
|
249
|
+
const w = world();
|
|
250
|
+
const edits = labelled(w);
|
|
251
|
+
await run(w, { code: 1 }, { dryRun: true });
|
|
252
|
+
assert.deepEqual(edits, []);
|
|
253
|
+
});
|
|
254
|
+
});
|
package/bin/lean/prompts.mjs
CHANGED
|
@@ -30,7 +30,7 @@ export const FORGEDOCK_CLI = fileURLToPath(new URL("../forgedock.mjs", import.me
|
|
|
30
30
|
/** #5347: every turn re-sends the whole session context, so independent read-only calls go out together, not one per turn. */
|
|
31
31
|
const BATCH_RULE = `One turn, many calls: when several reads, greps, git show/log/blame or gh calls do not depend on each other, issue them all in the same turn as parallel tool calls (or one shell call). One call per turn re-sends the whole context each time.`;
|
|
32
32
|
|
|
33
|
-
const HOST_RULES = `Host rules (many lanes share this machine): run only targeted tests (specific files or -k filters), never the full suite. Never create extra checkouts, copies or base clones of the repo; compare with git show or git diff origin/<base>. Never install browsers. Keep scratch files under $TMPDIR. Cap verification workers at $FORGE_HOST_PARALLELISM when set: turbo --concurrency, vitest/jest --maxWorkers, playwright --workers, node --test --test-concurrency (eslint via turbo). For any typecheck, lint or test you run, first run \`node $
|
|
33
|
+
const HOST_RULES = `Host rules (many lanes share this machine): run only targeted tests (specific files or -k filters), never the full suite. Never create extra checkouts, copies or base clones of the repo; compare with git show or git diff origin/<base>. Never install browsers. Keep scratch files under $TMPDIR. Cap verification workers at $FORGE_HOST_PARALLELISM when set: turbo --concurrency, vitest/jest --maxWorkers, playwright --workers, node --test --test-concurrency (eslint via turbo). For any typecheck, lint or test you run, first run \`node "$FORGEDOCK_CHECKS_CLI" --base origin/<base>\` after your edits and run the scoped commands it prints instead of the full tsc/eslint/test scripts (it widens itself when impact is unknown: lockfile, tsconfig, CI config); once they pass, rerun it with --publish to share the incremental caches. Lint changed packages only, never dependents (turbo ...[base], nx affected). node_modules/.venv may be hardlinked read-only from a shared cache: after changing a lockfile, or when an install fails with EACCES, delete that dir first (rm -rf is safe), then install; never chmod or edit files inside it.
|
|
34
34
|
Quiet output (tool results are re-read every later turn): run tests quietly (-q or a dot/summary reporter); on failure read \`tail -40\` plus the failing test ids (grep FAILED / not ok / FAIL), never the whole log. Send output over 8 KB to a $TMPDIR file; tail or grep it. Read each file's ranges once (sed -n a,bp or Read offset/limit, never a whole large file) and keep notes; don't re-read it.
|
|
35
35
|
Never use git stash (push, pop, apply, drop): the stash stack is shared by every lane of this repo and a pop can apply another lane's files. To set work aside, make a WIP commit (git commit -m wip) instead; git stash list and show stay allowed.
|
|
36
36
|
${BATCH_RULE}`;
|
|
@@ -123,6 +123,39 @@ ${d || "(no changes yet)"}
|
|
|
123
123
|
${est}Last validate result (${LEAN_DIR}/self-check.json, from \`forgedock check\`): ${c ? `\n${c.length > 4000 ? `${c.slice(0, 4000)}\n[truncated]` : c}` : "none recorded; run the validate commands."}`;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* #5812: the routed builder's opening digest. A build that starts fresh after BUILDER_ROUTE (instead of resuming the
|
|
128
|
+
* planning session) gets the plan's outcome, not its transcript: the frozen contract's deliverables and decisions, its
|
|
129
|
+
* open (non-deliver) requirements, the files planning read, its "Build reads:" list and the branch state. At most
|
|
130
|
+
* `maxBytes`; the contract and the investigation stay on disk as the authority.
|
|
131
|
+
*/
|
|
132
|
+
export function routeDigestPrompt({ contract = null, read = [], buildReads = "", planTokens = null, stat = "", diff = "", base = "", check = "", maxBytes = 32 * 1024 } = {}) {
|
|
133
|
+
const c = contract && typeof contract === "object" ? contract : {};
|
|
134
|
+
const one = (s, n) => String(s ?? "").replace(/\s+/g, " ").trim().slice(0, n);
|
|
135
|
+
const list = (xs, max) => `${xs.slice(0, max).map((x) => `- ${x}`).join("\n")}${xs.length > max ? `\n- (+${xs.length - max} more)` : ""}\n`;
|
|
136
|
+
const rows = (x) => (Array.isArray(x) ? x.filter((v) => v && typeof v === "object") : []);
|
|
137
|
+
const deliverables = rows(c.deliverables).map((d) => `${d.path ?? "?"}${d.change ? `: ${one(d.change, 160)}` : ""}`);
|
|
138
|
+
const decisions = rows(c.decisions).map((k) => `${k.id ?? "K?"} ${one(k.choice, 200)}${k.justification ? ` (${one(k.justification, 160)})` : ""}`);
|
|
139
|
+
const open = rows(c.requirements).filter((r) => r.disposition && r.disposition !== "deliver").map((r) => `${r.id ?? "R?"} ${r.disposition}: ${one(r.quote, 160)}`);
|
|
140
|
+
const reads = [...new Set((Array.isArray(read) ? read : []).filter((p) => typeof p === "string" && p))];
|
|
141
|
+
const budget = Math.max(2048, Number(maxBytes) || 0);
|
|
142
|
+
const st = String(stat ?? "").trim(), br = String(buildReads ?? "").trim().slice(0, 3000), ck = String(check ?? "").trim().slice(0, 2000);
|
|
143
|
+
const d = st ? boundDiff(String(diff ?? ""), { stat, base, maxBytes: Math.floor(budget / 3) }).trim() : "";
|
|
144
|
+
const sections = [
|
|
145
|
+
deliverables.length ? `Deliverables:\n${list(deliverables, 40)}` : "",
|
|
146
|
+
decisions.length ? `Decisions:\n${list(decisions, 20)}` : "",
|
|
147
|
+
open.length ? `Open (not delivered in this lane; do not implement):\n${list(open, 20)}` : "",
|
|
148
|
+
reads.length ? `Files planning read (already understood; re-read only what you edit):\n${list(reads, 40)}` : "",
|
|
149
|
+
br ? `Planning's build reads:\n${br}\n` : "",
|
|
150
|
+
st ? `Branch state (git diff --stat ${base}...HEAD):\n${st.slice(0, 3000)}\n${d ? `\n${d}\n` : ""}` : "",
|
|
151
|
+
ck ? `Last validate result (${LEAN_DIR}/self-check.json):\n${ck}\n` : "",
|
|
152
|
+
].join("");
|
|
153
|
+
const head = `\n\nRoute hand-off: planning ran in a separate session${planTokens ? ` (it ended at about ${planTokens} context tokens)` : ""} that this session does not inherit. Its outcome is on disk: ${CONTRACT_FILE} is the frozen authority and ${INVESTIGATION_FILE} holds the root cause, affected files and test plan; read both first. The digest below is what planning established; do not survey it again.\n\n<route_digest>\n`;
|
|
154
|
+
const room = budget - Buffer.byteLength(head) - 40;
|
|
155
|
+
const fitted = Buffer.byteLength(sections) <= room ? sections : `${Buffer.from(sections).subarray(0, Math.max(0, room)).toString().replace(/�+$/, "")}\n[digest truncated]\n`;
|
|
156
|
+
return `${head}${fitted}</route_digest>`;
|
|
157
|
+
}
|
|
158
|
+
|
|
126
159
|
/** #4392: the implement turn budget is spent; one bounded fresh session either finishes or stops with a typed digest. */
|
|
127
160
|
export function turnBudgetWrapupPrompt({ size = "?", budget = 0, used = 0, grant = 5, stat = "", diff = "", base = "", check = "" } = {}) {
|
|
128
161
|
const d = boundDiff(String(diff ?? ""), { stat, base, maxBytes: RESTART_DIFF_MAX_BYTES }).trim();
|
|
@@ -178,6 +211,7 @@ ${HOST_RULES}${toolchainRule(toolchain)}${sparseRule(sparse)}${factsRule(facts)}
|
|
|
178
211
|
### Test plan (bug issues: per deliver requirement, see the contract test_plan)
|
|
179
212
|
${LEAN_DIR}/classification.json{type,severity,exists_in,flag,exists_in_evidence:{cite,repro:{command,red_on_live,green_after}}}
|
|
180
213
|
|
|
214
|
+
A trusted comment recording a prod failure after the merged fix overrides ancestry: never report already-fixed for an outcome criterion from ancestry alone.
|
|
181
215
|
If the issue is already fixed or invalid, write ${RESULT_FILE} {"status":"already-fixed|invalid","summary":"one line","evidence":["file:line ..."]} and stop. A feature already reachable (another name, or a stdlib or wrapped dependency function) is a duplicate: INVALID, naming the equivalent and its path; its deprecation counts against an alias. If it is blocked, write {"status":"blocked","summary":"",...} with a typed "block" (rules below) and stop.
|
|
182
216
|
|
|
183
217
|
2. Otherwise write ${CONTRACT_FILE}, the frozen hand-off: a developer who never saw the issue must be able to implement and verify from this file alone.
|
|
@@ -232,12 +266,15 @@ The contract changes only through typed amendments in ${RESULT_FILE}, each with
|
|
|
232
266
|
- {"kind":"add-requirement","requirement":{"id":"R9","quote":"<verbatim from the issue>","disposition":"deliver|defer|post-deploy"},"why":""}: a missed requirement.
|
|
233
267
|
- {"kind":"defer|post-deploy","requirement":"R#","why":"","check":"<id>"}: separate work or a post-deploy check, filed as a follow-up. Not "type"; unknown kinds are rejected. One requirement id per row. An impossible deliverable is a defer, not a new kind.
|
|
234
268
|
- {"kind":"amend-requirement","requirement":"R#","text":"<revised wording>","why":""}: reworded.
|
|
235
|
-
- {"kind":"supersedes","guard":"#N","why":""}: overrides a guard_broken failure.
|
|
269
|
+
- {"kind":"supersedes","guard":"#N","why":""}: overrides a guard_broken failure; {"kind":"supersedes","mechanism":"<name>","why":""} retires every guard whose test this lane deletes.
|
|
236
270
|
- {"kind":"decision","decision":{"choice":"","anchors":["<base path>"],"supersedes":"<id>"},"why":""}: supersedes changes an H-row.
|
|
237
271
|
New keys: translate, never copy English; status entries in place.
|
|
238
272
|
Never report a deliver requirement as "deferred" or "follow-up" without an amendment.
|
|
239
273
|
Never name or number migration files by hand; use the generator.
|
|
274
|
+
New CI (#5760): join ci.budget.shared_regression_job, else annotate \`# FORGE:CI_BUDGET trigger= minutes= why=\`; a new workflow/job needs concurrency, timeout-minutes, paths, event if:.
|
|
240
275
|
A [type:e2e] requirement needs a validate that runs a real e2e check (repo e2e set, Playwright, live stack), not a stubbed unit test; else post-deploy.
|
|
276
|
+
A new keyword/regex classifier ships negative examples (inputs it must not match).
|
|
277
|
+
A forge.yaml outcome_evidence area change needs result outcome_evidence [{area,metric,corpus,before,after,better}] measured on recorded real inputs; its post-deploy checks get a numeric baseline.
|
|
241
278
|
A new workspace-package dependency in a package.json no deliverable names is blocked by the engine: add it through add-deliverable with a why naming the package, or do not add it.
|
|
242
279
|
If scripts/check-devdocs-freshness.sh exists, a behaviour change under its paths must update the matching dossier (devdocs/modules/*.md, per devdocs/index.yaml) in the same change; run it against the base first.
|
|
243
280
|
|
|
@@ -303,7 +340,7 @@ export function docsPlanNote(cfg) {
|
|
|
303
340
|
/** #5428: the page_gate rule for the planner; "" when forge.yaml pages is off. */
|
|
304
341
|
export function pagePlanNote(cfg) {
|
|
305
342
|
if (!cfg?.require?.length) return "";
|
|
306
|
-
return `\n\nThis repo gates public pages (forge.yaml pages.require: ${cfg.require.join(", ")}). When the issue adds or changes a public page, ${CONTRACT_FILE} must carry "page_gate":{"design_spec":"<approved FORGE:DESIGN_SPEC ref, from /design>","seo":{"intent":"<target query>","icp":"<named ICP${cfg.icp_doc ? ` from ${cfg.icp_doc}` : ""}>","title":"","h1":"","meta":"","structured_data":"<schema.org type>","links_in":[],"links_out":[],"gsc_baseline":"","measure_by":"YYYY-MM-DD"},"geo":{"surfaces":["llms.txt","llms-full","markdown mirror","ai-catalog","MCP tool description"],"agent_question":"<natural-language question that must resolve to the page>"}}, plus a sitemap entry, metadata, canonical and structured data in the page, and the result file must list page_gate.screenshots (390 and 1440 wide). Never render raw JSON first or null samples on a public page.`;
|
|
343
|
+
return `\n\nThis repo gates public pages (forge.yaml pages.require: ${cfg.require.join(", ")}). When the issue adds or changes a public page, ${CONTRACT_FILE} must carry "page_gate":{"design_spec":"<approved FORGE:DESIGN_SPEC ref, from /design>","seo":{"intent":"<target query>","icp":"<named ICP${cfg.icp_doc ? ` from ${cfg.icp_doc}` : ""}>","title":"","h1":"","meta":"","structured_data":"<schema.org type>","links_in":[],"links_out":[],"gsc_baseline":"","measure_by":"YYYY-MM-DD"},"geo":{"surfaces":["llms.txt","llms-full","markdown mirror","ai-catalog","MCP tool description"],"agent_question":"<natural-language question that must resolve to the page>"}}, plus a sitemap entry, metadata, canonical and structured data in the page, ${cfg.capture ? "and the engine captures the 390/1440 visual check itself for app/**/page.* routes (do not install anything for screenshots); any other page file still needs page_gate.screenshots as links or image paths (390 and 1440 wide)" : "and the result file must list page_gate.screenshots as links or image paths (390 and 1440 wide)"}. Never render raw JSON first or null samples on a public page.`;
|
|
307
344
|
}
|
|
308
345
|
|
|
309
346
|
export function reproPlanNote(on) {
|
|
@@ -605,3 +605,23 @@ describe("#5592 env.tool_missing recovery is not a verbatim replay", () => {
|
|
|
605
605
|
assert.match(r.rows[0].detail, /same `env\.tool_missing` as the run before it/);
|
|
606
606
|
});
|
|
607
607
|
});
|
|
608
|
+
|
|
609
|
+
describe("#5727 a recipe-less remote tool miss", () => {
|
|
610
|
+
const go = (script) => {
|
|
611
|
+
const calls = [];
|
|
612
|
+
return orchestrate({ issues: [7], parallel: 2, recovery: { maxAttempts: 1, mechanicalMaxAttempts: 1 }, readBody: async () => "",
|
|
613
|
+
remote: { max: 2, isRemote: () => true, place: () => ({ where: "remote", reason: "test" }), admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 },
|
|
614
|
+
runOne: async (_n, _l, ctx = {}) => { calls.push([ctx.placement?.where ?? null, ctx.recover?.attempt ?? 0]); return script[Math.min(calls.length - 1, script.length - 1)]; } }).then((rows) => ({ rows, calls }));
|
|
615
|
+
};
|
|
616
|
+
const noRecipe = { terminalReason: "needs-human", code: "env.tool_missing", detail: "Remote sandbox lacks forgedock, and no lane_tools recipe exists for it.", placement: { where: "remote" }, toolNoRecipe: true };
|
|
617
|
+
const other = { terminalReason: "needs-human", code: "env.tool_missing", detail: "Environment error: the host is missing promtool, so validate command(s) could not run", placement: { where: "local" } };
|
|
618
|
+
it("#5727 recipe-less remote tool miss recovers on the host without consuming an attempt", async () => {
|
|
619
|
+
const r = await go([noRecipe, other, { terminalReason: "merged", pr: 1 }]);
|
|
620
|
+
assert.deepEqual(r.calls, [["remote", 0], ["local", 1], ["local", 1]], "the free host recovery leaves the one attempt for the next failure");
|
|
621
|
+
assert.equal(r.rows.find((x) => x.issue === 7).outcome, "merged");
|
|
622
|
+
});
|
|
623
|
+
it("#5727 a recipe-less miss without the fact is charged as before", async () => {
|
|
624
|
+
const r = await go([{ ...noRecipe, toolNoRecipe: undefined }, other, { terminalReason: "merged", pr: 1 }]);
|
|
625
|
+
assert.equal(r.calls.length, 2);
|
|
626
|
+
});
|
|
627
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* #5751: recurrence routing. A new issue that matches at least `threshold` earlier merged fixes by symptom (subject recall
|
|
5
|
+
* or an explicit `Recurs #n` link) AND by area (the fix touched a path the issue names) is a recurrence: the lane runs as a
|
|
6
|
+
* design lane (no light lane, a stricter plan prompt, a contract `design` block) instead of adding a further fix.
|
|
7
|
+
* Deterministic: zero LLM calls. The engine's inputs are subjectHistory rows (context.mjs) and the merged PRs' file lists.
|
|
8
|
+
*/
|
|
9
|
+
import { OUTCOME_CODES as C } from "../engine/outcome-codes.mjs";
|
|
10
|
+
import { subjectHistory } from "./context.mjs";
|
|
11
|
+
|
|
12
|
+
export const RECURRENCE_DEFAULTS = Object.freeze({ mode: "on", threshold: 2 });
|
|
13
|
+
/** At most this many merged rows have their file lists read (one GitHub call each). */
|
|
14
|
+
export const MAX_RECURRENCE_ROWS = 6;
|
|
15
|
+
|
|
16
|
+
const clean = (p) => String(p ?? "").trim().replace(/^\.?\/+/, "").replace(/\/+$/, "");
|
|
17
|
+
const list = (v) => (Array.isArray(v) ? v : typeof v === "string" ? v.split(",") : []).map((x) => String(x).trim()).filter(Boolean);
|
|
18
|
+
const COUNTER_SEP = " -- "; // `pattern -- glob, glob`: the git grep pathspec separator
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* forge.yaml `recurrence:` (absent: the defaults, mode on). `hot_areas` is a list of {name, paths} or a block map
|
|
22
|
+
* {name: "glob, glob"}; `counters` a list of {name, pattern, paths} or a block map {name: "pattern -- glob, glob"}.
|
|
23
|
+
* @returns {{mode:"on"|"off", threshold:number, hotAreas:{name:string, paths:string[]}[], counters:{name:string, pattern:string, paths:string[]}[]}}
|
|
24
|
+
*/
|
|
25
|
+
export function parseRecurrenceConfig(raw) {
|
|
26
|
+
const r = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
27
|
+
const m = String(r.mode ?? "").trim().toLowerCase();
|
|
28
|
+
const mode = r.mode === false || m === "off" || m === "false" ? "off" : RECURRENCE_DEFAULTS.mode;
|
|
29
|
+
const t = Number(r.threshold);
|
|
30
|
+
const threshold = Number.isInteger(t) && t >= 1 ? t : RECURRENCE_DEFAULTS.threshold;
|
|
31
|
+
const rows = (v) => (Array.isArray(v) ? v : v && typeof v === "object" ? Object.entries(v).map(([name, val]) => ({ name, val })) : []);
|
|
32
|
+
const hotAreas = rows(r.hot_areas).map((x) => ({ name: String(x?.name ?? "").trim(), paths: list(x?.paths ?? x?.val).map(clean) }))
|
|
33
|
+
.filter((a) => a.name && a.paths.length);
|
|
34
|
+
const counters = rows(r.counters).map((x) => {
|
|
35
|
+
if (x?.val !== undefined) {
|
|
36
|
+
const s = String(x.val), i = s.lastIndexOf(COUNTER_SEP);
|
|
37
|
+
return { name: String(x.name).trim(), pattern: (i >= 0 ? s.slice(0, i) : s).trim(), paths: i >= 0 ? list(s.slice(i + COUNTER_SEP.length)).map(clean) : [] };
|
|
38
|
+
}
|
|
39
|
+
return { name: String(x?.name ?? "").trim(), pattern: String(x?.pattern ?? "").trim(), paths: list(x?.paths).map(clean) };
|
|
40
|
+
}).filter((c) => c.name && c.pattern);
|
|
41
|
+
return { mode, threshold, hotAreas, counters };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Issue numbers named by `Recurs #n` (also `Recurs: #n`, `Recurs of #n`, `Recurs #n, #m`). */
|
|
45
|
+
export function recursLinks(body = "") {
|
|
46
|
+
const out = new Set();
|
|
47
|
+
for (const m of String(body ?? "").matchAll(/\brecurs(?:\s+of)?\s*:?\s*((?:#\d+[\s,]*(?:and\s+)?)+)/gi)) for (const n of m[1].matchAll(/#(\d+)/g)) out.add(Number(n[1]));
|
|
48
|
+
return [...out].filter((n) => Number.isSafeInteger(n) && n > 0);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Two paths overlap when they are equal or one is a directory prefix of the other. */
|
|
52
|
+
export function pathsOverlap(a, b) {
|
|
53
|
+
const x = clean(a), y = clean(b);
|
|
54
|
+
return Boolean(x && y) && (x === y || x.startsWith(`${y}/`) || y.startsWith(`${x}/`));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Count earlier merged fixes on the same symptom and the same area. A subjectHistory row counts when it is a merged PR
|
|
59
|
+
* whose files (`mergedPrFiles[number]`) overlap a path the issue names. A `Recurs #n` link is an explicit symptom match:
|
|
60
|
+
* it counts when its files overlap or are unknown (the author declared the same area). Rows without overlap never count.
|
|
61
|
+
* @returns {{recurs:boolean, count:number, threshold:number, evidence:{number:number, title:string, via:string, paths:string[]}[], reason:string}}
|
|
62
|
+
*/
|
|
63
|
+
export function detectRecurrence({ rows = [], mergedPrFiles = {}, body = "", namedPaths = [], threshold = RECURRENCE_DEFAULTS.threshold } = {}) {
|
|
64
|
+
const named = [...new Set((namedPaths ?? []).map(clean).filter(Boolean))];
|
|
65
|
+
const filesOf = (n) => (mergedPrFiles instanceof Map ? mergedPrFiles.get(n) : mergedPrFiles?.[n]);
|
|
66
|
+
const evidence = [], seen = new Set();
|
|
67
|
+
for (const r of rows ?? []) {
|
|
68
|
+
const n = Number(r?.number);
|
|
69
|
+
if (!Number.isSafeInteger(n) || seen.has(n) || r?.kind !== "PR" || r?.status !== "merged") continue;
|
|
70
|
+
const paths = (filesOf(n) ?? []).map(clean).filter((f) => named.some((p) => pathsOverlap(f, p)));
|
|
71
|
+
if (!paths.length) continue;
|
|
72
|
+
seen.add(n);
|
|
73
|
+
evidence.push({ number: n, title: String(r.title ?? ""), via: `subject (${(r.matched ?? []).join(", ")})`, paths: [...new Set(paths)] });
|
|
74
|
+
}
|
|
75
|
+
for (const n of recursLinks(body)) {
|
|
76
|
+
if (seen.has(n)) continue;
|
|
77
|
+
const files = filesOf(n);
|
|
78
|
+
const paths = Array.isArray(files) ? files.map(clean).filter((f) => named.some((p) => pathsOverlap(f, p))) : null;
|
|
79
|
+
if (paths && !paths.length) continue;
|
|
80
|
+
seen.add(n);
|
|
81
|
+
evidence.push({ number: n, title: "", via: "Recurs link", paths: paths ?? [] });
|
|
82
|
+
}
|
|
83
|
+
const t = Number.isInteger(threshold) && threshold >= 1 ? threshold : RECURRENCE_DEFAULTS.threshold;
|
|
84
|
+
const count = evidence.length, recurs = count >= t;
|
|
85
|
+
const reason = recurs
|
|
86
|
+
? `recurrence: ${count} earlier merged fix(es) on the same symptom and area (threshold ${t}): ${evidence.map((e) => `#${e.number}${e.paths.length ? ` (${e.paths.slice(0, 3).join(", ")})` : ""}`).join(", ")}`
|
|
87
|
+
: "";
|
|
88
|
+
return { recurs, count, threshold: t, evidence, reason };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The engine-side gather: subjectHistory rows plus one file-list read per merged row (capped). `io`: {gh, git}. Never
|
|
93
|
+
* throws: a failed source contributes nothing and lands in `errors`.
|
|
94
|
+
*/
|
|
95
|
+
export async function recurrenceFacts({ io, repo, issue, title = "", body = "", base = null, namedPaths = [], threshold, exclude = [] }) {
|
|
96
|
+
const errors = [];
|
|
97
|
+
let rows = [];
|
|
98
|
+
try { const h = await subjectHistory({ io, repo, issue, title, body, base, exclude }); rows = h.rows ?? []; errors.push(...(h.errors ?? [])); } catch (e) { errors.push(`recurrence: ${String(e?.message ?? e).slice(0, 80)}`); }
|
|
99
|
+
const wanted = [...new Set([...rows.filter((r) => r?.kind === "PR" && r?.status === "merged").map((r) => Number(r.number)), ...recursLinks(body)])].slice(0, MAX_RECURRENCE_ROWS);
|
|
100
|
+
const mergedPrFiles = {};
|
|
101
|
+
if (namedPaths.length) {
|
|
102
|
+
for (const n of wanted) {
|
|
103
|
+
try {
|
|
104
|
+
const out = String(await io.gh(["api", `repos/${repo}/pulls/${n}/files`, "--paginate", "--jq", ".[].filename"]));
|
|
105
|
+
mergedPrFiles[n] = out.split("\n").map((x) => x.trim()).filter(Boolean);
|
|
106
|
+
} catch { /* not a PR (an issue link) or unreadable: unknown files */ }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return { ...detectRecurrence({ rows, mergedPrFiles, body, namedPaths, threshold }), errors };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The design lane's plan instruction (#5751): why the earlier fixes failed, delete or replace, a measurable outcome. */
|
|
113
|
+
export function designLaneNote(detection) {
|
|
114
|
+
if (!detection?.recurs) return "";
|
|
115
|
+
const ev = detection.evidence.map((e) => `- #${e.number}${e.title ? ` ${e.title}` : ""} [${e.via}]${e.paths.length ? `: ${e.paths.join(", ")}` : ""}`).join("\n");
|
|
116
|
+
return `\n\nDESIGN LANE (#5751): this issue recurs. ${detection.count} earlier merged fix(es) hit the same symptom in the same area:\n${ev}\nDo not add another patch on top of them. Read each earlier fix (gh pr view N, git show) as an active input, then put a "design" object in .forge-lean/contract.json:
|
|
117
|
+
{"design":{"why_failed":"<why the earlier fixes did not hold, naming them>","disposition":"delete|replace|extend","outcome":{"metric":"<what is measured>","target":"<the value that shows it held>"}}}
|
|
118
|
+
Prefer "delete" or "replace" of the earlier fixes; "extend" needs its reason in why_failed. The outcome needs a validate (test, counter or check) that measures it. When the redesign is too big for one lane, decompose it into ordinary lanes with the split-required block.`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** #5751: a design lane's contract must carry design {why_failed, disposition delete|replace|extend, outcome {metric, target}}. */
|
|
122
|
+
export function designContractFailures(contract, detection) {
|
|
123
|
+
if (!detection?.recurs) return [];
|
|
124
|
+
const d = contract?.design, problems = [];
|
|
125
|
+
const s = (v) => typeof v === "string" && v.trim();
|
|
126
|
+
if (!d || typeof d !== "object" || Array.isArray(d)) problems.push("no design block");
|
|
127
|
+
else {
|
|
128
|
+
if (!s(d.why_failed)) problems.push("design.why_failed is empty");
|
|
129
|
+
if (!["delete", "replace", "extend"].includes(String(d.disposition ?? "").trim())) problems.push("design.disposition is not delete, replace or extend");
|
|
130
|
+
if (!s(d.outcome?.metric) || !(s(d.outcome?.target) || Number.isFinite(d.outcome?.target))) problems.push("design.outcome needs a metric and a target");
|
|
131
|
+
}
|
|
132
|
+
return problems.length ? [{ code: C.RECURRENCE_DESIGN_MISSING, kind: "design_missing", detail: `recurring issue (${detection.count} earlier fixes) routed to a design lane: ${problems.join("; ")}` }] : [];
|
|
133
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { parseRecurrenceConfig, detectRecurrence, recursLinks, pathsOverlap, recurrenceFacts, designLaneNote, designContractFailures } from "./recurrence.mjs";
|
|
6
|
+
|
|
7
|
+
const row = (number, o = {}) => ({ number, kind: "PR", status: "merged", title: `fix leak ${number}`, matched: ["reservation", "leak"], ...o });
|
|
8
|
+
const NAMED = ["src/billing/reserve.js"];
|
|
9
|
+
|
|
10
|
+
describe("recurrence config (#5751)", () => {
|
|
11
|
+
it("defaults to mode on, threshold 2, no hot areas or counters", () => {
|
|
12
|
+
assert.deepEqual(parseRecurrenceConfig(undefined), { mode: "on", threshold: 2, hotAreas: [], counters: [] });
|
|
13
|
+
});
|
|
14
|
+
it("reads mode off, a threshold, list and block-map hot areas and counters", () => {
|
|
15
|
+
const c = parseRecurrenceConfig({ mode: "off", threshold: "3", hot_areas: { billing: "src/billing/**, ./src/pay.js" }, counters: [{ name: "flags", pattern: "FLAG_[A-Z]+", paths: "src/**" }] });
|
|
16
|
+
assert.equal(c.mode, "off");
|
|
17
|
+
assert.equal(c.threshold, 3);
|
|
18
|
+
assert.deepEqual(c.hotAreas, [{ name: "billing", paths: ["src/billing/**", "src/pay.js"] }]);
|
|
19
|
+
assert.deepEqual(c.counters, [{ name: "flags", pattern: "FLAG_[A-Z]+", paths: ["src/**"] }]);
|
|
20
|
+
assert.deepEqual(parseRecurrenceConfig({ counters: { exports: "^export (a|b) -- bin/*.mjs" } }).counters, [{ name: "exports", pattern: "^export (a|b)", paths: ["bin/*.mjs"] }]);
|
|
21
|
+
assert.equal(parseRecurrenceConfig({ mode: false, threshold: 0 }).mode, "off");
|
|
22
|
+
assert.equal(parseRecurrenceConfig({ threshold: 0 }).threshold, 2, "an invalid threshold keeps the default");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("recurrence detection (#5751)", () => {
|
|
27
|
+
it("two merged fixes on the same symptom touching a named path route to a design lane and record the reason", () => {
|
|
28
|
+
const d = detectRecurrence({ rows: [row(10), row(11)], mergedPrFiles: { 10: ["src/billing/reserve.js"], 11: ["src/billing/reserve.js", "README.md"] }, namedPaths: NAMED });
|
|
29
|
+
assert.equal(d.recurs, true);
|
|
30
|
+
assert.equal(d.count, 2);
|
|
31
|
+
assert.deepEqual(d.evidence.map((e) => e.number), [10, 11]);
|
|
32
|
+
assert.match(d.reason, /^recurrence: 2 earlier merged fix\(es\) on the same symptom and area \(threshold 2\): #10 \(src\/billing\/reserve\.js\), #11/);
|
|
33
|
+
});
|
|
34
|
+
it("one matching fix does not route", () => {
|
|
35
|
+
const d = detectRecurrence({ rows: [row(10)], mergedPrFiles: { 10: NAMED }, namedPaths: NAMED });
|
|
36
|
+
assert.equal(d.recurs, false);
|
|
37
|
+
assert.equal(d.count, 1);
|
|
38
|
+
assert.equal(d.reason, "");
|
|
39
|
+
});
|
|
40
|
+
it("symptom matches without path overlap, unmerged rows and issues do not count", () => {
|
|
41
|
+
const d = detectRecurrence({ rows: [row(10), row(11), row(12, { status: "closed unmerged" }), row(13, { kind: "issue", status: "completed" })],
|
|
42
|
+
mergedPrFiles: { 10: ["src/other.js"], 11: ["docs/x.md"], 12: NAMED, 13: NAMED }, namedPaths: NAMED });
|
|
43
|
+
assert.equal(d.recurs, false);
|
|
44
|
+
assert.equal(d.count, 0);
|
|
45
|
+
assert.equal(detectRecurrence({ rows: [row(10), row(11)], mergedPrFiles: { 10: NAMED, 11: NAMED }, namedPaths: [] }).recurs, false, "an issue naming no path has no area");
|
|
46
|
+
});
|
|
47
|
+
it("a directory named by the issue overlaps the files under it", () => {
|
|
48
|
+
assert.equal(pathsOverlap("src/billing/reserve.js", "src/billing"), true);
|
|
49
|
+
assert.equal(pathsOverlap("src/billingx.js", "src/billing"), false);
|
|
50
|
+
assert.equal(detectRecurrence({ rows: [row(10), row(11)], mergedPrFiles: { 10: ["src/billing/a.js"], 11: ["src/billing/b.js"] }, namedPaths: ["src/billing/"] }).recurs, true);
|
|
51
|
+
});
|
|
52
|
+
it("Recurs #n links count: unknown files are the author's declaration, files elsewhere are not", () => {
|
|
53
|
+
assert.deepEqual(recursLinks("Recurs #10, #11\nalso recurs of #12 and Recurs: #13"), [10, 11, 12, 13]);
|
|
54
|
+
const d = detectRecurrence({ rows: [row(10)], mergedPrFiles: { 10: NAMED }, body: "Recurs #10, #20", namedPaths: NAMED });
|
|
55
|
+
assert.equal(d.count, 2, "#10 counts once; #20 (files unknown) counts");
|
|
56
|
+
assert.deepEqual(d.evidence.map((e) => [e.number, e.via]), [[10, "subject (reservation, leak)"], [20, "Recurs link"]]);
|
|
57
|
+
assert.equal(detectRecurrence({ rows: [row(10)], mergedPrFiles: { 10: NAMED, 21: ["elsewhere.js"] }, body: "Recurs #21", namedPaths: NAMED }).recurs, false);
|
|
58
|
+
});
|
|
59
|
+
it("the threshold is configurable", () => {
|
|
60
|
+
assert.equal(detectRecurrence({ rows: [row(10), row(11)], mergedPrFiles: { 10: NAMED, 11: NAMED }, namedPaths: NAMED, threshold: 3 }).recurs, false);
|
|
61
|
+
assert.equal(detectRecurrence({ rows: [row(10)], mergedPrFiles: { 10: NAMED }, namedPaths: NAMED, threshold: 1 }).recurs, true);
|
|
62
|
+
});
|
|
63
|
+
it("recurrenceFacts reads subject history and each merged PR's files, with no LLM call", async () => {
|
|
64
|
+
const calls = [];
|
|
65
|
+
const gh = async (a) => {
|
|
66
|
+
calls.push(a.join(" "));
|
|
67
|
+
if (a.includes("search/issues")) return [10, 11].map((n) => JSON.stringify({ number: n, title: `fix ${n}`, pr: true, merged: true })).join("\n");
|
|
68
|
+
const m = /pulls\/(\d+)\/files/.exec(a.join(" "));
|
|
69
|
+
if (m) return m[1] === "10" ? "src/billing/reserve.js\n" : "src/billing/reserve.js\nx.md\n";
|
|
70
|
+
throw new Error("unexpected");
|
|
71
|
+
};
|
|
72
|
+
const d = await recurrenceFacts({ io: { gh }, repo: "o/r", issue: 7, title: "reservation leak on 429", body: "See src/billing/reserve.js", namedPaths: NAMED, threshold: 2 });
|
|
73
|
+
assert.equal(d.recurs, true);
|
|
74
|
+
assert.deepEqual(d.evidence.map((e) => e.number), [11, 10]);
|
|
75
|
+
assert.ok(calls.some((c) => c.includes("pulls/10/files")) && calls.some((c) => c.includes("pulls/11/files")));
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("design lane (#5751)", () => {
|
|
80
|
+
const det = detectRecurrence({ rows: [row(10), row(11)], mergedPrFiles: { 10: NAMED, 11: NAMED }, namedPaths: NAMED });
|
|
81
|
+
it("the plan note names the earlier fixes and asks why they failed, delete or replace, a measurable outcome and allows a split", () => {
|
|
82
|
+
const n = designLaneNote(det);
|
|
83
|
+
assert.match(n, /DESIGN LANE/);
|
|
84
|
+
assert.match(n, /#10 fix leak 10/);
|
|
85
|
+
assert.match(n, /why_failed/);
|
|
86
|
+
assert.match(n, /delete\|replace\|extend/);
|
|
87
|
+
assert.match(n, /"metric"/);
|
|
88
|
+
assert.match(n, /split-required/);
|
|
89
|
+
assert.equal(designLaneNote({ recurs: false }), "");
|
|
90
|
+
assert.equal(designLaneNote(null), "");
|
|
91
|
+
});
|
|
92
|
+
it("a design lane's contract must carry why_failed, a disposition and a measurable outcome", () => {
|
|
93
|
+
assert.equal(designContractFailures({}, det)[0].kind, "design_missing");
|
|
94
|
+
assert.match(designContractFailures({}, det)[0].detail, /no design block/);
|
|
95
|
+
assert.match(designContractFailures({ design: { why_failed: "", disposition: "replace", outcome: { metric: "m", target: 0 } } }, det)[0].detail, /why_failed is empty/);
|
|
96
|
+
assert.deepEqual(designContractFailures({ design: { why_failed: "w", disposition: "delete", outcome: { metric: "m", target: 0 } } }, det), []);
|
|
97
|
+
assert.deepEqual(designContractFailures({}, { recurs: false }), [], "an ordinary lane needs no design block");
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -38,6 +38,7 @@ const PIPELINE = obj({ workflow: S, trigger: en("push", "dispatch"), inputs: { t
|
|
|
38
38
|
export const POLICY_SCHEMA = obj({
|
|
39
39
|
schema: { t: "integer", e: [1] },
|
|
40
40
|
branches: obj({ default: S, integration: SN, train: S, release: S, hotfix: S }),
|
|
41
|
+
release: obj({ hold_merges_during_release_ci: B }), // #5709: default true (applied by release-merge-hold.mjs callers)
|
|
41
42
|
trust: obj({ actors: list(), require_verified_commits: B }),
|
|
42
43
|
state: obj({ ledger_prefix: S, lease_ttl_s: N, heartbeat_s: N }),
|
|
43
44
|
units: { t: "map", v: obj({ paths: list(), image: SN, criticality: en("low", "medium", "high"), tests: list(), verify: list(), service_pipeline: B, single_host_ok: B, dockerfile: SN, surface: en("service", "web", "edge") }) },
|
|
@@ -45,7 +46,7 @@ export const POLICY_SCHEMA = obj({
|
|
|
45
46
|
contracts: list(obj({ producer: S, consumers: list(), paths: list(), additive_only: B, regenerate: SN })),
|
|
46
47
|
forces: list(obj({ paths: list(), pipeline: en("full", "service", "hotfix"), reason: S })),
|
|
47
48
|
classify: obj({ min_confidence: N, text_only_cap: N, triage_max_per_hour: N, exists_in_evidence: en("mechanical", "llm") }),
|
|
48
|
-
risk: obj({ rules: list(obj({ when: obj({ migration: B, paths: list(), contract: B, rolled_units_gt: N, diff_lines_gt: N
|
|
49
|
+
risk: obj({ rules: list(obj({ when: obj({ migration: B, paths: list(), contract: B, rolled_units_gt: N, diff_lines_gt: N }), risk: en("low", "medium", "high"), forces: S, requires: S })) }),
|
|
49
50
|
features: obj({ flag_policy: en("require", "warn", "off") }), // #5571: a feature wave adding no rollout key: require = refuse, warn = WARN, off = nothing; lanes.<lane>.flag_policy wins
|
|
50
51
|
plan: obj({ approval: en("wait", "auto", "auto-if"), skip_labels: list(), require_design_gate: B, max_issues: N, stale_snapshot_s: N }),
|
|
51
52
|
lanes: { t: "map", v: obj({ pipeline: S, ci_tier: S, approval: S, budget: S, base: en("live", "integration", "default"), units_max: N, max_risk: en("low", "medium", "high"), train_max_issues: N, train_max_units: N, soak_min: { t: "any" }, flag_policy: en("require", "warn", "off"), requires: list() }) },
|
|
@@ -7,6 +7,7 @@ import { join } from "node:path";
|
|
|
7
7
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
8
8
|
import { parsePolicy, validatePolicy, readPolicy, INIT_PROFILE, checkConfigFromCli, dockerfileCoverage, dockerfileSources, initFromCli, POLICY_PATH } from "./release-config.mjs";
|
|
9
9
|
import { releaseFromCli } from "./release.mjs";
|
|
10
|
+
import { DEFAULT_RISK_RULES } from "./release-classify.mjs";
|
|
10
11
|
|
|
11
12
|
const OK = `schema: 1
|
|
12
13
|
branches: {default: main, integration: staging}
|
|
@@ -47,6 +48,18 @@ describe("validate", () => {
|
|
|
47
48
|
});
|
|
48
49
|
});
|
|
49
50
|
|
|
51
|
+
describe("risk.rules requires (#5700)", () => {
|
|
52
|
+
it("DEFAULT_RISK_RULES passes validatePolicy", () => {
|
|
53
|
+
const r = parsePolicy(OK);
|
|
54
|
+
assert.deepEqual(validatePolicy({ ...r.policy, risk: { rules: DEFAULT_RISK_RULES } }), []);
|
|
55
|
+
});
|
|
56
|
+
it("accepts rule-level requires and rejects when.requires", () => {
|
|
57
|
+
const rule = (body) => OK + `risk: {rules: [${body}]}\n`;
|
|
58
|
+
assert.deepEqual(check(rule('{when: {paths: ["x/**"]}, risk: high, requires: rollout-declaration}')), []);
|
|
59
|
+
assert.match(check(rule('{when: {paths: ["x/**"], requires: rollout-declaration}, risk: high}')).join(), /requires: unknown key/);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
50
63
|
describe("ci.fix (#5567)", () => {
|
|
51
64
|
it("accepts max_rounds, co_start and full_run_workflow; rejects unknown keys and a non-integer max_rounds", () => {
|
|
52
65
|
assert.deepEqual(check(OK.replace("ci:\n", "ci:\n fix: {max_rounds: 1, co_start: true, full_run_workflow: full.yml}\n")), []);
|
|
@@ -179,4 +192,9 @@ describe("features.flag_policy (#5571)", () => {
|
|
|
179
192
|
for (const v of ["require", "warn", "off"]) assert.deepEqual(check(OK + `features: {flag_policy: ${v}}\n`), [], v);
|
|
180
193
|
assert.match(check(OK + "features: {flag_policy: maybe}\n").join(), /flag_policy/);
|
|
181
194
|
});
|
|
195
|
+
|
|
196
|
+
it("release.hold_merges_during_release_ci is a boolean (#5709)", () => {
|
|
197
|
+
for (const v of ["true", "false"]) assert.deepEqual(check(OK + `release: {hold_merges_during_release_ci: ${v}}\n`), [], v);
|
|
198
|
+
assert.match(check(OK + "release: {hold_merges_during_release_ci: maybe}\n").join(), /hold_merges_during_release_ci/);
|
|
199
|
+
});
|
|
182
200
|
});
|
|
@@ -15,11 +15,11 @@ import { UNSKIPPABLE_CLASSES, isUnskippable, parseFlakeConfig, canQuarantine } f
|
|
|
15
15
|
|
|
16
16
|
export const CONTROL_SCHEMA = "forgedock.release.control/v1";
|
|
17
17
|
export const CONTROL_MARKER = "FORGE:CONTROL";
|
|
18
|
-
export const VERBS = ["hold", "resume", "cancel", "lane", "exempt", "freeze", "unfreeze", "demote", "promote", "rollback", "regate"];
|
|
18
|
+
export const VERBS = ["hold", "resume", "cancel", "lane", "exempt", "freeze", "unfreeze", "demote", "promote", "rollback", "regate", "merge-hold", "merge-release"];
|
|
19
19
|
export { UNSKIPPABLE_CLASSES as UNSKIPPABLE };
|
|
20
20
|
export const EXEMPT_MAX_H = { skip: 24, quarantine: 14 * 24 };
|
|
21
21
|
export const LANES = ["train", "release", "p0", "exclude"];
|
|
22
|
-
const OWNED = ["holds", "cancelled", "lanes", "exemptions", "freeze", "gateModes", "rollbacks", "regates"];
|
|
22
|
+
const OWNED = ["holds", "cancelled", "lanes", "exemptions", "freeze", "gateModes", "rollbacks", "regates", "mergeHold"];
|
|
23
23
|
export const DEMOTE_MAX_H = 30 * 24;
|
|
24
24
|
const BREAK_GLASS = /^(override_freeze|acknowledge_hotfix_revert|override_.*|acknowledge_.*)$/;
|
|
25
25
|
|
|
@@ -81,6 +81,8 @@ export async function runControl(verb, argv, ctx) {
|
|
|
81
81
|
if (verb === "resume") delete next[id]; else next[id] = { reason, actor, at };
|
|
82
82
|
return { patch: { [key]: next }, before, after: next[id] ?? null };
|
|
83
83
|
};
|
|
84
|
+
} else if (verb === "merge-hold" || verb === "merge-release") { // #5709: a manual hold on lane merges into the integration branch
|
|
85
|
+
apply = (a) => ({ patch: { mergeHold: verb === "merge-hold" ? { reason, actor, at } : null }, before: a.mergeHold ?? null, after: verb === "merge-hold" ? { reason, actor, at } : null });
|
|
84
86
|
} else if (verb === "lane") {
|
|
85
87
|
const force = flagOf(argv, "--force");
|
|
86
88
|
if (!LANES.includes(force)) return fail(`lane: --force must be one of ${LANES.join("|")}`);
|
|
@@ -186,4 +186,19 @@ describe("release control regate verb (#5584)", () => {
|
|
|
186
186
|
assert.match((await runControl("regate", [RID, "--ref", "f"], base(w))).error, /--reason is required/);
|
|
187
187
|
assert.match((await runControl("regate", [RID, "--reason", "r"], base(w))).error, /no release/);
|
|
188
188
|
});
|
|
189
|
+
|
|
190
|
+
it("merge-hold / merge-release set and clear a manual hold, audited (#5709)", async () => {
|
|
191
|
+
const w = world();
|
|
192
|
+
assert.equal((await runControl("merge-hold", [], base(w))).error, "merge-hold: --reason is required");
|
|
193
|
+
const h = await runControl("merge-hold", ["--reason", "release CI"], base(w));
|
|
194
|
+
assert.equal(h.ok, true);
|
|
195
|
+
assert.equal(w.active.mergeHold.reason, "release CI");
|
|
196
|
+
assert.equal(h.entry.verb, "merge-hold"); assert.equal(h.entry.before, null); assert.equal(h.entry.after.reason, "release CI");
|
|
197
|
+
assert.match(w.controls, /"verb":"merge-hold"/);
|
|
198
|
+
const r = await runControl("merge-release", ["--reason", "done"], base(w));
|
|
199
|
+
assert.equal(r.ok, true);
|
|
200
|
+
assert.equal(w.active.mergeHold ?? null, null);
|
|
201
|
+
assert.equal(r.entry.before.reason, "release CI");
|
|
202
|
+
assert.match(w.controls, /"verb":"merge-release"/);
|
|
203
|
+
});
|
|
189
204
|
});
|