forgedock 1.67.0 → 1.68.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 +1 -0
- package/bin/engine/outcome-codes.mjs +1 -0
- package/bin/engine-cli.mjs +99 -12
- package/bin/engine.mjs +10 -0
- package/bin/forgedock.mjs +17 -1
- package/bin/help-text.mjs +1 -0
- package/bin/lean/admission.mjs +21 -0
- package/bin/lean/admission.test.mjs +30 -0
- package/bin/lean/advisory.test.mjs +25 -10
- package/bin/lean/amendment-schema.mjs +3 -4
- package/bin/lean/attempts.mjs +34 -31
- package/bin/lean/attempts.test.mjs +33 -19
- package/bin/lean/basered.mjs +26 -0
- package/bin/lean/batch-health.mjs +17 -12
- package/bin/lean/batch-health.test.mjs +39 -11
- package/bin/lean/batch.test.mjs +51 -2
- package/bin/lean/ci-gate.mjs +2 -90
- package/bin/lean/ci-gate.test.mjs +1 -127
- package/bin/lean/ci-precheck.mjs +25 -8
- package/bin/lean/ci-precheck.test.mjs +24 -0
- package/bin/lean/clear-breaker.test.mjs +4 -3
- package/bin/lean/commentstate.mjs +10 -5
- package/bin/lean/commentstate.test.mjs +12 -1
- package/bin/lean/conformance.e2e.test.mjs +9 -6
- package/bin/lean/conformance.mjs +56 -196
- package/bin/lean/conformance.test.mjs +40 -376
- package/bin/lean/depcache.mjs +100 -10
- package/bin/lean/depcache.test.mjs +105 -0
- package/bin/lean/docsgate.mjs +0 -32
- package/bin/lean/docsgate.test.mjs +2 -23
- package/bin/lean/effects-cap.test.mjs +9 -1
- package/bin/lean/effects-killtree.test.mjs +35 -0
- package/bin/lean/effects.mjs +42 -24
- package/bin/lean/engine-readmit.test.mjs +35 -0
- package/bin/lean/envgap.mjs +93 -0
- package/bin/lean/envgap.test.mjs +53 -0
- package/bin/lean/execution.mjs +10 -4
- package/bin/lean/execution.test.mjs +12 -0
- package/bin/lean/failure-census.mjs +170 -0
- package/bin/lean/failure-census.test.mjs +59 -0
- package/bin/lean/guardgate.test.mjs +2 -3
- package/bin/lean/heavy.mjs +33 -4
- package/bin/lean/heavy.test.mjs +38 -6
- package/bin/lean/hotarea.mjs +0 -36
- package/bin/lean/hotarea.test.mjs +1 -22
- package/bin/lean/issuewatch-verify.mjs +19 -4
- package/bin/lean/issuewatch.mjs +21 -4
- package/bin/lean/issuewatch.test.mjs +48 -1
- package/bin/lean/lane-audit-gap.mjs +66 -0
- package/bin/lean/lane-audit-gap.test.mjs +59 -0
- package/bin/lean/lane-audit-llm.mjs +5 -0
- package/bin/lean/lane-audit-query.mjs +47 -0
- package/bin/lean/lane-audit-query.test.mjs +44 -0
- package/bin/lean/lane-audit-signatures.mjs +33 -0
- package/bin/lean/lane-audit.mjs +110 -0
- package/bin/lean/lane-audit.test.mjs +97 -0
- package/bin/lean/lane-recovery.test.mjs +33 -0
- package/bin/lean/lanecheck.mjs +5 -3
- package/bin/lean/lanecheck.test.mjs +6 -0
- package/bin/lean/lean.mjs +206 -148
- package/bin/lean/lean.test.mjs +406 -190
- package/bin/lean/limits.mjs +17 -0
- package/bin/lean/limits.test.mjs +15 -1
- package/bin/lean/live-execution.mjs +21 -2
- package/bin/lean/live-execution.test.mjs +39 -0
- package/bin/lean/orchestrate-attempts.test.mjs +17 -9
- package/bin/lean/orchestrate-envhold.test.mjs +47 -0
- package/bin/lean/orchestrate-heldroot.test.mjs +72 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +59 -1
- package/bin/lean/orchestrate-overload-recovery.test.mjs +37 -0
- package/bin/lean/orchestrate-pause.test.mjs +53 -1
- package/bin/lean/orchestrate-reconcile.test.mjs +17 -0
- package/bin/lean/orchestrate-relaunch-gates.test.mjs +57 -0
- package/bin/lean/orchestrate-stacking.test.mjs +10 -0
- package/bin/lean/orchestrate.mjs +188 -33
- package/bin/lean/postdeploy-check.test.mjs +1 -3
- package/bin/lean/precheck.mjs +20 -0
- package/bin/lean/preflight.mjs +100 -11
- package/bin/lean/preflight.test.mjs +44 -4
- package/bin/lean/prompts.mjs +10 -21
- package/bin/lean/recurrence.mjs +6 -148
- package/bin/lean/recurrence.test.mjs +11 -147
- package/bin/lean/release-flakes.mjs +14 -2
- package/bin/lean/release-flakes.test.mjs +17 -1
- package/bin/lean/release-ledger.mjs +19 -1
- package/bin/lean/release-ledger.test.mjs +23 -0
- package/bin/lean/release-preflight.mjs +28 -0
- package/bin/lean/release-preflight.test.mjs +42 -1
- package/bin/lean/release-review.mjs +40 -5
- package/bin/lean/release-review.test.mjs +43 -2
- package/bin/lean/release.mjs +43 -14
- package/bin/lean/release.test.mjs +32 -0
- package/bin/lean/retry.mjs +1 -1
- package/bin/lean/retry.test.mjs +6 -1
- package/bin/lean/rotator.mjs +9 -0
- package/bin/lean/rotator.test.mjs +11 -1
- package/bin/lean/sandbox-remote.mjs +16 -9
- package/bin/lean/schedd.mjs +11 -6
- package/bin/lean/schedd.test.mjs +65 -5
- package/bin/lean/selfreview.mjs +1 -1
- package/bin/lean/statuscomment.mjs +4 -1
- package/bin/lean/validate-catalog.mjs +108 -0
- package/bin/lean/validate-catalog.test.mjs +46 -1
- package/bin/lean/verify.mjs +1 -1
- package/bin/pool/affinity.test.mjs +91 -0
- package/bin/pool/agent.mjs +143 -9
- package/bin/pool/cache-sweep.mjs +31 -10
- package/bin/pool/ci-autoscale.mjs +160 -0
- package/bin/pool/cli.mjs +37 -8
- package/bin/pool/docker.mjs +3 -0
- package/bin/pool/engine-placement.test.mjs +94 -0
- package/bin/pool/lane-target.mjs +41 -0
- package/bin/pool/lane-tools.mjs +7 -2
- package/bin/pool/lane-tools.test.mjs +9 -0
- package/bin/pool/mirror-seed.mjs +15 -11
- package/bin/pool/router.mjs +88 -32
- package/bin/pool/version.mjs +29 -2
- package/bin/review-staging.mjs +11 -3
- package/bin/runner.mjs +59 -11
- package/bin/stats/release.mjs +7 -0
- package/bin/stats/release.test.mjs +20 -0
- package/bin/stats/scorecard.mjs +187 -0
- package/bin/stats/scorecard.test.mjs +89 -0
- package/docs/CONFIG.md +41 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/STATS.md +17 -0
- package/package.json +1 -1
- package/pool/image/Dockerfile +14 -2
- package/pool/image/manifest.json +25 -0
- package/pool/image/mirror.sh +11 -2
- package/pool/install/install-agent.ps1 +11 -4
- package/scripts/ci-local/adapters/github-actions.mjs +8 -0
- package/scripts/ci-local/cli.mjs +1 -1
- package/scripts/ci-local/plan.mjs +3 -2
- package/scripts/ci-local.test.sh +11 -0
- package/scripts/failure-census.mjs +67 -0
- package/scripts/review-finalize.sh +5 -5
- package/scripts/review-finalize.test.sh +8 -1
- package/scripts/verify-phase-trail.sh +11 -0
- package/scripts/verify-phase-trail.test.sh +9 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
3
|
+
// #6106: deterministic classification of environment gaps. A missing tool, binary, interpreter, recipe, package or sandbox
|
|
4
|
+
// capability is an `env.*` outcome that recovers on its own, never ci.red or a human block. Genuine human reasons stay human.
|
|
5
|
+
import { OUTCOME_CODES } from "../engine/outcome-codes.mjs";
|
|
6
|
+
|
|
7
|
+
/** A check command's output that says the tool (not the change) is what failed. */
|
|
8
|
+
export const CHECK_TOOL_GAP_RE = /PATH pass-through wrapper with no real binary|command not found|(?:^|\n)\s*(?:\S+:\s*)?(?:sh|bash|zsh): (?:\d+: )?\S+: not found|not found in PATH|: No such file or directory[^\n]*node_modules\/\.bin|\bENOENT\b[^\n]{0,60}spawn|no module named|ModuleNotFoundError|cannot connect to the docker daemon|no docker daemon/i;
|
|
9
|
+
|
|
10
|
+
/** Words that make a block a real human decision, whatever else it says. */
|
|
11
|
+
const HUMAN_SIGNAL_RE = /\bapprov|sign[- ]?off|\bspend\b|\bbudget\b|purchase|\bpayment|\bcustomer|\blegal\b|\bsecrets?\b|password|passphrase|api[- ]?key|\btoken\b|\bcredentials?\b|\bpricing\b|owner (?:decision|call)|which (?:option|approach|product)/i;
|
|
12
|
+
|
|
13
|
+
const SANDBOX_CAP_RE = /\bsandbox\b[^.\n]{0,80}\b(?:lacks?|missing|has no|without|cannot|can't|does not have|doesn't have|no access)\b|\b(?:lacks?|missing|no|without)\b[^.\n]{0,40}\bsandbox (?:capabilit|access|network|docker|gpu)/i;
|
|
14
|
+
const TOOL_GAP_BLOCK_RE = [
|
|
15
|
+
/\b(?:no|missing|lacks?|without|not (?:installed|available|found)|only)\b[^.\n]{0,60}\b(?:interpreter|python\s?3\.\d+|python\s?\d|node(?:\.js)?\s?\d+|binary|binaries|toolchain|runtime|docker|compiler|executable)\b/i,
|
|
16
|
+
/\b(?:interpreter|binary|executable|toolchain)\b[^.\n]{0,60}\b(?:not (?:installed|available|found)|missing|absent|only)\b/i,
|
|
17
|
+
/\blane[-_ ]?tools?\b|\brecipes?\b/i,
|
|
18
|
+
/\b(?:package|module|library|dependency|dependencies)\b[^.\n]{0,60}\b(?:not installed|missing|not found|cannot be installed|unavailable)\b/i,
|
|
19
|
+
/\b(?:not installed|command not found|no module named|ModuleNotFoundError)\b/i,
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The env code for a builder block whose declared reason is a human one, or null to keep it human.
|
|
24
|
+
* @param {string} why the block's typed reason ("product-decision", "credentials", ...)
|
|
25
|
+
* @param {string} text the builder's summary/reason
|
|
26
|
+
* @returns {string|null} OUTCOME_CODES.ENV_TOOL_MISSING | ENV_CAPABILITY_REMOTE | null
|
|
27
|
+
*/
|
|
28
|
+
export function envGapBlockCode(why, text) {
|
|
29
|
+
if (!["product-decision", "credentials"].includes(String(why))) return null;
|
|
30
|
+
const s = String(text ?? "");
|
|
31
|
+
if (!s || HUMAN_SIGNAL_RE.test(s)) return null;
|
|
32
|
+
if (SANDBOX_CAP_RE.test(s)) return OUTCOME_CODES.ENV_CAPABILITY_REMOTE;
|
|
33
|
+
if (TOOL_GAP_BLOCK_RE.some((re) => re.test(s))) return OUTCOME_CODES.ENV_TOOL_MISSING;
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The failed check results (`{command, rc, output}`) whose output names a missing tool. */
|
|
38
|
+
export function toolGapFailures(failed = []) {
|
|
39
|
+
return failed.filter((f) => CHECK_TOOL_GAP_RE.test(String(f?.output ?? "")));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Package directories a check command line works in (`cd web && ...`, `--prefix web`, `-C web`, `--cwd web`, `web/node_modules/.bin/x`)
|
|
44
|
+
* that carry a package.json but no installed node_modules: dependencies to prepare before the checks run.
|
|
45
|
+
* @param {string[]} commands
|
|
46
|
+
* @param {(rel: string) => boolean} exists path relative to the worktree
|
|
47
|
+
*/
|
|
48
|
+
export function packageDirsMissingDeps(commands = [], exists = () => false) {
|
|
49
|
+
const dirs = new Set();
|
|
50
|
+
const add = (d) => {
|
|
51
|
+
const dir = String(d ?? "").replace(/^\.\//, "").replace(/\/+$/, "");
|
|
52
|
+
if (!dir || dir.startsWith("/") || dir.split("/").includes("..") || /[$`*]/.test(dir)) return;
|
|
53
|
+
dirs.add(dir);
|
|
54
|
+
};
|
|
55
|
+
for (const c of commands) {
|
|
56
|
+
const s = String(c ?? "");
|
|
57
|
+
for (const m of s.matchAll(/(?:^|[\s;&|(])cd\s+([^\s;&|)]+)/g)) add(m[1]);
|
|
58
|
+
for (const m of s.matchAll(/(?:--prefix|--cwd|-C|--dir)[ =]([^\s;&|)]+)/g)) add(m[1]);
|
|
59
|
+
for (const m of s.matchAll(/(?:^|[\s"'])((?:\.\/)?[\w.-]+(?:\/[\w.-]+)*?)\/node_modules\/\.bin\//g)) add(m[1]);
|
|
60
|
+
}
|
|
61
|
+
return [...dirs].filter((d) => exists(`${d}/package.json`) && !exists(`${d}/node_modules`));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// #6094: test-file names in check output. A linear token scan (split on non-path characters, then an anchored test of each
|
|
65
|
+
// basename): the earlier single regex nested quantifiers over overlapping classes and backtracked exponentially on long
|
|
66
|
+
// path-like output, which froze the lane (and the test suite) in a microtask-free spin.
|
|
67
|
+
const TEST_BASENAME_RES = [/^[\w@.-]+\.(?:test|spec)\.[cm]?[jt]sx?$/, /^(?:test_[\w-]+|[\w-]+_test)\.(?:py|go|rb|rs)$/, /^[\w-]+Tests?\.(?:java|kt|cs)$/];
|
|
68
|
+
const MAX_SCAN_CHARS = 512 * 1024, MAX_TOKEN_CHARS = 400;
|
|
69
|
+
function testFilesNamed(output) {
|
|
70
|
+
const text = String(output ?? "");
|
|
71
|
+
const out = new Set();
|
|
72
|
+
for (const raw of (text.length > MAX_SCAN_CHARS ? text.slice(-MAX_SCAN_CHARS) : text).split(/[^\w@./-]+/)) {
|
|
73
|
+
if (!raw || raw.length > MAX_TOKEN_CHARS) continue;
|
|
74
|
+
const tok = raw.replace(/^[./]+(?=[\w@])/, "").replace(/[.]+$/, "");
|
|
75
|
+
const slash = tok.lastIndexOf("/");
|
|
76
|
+
const base = slash < 0 ? tok : tok.slice(slash + 1);
|
|
77
|
+
if (base && TEST_BASENAME_RES.some((re) => re.test(base))) out.add(tok);
|
|
78
|
+
}
|
|
79
|
+
return [...out];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* #6094: a failing check whose output names test files and none of them is in the diff is not caused by the change: the lane
|
|
84
|
+
* reruns it once before treating it as red. Returns false when the output names no test file (cannot tell: not unrelated).
|
|
85
|
+
* @param {string} output
|
|
86
|
+
* @param {string[]} changed files the lane's diff touches
|
|
87
|
+
*/
|
|
88
|
+
export function failureOutsideDiff(output, changed = []) {
|
|
89
|
+
const named = testFilesNamed(output);
|
|
90
|
+
if (!named.length) return false;
|
|
91
|
+
const touched = (p) => changed.some((c) => c === p || c.endsWith(`/${p}`) || p.endsWith(`/${c}`) || c.split("/").pop() === p.split("/").pop());
|
|
92
|
+
return !named.some(touched);
|
|
93
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { envGapBlockCode, toolGapFailures, packageDirsMissingDeps, failureOutsideDiff } from "./envgap.mjs";
|
|
6
|
+
|
|
7
|
+
describe("#6106 env gap classification", () => {
|
|
8
|
+
it("a check that fails on a PATH pass-through wrapper with no real binary is a tool gap", () => {
|
|
9
|
+
const out = "forgedock heavy: eslint at /w/web/node_modules/.bin/eslint is a PATH pass-through wrapper with no real binary behind it";
|
|
10
|
+
assert.equal(toolGapFailures([{ command: "cd web && eslint .", rc: 127, output: out }, { command: "node --test", rc: 1, output: "not ok 1 - assertion" }]).length, 1);
|
|
11
|
+
assert.equal(toolGapFailures([{ command: "x", rc: 1, output: "AssertionError: expected 1 to equal 2" }]).length, 0);
|
|
12
|
+
});
|
|
13
|
+
it("block reasons naming a missing tool/interpreter/recipe/sandbox capability map to env codes", () => {
|
|
14
|
+
assert.equal(envGapBlockCode("product-decision", "the yaml lane-tools recipe lives in the engine"), "env.tool_missing");
|
|
15
|
+
assert.equal(envGapBlockCode("credentials", "no Python 3.11 interpreter (only 3.12.3)"), "env.tool_missing");
|
|
16
|
+
assert.equal(envGapBlockCode("credentials", "the sandbox lacks network access to the registry"), "env.capability_remote");
|
|
17
|
+
});
|
|
18
|
+
it("genuine human reasons stay human", () => {
|
|
19
|
+
assert.equal(envGapBlockCode("product-decision", "needs Stripe approval"), null);
|
|
20
|
+
assert.equal(envGapBlockCode("credentials", "no docker credentials: need the registry token"), null);
|
|
21
|
+
assert.equal(envGapBlockCode("product-decision", "which option should the product take?"), null);
|
|
22
|
+
assert.equal(envGapBlockCode("approval", "no interpreter"), null);
|
|
23
|
+
});
|
|
24
|
+
it("package dirs the checks touch that have a manifest but no node_modules are found", () => {
|
|
25
|
+
const have = new Set(["web/package.json", "api/package.json", "api/node_modules"]);
|
|
26
|
+
const exists = (p) => have.has(p);
|
|
27
|
+
assert.deepEqual(packageDirsMissingDeps(["cd web && npx eslint .", "cd api && npm test", "node --test"], exists), ["web"]);
|
|
28
|
+
assert.deepEqual(packageDirsMissingDeps(["npm --prefix web run lint"], exists), ["web"]);
|
|
29
|
+
assert.deepEqual(packageDirsMissingDeps(["web/node_modules/.bin/eslint src"], exists), ["web"]);
|
|
30
|
+
assert.deepEqual(packageDirsMissingDeps(["cd ../x && ls"], () => true), []);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("#6094 failures outside the diff", () => {
|
|
35
|
+
it("names a test file the diff does not touch -> outside; touched or unnamed -> not", () => {
|
|
36
|
+
const out = "not ok 5 - ten concurrent\n location: '/w/bin/tests/mirror-script.test.mjs:48:3'";
|
|
37
|
+
assert.equal(failureOutsideDiff(out, ["bin/lean/release.mjs"]), true);
|
|
38
|
+
assert.equal(failureOutsideDiff(out, ["bin/tests/mirror-script.test.mjs"]), false);
|
|
39
|
+
assert.equal(failureOutsideDiff("make: *** [lint] Error 1", ["a.js"]), false);
|
|
40
|
+
assert.equal(failureOutsideDiff("FAILED tests/test_api.py::t - x", ["web/app.ts"]), true);
|
|
41
|
+
});
|
|
42
|
+
it("scans long path-like output in linear time (the old regex backtracked exponentially and froze the lane)", () => {
|
|
43
|
+
const evil = `${"a/".repeat(20000)}b ${"x.".repeat(20000)}y ${"@-".repeat(20000)}`;
|
|
44
|
+
const t0 = Date.now();
|
|
45
|
+
assert.equal(failureOutsideDiff(evil, ["a.js"]), false);
|
|
46
|
+
assert.equal(failureOutsideDiff(`${evil}\n at /w/src/deep/app.spec.ts:3:1`, ["a.js"]), true);
|
|
47
|
+
assert.ok(Date.now() - t0 < 2000, `took ${Date.now() - t0} ms`);
|
|
48
|
+
});
|
|
49
|
+
it("names Go/Java/py test files and strips ./ prefixes", () => {
|
|
50
|
+
assert.equal(failureOutsideDiff("--- FAIL: TestX (0.00s)\n ./pkg/foo_test.go:12: boom", ["pkg/foo_test.go"]), false);
|
|
51
|
+
assert.equal(failureOutsideDiff("at src/com/x/FooTest.java:9", ["src/Bar.java"]), true);
|
|
52
|
+
});
|
|
53
|
+
});
|
package/bin/lean/execution.mjs
CHANGED
|
@@ -297,11 +297,14 @@ export function detectNeeds(text, exec = null, { prose = false } = {}) {
|
|
|
297
297
|
|
|
298
298
|
/**
|
|
299
299
|
* #5652: may a remote lane that lacks a tool or host capability be re-placed on the dispatching host? An explicit
|
|
300
|
-
* `execution.host_fallback` wins; else off when forge.yaml `host.role` is `orchestrator`; else
|
|
300
|
+
* `execution.host_fallback` wins; else off when forge.yaml `host.role` is `orchestrator`; else off in `mode: remote` (#5746);
|
|
301
|
+
* else on (hybrid and local unchanged).
|
|
301
302
|
*/
|
|
302
|
-
export function hostFallbackAllowed({ hostFallback = null, hostRole = null } = {}) {
|
|
303
|
+
export function hostFallbackAllowed({ hostFallback = null, hostRole = null, mode = null } = {}) {
|
|
303
304
|
if (typeof hostFallback === "boolean") return hostFallback;
|
|
304
|
-
|
|
305
|
+
if (String(hostRole ?? "").trim().toLowerCase() === "orchestrator") return false;
|
|
306
|
+
// #5746: in remote mode the host is not a fallback unless the repo opts in with host_fallback: true
|
|
307
|
+
return mode !== "remote";
|
|
305
308
|
}
|
|
306
309
|
|
|
307
310
|
/** Declared host capabilities a remote lane's block summary names (#4542); empty when it names none the host has. */
|
|
@@ -404,7 +407,10 @@ export function placeLane({ exec = null, verifyMode = "local", labels = [], weig
|
|
|
404
407
|
const missing = (Array.isArray(needs) ? needs : []).map(String).filter((n) => n && !(Array.isArray(relays) ? relays : []).includes(n));
|
|
405
408
|
if (missing.length) return { where: "local", reason: `host capability: ${missing.join(", ")}` };
|
|
406
409
|
}
|
|
407
|
-
if (mode !== "hybrid") {
|
|
410
|
+
if (mode !== "hybrid") {
|
|
411
|
+
const where = placement(exec);
|
|
412
|
+
return { where, reason: `mode ${EXECUTION_MODES.includes(mode) ? mode : "local"}` };
|
|
413
|
+
}
|
|
408
414
|
if (!(Number.isInteger(exec.maxRemote) && exec.maxRemote >= 1)) return { where: "local", reason: "max_remote 0" };
|
|
409
415
|
if (verifyMode === "ci") return { where: "local", reason: "verify.mode ci: validation runs on CI, not billed twice" };
|
|
410
416
|
const names = (Array.isArray(labels) ? labels : []).map((l) => String(l ?? "").trim().toLowerCase());
|
|
@@ -1409,6 +1409,18 @@ describe("providerLanes: a halted batch keeps its sandbox for adopt (#5669)", ()
|
|
|
1409
1409
|
});
|
|
1410
1410
|
});
|
|
1411
1411
|
|
|
1412
|
+
describe("#5746 remote-mode host fallback and max_remote 0", () => {
|
|
1413
|
+
it("hostFallbackAllowed: remote unset false, hybrid true, explicit true wins", () => {
|
|
1414
|
+
assert.equal(hostFallbackAllowed({ mode: "remote" }), false);
|
|
1415
|
+
assert.equal(hostFallbackAllowed({ mode: "hybrid" }), true);
|
|
1416
|
+
assert.equal(hostFallbackAllowed({ mode: "remote", hostFallback: true }), true);
|
|
1417
|
+
});
|
|
1418
|
+
it("placeLane: remote mode with max_remote 0 stays remote (#5933 pauses starts, never the host)", () => {
|
|
1419
|
+
assert.equal(placeLane({ exec: { mode: "remote", maxRemote: 0 } }).where, "remote");
|
|
1420
|
+
assert.equal(placeLane({ exec: { mode: "remote", maxRemote: 2 } }).reason, "mode remote");
|
|
1421
|
+
});
|
|
1422
|
+
});
|
|
1423
|
+
|
|
1412
1424
|
describe("public-repo default placement (#5748)", () => {
|
|
1413
1425
|
const OPT = parseExecution({ public_default: "actions" }); // #5900: the actions default is opt-in
|
|
1414
1426
|
it("actions is a known provider; plan, job_limit, ci_reserve and dispatcher parse", () => {
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Failure census (2026-11-26): classify why lanes did not take the happy path, from the register itself, so an agent
|
|
5
|
+
* working on a pipeline fix reads measured failure classes instead of guessing. Pure functions only (no I/O): the CLI
|
|
6
|
+
* (scripts/failure-census.mjs) feeds issue comments and batch log rows in.
|
|
7
|
+
*
|
|
8
|
+
* Inputs it understands (all ForgeDock annotations on issues):
|
|
9
|
+
* - FORGE:NEEDS_HUMAN / FORGE:PARKED bodies: one park each, classified into a bucket and normalised failure rows;
|
|
10
|
+
* - FORGE:AMENDMENT-STATE JSON: the last state per issue gives the distinct amendments (kind + why class);
|
|
11
|
+
* - FORGE:BASE_SYNC bodies: conflicted files.
|
|
12
|
+
* Batch log rows (`~/.forge/batches/<id>/log.jsonl`): outcome/code counts and per-phase timing.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** Ordered: the first matching bucket wins. Patterns match the park body (rows and prose). */
|
|
16
|
+
export const PARK_BUCKETS = Object.freeze([
|
|
17
|
+
["sandbox_tool_gap", /Remote sandbox lacks|lane_tools recipe|sandbox is missing/i],
|
|
18
|
+
["recurrence_design", /recurrence\.design_missing/],
|
|
19
|
+
["post_deploy_check_id", /post-deploy check (id|'[^']*') is neither/],
|
|
20
|
+
["amendment_syntax", /unknown or incomplete amendment|amendment kind '|amendment not accepted/],
|
|
21
|
+
["substitute_validate", /substituted `|substitute-validate|substitute_unverified/],
|
|
22
|
+
["deferral", /unjustified_deferral|untracked_deferral|reported "deferred"/],
|
|
23
|
+
["no_status", /reported "no status"/],
|
|
24
|
+
["omission_narrowed", /conformance\.omission|requirement narrowed/],
|
|
25
|
+
["scope_creep", /scope_creep|outside the contract's deliverables/],
|
|
26
|
+
["validate_failed", /validate [A-Z]?\d+ .*failed|frozen command runs and fails|Declared check command\(s\) failing/],
|
|
27
|
+
["ci_red", /Required check\(s\) failed|ci\.red|CI verification failed/],
|
|
28
|
+
["env_setup", /Environment error|env\.(setup_failed|tool_missing|validate_timeout|validate_placement|repro_unrunnable|capability_remote)/],
|
|
29
|
+
["builder_blocked", /Builder is blocked|builder\.(blocked|no_commit)|Builder made no commit/],
|
|
30
|
+
["review_incomplete", /review\.(incomplete|failed|unparseable)|Review FAIL/],
|
|
31
|
+
["e2e_unverified", /e2e_unverified|e2e_placement/],
|
|
32
|
+
["design_spec", /design\.spec_required|FORGE:DESIGN_SPEC|Design gate/],
|
|
33
|
+
["contract_invalid", /contract is still invalid|contract\.invalid/],
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
/** Bucket of one park body; "other" when no pattern matches. */
|
|
37
|
+
export function parkBucket(body) {
|
|
38
|
+
const b = String(body ?? "");
|
|
39
|
+
for (const [name, re] of PARK_BUCKETS) if (re.test(b)) return name;
|
|
40
|
+
return "other";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The `- code: detail` rows of a NEEDS_HUMAN/PARKED body, normalised so repeats across issues group together. */
|
|
44
|
+
export function parkRows(body) {
|
|
45
|
+
return String(body ?? "").split("\n").filter((l) => /^- [a-z_]+\.[a-z_]+:/.test(l)).map(normalizeRow);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Collapse ids, numbers, quotes and code spans so identical defects compare equal. */
|
|
49
|
+
export function normalizeRow(row) {
|
|
50
|
+
return String(row).replace(/^- /, "").replace(/\bR\d+\b/g, "R#").replace(/\b[GV]\d+\b/g, "V#").replace(/#\d+/g, "#N")
|
|
51
|
+
.replace(/`[^`]*`/g, "`…`").replace(/\("[^]*$/, "").replace(/"[^"]{40,}"/g, "\"…\"").replace(/\d+/g, "N").trim().slice(0, 140);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const AMENDMENT_STATE_RE = /FORGE:AMENDMENT-STATE (\{.*\}) -->/;
|
|
55
|
+
/** The distinct amendments of the LAST amendment state on an issue (earlier states are replayed into it). */
|
|
56
|
+
export function lastAmendments(comments) {
|
|
57
|
+
let last = null;
|
|
58
|
+
for (const c of comments ?? []) {
|
|
59
|
+
const m = AMENDMENT_STATE_RE.exec(String(c?.body ?? ""));
|
|
60
|
+
if (!m) continue;
|
|
61
|
+
try { last = JSON.parse(m[1]); } catch { /* a malformed state is skipped */ }
|
|
62
|
+
}
|
|
63
|
+
return Array.isArray(last?.amendments) ? last.amendments : [];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Why-class of one amendment: broken frozen command, post-deploy measurement, naming, or other. */
|
|
67
|
+
export function amendmentWhyClass(a) {
|
|
68
|
+
const w = String(a?.why ?? "");
|
|
69
|
+
if (/on the (unchanged )?base|origin\/staging|fails before|not on the .*path|ModuleNotFound|cannot import|not installed|command not found|timed out|sandbox|lacks/i.test(w)) return "frozen_command_broken_or_env";
|
|
70
|
+
if (/requirement|post-deploy|measur|production|after deploy/i.test(w)) return "post_deploy_or_measurement";
|
|
71
|
+
if (/duplicate|rename|name/i.test(w)) return "naming_or_decision";
|
|
72
|
+
if (/docs freshness|dossier|registry|check id/i.test(w)) return "forced_by_another_gate";
|
|
73
|
+
return "other";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Conflicted files listed by a FORGE:BASE_SYNC body ("conflicts in `a`, `b`"). */
|
|
77
|
+
export function baseSyncConflicts(body) {
|
|
78
|
+
const m = /\*\*Result:\*\* conflicts in ([^\n]+)/.exec(String(body ?? ""));
|
|
79
|
+
return m ? [...m[1].matchAll(/`([^`]+)`/g)].map((x) => x[1]) : [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const inc = (o, k, by = 1) => { o[k] = (o[k] ?? 0) + by; return o; };
|
|
83
|
+
const top = (o, n) => Object.entries(o).sort((a, b) => b[1] - a[1]).slice(0, n);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Census over issues: `issues` = [{number, title, comments: [{body, createdAt, author}]}]. Returns plain data:
|
|
87
|
+
* parks by bucket (+ issues), by day x bucket, top normalised rows, repeat parks (identical rows back to back),
|
|
88
|
+
* amendments by kind x why class, conflict hotspots, and the most-parked issues.
|
|
89
|
+
*/
|
|
90
|
+
export function censusIssues(issues) {
|
|
91
|
+
const out = { issues: 0, withParks: 0, parks: 0, repeats: 0, buckets: {}, bucketIssues: {}, byDay: {}, rows: {}, amendments: {}, amendmentIssues: {}, conflicts: {}, baseSyncs: 0, mostParked: [] };
|
|
92
|
+
const perIssue = [];
|
|
93
|
+
for (const iss of issues ?? []) {
|
|
94
|
+
out.issues++;
|
|
95
|
+
let parks = 0, prev = null;
|
|
96
|
+
for (const c of iss.comments ?? []) {
|
|
97
|
+
const body = String(c?.body ?? "");
|
|
98
|
+
if (/FORGE:BASE_SYNC/.test(body)) { out.baseSyncs++; for (const f of baseSyncConflicts(body)) inc(out.conflicts, f); }
|
|
99
|
+
if (!/FORGE:(NEEDS_HUMAN|PARKED)/.test(body)) continue;
|
|
100
|
+
const rows = parkRows(body), bucket = parkBucket(body), key = rows.slice().sort().join("|");
|
|
101
|
+
parks++; out.parks++;
|
|
102
|
+
inc(out.buckets, bucket);
|
|
103
|
+
(out.bucketIssues[bucket] ??= new Set()).add(iss.number);
|
|
104
|
+
const day = String(c?.createdAt ?? "").slice(0, 10) || "unknown";
|
|
105
|
+
inc((out.byDay[day] ??= {}), bucket);
|
|
106
|
+
if (prev !== null && rows.length && key === prev) out.repeats++;
|
|
107
|
+
prev = key;
|
|
108
|
+
for (const r of new Set(rows)) inc(out.rows, r);
|
|
109
|
+
}
|
|
110
|
+
for (const a of lastAmendments(iss.comments)) {
|
|
111
|
+
const k = `${a?.kind ?? "?"} :: ${amendmentWhyClass(a)}`;
|
|
112
|
+
inc(out.amendments, k);
|
|
113
|
+
(out.amendmentIssues[k] ??= new Set()).add(iss.number);
|
|
114
|
+
}
|
|
115
|
+
if (parks) { out.withParks++; perIssue.push({ number: iss.number, title: String(iss.title ?? "").slice(0, 80), parks }); }
|
|
116
|
+
}
|
|
117
|
+
out.mostParked = perIssue.sort((a, b) => b.parks - a.parks).slice(0, 15);
|
|
118
|
+
for (const k of ["bucketIssues", "amendmentIssues"]) for (const b of Object.keys(out[k])) out[k][b] = out[k][b].size;
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Census over batch log rows ({outcome, code, phases:{name:{ms}}}): outcome/code counts and per-phase median/p90 (merged lanes). */
|
|
123
|
+
export function censusBatchRows(rows) {
|
|
124
|
+
const outcomes = {}, deferred = {}, needsHuman = {}, phases = {};
|
|
125
|
+
for (const r of rows ?? []) {
|
|
126
|
+
if (!r || r.outcome == null) continue;
|
|
127
|
+
inc(outcomes, r.outcome);
|
|
128
|
+
if (r.outcome === "deferred") inc(deferred, r.code ?? "null");
|
|
129
|
+
if (r.outcome === "needs-human") inc(needsHuman, r.code ?? "null");
|
|
130
|
+
if (r.outcome === "merged" && r.phases && typeof r.phases === "object") {
|
|
131
|
+
for (const [k, v] of Object.entries(r.phases)) if (Number.isFinite(v?.ms)) (phases[k] ??= []).push(v.ms);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const q = (xs, p) => { const s = [...xs].sort((a, b) => a - b); return s.length ? s[Math.min(s.length - 1, Math.floor(s.length * p))] : null; };
|
|
135
|
+
const phaseStats = Object.fromEntries(Object.entries(phases).map(([k, xs]) => [k, { n: xs.length, median_min: Math.round(q(xs, 0.5) / 6000) / 10, p90_min: Math.round(q(xs, 0.9) / 6000) / 10 }]));
|
|
136
|
+
return { outcomes, deferred, needsHuman, phases: phaseStats };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Markdown report of both censuses. */
|
|
140
|
+
export function renderCensus({ repo, since, issues, batches }) {
|
|
141
|
+
const L = [`# Failure census: ${repo}${since ? ` (since ${since})` : ""}`, ""];
|
|
142
|
+
if (issues) {
|
|
143
|
+
L.push(`Issues scanned: ${issues.issues}; with parks: ${issues.withParks}; parks (NEEDS_HUMAN/PARKED): ${issues.parks}; identical back-to-back repeats: ${issues.repeats}`, "", "## Parks by class", "", "| class | parks | issues |", "|---|---|---|");
|
|
144
|
+
for (const [b, n] of top(issues.buckets, 30)) L.push(`| ${b} | ${n} | ${issues.bucketIssues[b] ?? 0} |`);
|
|
145
|
+
const days = Object.keys(issues.byDay).sort(), cls = top(issues.buckets, 6).map(([b]) => b);
|
|
146
|
+
if (days.length) {
|
|
147
|
+
L.push("", "## Parks per day (top classes)", "", `| day | ${cls.join(" | ")} | other |`, `|---|${cls.map(() => "---").join("|")}|---|`);
|
|
148
|
+
for (const d of days) { const row = issues.byDay[d]; const rest = Object.entries(row).filter(([k]) => !cls.includes(k)).reduce((s, [, v]) => s + v, 0); L.push(`| ${d} | ${cls.map((c) => row[c] ?? 0).join(" | ")} | ${rest} |`); }
|
|
149
|
+
}
|
|
150
|
+
L.push("", "## Most frequent failure rows (normalised)", "", "| count | row |", "|---|---|");
|
|
151
|
+
for (const [r, n] of top(issues.rows, 20)) L.push(`| ${n} | ${r.replace(/\\/g, "\\\\").replace(/\|/g, "\\|")} |`);
|
|
152
|
+
L.push("", "## Amendments (last state per issue): kind :: why class", "", "| amendment | count | issues |", "|---|---|---|");
|
|
153
|
+
for (const [k, n] of top(issues.amendments, 20)) L.push(`| ${k} | ${n} | ${issues.amendmentIssues[k] ?? 0} |`);
|
|
154
|
+
L.push("", `## Base-sync conflict hotspots (${issues.baseSyncs} base syncs)`, "", "| file | conflicts |", "|---|---|");
|
|
155
|
+
for (const [f, n] of top(issues.conflicts, 15)) L.push(`| \`${f}\` | ${n} |`);
|
|
156
|
+
L.push("", "## Most-parked issues", "", "| issue | parks | title |", "|---|---|---|");
|
|
157
|
+
for (const i of issues.mostParked) L.push(`| #${i.number} | ${i.parks} | ${i.title.replace(/\\/g, "\\\\").replace(/\|/g, "\\|")} |`);
|
|
158
|
+
}
|
|
159
|
+
if (batches) {
|
|
160
|
+
L.push("", "## Batch logs", "", "| outcome | rows |", "|---|---|");
|
|
161
|
+
for (const [k, n] of top(batches.outcomes, 15)) L.push(`| ${k} | ${n} |`);
|
|
162
|
+
L.push("", "| deferred code | rows |", "|---|---|");
|
|
163
|
+
for (const [k, n] of top(batches.deferred, 10)) L.push(`| ${k} | ${n} |`);
|
|
164
|
+
L.push("", "| needs-human code | rows |", "|---|---|");
|
|
165
|
+
for (const [k, n] of top(batches.needsHuman, 12)) L.push(`| ${k} | ${n} |`);
|
|
166
|
+
L.push("", "| phase (merged lanes) | n | median min | p90 min |", "|---|---|---|---|");
|
|
167
|
+
for (const [k, v] of Object.entries(batches.phases).sort((a, b) => b[1].median_min - a[1].median_min)) L.push(`| ${k} | ${v.n} | ${v.median_min} | ${v.p90_min} |`);
|
|
168
|
+
}
|
|
169
|
+
return L.join("\n") + "\n";
|
|
170
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 { parkBucket, parkRows, normalizeRow, lastAmendments, amendmentWhyClass, baseSyncConflicts, censusIssues, censusBatchRows, renderCensus } from "./failure-census.mjs";
|
|
6
|
+
|
|
7
|
+
const nh = (rows, prose = "") => `<!-- FORGE:NEEDS_HUMAN -->\n## Needs human\n${prose}\n${rows.map((r) => `- ${r}`).join("\n")}`;
|
|
8
|
+
|
|
9
|
+
describe("failure census", () => {
|
|
10
|
+
it("buckets parks by the first matching class", () => {
|
|
11
|
+
assert.equal(parkBucket("Remote sandbox lacks yaml, and no lane_tools recipe exists for it."), "sandbox_tool_gap");
|
|
12
|
+
assert.equal(parkBucket(nh(["recurrence.design_missing: recurring issue routed to a design lane: no design block"])), "recurrence_design");
|
|
13
|
+
assert.equal(parkBucket(nh(["conformance.unimplemented: R13 post-deploy check id is neither on the default branch nor added by this PR (.forge/post-deploy-checks.json)"])), "post_deploy_check_id");
|
|
14
|
+
assert.equal(parkBucket(nh(["conformance.unimplemented: unknown or incomplete amendment: amendment kind 'supersedes' needs guard"])), "amendment_syntax");
|
|
15
|
+
assert.equal(parkBucket(nh(['conformance.unimplemented: R4 reported "no status" ("x")'])), "no_status");
|
|
16
|
+
assert.equal(parkBucket("Required check(s) failed on PR #6011 (Spec-size budget) and the builder made no new commit for it"), "ci_red");
|
|
17
|
+
assert.equal(parkBucket("something new"), "other");
|
|
18
|
+
});
|
|
19
|
+
it("normalises rows so the same defect on different issues groups together", () => {
|
|
20
|
+
const a = normalizeRow('- conformance.unimplemented: R13 post-deploy check id is neither on the default branch nor added by this PR (.forge/post-deploy-checks.json) ("quote one")');
|
|
21
|
+
const b = normalizeRow('- conformance.unimplemented: R7 post-deploy check id is neither on the default branch nor added by this PR (.forge/post-deploy-checks.json) ("another")');
|
|
22
|
+
assert.equal(a, b);
|
|
23
|
+
assert.deepEqual(parkRows(nh(["a.b: one", "c.d: two"], "prose line")).length, 2);
|
|
24
|
+
});
|
|
25
|
+
it("uses only the last amendment state and classifies why", () => {
|
|
26
|
+
const st = (am) => ({ body: `<!-- FORGE:AMENDMENT-STATE ${JSON.stringify({ contract: "x", amendments: am })} -->` });
|
|
27
|
+
const am = lastAmendments([st([{ kind: "decision", why: "rename" }]), { body: "noise" }, st([{ kind: "substitute-validate", why: "fails on the unchanged base too" }, { kind: "add-deliverable", path: "devdocs/x.md", why: "docs freshness rule" }])]);
|
|
28
|
+
assert.deepEqual(am.map((a) => a.kind), ["substitute-validate", "add-deliverable"]);
|
|
29
|
+
assert.equal(amendmentWhyClass(am[0]), "frozen_command_broken_or_env");
|
|
30
|
+
assert.equal(amendmentWhyClass(am[1]), "forced_by_another_gate");
|
|
31
|
+
assert.deepEqual(lastAmendments([{ body: "<!-- FORGE:AMENDMENT-STATE {broken -->" }]), []);
|
|
32
|
+
});
|
|
33
|
+
it("reads base-sync conflict files", () => {
|
|
34
|
+
assert.deepEqual(baseSyncConflicts("## Base Sync\n**Result:** conflicts in `devdocs/modules/lean.md`, `.forge/post-deploy-checks.json`\n"), ["devdocs/modules/lean.md", ".forge/post-deploy-checks.json"]);
|
|
35
|
+
assert.deepEqual(baseSyncConflicts("**Result:** clean merge"), []);
|
|
36
|
+
});
|
|
37
|
+
it("counts parks, identical back-to-back repeats, amendments and hotspots per issue", () => {
|
|
38
|
+
const row = "conformance.unimplemented: unknown or incomplete amendment: amendment kind 'supersedes' needs guard";
|
|
39
|
+
const c = censusIssues([
|
|
40
|
+
{ number: 1, title: "one", comments: [{ body: nh([row]), createdAt: "2026-11-24T01:00:00Z" }, { body: nh([row]), createdAt: "2026-11-24T02:00:00Z" }, { body: "<!-- FORGE:BASE_SYNC -->\n## Base Sync\n**Result:** conflicts in `a.md`" }] },
|
|
41
|
+
{ number: 2, title: "two", comments: [{ body: nh([], "Remote sandbox lacks bash, and no lane_tools recipe exists for it."), createdAt: "2026-11-25T01:00:00Z" }] },
|
|
42
|
+
{ number: 3, title: "clean", comments: [{ body: "hello" }] },
|
|
43
|
+
]);
|
|
44
|
+
assert.equal(c.issues, 3); assert.equal(c.withParks, 2); assert.equal(c.parks, 3); assert.equal(c.repeats, 1);
|
|
45
|
+
assert.equal(c.buckets.amendment_syntax, 2); assert.equal(c.bucketIssues.amendment_syntax, 1);
|
|
46
|
+
assert.equal(c.byDay["2026-11-25"].sandbox_tool_gap, 1);
|
|
47
|
+
assert.equal(c.conflicts["a.md"], 1); assert.equal(c.mostParked[0].number, 1);
|
|
48
|
+
assert.match(renderCensus({ repo: "o/r", issues: c }), /\| amendment_syntax \| 2 \| 1 \|/);
|
|
49
|
+
});
|
|
50
|
+
it("summarises batch rows: outcomes, deferral codes and merged-lane phase timing", () => {
|
|
51
|
+
const b = censusBatchRows([
|
|
52
|
+
{ outcome: "merged", phases: { implement: { ms: 300000 }, ci_wait: { ms: 600000 } } },
|
|
53
|
+
{ outcome: "merged", phases: { implement: { ms: 420000 } } },
|
|
54
|
+
{ outcome: "deferred", code: "sandbox.capacity" }, { outcome: "needs-human", code: "ci.red" }, { issue: 1 },
|
|
55
|
+
]);
|
|
56
|
+
assert.equal(b.outcomes.merged, 2); assert.equal(b.deferred["sandbox.capacity"], 1); assert.equal(b.needsHuman["ci.red"], 1);
|
|
57
|
+
assert.equal(b.phases.implement.n, 2); assert.equal(b.phases.ci_wait.median_min, 10);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -83,10 +83,9 @@ test("an accepted supersedes amendment passes the precheck and names the superse
|
|
|
83
83
|
assert.deepEqual(supersededIds(a.contract, []), [], "only selected guards are retired");
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
test("a supersedes amendment without a guard id is
|
|
86
|
+
test("a supersedes amendment without a guard id is not applied (#6083)", () => {
|
|
87
87
|
const a = applyAmendments({ requirements: [], deliverables: [] }, [{ kind: "supersedes", why: "x" }, { kind: "supersedes", guard: "abc", why: "x" }]);
|
|
88
|
-
assert.
|
|
89
|
-
assert.match(a.problems[0], /needs guard/);
|
|
88
|
+
assert.deepEqual(a.contract.supersedes ?? [], []);
|
|
90
89
|
});
|
|
91
90
|
|
|
92
91
|
test("a lane touching no guarded hunk selects nothing and runs no git or test", async () => {
|
package/bin/lean/heavy.mjs
CHANGED
|
@@ -25,7 +25,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
25
25
|
import { writeAtomic } from "./batch.mjs";
|
|
26
26
|
import { schedDir, pidAlive, DEFAULT_PRIORITY } from "./sched.mjs";
|
|
27
27
|
import { which } from "./toolchain.mjs";
|
|
28
|
-
import { hostParallelism } from "./admission.mjs";
|
|
28
|
+
import { hostParallelism, quotaCores } from "./admission.mjs";
|
|
29
29
|
import { lowerPriority } from "./hostload.mjs";
|
|
30
30
|
|
|
31
31
|
export const HEAVY_DEFAULTS = Object.freeze({ enabled: true, max: null, step_mem_mb: 2048, reserve_mb: 1024, ramp_s: 60, max_wait_s: 1800 });
|
|
@@ -253,6 +253,33 @@ export async function acquireHeavy(h, entry = {}, { pollMs = HEAVY_POLL_MS, slee
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
/**
|
|
257
|
+
* #6047: remote-token backend, chosen when CS_HEAVY_BASE (the pool agent's per-sandbox /heavy route) is set. Acquire polls
|
|
258
|
+
* while the agent denies, renews the lease on a timer, release is best effort; an unreachable or erroring agent, or a wait past
|
|
259
|
+
* `maxWaitMs`, fails open (the step runs, `failOpen: true`). `fetchFn` returns {status, json()}.
|
|
260
|
+
*/
|
|
261
|
+
export async function acquireRemote({ base, credToken = "", fetchFn = (u, o) => fetch(u, o), sleep = (ms) => new Promise((r) => setTimeout(r, ms)), now = () => Date.now(), pollMs = 5000, renewMs = 60000, maxWaitMs = HEAVY_DEFAULTS.max_wait_s * 1000, setTimer = setInterval, clearTimer = clearInterval } = {}) {
|
|
262
|
+
const call = async (action, body) => {
|
|
263
|
+
const r = await fetchFn(`${base}/${action}`, { method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${credToken}` }, body: JSON.stringify(body ?? {}), signal: AbortSignal.timeout(10000) });
|
|
264
|
+
if (r.status !== 200) throw new Error(`heavy ${action}: HTTP ${r.status}`);
|
|
265
|
+
return r.json();
|
|
266
|
+
};
|
|
267
|
+
const t0 = now(), open = { waitMs: 0, queued: 0, holders: 1, release: () => {} };
|
|
268
|
+
for (;;) {
|
|
269
|
+
let r;
|
|
270
|
+
try { r = await call("acquire"); } catch { return { ...open, waitMs: now() - t0, failOpen: true }; }
|
|
271
|
+
if (r?.granted && r.token) {
|
|
272
|
+
const token = r.token, timer = setTimer(() => { call("renew", { token }).catch(() => {}); }, renewMs);
|
|
273
|
+
timer?.unref?.();
|
|
274
|
+
let released = false;
|
|
275
|
+
return { ...open, waitMs: now() - t0, token, release: () => { if (released) return; released = true; clearTimer(timer); call("release", { token }).catch(() => {}); } };
|
|
276
|
+
}
|
|
277
|
+
if (now() - t0 >= maxWaitMs) return { ...open, waitMs: now() - t0, failOpen: true, timedOut: true };
|
|
278
|
+
await sleep(Math.min(pollMs, Math.max(1, Number(r?.retry_after_s) * 1000 || pollMs)));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const cgroupRead = (f) => readFileSync(f, "utf8");
|
|
282
|
+
|
|
256
283
|
/** Default lane effect: `acquire(entry, cfg)` → {waitMs, queued, release()} (cfg = the lane's forge.yaml heavy keys); `stats()`; `lane(pids)` (#4405). */
|
|
257
284
|
export function makeHeavyIo({ dir = schedDir(), env = process.env, host } = {}) {
|
|
258
285
|
const open = (cfg) => openHeavy(dir, { cfg, env, ...(host ? { host } : {}) });
|
|
@@ -385,7 +412,7 @@ export function labelDockerArgs(name, args, env = {}) {
|
|
|
385
412
|
* CLI body: `run --name <n> -- <real> args...`. Pass-through when FORGE_HEAVY_HELD is set or the step is llm; else
|
|
386
413
|
* acquire, run with FORGE_HEAVY_HELD=1 and FORGE_HOST_PARALLELISM from live holders, release, propagate the exit.
|
|
387
414
|
*/
|
|
388
|
-
export async function runWrapped(argv, { env: env0 = process.env, open = openHeavy, run = spawnInherit, host } = {}) {
|
|
415
|
+
export async function runWrapped(argv, { env: env0 = process.env, open = openHeavy, run = spawnInherit, host, remote = acquireRemote, read = cgroupRead } = {}) {
|
|
389
416
|
let env = env0;
|
|
390
417
|
const sep = argv.indexOf("--");
|
|
391
418
|
if (argv[0] !== "run" || sep < 0 || !argv[sep + 1]) throw new Error("usage: heavy.mjs run --name <name> -- <command> [args...]");
|
|
@@ -398,12 +425,14 @@ export async function runWrapped(argv, { env: env0 = process.env, open = openHea
|
|
|
398
425
|
cmd = g0.cmd; env = g0.env; args = labelDockerArgs(name, args, env);
|
|
399
426
|
if (env.FORGE_HEAVY_HELD || env.FORGE_HEAVY_DISABLED === "1" || classifyStep(name, args) === "llm") return run(cmd, args, env);
|
|
400
427
|
const hostP = host ?? defaultHost();
|
|
401
|
-
const h = open(env.FORGEDOCK_SCHED_DIR || schedDir(env), { env, host: hostP });
|
|
402
428
|
const priority = Number.isFinite(Number(env.FORGE_LANE_PRIORITY)) && String(env.FORGE_LANE_PRIORITY).trim() !== "" ? Number(env.FORGE_LANE_PRIORITY) : DEFAULT_PRIORITY;
|
|
403
429
|
const phase = env.FORGE_LANE_PHASE || "step";
|
|
404
|
-
const
|
|
430
|
+
const useRemote = Boolean(env.CS_HEAVY_BASE); // #6047: the pool agent's token semaphore; fail-open, else the local file semaphore
|
|
431
|
+
const g = useRemote ? await remote({ base: env.CS_HEAVY_BASE, credToken: env.CS_CRED_TOKEN ?? "", maxWaitMs: c.max_wait_s * 1000 })
|
|
432
|
+
: await acquireHeavy(open(env.FORGEDOCK_SCHED_DIR || schedDir(env), { env, host: hostP }), { issue: Number(env.FORGE_LANE_ISSUE) || null, phase, priority, mb: c.step_mem_mb });
|
|
405
433
|
if (env.FORGE_HEAVY_WAITS) { try { appendFileSync(env.FORGE_HEAVY_WAITS, JSON.stringify({ phase, name, waitMs: g.waitMs, queued: g.queued }) + "\n"); } catch { /* metrics are best effort */ } }
|
|
406
434
|
let cores = 1; try { cores = hostP.cores() || 1; } catch { /* 1 */ }
|
|
435
|
+
cores = quotaCores({ cores, read, env }); // #6047: the container's CPU quota, never the VM
|
|
407
436
|
const childEnv = { ...env, FORGE_HEAVY_HELD: "1",
|
|
408
437
|
...(env.FORGE_HEAVY_PARALLELISM_PINNED === "1" ? {} : { FORGE_HOST_PARALLELISM: String(hostParallelism({ cores, lanes: g.holders })) }) };
|
|
409
438
|
// #5174: a gated step runs at nice 10 / ionice idle so local test runners and installs do not starve the schedd event loop.
|
package/bin/lean/heavy.test.mjs
CHANGED
|
@@ -6,12 +6,13 @@ import { spawnSync } from "node:child_process";
|
|
|
6
6
|
import { writeFileSync, readFileSync, mkdirSync, chmodSync, existsSync } from "node:fs";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
9
|
-
import { guardChain, isPassThroughWrapper, SHIM_LOOP_MAX, SHIM_DEPTH_MAX, classifyStep, heavyConfig, openHeavy, acquireHeavy, writeHeavyShims, heavyShimScript, sumWaits, runWrapped, HEAVY_BINS, isHeavyProcess } from "./heavy.mjs";
|
|
9
|
+
import { guardChain, isPassThroughWrapper, SHIM_LOOP_MAX, SHIM_DEPTH_MAX, classifyStep, heavyConfig, openHeavy, acquireHeavy, writeHeavyShims, heavyShimScript, sumWaits, runWrapped, acquireRemote, HEAVY_BINS, isHeavyProcess } from "./heavy.mjs";
|
|
10
10
|
import { checkAdmission, ADMISSION_DEFAULTS, localLaneCap } from "./admission.mjs";
|
|
11
11
|
import { formatAlertLines, formatWaitSummary } from "./orchestrate.mjs";
|
|
12
12
|
import { readHeavy, readAdmission, liveLaneCap } from "../engine-cli.mjs";
|
|
13
13
|
import { makeRampStore } from "./effects.mjs";
|
|
14
14
|
|
|
15
|
+
const noCgroup = () => { throw new Error("no cgroup"); }; // #6047: the test host's own CPU quota must not change expected worker counts
|
|
15
16
|
// Injected pids, clock and host: `live` is the set of pids the registry sees as alive; `mem` the MemAvailable in MB.
|
|
16
17
|
const world = ({ mem = 12000, cores = 4, swapFree = 0 } = {}) => {
|
|
17
18
|
const live = new Set(), clock = { t: 1_000_000 }, h = { mem, cores, swapFree };
|
|
@@ -208,16 +209,16 @@ describe("heavy shims and the run wrapper (#4169)", () => {
|
|
|
208
209
|
const open = (dir, o) => { w.live.add(process.pid); return openHeavy(dir, { ...o, alive: (p) => w.live.has(p) }); };
|
|
209
210
|
const host = { memAvailableMb: () => 64000, cores: () => 8 };
|
|
210
211
|
const run = async (cmd, args, e) => { calls.push({ cmd, args, held: e.FORGE_HEAVY_HELD, par: e.FORGE_HOST_PARALLELISM, holders: openHeavy(w.dir, { host }).stats().holders }); return { code: 3, signal: null }; };
|
|
211
|
-
assert.deepEqual(await runWrapped(["run", "--name", "tsc", "--", "/r/tsc", "--noEmit"], { env, open, run, host }), { code: 3, signal: null });
|
|
212
|
+
assert.deepEqual(await runWrapped(["run", "--name", "tsc", "--", "/r/tsc", "--noEmit"], { env, open, run, host, read: noCgroup }), { code: 3, signal: null });
|
|
212
213
|
assert.deepEqual(calls[0], { cmd: "/r/tsc", args: ["--noEmit"], held: "1", par: "8", holders: 1 });
|
|
213
214
|
assert.equal(openHeavy(w.dir, { host }).stats().holders, 0, "released after the step");
|
|
214
215
|
assert.deepEqual(sumWaits(readFileSync(waitsFile, "utf8")), { waits: { implement: JSON.parse(readFileSync(waitsFile, "utf8")).waitMs }, queueMax: 1 });
|
|
215
|
-
await runWrapped(["run", "--name", "tsc", "--", "/r/tsc", "--version"], { env, open, run, host });
|
|
216
|
-
await runWrapped(["run", "--name", "pnpm", "--", "/r/pnpm", "install"], { env: { ...env, FORGE_HEAVY_HELD: "1" }, open, run, host });
|
|
216
|
+
await runWrapped(["run", "--name", "tsc", "--", "/r/tsc", "--version"], { env, open, run, host, read: noCgroup });
|
|
217
|
+
await runWrapped(["run", "--name", "pnpm", "--", "/r/pnpm", "install"], { env: { ...env, FORGE_HEAVY_HELD: "1" }, open, run, host, read: noCgroup });
|
|
217
218
|
assert.deepEqual(calls.slice(1).map((c) => [c.held, c.holders]), [[undefined, 0], ["1", 0]], "llm and nested calls take no slot");
|
|
218
|
-
await runWrapped(["run", "--name", "tsc", "--", "/r/tsc"], { env: { ...env, FORGE_HOST_PARALLELISM: "2", FORGE_HEAVY_PARALLELISM_PINNED: "1" }, open, run, host });
|
|
219
|
+
await runWrapped(["run", "--name", "tsc", "--", "/r/tsc"], { env: { ...env, FORGE_HOST_PARALLELISM: "2", FORGE_HEAVY_PARALLELISM_PINNED: "1" }, open, run, host, read: noCgroup });
|
|
219
220
|
assert.equal(calls.at(-1).par, "2", "an operator-set FORGE_HOST_PARALLELISM wins");
|
|
220
|
-
await assert.rejects(runWrapped(["run", "--name", "x"], { env, open, run, host }), /usage/);
|
|
221
|
+
await assert.rejects(runWrapped(["run", "--name", "x"], { env, open, run, host, read: noCgroup }), /usage/);
|
|
221
222
|
});
|
|
222
223
|
|
|
223
224
|
it("sumWaits sums per phase and ignores bad lines; formatWaitSummary renders the batch-report line", () => {
|
|
@@ -488,3 +489,34 @@ describe("admission ramp (#5845)", () => {
|
|
|
488
489
|
assert.equal(makeRampStore({ dir: join(tmpDir("ramp-"), "none", "x") }).rampingMb(60), null, "an unreadable stamp dir is unknown, not zero");
|
|
489
490
|
});
|
|
490
491
|
});
|
|
492
|
+
|
|
493
|
+
describe("remote token backend (#6047)", () => {
|
|
494
|
+
const resp = (status, body) => ({ status, json: async () => body });
|
|
495
|
+
const opts = (calls, replies) => ({ base: "http://h/sandboxes/l1/heavy", credToken: "tok", pollMs: 1, sleep: async () => {}, setTimer: () => ({ unref() {} }), clearTimer: () => {},
|
|
496
|
+
fetchFn: async (u, o) => { calls.push(u.split("/heavy/")[1]); const r = replies.shift(); if (r instanceof Error) throw r; return r ?? resp(200, { ok: true }); } });
|
|
497
|
+
it("grant: acquires, then release posts the token back", async () => {
|
|
498
|
+
const calls = [], g = await acquireRemote(opts(calls, [resp(200, { granted: true, token: "t1" })]));
|
|
499
|
+
assert.equal(g.token, "t1"); g.release(); g.release();
|
|
500
|
+
await new Promise((r) => setImmediate(r));
|
|
501
|
+
assert.deepEqual(calls, ["acquire", "release"]);
|
|
502
|
+
});
|
|
503
|
+
it("deny then poll until granted", async () => {
|
|
504
|
+
const calls = [], g = await acquireRemote(opts(calls, [resp(200, { granted: false, retry_after_s: 1 }), resp(200, { granted: false }), resp(200, { granted: true, token: "t2" })]));
|
|
505
|
+
assert.equal(g.token, "t2"); assert.equal(calls.filter((c) => c === "acquire").length, 3);
|
|
506
|
+
});
|
|
507
|
+
it("fails open when the agent is unreachable or errors", async () => {
|
|
508
|
+
assert.equal((await acquireRemote(opts([], [new Error("ECONNREFUSED")]))).failOpen, true);
|
|
509
|
+
assert.equal((await acquireRemote(opts([], [resp(500, {})]))).failOpen, true);
|
|
510
|
+
});
|
|
511
|
+
it("runWrapped uses the remote backend only when CS_HEAVY_BASE is set; otherwise the local file semaphore", async () => {
|
|
512
|
+
const ran = [], run = async (cmd, args, env) => { ran.push(env); return { code: 0, signal: null }; };
|
|
513
|
+
let remoteCalls = 0, localOpens = 0;
|
|
514
|
+
const remote = async () => { remoteCalls++; return { waitMs: 0, holders: 1, release() {} }; };
|
|
515
|
+
const dir = tmpDir("heavy-rw-"), host = { memAvailableMb: () => 12000, cores: () => 4 };
|
|
516
|
+
await runWrapped(["run", "--name", "pnpm", "--", "pnpm", "install"], { env: { CS_HEAVY_BASE: "http://h/x", FORGEDOCK_SCHED_DIR: dir }, run, remote, host, read: () => { throw new Error("none"); } });
|
|
517
|
+
assert.equal(remoteCalls, 1);
|
|
518
|
+
await runWrapped(["run", "--name", "pnpm", "--", "pnpm", "install"], { env: { FORGEDOCK_SCHED_DIR: dir }, run, remote, host, open: (d, o) => { localOpens++; return openHeavy(d, { ...o, host }); }, read: () => { throw new Error("none"); } });
|
|
519
|
+
assert.equal(remoteCalls, 1); assert.equal(localOpens, 1);
|
|
520
|
+
assert.equal(ran[0].FORGE_HEAVY_HELD, "1");
|
|
521
|
+
});
|
|
522
|
+
});
|