forgedock 1.53.0 → 1.54.1
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/.claude-plugin/marketplace.json +51 -0
- package/README.md +8 -2
- package/bin/auth/app-manifest.mjs +89 -0
- package/bin/auth/app-manifest.test.mjs +75 -0
- package/bin/auth/app-token.mjs +258 -0
- package/bin/auth/app-token.test.mjs +240 -0
- package/bin/brand.mjs +7 -0
- package/bin/config-history.mjs +151 -0
- package/bin/config-schema.mjs +115 -0
- package/bin/demo.mjs +65 -11
- package/bin/engine/outcome-codes.mjs +6 -3
- package/bin/engine/telemetry-seam.mjs +8 -2
- package/bin/engine/telemetry-seam.test.mjs +17 -0
- package/bin/engine-cli.mjs +57 -20
- package/bin/first-run.mjs +122 -0
- package/bin/forgedock.mjs +128 -146
- package/bin/help-text.mjs +144 -0
- package/bin/hooks/pre-tool-use.mjs +7 -0
- package/bin/journey.mjs +82 -83
- package/bin/lean/acceptance.mjs +313 -0
- package/bin/lean/acceptance.test.mjs +215 -0
- package/bin/lean/activation.mjs +18 -0
- package/bin/lean/activation.test.mjs +23 -1
- package/bin/lean/batch-health.mjs +74 -1
- package/bin/lean/batch-health.test.mjs +54 -1
- package/bin/lean/batch.test.mjs +11 -9
- package/bin/lean/branchlock.mjs +54 -0
- package/bin/lean/branchlock.test.mjs +49 -0
- package/bin/lean/ceiling.mjs +72 -0
- package/bin/lean/ceiling.test.mjs +54 -0
- package/bin/lean/ci-budget.mjs +366 -0
- package/bin/lean/ci-budget.test.mjs +167 -0
- package/bin/lean/conformance.e2e.test.mjs +7 -0
- package/bin/lean/conformance.mjs +77 -19
- package/bin/lean/conformance.test.mjs +129 -3
- package/bin/lean/context.mjs +35 -6
- package/bin/lean/context.test.mjs +27 -1
- package/bin/lean/depcache.mjs +25 -1
- package/bin/lean/depcache.test.mjs +26 -0
- package/bin/lean/e2e.mjs +18 -2
- package/bin/lean/e2e.test.mjs +26 -1
- package/bin/lean/effects.mjs +40 -11
- package/bin/lean/execution.test.mjs +24 -0
- package/bin/lean/facts.mjs +3 -3
- package/bin/lean/facts.test.mjs +5 -0
- package/bin/lean/fixround.mjs +14 -0
- package/bin/lean/fixround.test.mjs +25 -2
- package/bin/lean/gh-assoc.test.mjs +2 -1
- package/bin/lean/integration.mjs +100 -9
- package/bin/lean/integration.test.mjs +98 -0
- package/bin/lean/issuewatch-parity.mjs +64 -0
- package/bin/lean/issuewatch-parity.test.mjs +127 -0
- package/bin/lean/issuewatch-release.test.mjs +1 -1
- package/bin/lean/issuewatch.mjs +34 -5
- package/bin/lean/issuewatch.test.mjs +3 -2
- package/bin/lean/lean.mjs +316 -74
- package/bin/lean/lean.test.mjs +397 -24
- package/bin/lean/mechfix.mjs +136 -0
- package/bin/lean/mechfix.test.mjs +95 -0
- package/bin/lean/orchestrate.mjs +20 -2
- package/bin/lean/phaseledger.mjs +47 -5
- package/bin/lean/phaseledger.test.mjs +30 -1
- package/bin/lean/precheck.mjs +23 -4
- package/bin/lean/precheck.test.mjs +14 -1
- package/bin/lean/prereq.mjs +28 -0
- package/bin/lean/prereq.test.mjs +20 -0
- package/bin/lean/probe.mjs +4 -2
- package/bin/lean/prodparity.mjs +52 -0
- package/bin/lean/prodparity.test.mjs +67 -0
- package/bin/lean/prompts.mjs +69 -12
- package/bin/lean/recovery.test.mjs +1 -1
- package/bin/lean/release-io.test.mjs +42 -0
- package/bin/lean/release-postmerge.mjs +6 -0
- package/bin/lean/release-preflight.mjs +58 -0
- package/bin/lean/release-preflight.test.mjs +114 -0
- package/bin/lean/release-rehearsal.mjs +8 -7
- package/bin/lean/release-review.mjs +67 -11
- package/bin/lean/release-review.test.mjs +128 -1
- package/bin/lean/release-snapshot.mjs +188 -0
- package/bin/lean/release-snapshot.test.mjs +190 -0
- package/bin/lean/release.mjs +87 -13
- package/bin/lean/release.test.mjs +104 -0
- package/bin/lean/render.mjs +1 -1
- package/bin/lean/replan.mjs +184 -0
- package/bin/lean/replan.test.mjs +110 -0
- package/bin/lean/resume.mjs +9 -7
- package/bin/lean/resume.test.mjs +16 -0
- package/bin/lean/schedd.mjs +34 -1
- package/bin/lean/schedd.test.mjs +21 -1
- package/bin/lean/selfreview.mjs +94 -0
- package/bin/lean/selfreview.test.mjs +58 -1
- package/bin/lean/selftest-gate.mjs +22 -0
- package/bin/lean/selftest-gate.test.mjs +18 -1
- package/bin/lean/selftest-journey.mjs +234 -0
- package/bin/lean/selftest-journey.test.mjs +130 -0
- package/bin/lean/selftest-live.mjs +2 -1
- package/bin/lean/seqlease.mjs +35 -1
- package/bin/lean/seqlease.test.mjs +15 -0
- package/bin/lean/seqreserve.e2e.test.mjs +135 -0
- package/bin/lean/seqreserve.mjs +73 -0
- package/bin/lean/seqreserve.test.mjs +134 -0
- package/bin/lean/sequence.mjs +35 -6
- package/bin/lean/seqversioned.mjs +147 -0
- package/bin/lean/stagestamp.mjs +28 -0
- package/bin/lean/stagestamp.test.mjs +32 -0
- package/bin/lean/surfaces.mjs +75 -0
- package/bin/lean/surfaces.test.mjs +59 -0
- package/bin/lean/toolplace.mjs +28 -0
- package/bin/lean/toolplace.test.mjs +24 -0
- package/bin/lean/toolstats.mjs +3 -1
- package/bin/lean/toolstats.test.mjs +11 -0
- package/bin/lean/validatebest.mjs +28 -0
- package/bin/lean/validatebest.test.mjs +27 -0
- package/bin/pool/agent.mjs +9 -0
- package/bin/pool/docker.mjs +5 -0
- package/bin/pool/router.mjs +8 -4
- package/bin/prereqs.mjs +111 -0
- package/bin/replay-timelapse.mjs +149 -0
- package/bin/review-staging.mjs +100 -16
- package/bin/review-staging.test.mjs +18 -0
- package/bin/runner.mjs +49 -7
- package/bin/splash-install.mjs +157 -0
- package/bin/stats/aggregate.mjs +8 -1
- package/bin/stats/conformance-outcomes.mjs +100 -19
- package/bin/stats/conformance-outcomes.test.mjs +87 -1
- package/bin/stats/depth.mjs +88 -31
- package/bin/stats/depth.test.mjs +63 -38
- package/bin/stats/efficiency.mjs +26 -5
- package/bin/stats/efficiency.test.mjs +45 -1
- package/bin/stats/first-review.mjs +77 -0
- package/bin/stats/first-review.test.mjs +36 -0
- package/bin/stats/firstmerge.mjs +40 -0
- package/bin/stats/firstmerge.test.mjs +41 -0
- package/bin/stats/github-source.mjs +51 -13
- package/bin/stats/index.mjs +91 -15
- package/bin/stats/local-source.mjs +1 -0
- package/bin/stats/origin.mjs +80 -0
- package/bin/stats/origin.test.mjs +58 -0
- package/bin/stats/render.mjs +3 -1
- package/bin/stats/scoreboard.mjs +137 -0
- package/bin/stats/scoreboard.test.mjs +87 -0
- package/bin/stats/stats.test.mjs +80 -0
- package/bin/tui.mjs +3 -2
- package/commands/bootstrap.md +15 -14
- package/commands/deploy-pr.md +18 -3
- package/commands/forge-stats.md +1 -1
- package/commands/forgedock-ci-setup.md +28 -0
- package/commands/forgedock-init.md +4 -5
- package/commands/issue.md +2 -0
- package/commands/milestone.md +9 -1
- package/commands/replay.md +2 -0
- package/commands/review-pr-staging.md +4 -1
- package/commands/work-on/close.md +8 -0
- package/docs/CI.md +1 -1
- package/docs/CONFIG.md +105 -10
- package/docs/ISSUE-WATCH.md +23 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/REPLAY.md +9 -0
- package/docs/SELFTEST.md +11 -0
- package/docs/STATS.md +19 -2
- package/docs/eval/README.md +6 -0
- package/docs/eval/adversarial-bench.md +68 -0
- package/docs/eval/corpus/adversarial-v1.json +285 -0
- package/docs/eval/feature-bench.md +42 -0
- package/docs/eval/feature-specs/crud-auth/journeys/notes-crud-isolated.mjs +21 -0
- package/docs/eval/feature-specs/crud-auth/journeys/register-login.mjs +12 -0
- package/docs/eval/feature-specs/crud-auth/spec.md +15 -0
- package/docs/site/start-a-new-project.md +2 -1
- package/package.json +5 -2
- package/plugins/forgedock-splash/.claude-plugin/plugin.json +10 -0
- package/plugins/forgedock-splash/README.md +27 -0
- package/plugins/forgedock-splash/hooks/hooks.json +1 -0
- package/plugins/forgedock-splash/hooks/register.tsx +74 -0
- package/plugins/forgedock-splash/hooks/scene.ts +222 -0
- package/plugins/forgedock-splash/types/index.d.ts +10 -0
- package/scripts/bench-adversarial.mjs +216 -0
- package/scripts/bench-feature.mjs +170 -0
- package/scripts/bench-lightlane.mjs +2 -2
- package/scripts/bootstrap-create.mjs +2 -2
- package/scripts/bootstrap-validate.mjs +35 -2
- package/scripts/check-spec-size.sh +4 -3
- package/scripts/check-spec-size.test.sh +3 -0
- package/scripts/plan-validate-live.mjs +40 -6
- package/scripts/review-pr-staging-scope.test.sh +1 -1
- package/scripts/review-staging-post.sh +23 -0
- package/scripts/review-staging-post.test.sh +8 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Mechanical fixes (#5348): the enumerating-test and duplicate-export gates already name the exact change, so the engine
|
|
5
|
+
* applies it itself and re-runs the detector; a model session starts only for what is left. No model, never throws.
|
|
6
|
+
* Both functions return {applied, remaining} over the findings they were given; `remaining` keeps the unproven ones.
|
|
7
|
+
*/
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import { join, posix } from "node:path";
|
|
10
|
+
|
|
11
|
+
const STR = /(["'`])(?:(?!\1)[^\\\n]|\\.)*\1/g;
|
|
12
|
+
const ALL_STRINGS = /^\s*(?:(["'`])(?:(?!\1)[^\\\n]|\\.)*\1\s*(?:,\s*|$))+$/;
|
|
13
|
+
|
|
14
|
+
/** Spans of every `[...]` in `text` (string literals skipped): [{start, end}] with `end` the index of the `]`. */
|
|
15
|
+
function arraySpans(text) {
|
|
16
|
+
const spans = [], stack = [];
|
|
17
|
+
for (let i = 0; i < text.length; i++) {
|
|
18
|
+
const c = text[i];
|
|
19
|
+
if (c === '"' || c === "'" || c === "`") { // skip a string literal
|
|
20
|
+
for (i++; i < text.length && text[i] !== c && text[i] !== "\n"; i++) if (text[i] === "\\") i++;
|
|
21
|
+
} else if (c === "[") stack.push(i);
|
|
22
|
+
else if (c === "]" && stack.length) spans.push({ start: stack.pop(), end: i });
|
|
23
|
+
}
|
|
24
|
+
return spans;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const lineOf = (text, idx) => text.slice(0, idx).split("\n").length;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Add `symbols` to the array literal of string literals that covers 1-based `line` of `text`. Only an unambiguous list
|
|
31
|
+
* (2+ elements, strings only) is edited; the new entry copies the neighbours' quote and layout.
|
|
32
|
+
* @returns {{text: string, inserted: string[]}} `inserted` is empty when the list was not recognised.
|
|
33
|
+
*/
|
|
34
|
+
export function insertIntoList(text, line, symbols) {
|
|
35
|
+
const span = arraySpans(text)
|
|
36
|
+
.filter((s) => lineOf(text, s.start) <= line && line <= lineOf(text, s.end))
|
|
37
|
+
.sort((a, b) => (a.end - a.start) - (b.end - b.start))
|
|
38
|
+
.find((s) => ALL_STRINGS.test(text.slice(s.start + 1, s.end)) && [...text.slice(s.start + 1, s.end).matchAll(STR)].length >= 2);
|
|
39
|
+
if (!span) return { text, inserted: [] };
|
|
40
|
+
const body = text.slice(span.start + 1, span.end);
|
|
41
|
+
const items = [...body.matchAll(STR)];
|
|
42
|
+
const have = new Set(items.map((m) => m[0].slice(1, -1)));
|
|
43
|
+
const quote = items[0][0][0];
|
|
44
|
+
const fresh = [...new Set(symbols)].filter((s) => !have.has(s) && !/[\\"'`\n]/.test(s));
|
|
45
|
+
if (!fresh.length) return { text, inserted: [] };
|
|
46
|
+
const lit = (s) => `${quote}${s}${quote}`;
|
|
47
|
+
const last = items[items.length - 1], lastEnd = span.start + 1 + last.index + last[0].length;
|
|
48
|
+
const trailing = /^\s*,/.exec(text.slice(lastEnd)); // a comma after the last element
|
|
49
|
+
const at = trailing ? lastEnd + trailing[0].length : lastEnd;
|
|
50
|
+
let add;
|
|
51
|
+
if (body.includes("\n")) {
|
|
52
|
+
const ls = text.lastIndexOf("\n", lastEnd) + 1, indent = /^\s*/.exec(text.slice(ls, lastEnd))[0];
|
|
53
|
+
add = trailing ? fresh.map((s) => `\n${indent}${lit(s)},`).join("") : fresh.map((s) => `,\n${indent}${lit(s)}`).join("");
|
|
54
|
+
} else add = trailing ? fresh.map((s) => ` ${lit(s)},`).join("") : fresh.map((s) => `, ${lit(s)}`).join("");
|
|
55
|
+
return { text: text.slice(0, at) + add + text.slice(at), inserted: fresh };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Enumerating tests: write every missing symbol into the list its test keeps. @param missing [{symbol, module, test, line}]
|
|
60
|
+
* @returns {{applied: object[], remaining: object[]}}
|
|
61
|
+
*/
|
|
62
|
+
export function applyEnumerating({ missing = [], cwd, fsx = fs } = {}) {
|
|
63
|
+
const applied = [], remaining = [];
|
|
64
|
+
const byTest = new Map();
|
|
65
|
+
for (const m of missing) { if (!byTest.has(m.test)) byTest.set(m.test, []); byTest.get(m.test).push(m); }
|
|
66
|
+
for (const [test, rows] of byTest) {
|
|
67
|
+
let text;
|
|
68
|
+
try { text = fsx.readFileSync(join(cwd, test), "utf8"); } catch { remaining.push(...rows); continue; }
|
|
69
|
+
const groups = new Map();
|
|
70
|
+
for (const m of rows) { const k = `${m.line}\0${m.module}`; if (!groups.has(k)) groups.set(k, []); groups.get(k).push(m); }
|
|
71
|
+
let changed = false;
|
|
72
|
+
const mine = []; // this test's applied rows: a failed write moves only these, never another test's
|
|
73
|
+
// bottom-up: an insertion only shifts the lines below it, so the detector's line numbers stay valid
|
|
74
|
+
for (const g of [...groups.values()].sort((a, b) => b[0].line - a[0].line)) {
|
|
75
|
+
const r = insertIntoList(text, g[0].line, g.map((m) => m.symbol));
|
|
76
|
+
const done = new Set(r.inserted);
|
|
77
|
+
for (const m of g) (done.has(m.symbol) ? mine : remaining).push(m);
|
|
78
|
+
if (r.inserted.length) { text = r.text; changed = true; }
|
|
79
|
+
}
|
|
80
|
+
if (changed) { try { fsx.writeFileSync(join(cwd, test), text); } catch { remaining.push(...mine); continue; } }
|
|
81
|
+
applied.push(...mine);
|
|
82
|
+
}
|
|
83
|
+
return { applied, remaining };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
87
|
+
const pascal = (s) => String(s).split(/[^A-Za-z0-9]+/).filter(Boolean).map(cap).join("");
|
|
88
|
+
|
|
89
|
+
/** `<AppPrefix><Symbol>`: the prefix is the declaring file's directory (its stem for an index file), cased like the symbol. */
|
|
90
|
+
export function renamedExport(symbol, path) {
|
|
91
|
+
const stem = posix.basename(path).replace(/\.[^.]+$/, "");
|
|
92
|
+
const dir = posix.basename(posix.dirname(path));
|
|
93
|
+
const prefix = pascal(stem === "index" || stem === "mod" ? dir : stem) || pascal(dir);
|
|
94
|
+
if (!prefix) return null;
|
|
95
|
+
const lower = /^[a-z]/.test(symbol);
|
|
96
|
+
return lower ? `${prefix.charAt(0).toLowerCase()}${prefix.slice(1)}${cap(symbol)}` : `${prefix}${cap(symbol)}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const word = (s) => new RegExp(`(?<![\\w$])${s.replace(/[\\$]/g, "\\$&")}(?![\\w$])`, "g");
|
|
100
|
+
|
|
101
|
+
/** True when `text` binds `name` from another module (ES import / `export {..} from`, python from-import): such a file references the lane's export, it does not merely declare its own. */
|
|
102
|
+
function importsName(text, name) {
|
|
103
|
+
const clauses = [...text.matchAll(/^\s*(?:import|export)\s+(?:type\s+)?([^;"'`]*?)\s*from\s*["'][^"']*["']/gm), ...text.matchAll(/^\s*from\s+\S+\s+import\s+(.*)$/gm)];
|
|
104
|
+
return clauses.some((m) => word(name).test(m[1]));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Duplicate exports: rename the lane's new export to `<AppPrefix><Symbol>` when the name occurs only in its declaring file and the
|
|
109
|
+
* other files that declare it themselves (`others`; so no importer, registry or test keyed by the name can be left behind) and never as a property, string or label.
|
|
110
|
+
* @param dups [{symbol, path, others}]; `git(args)` returns stdout
|
|
111
|
+
* @returns {Promise<{applied: object[], remaining: object[]}>}
|
|
112
|
+
*/
|
|
113
|
+
export async function renameDuplicates({ dups = [], cwd, git, fsx = fs } = {}) {
|
|
114
|
+
const applied = [], remaining = [];
|
|
115
|
+
const grep = async (name) => { try { return String(await git(["-c", "core.quotepath=off", "grep", "-l", "-w", "-e", name])).split("\n").map((l) => l.trim()).filter(Boolean); } catch { return []; } };
|
|
116
|
+
for (const d of dups) {
|
|
117
|
+
try {
|
|
118
|
+
const next = renamedExport(d.symbol, d.path);
|
|
119
|
+
if (!next || next === d.symbol || (await grep(next)).length) { remaining.push(d); continue; }
|
|
120
|
+
const files = await grep(d.symbol);
|
|
121
|
+
const others = d.others ?? [];
|
|
122
|
+
const reads = (f) => { try { return fsx.readFileSync(join(cwd, f), "utf8"); } catch { return null; } };
|
|
123
|
+
// the detector's others declare the name themselves, so they cannot import ours; a barrel (import then export) is listed as a declarer but does import it
|
|
124
|
+
if (others.some((f) => { const t = reads(f); return t === null || importsName(t, d.symbol); })) { remaining.push(d); continue; }
|
|
125
|
+
const ours = new Set([d.path, ...others]);
|
|
126
|
+
if (!files.includes(d.path) || files.some((f) => !ours.has(f))) { remaining.push(d); continue; }
|
|
127
|
+
const text = fsx.readFileSync(join(cwd, d.path), "utf8");
|
|
128
|
+
const re = word(d.symbol);
|
|
129
|
+
const bad = [...text.matchAll(re)].some((m) => /[.'"`]$/.test(text.slice(Math.max(0, m.index - 1), m.index)) || /^\s*[:'"`]/.test(text.slice(m.index + d.symbol.length, m.index + d.symbol.length + 2)));
|
|
130
|
+
if (bad) { remaining.push(d); continue; }
|
|
131
|
+
fsx.writeFileSync(join(cwd, d.path), text.replace(re, next));
|
|
132
|
+
applied.push({ ...d, renamedTo: next });
|
|
133
|
+
} catch { remaining.push(d); }
|
|
134
|
+
}
|
|
135
|
+
return { applied, remaining };
|
|
136
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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 fs from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { insertIntoList, applyEnumerating, renamedExport, renameDuplicates } from "./mechfix.mjs";
|
|
8
|
+
import { tmpDir } from "../tests/_tmp.mjs";
|
|
9
|
+
|
|
10
|
+
const tmp = () => tmpDir("mechfix-");
|
|
11
|
+
|
|
12
|
+
describe("#5348 enumerating list insertion", () => {
|
|
13
|
+
it("appends to a one-per-line list, copying quote, indent and the trailing comma", () => {
|
|
14
|
+
const src = `const names = [\n "alpha",\n "beta",\n "gamma",\n];\n`;
|
|
15
|
+
const r = insertIntoList(src, 3, ["delta"]);
|
|
16
|
+
assert.deepEqual(r.inserted, ["delta"]);
|
|
17
|
+
assert.equal(r.text, `const names = [\n "alpha",\n "beta",\n "gamma",\n "delta",\n];\n`);
|
|
18
|
+
});
|
|
19
|
+
it("appends to a one-line list without a trailing comma", () => {
|
|
20
|
+
const r = insertIntoList(`assert.deepEqual(keys, ['a1', 'b2', 'c3']);\n`, 1, ["d4", "e5"]);
|
|
21
|
+
assert.equal(r.text, `assert.deepEqual(keys, ['a1', 'b2', 'c3', 'd4', 'e5']);\n`);
|
|
22
|
+
});
|
|
23
|
+
it("leaves a name already listed, and a list that is not all string literals, alone", () => {
|
|
24
|
+
assert.deepEqual(insertIntoList(`x(["aa", "bb", "cc"]);\n`, 1, ["bb"]).inserted, []);
|
|
25
|
+
assert.deepEqual(insertIntoList(`x(["aa", bb, "cc"]);\n`, 1, ["dd"]).inserted, []);
|
|
26
|
+
assert.deepEqual(insertIntoList(`x(["aa"]);\n`, 1, ["dd"]).inserted, [], "one element is not a sibling list");
|
|
27
|
+
});
|
|
28
|
+
it("applyEnumerating edits the test file and reports what it could not place", () => {
|
|
29
|
+
const cwd = tmp();
|
|
30
|
+
fs.writeFileSync(join(cwd, "a.test.mjs"), `const L = ["one", "two", "three"];\nconst M = ["x1", "x2", "x3"];\n`);
|
|
31
|
+
const missing = [
|
|
32
|
+
{ symbol: "four", module: "m", test: "a.test.mjs", line: 1 },
|
|
33
|
+
{ symbol: "x4", module: "n", test: "a.test.mjs", line: 2 },
|
|
34
|
+
{ symbol: "gone", module: "m", test: "missing.test.mjs", line: 1 },
|
|
35
|
+
];
|
|
36
|
+
const r = applyEnumerating({ missing, cwd });
|
|
37
|
+
assert.deepEqual(r.applied.map((m) => m.symbol).sort(), ["four", "x4"]);
|
|
38
|
+
assert.deepEqual(r.remaining.map((m) => m.symbol), ["gone"]);
|
|
39
|
+
assert.equal(fs.readFileSync(join(cwd, "a.test.mjs"), "utf8"), `const L = ["one", "two", "three", "four"];\nconst M = ["x1", "x2", "x3", "x4"];\n`);
|
|
40
|
+
});
|
|
41
|
+
it("a failed write moves only that test's rows to remaining, not another test's applied rows", () => {
|
|
42
|
+
const cwd = tmp();
|
|
43
|
+
fs.writeFileSync(join(cwd, "a.test.mjs"), `const L = ["one", "two", "three"];\n`);
|
|
44
|
+
fs.writeFileSync(join(cwd, "b.test.mjs"), `const M = ["x1", "x2", "x3"];\nconst N = [a, b];\n`);
|
|
45
|
+
const missing = [
|
|
46
|
+
{ symbol: "four", module: "m", test: "a.test.mjs", line: 1 },
|
|
47
|
+
{ symbol: "x4", module: "n", test: "b.test.mjs", line: 1 },
|
|
48
|
+
{ symbol: "nope", module: "o", test: "b.test.mjs", line: 2 },
|
|
49
|
+
];
|
|
50
|
+
const fsx = { ...fs, writeFileSync: (f, t) => { if (String(f).endsWith("b.test.mjs")) throw new Error("EROFS"); return fs.writeFileSync(f, t); } };
|
|
51
|
+
const r = applyEnumerating({ missing, cwd, fsx });
|
|
52
|
+
assert.deepEqual(r.applied.map((m) => m.symbol), ["four"]);
|
|
53
|
+
assert.deepEqual(r.remaining.map((m) => m.symbol).sort(), ["nope", "x4"]);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("#5348 duplicate export rename", () => {
|
|
58
|
+
it("names the export after its app, cased like the symbol", () => {
|
|
59
|
+
assert.equal(renamedExport("Button", "apps/web/ui.ts"), "UiButton");
|
|
60
|
+
assert.equal(renamedExport("loadAll", "apps/web/index.ts"), "webLoadAll");
|
|
61
|
+
});
|
|
62
|
+
const world = (files) => {
|
|
63
|
+
const cwd = tmp();
|
|
64
|
+
for (const [f, text] of Object.entries(files)) { fs.mkdirSync(join(cwd, f, ".."), { recursive: true }); fs.writeFileSync(join(cwd, f), text); }
|
|
65
|
+
const git = async (a) => {
|
|
66
|
+
const name = a[a.indexOf("-e") + 1];
|
|
67
|
+
const hit = Object.entries(files).filter(([, t]) => new RegExp(`(?<![\\w$])${name}(?![\\w$])`).test(fs.readFileSync(join(cwd, ...[Object.keys(files).find((k) => files[k] === t)]), "utf8"))).map(([f]) => f);
|
|
68
|
+
if (!hit.length) throw new Error("exit 1");
|
|
69
|
+
return hit.join("\n");
|
|
70
|
+
};
|
|
71
|
+
return { cwd, git };
|
|
72
|
+
};
|
|
73
|
+
it("renames an export only its declaring file mentions", async () => {
|
|
74
|
+
const { cwd, git } = world({ "app/ui.ts": `export const Button = 1;\nexport const y = Button + 1;\n`, "app/other.ts": `export const Button = 2;\n` });
|
|
75
|
+
const r = await renameDuplicates({ dups: [{ symbol: "Button", path: "app/ui.ts", others: ["app/other.ts"] }], cwd, git });
|
|
76
|
+
assert.equal(r.applied.length, 1); assert.equal(r.remaining.length, 0);
|
|
77
|
+
assert.equal(fs.readFileSync(join(cwd, "app/ui.ts"), "utf8"), `export const UiButton = 1;\nexport const y = UiButton + 1;\n`);
|
|
78
|
+
assert.equal(fs.readFileSync(join(cwd, "app/other.ts"), "utf8"), `export const Button = 2;\n`);
|
|
79
|
+
});
|
|
80
|
+
it("leaves it for a session when a detector other is a barrel that imports the name", async () => {
|
|
81
|
+
const w = world({ "app/ui.ts": `export const Button = 1;\n`, "app/index.ts": `import { Button } from "./ui";\nexport { Button };\n` });
|
|
82
|
+
const r = await renameDuplicates({ dups: [{ symbol: "Button", path: "app/ui.ts", others: ["app/index.ts"] }], cwd: w.cwd, git: w.git });
|
|
83
|
+
assert.equal(r.applied.length, 0); assert.equal(r.remaining.length, 1);
|
|
84
|
+
assert.equal(fs.readFileSync(join(w.cwd, "app/ui.ts"), "utf8"), `export const Button = 1;\n`);
|
|
85
|
+
});
|
|
86
|
+
it("leaves it for a session when another file references the name, or it is used as a property", async () => {
|
|
87
|
+
let w = world({ "app/ui.ts": `export const Button = 1;\n`, "app/use.ts": `import { Button } from "./ui";\n` });
|
|
88
|
+
let r = await renameDuplicates({ dups: [{ symbol: "Button", path: "app/ui.ts", others: ["app/other.ts"] }], cwd: w.cwd, git: w.git });
|
|
89
|
+
assert.equal(r.applied.length, 0); assert.equal(r.remaining.length, 1);
|
|
90
|
+
w = world({ "app/ui.ts": `export const Button = 1;\nexport const map = { Button: 2 };\n` });
|
|
91
|
+
r = await renameDuplicates({ dups: [{ symbol: "Button", path: "app/ui.ts", others: ["x.ts"] }], cwd: w.cwd, git: w.git });
|
|
92
|
+
assert.equal(r.remaining.length, 1);
|
|
93
|
+
assert.match(fs.readFileSync(join(w.cwd, "app/ui.ts"), "utf8"), /export const Button = 1/);
|
|
94
|
+
});
|
|
95
|
+
});
|
package/bin/lean/orchestrate.mjs
CHANGED
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
* the queue order except that decomposed sub-issues go first. A settled row carries `est_minutes` (estimated vs. actual).
|
|
122
122
|
*/
|
|
123
123
|
import { parseDependsOn } from "../engine/phases.mjs";
|
|
124
|
-
import { classifyNeedsHuman, recoveryCodeOf, recoveryClassOf, OUTCOME_CODES } from "../engine/outcome-codes.mjs";
|
|
124
|
+
import { classifyNeedsHuman, recoveryCodeOf, recoveryClassOf, OUTCOME_CODES, ENV_VALIDATE_PLACEMENT, MECHANICAL_CODES } from "../engine/outcome-codes.mjs";
|
|
125
125
|
import { detectGateDeadlock, formatGateDeadlock } from "./gatewatch.mjs";
|
|
126
126
|
import { recoveryEvidence } from "./render.mjs";
|
|
127
127
|
import { renderAlerts } from "../stats/render.mjs";
|
|
@@ -133,6 +133,8 @@ import { mapLimit } from "./pmap.mjs";
|
|
|
133
133
|
import { quotaRequeue } from "./rotator.mjs";
|
|
134
134
|
import { joinsDecomposed, addsEpicChildren, selectChildren, edgeText, DEFAULT_POLL_S } from "./autochildren.mjs";
|
|
135
135
|
import { formatOverload } from "./hostload.mjs";
|
|
136
|
+
import { lackedTools } from "./toolplace.mjs";
|
|
137
|
+
import { openPrerequisites } from "./prereq.mjs";
|
|
136
138
|
|
|
137
139
|
// A dependency that finished like this no longer blocks its dependents.
|
|
138
140
|
const SATISFIED = new Set(["merged", "invalid"]);
|
|
@@ -385,6 +387,12 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
385
387
|
// #4542: a lane recovering from a remote capability block runs on the host, which has the capability.
|
|
386
388
|
// #4785: a tool-missing recovery too: the sandbox that lacked the tool is not chosen again.
|
|
387
389
|
if ([OUTCOME_CODES.ENV_CAPABILITY_REMOTE, OUTCOME_CODES.ENV_TOOL_MISSING].includes(recovering.get(n)?.code)) return { where: "local", reason: `host capability: recovering ${recovering.get(n).code}` };
|
|
390
|
+
// #5371: a mechanical recovery never repeats the placement of the run that failed (a remote sandbox env defect recurs there), and a remote validate failure is rerun on the host
|
|
391
|
+
if (recovering.get(n)?.code === ENV_VALIDATE_PLACEMENT || (MECHANICAL_CODES.includes(recovering.get(n)?.code) && recovering.get(n)?.where === "remote")) return { where: "local", reason: `different placement: recovering ${recovering.get(n).code} off the remote run` };
|
|
392
|
+
{ // #5331: a frozen contract naming a tool the sandbox is known to lack runs on the host (`remote.lacks`, `remote.contractOf(n)`; both optional)
|
|
393
|
+
const lk = lackedTools(remote.contractOf?.(n), remote.lacks);
|
|
394
|
+
if (lk.tools.length) return { where: "local", reason: `host tool: sandbox lacks ${lk.tools.join(", ")}` };
|
|
395
|
+
}
|
|
388
396
|
if (budgetLocal) return { where: "local", reason: `fallback to local: execution budget: ${budgetHit ?? "cap reached"}` };
|
|
389
397
|
try {
|
|
390
398
|
if (typeof remote.place === "function") {
|
|
@@ -498,6 +506,14 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
498
506
|
};
|
|
499
507
|
// #4409: `head` (decomposed sub-issues) puts them at the front of the queue in their given order; a sub-issue's
|
|
500
508
|
// estimate is the parent's ÷ N, floored at the M default.
|
|
509
|
+
// #5340: an open declared prerequisite outside the batch joins it, so edges() orders it first (no run that can only end dependency-open).
|
|
510
|
+
const pullPrerequisites = async (ns) => {
|
|
511
|
+
for (const n of ns) {
|
|
512
|
+
if (results.has(n)) continue;
|
|
513
|
+
const { pull } = await openPrerequisites({ deps: deps.get(n) ?? [], inBatch: (d) => set.has(d), results, issueState, issueLabels });
|
|
514
|
+
if (pull.length) { await addIssues(pull); decided({ issue: n, what: `prerequisite ${pull.map((d) => `#${d}`).join(", ")} is open: pulled into the batch ahead of it`, why: "declared Depends on, outside the batch", alternative: "start the run and end dependency-open" }); }
|
|
515
|
+
}
|
|
516
|
+
};
|
|
501
517
|
const addIssues = async (ns, { head = false, parent = null } = {}) => {
|
|
502
518
|
const fresh = ns.filter((d) => !set.has(d));
|
|
503
519
|
for (const d of fresh) {
|
|
@@ -510,6 +526,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
510
526
|
if (head) { pending.splice(at++, 0, d); heads.add(d); } else pending.push(d);
|
|
511
527
|
enqueued.set(d, now());
|
|
512
528
|
}
|
|
529
|
+
await pullPrerequisites(fresh);
|
|
513
530
|
noteCrossLane();
|
|
514
531
|
};
|
|
515
532
|
// New issues (a fresh batch, or extra issues passed to a resume) join the queue.
|
|
@@ -523,6 +540,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
523
540
|
await mapLimit(unread, setupConcurrency, async (n) => { await readDeps(n); setup.read++; save(); });
|
|
524
541
|
setup = null;
|
|
525
542
|
}
|
|
543
|
+
await pullPrerequisites([...pending]);
|
|
526
544
|
if (estimate) for (const n of order) { // a resume that enabled the estimator
|
|
527
545
|
if (estimates.has(n) || results.has(n)) continue;
|
|
528
546
|
let b = ""; try { b = await readBody(n); } catch { b = ""; }
|
|
@@ -913,7 +931,7 @@ export async function orchestrate({ issues, parallel = 3, runOne, readBody, pref
|
|
|
913
931
|
classUsed.set(`${n}:${cls}`, attempt);
|
|
914
932
|
// #4315: the full lane detail is kept (never firstLine) for the relabel when the batch stops before this attempt
|
|
915
933
|
recoveries.set(n, (recoveries.get(n) ?? 0) + 1); recovering.set(n, { code, attempt, max, cost_usd: Number(row.cost_usd) || 0, minutes: Number(row.minutes) || 0,
|
|
916
|
-
detail: String(row.detail ?? ""), outcome: row.outcome, ...(row.code ? { result_code: row.code } : {}), prev_attempt: prior?.attempt ?? 0 });
|
|
934
|
+
detail: String(row.detail ?? ""), outcome: row.outcome, ...(row.placement?.where ? { where: row.placement.where } : {}), ...(row.code ? { result_code: row.code } : {}), prev_attempt: prior?.attempt ?? 0 });
|
|
917
935
|
requeue(n, 0); done(); save();
|
|
918
936
|
decided({ issue: n, what: `recovery lane for ${code} (attempt ${attempt}/${max}); dependents stay queued`, why: firstLine(row.detail) || code,
|
|
919
937
|
alternative: "leave needs-human for the operator and skip the dependents" });
|
package/bin/lean/phaseledger.mjs
CHANGED
|
@@ -5,11 +5,15 @@
|
|
|
5
5
|
* The lane marks the phase it enters; entering one closes the previous, so the lane phases sum to the lane's wall time.
|
|
6
6
|
* `queue_wait` (and, for a remote lane, the sandbox start the dispatcher saw) happens before the lane clock starts, so the
|
|
7
7
|
* batch runner adds them to the row; they are not part of the lane-wall sum.
|
|
8
|
-
* Row shape: `phases: { <id>: { ms, model_ms?, usd? } }`. FORGE:TELEMETRY values are scalars, so `flattenPhases` gives
|
|
9
|
-
* `phase_<id>_ms|_model_ms|_usd` keys for it and `unflattenPhases` reads them back.
|
|
8
|
+
* Row shape: `phases: { <id>: { ms, model_ms?, usd?, wait? } }`. FORGE:TELEMETRY values are scalars, so `flattenPhases` gives
|
|
9
|
+
* `phase_<id>_ms|_model_ms|_usd|_wait_<cause>_ms` keys for it and `unflattenPhases` reads them back.
|
|
10
|
+
* #5349: `wait` is the phase's non-model time by cause (WAIT_CAUSES); what no typed wait explains is `command` (`sandbox` in
|
|
11
|
+
* sandbox_start), so model_ms + the wait causes close to ms.
|
|
10
12
|
*/
|
|
11
13
|
|
|
12
14
|
export const LANE_PHASES = Object.freeze(["queue_wait", "sandbox_start", "deps_install", "validate", "plan", "implement", "precheck", "review", "ci_wait", "base_sync", "merge"]);
|
|
15
|
+
/** Why a lane was not in a model call: queued for a heavy slot, paused for host load, rate-limited, sandbox start, or running a command. */
|
|
16
|
+
export const WAIT_CAUSES = Object.freeze(["heavy_queue", "host_load", "rate_limit", "sandbox", "command"]);
|
|
13
17
|
const isNum = (x) => typeof x === "number" && Number.isFinite(x);
|
|
14
18
|
|
|
15
19
|
function pct(values, p) {
|
|
@@ -19,10 +23,19 @@ function pct(values, p) {
|
|
|
19
23
|
return v[Math.max(0, Math.ceil((v.length * p) / 100) - 1)];
|
|
20
24
|
}
|
|
21
25
|
|
|
26
|
+
/** Typed waits rounded, plus the residual (ms - model - typed waits, never negative) as `sandbox` in sandbox_start, else `command`. */
|
|
27
|
+
function waitOf(ms, modelMs, typed = {}, id) {
|
|
28
|
+
const w = {};
|
|
29
|
+
for (const c of WAIT_CAUSES) if (typed[c] > 0) w[c] = Math.round(typed[c]);
|
|
30
|
+
const rest = Math.round(ms - modelMs - Object.values(w).reduce((a, b) => a + b, 0));
|
|
31
|
+
if (rest > 0) { const c = id === "sandbox_start" ? "sandbox" : "command"; w[c] = (w[c] ?? 0) + rest; }
|
|
32
|
+
return w;
|
|
33
|
+
}
|
|
34
|
+
|
|
22
35
|
/** Sequential ledger starting in `first` at `start`. `now` is the lane clock. */
|
|
23
36
|
export function createLedger(now, first = "sandbox_start", start = now()) {
|
|
24
37
|
let cur = LANE_PHASES.includes(first) ? first : null, since = start;
|
|
25
|
-
const ms = {}, model = {}, usd = {};
|
|
38
|
+
const ms = {}, model = {}, usd = {}, wait = {};
|
|
26
39
|
const close = (t) => { if (cur) ms[cur] = (ms[cur] ?? 0) + Math.max(0, t - since); };
|
|
27
40
|
const enter = (phase) => {
|
|
28
41
|
if (!LANE_PHASES.includes(phase) || phase === cur) return;
|
|
@@ -42,6 +55,12 @@ export function createLedger(now, first = "sandbox_start", start = now()) {
|
|
|
42
55
|
if (isNum(modelMs) && modelMs > 0) model[id] = (model[id] ?? 0) + modelMs;
|
|
43
56
|
if (isNum(cost) && cost > 0) usd[id] = (usd[id] ?? 0) + cost;
|
|
44
57
|
},
|
|
58
|
+
/** `waitMs` of `cause` (a typed wait) spent in `phase` (the current one when it is not a ledger phase). */
|
|
59
|
+
addWait(phase, cause, waitMs) {
|
|
60
|
+
const id = LANE_PHASES.includes(phase) ? phase : cur;
|
|
61
|
+
if (!id || !WAIT_CAUSES.includes(cause) || !isNum(waitMs) || waitMs <= 0) return;
|
|
62
|
+
(wait[id] ??= {})[cause] = (wait[id][cause] ?? 0) + waitMs;
|
|
63
|
+
},
|
|
45
64
|
/** The ledger as of now (the open phase counted up to now); does not end the current phase. */
|
|
46
65
|
snapshot() {
|
|
47
66
|
const t = now(), total = { ...ms };
|
|
@@ -49,7 +68,8 @@ export function createLedger(now, first = "sandbox_start", start = now()) {
|
|
|
49
68
|
const out = {};
|
|
50
69
|
for (const id of LANE_PHASES) {
|
|
51
70
|
if (!(id in total) && !(id in model) && !(id in usd)) continue;
|
|
52
|
-
|
|
71
|
+
const w = waitOf(total[id] ?? 0, model[id] ?? 0, wait[id], id);
|
|
72
|
+
out[id] = { ms: Math.round(total[id] ?? 0), ...(model[id] ? { model_ms: Math.round(model[id]) } : {}), ...(usd[id] ? { usd: Math.round(usd[id] * 1e6) / 1e6 } : {}), ...(Object.keys(w).length ? { wait: w } : {}) };
|
|
53
73
|
}
|
|
54
74
|
return out;
|
|
55
75
|
},
|
|
@@ -69,6 +89,7 @@ export function flattenPhases(phases) {
|
|
|
69
89
|
if (isNum(v.ms)) out[`phase_${id}_ms`] = v.ms;
|
|
70
90
|
if (isNum(v.model_ms)) out[`phase_${id}_model_ms`] = v.model_ms;
|
|
71
91
|
if (isNum(v.usd)) out[`phase_${id}_usd`] = v.usd;
|
|
92
|
+
for (const c of WAIT_CAUSES) if (isNum(v.wait?.[c])) out[`phase_${id}_wait_${c}_ms`] = v.wait[c];
|
|
72
93
|
}
|
|
73
94
|
return out;
|
|
74
95
|
}
|
|
@@ -78,7 +99,9 @@ export function unflattenPhases(rec) {
|
|
|
78
99
|
for (const id of LANE_PHASES) {
|
|
79
100
|
const ms = rec?.[`phase_${id}_ms`], mm = rec?.[`phase_${id}_model_ms`], usd = rec?.[`phase_${id}_usd`];
|
|
80
101
|
if (!isNum(ms)) continue;
|
|
81
|
-
|
|
102
|
+
const wait = {};
|
|
103
|
+
for (const c of WAIT_CAUSES) if (isNum(rec?.[`phase_${id}_wait_${c}_ms`])) wait[c] = rec[`phase_${id}_wait_${c}_ms`];
|
|
104
|
+
out[id] = { ms, ...(isNum(mm) ? { model_ms: mm } : {}), ...(isNum(usd) ? { usd } : {}), ...(Object.keys(wait).length ? { wait } : {}) };
|
|
82
105
|
}
|
|
83
106
|
return out;
|
|
84
107
|
}
|
|
@@ -103,6 +126,25 @@ export function summarizePhases(list) {
|
|
|
103
126
|
return { n: lanes.length, phases, largest: largest ? { phase: largest, share: total > 0 ? phases[largest].sum / total : 0 } : null };
|
|
104
127
|
}
|
|
105
128
|
|
|
129
|
+
/**
|
|
130
|
+
* #5349: non-model time over the given `phases` objects: per phase the summed wall, model and wait-by-cause, and the totals.
|
|
131
|
+
* Only lanes that carry a `wait` breakdown count (older runs have none); `{ n: 0, ... }` when there is none.
|
|
132
|
+
*/
|
|
133
|
+
export function summarizeWaits(list) {
|
|
134
|
+
const lanes = (list ?? []).filter((p) => p && typeof p === "object" && Object.values(p).some((v) => v?.wait && typeof v.wait === "object"));
|
|
135
|
+
const phases = {}, total = { ms: 0, model_ms: 0, wait: {} }, per = {}; // per[id][cause]: one value per lane, for p50/p90
|
|
136
|
+
for (const p of lanes) for (const [id, v] of Object.entries(p)) {
|
|
137
|
+
if (!LANE_PHASES.includes(id) || !isNum(v?.ms) || id === "queue_wait") continue;
|
|
138
|
+
const g = (phases[id] ??= { ms: 0, model_ms: 0, wait: {} });
|
|
139
|
+
for (const c of WAIT_CAUSES) if (isNum(v.wait?.[c])) ((per[id] ??= {})[c] ??= []).push(v.wait[c]);
|
|
140
|
+
g.ms += v.ms; total.ms += v.ms;
|
|
141
|
+
if (isNum(v.model_ms)) { g.model_ms += v.model_ms; total.model_ms += v.model_ms; }
|
|
142
|
+
for (const c of WAIT_CAUSES) if (isNum(v.wait?.[c])) { g.wait[c] = (g.wait[c] ?? 0) + v.wait[c]; total.wait[c] = (total.wait[c] ?? 0) + v.wait[c]; }
|
|
143
|
+
}
|
|
144
|
+
for (const [id, byCause] of Object.entries(per)) phases[id].pct = Object.fromEntries(Object.entries(byCause).map(([c, vs]) => [c, { p50: pct(vs, 50), p90: pct(vs, 90) }]));
|
|
145
|
+
return { n: lanes.length, phases, total };
|
|
146
|
+
}
|
|
147
|
+
|
|
106
148
|
const min = (ms) => `${(ms / 60000).toFixed(1)}m`;
|
|
107
149
|
|
|
108
150
|
/** Report line(s) for p50/p90 per phase and the largest phase; `n/a` when no lane carried a ledger. Never throws. */
|
|
@@ -4,7 +4,7 @@ import { describe, it } from "node:test";
|
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { phasesOf } from "./orchestrate.mjs";
|
|
6
6
|
import { aggregate } from "../stats/aggregate.mjs";
|
|
7
|
-
import { LANE_PHASES, createLedger, laneSum, withinWall, flattenPhases, unflattenPhases, summarizePhases, formatLedgerSummary } from "./phaseledger.mjs";
|
|
7
|
+
import { LANE_PHASES, createLedger, laneSum, withinWall, flattenPhases, unflattenPhases, summarizePhases, formatLedgerSummary, WAIT_CAUSES, summarizeWaits } from "./phaseledger.mjs";
|
|
8
8
|
|
|
9
9
|
const clock = () => { let t = 1000; const f = () => t; f.tick = (ms) => { t += ms; }; return f; };
|
|
10
10
|
|
|
@@ -69,4 +69,33 @@ describe("phase ledger (#4908)", () => {
|
|
|
69
69
|
assert.equal(t?.ledger.n, 1);
|
|
70
70
|
assert.equal(t.ledger.largest.phase, "implement");
|
|
71
71
|
});
|
|
72
|
+
|
|
73
|
+
it("attributes non-model time to named causes that close to the phase wall (#5349)", () => {
|
|
74
|
+
const now = clock(), L = createLedger(now);
|
|
75
|
+
L.enter("plan"); now.tick(100000);
|
|
76
|
+
L.addModel("plan", 30000, 0.1);
|
|
77
|
+
L.addWait("plan", "heavy_queue", 20000); L.addWait("plan", "rate_limit", 10000); L.addWait("plan", "bogus", 5); L.addWait("nope", "host_load", 1000);
|
|
78
|
+
L.enter("implement"); now.tick(50000);
|
|
79
|
+
const p = L.snapshot();
|
|
80
|
+
assert.deepEqual(p.plan.wait, { heavy_queue: 20000, rate_limit: 10000, host_load: 1000, command: 39000 });
|
|
81
|
+
assert.equal(p.plan.model_ms + Object.values(p.plan.wait).reduce((a, b) => a + b, 0), p.plan.ms);
|
|
82
|
+
assert.deepEqual(p.implement.wait, { command: 50000 });
|
|
83
|
+
assert.equal(createLedger(clock()).snapshot().plan, undefined);
|
|
84
|
+
const first = createLedger(now); now.tick(7000);
|
|
85
|
+
assert.deepEqual(first.snapshot().sandbox_start.wait, { sandbox: 7000 });
|
|
86
|
+
assert.ok(WAIT_CAUSES.includes("host_load"));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("wait round-trips through the flattened telemetry keys and aggregates by cause; old rows stay n/a (#5349)", () => {
|
|
90
|
+
const p = { plan: { ms: 10, model_ms: 4, wait: { heavy_queue: 3, command: 3 } }, merge: { ms: 7 } };
|
|
91
|
+
const flat = flattenPhases(p);
|
|
92
|
+
assert.equal(flat.phase_plan_wait_heavy_queue_ms, 3);
|
|
93
|
+
assert.deepEqual(unflattenPhases(flat), p);
|
|
94
|
+
const s = summarizeWaits([p, { plan: { ms: 5 } }, null]);
|
|
95
|
+
assert.equal(s.n, 1);
|
|
96
|
+
assert.deepEqual(s.total, { ms: 17, model_ms: 4, wait: { heavy_queue: 3, command: 3 } });
|
|
97
|
+
assert.equal(summarizeWaits([{ plan: { ms: 5 } }]).n, 0);
|
|
98
|
+
const q = summarizeWaits([1, 2, 3, 4].map((n) => ({ plan: { ms: 10 * n, wait: { heavy_queue: n * 1000 } } })));
|
|
99
|
+
assert.deepEqual(q.phases.plan.pct.heavy_queue, { p50: 2500, p90: 4000 });
|
|
100
|
+
});
|
|
72
101
|
});
|
package/bin/lean/precheck.mjs
CHANGED
|
@@ -14,6 +14,23 @@ import { loadavg, cpus } from "node:os";
|
|
|
14
14
|
import { scopeChecks, selectCommands, mergeChecks } from "./testmap.mjs";
|
|
15
15
|
import { LOG_CAP } from "./verify.mjs";
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* #5332: a check that hit its own timeout even after the one longer retry (rc 124) is host load, not a failing check.
|
|
19
|
+
* `failed` are the real failures (builder-visible, ci.red); `timedOut` are left to CI or end a recoverable timeout code.
|
|
20
|
+
*/
|
|
21
|
+
export function splitPrecheckResults(results) {
|
|
22
|
+
const list = Array.isArray(results) ? results : [];
|
|
23
|
+
return { failed: list.filter((r) => r.rc !== 0 && r.rc !== TIMEOUT_RC), timedOut: list.filter((r) => r.rc === TIMEOUT_RC) };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** #5332: names each timed-out command and its limit (the `(timed out after Ns)` the run reported, i.e. the retry's, else `limitMs`). */
|
|
27
|
+
export function timedOutDetail(timedOut, limitMs) {
|
|
28
|
+
return (timedOut ?? []).map((t) => {
|
|
29
|
+
const m = /\(timed out after (\d+)s\)/.exec(String(t.output ?? "")), s = m ? Number(m[1]) : Number(limitMs) > 0 && Number.isFinite(Number(limitMs)) ? Math.round(Number(limitMs) / 1000) : null;
|
|
30
|
+
return `\`${t.command}\` (timed out${s ? ` after ${s} s` : ""}, exit 124)`;
|
|
31
|
+
}).join(", ");
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
/** #4364: the engine's check plan for `forgedock check` (written beside contract.json) and the CLI's last run record. */
|
|
18
35
|
export const CHECK_PLAN_FILE = ".forge-lean/check-plan.json";
|
|
19
36
|
export const SELF_CHECK_FILE = ".forge-lean/self-check.json";
|
|
@@ -176,7 +193,7 @@ export function selfCheckState(record, fingerprint) {
|
|
|
176
193
|
* heavy binaries. ok = every command that ran exited 0 (deferred and `ci` are not failures, as in the engine).
|
|
177
194
|
* @param {{contract:object, plan:{mode?:string, commands:string[], budgetMs:number, perCommandMs:number}, parallelism?:number, now?:() => number, run:Function}} p
|
|
178
195
|
*/
|
|
179
|
-
export async function selfCheck({ contract, plan, parallelism = 1, now = () => Date.now(), run }) {
|
|
196
|
+
export async function selfCheck({ contract, plan, parallelism = 1, now = () => Date.now(), run, review = [] }) {
|
|
180
197
|
const vals = (Array.isArray(contract?.validate) ? contract.validate : []).filter((v) => v && String(v.command ?? "").trim());
|
|
181
198
|
const ci = plan?.mode === "ci", per = Number(plan?.perCommandMs) > 0 ? Number(plan.perCommandMs) : 300000;
|
|
182
199
|
const validate = [];
|
|
@@ -190,8 +207,9 @@ export async function selfCheck({ contract, plan, parallelism = 1, now = () => D
|
|
|
190
207
|
}
|
|
191
208
|
const pre = await runChecks({ commands: plan?.commands ?? [], parallelism, budgetMs: plan?.budgetMs ?? 0, perCommandMs: per, now, run });
|
|
192
209
|
const commands = [...pre.results];
|
|
193
|
-
|
|
194
|
-
|
|
210
|
+
// #5345: the reviewer's deterministic findings (selfreview.mjs) are failures of the check, so a red tree is never sent to review
|
|
211
|
+
const ok = [...validate, ...commands].every((x) => x.status || x.rc === 0) && review.length === 0;
|
|
212
|
+
return { ok, validate, commands, deferred: pre.deferred, ...(review.length ? { review } : {}) };
|
|
195
213
|
}
|
|
196
214
|
|
|
197
215
|
/** #4390: summary lines naming a failing test, as common runners print them (pytest, TAP/node --test, jest/vitest, go, cargo). */
|
|
@@ -225,6 +243,7 @@ export function formatCheckTable(r, cap = LOG_CAP) {
|
|
|
225
243
|
const failed = rows.filter((x) => !x.status && x.rc !== 0);
|
|
226
244
|
const per = Math.max(500, Math.floor(cap / Math.max(1, failed.length))); // verify.mjs capLogs share
|
|
227
245
|
for (const f of failed) out.push("", `--- ${f.label} (exit ${f.rc})`, quietFailure(f.output, { maxChars: per, logPath: f.logPath ?? null }));
|
|
228
|
-
|
|
246
|
+
for (const f of r.review ?? []) out.push(`FAIL review ${f.code}: ${f.detail}`);
|
|
247
|
+
out.push("", r.ok ? "check: PASS" : `check: FAIL (${failed.length + (r.review?.length ?? 0)} failing)`);
|
|
229
248
|
return out.join("\n");
|
|
230
249
|
}
|
|
@@ -6,7 +6,7 @@ import { writeFileSync } from "node:fs";
|
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
8
8
|
import { formatFirstPassSummary } from "./fixround.mjs";
|
|
9
|
-
import { runChecks, retryTimeoutMs, runWithTimeoutRetry, formatPrecheckSummary, planPrecheck, selfCheck, selfCheckState, formatCheckTable, worktreeFingerprint, quietFailure } from "./precheck.mjs";
|
|
9
|
+
import { runChecks, retryTimeoutMs, runWithTimeoutRetry, formatPrecheckSummary, planPrecheck, selfCheck, selfCheckState, formatCheckTable, worktreeFingerprint, quietFailure, splitPrecheckResults, timedOutDetail } from "./precheck.mjs";
|
|
10
10
|
import { execFileSync } from "node:child_process";
|
|
11
11
|
import { readPrecheckBudget } from "../engine-cli.mjs";
|
|
12
12
|
import { orchestrate } from "./orchestrate.mjs";
|
|
@@ -282,3 +282,16 @@ describe("check timeout is infrastructure (#4589)", () => {
|
|
|
282
282
|
assert.deepEqual([x.retried, x.r.rc, x.r.output], [true, 0, "2000"]);
|
|
283
283
|
});
|
|
284
284
|
});
|
|
285
|
+
|
|
286
|
+
describe("#5332 timed-out checks are not failing checks", () => {
|
|
287
|
+
it("splitPrecheckResults separates rc 124 from real failures", () => {
|
|
288
|
+
const r = [{ command: "a", rc: 0 }, { command: "b", rc: 124 }, { command: "c", rc: 1 }];
|
|
289
|
+
const { failed, timedOut } = splitPrecheckResults(r);
|
|
290
|
+
assert.deepEqual(failed.map((x) => x.command), ["c"]); assert.deepEqual(timedOut.map((x) => x.command), ["b"]);
|
|
291
|
+
assert.deepEqual(splitPrecheckResults(undefined), { failed: [], timedOut: [] });
|
|
292
|
+
});
|
|
293
|
+
it("timedOutDetail names the command and its limit", () => {
|
|
294
|
+
assert.equal(timedOutDetail([{ command: "make t", rc: 124, output: "x\n(timed out after 900s)" }], 300000), "`make t` (timed out after 900 s, exit 124)");
|
|
295
|
+
assert.equal(timedOutDetail([{ command: "make t", rc: 124, output: "" }], 300000), "`make t` (timed out after 300 s, exit 124)");
|
|
296
|
+
});
|
|
297
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Dependency-ordered admission (#5340): a declared prerequisite (`Depends on #N`) outside the batch is open on GitHub, so
|
|
5
|
+
* a run of the dependent can only end `dependency-open` and is retried. Orchestrate pulls such a prerequisite into the
|
|
6
|
+
* batch up front, so its DAG orders it first, instead of discovering it after a wasted run. A closed prerequisite is
|
|
7
|
+
* satisfied; a `needs-human` one is parked and not pulled in (the engine's own admission still refuses the dependent).
|
|
8
|
+
* Fail-open: an unreadable state or label adds nothing. Probes are injected.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {{deps:number[], inBatch:(n:number)=>boolean, results?:Map<number,object>, issueState?:Function, issueLabels?:Function}} p
|
|
13
|
+
* @returns {Promise<{pull:number[], parked:number[]}>} open prerequisites to add to the batch, and parked ones left out
|
|
14
|
+
*/
|
|
15
|
+
export async function openPrerequisites({ deps = [], inBatch, results = new Map(), issueState = null, issueLabels = null }) {
|
|
16
|
+
const pull = [], parked = [];
|
|
17
|
+
if (typeof issueState !== "function") return { pull, parked }; // no state probe: nothing is known to be open
|
|
18
|
+
for (const d of [...new Set(deps)]) {
|
|
19
|
+
if (inBatch(d) || results.has(d)) continue;
|
|
20
|
+
let st = "";
|
|
21
|
+
try { st = String((await issueState(d)) ?? "").toUpperCase(); } catch { st = ""; }
|
|
22
|
+
if (st !== "OPEN") continue; // closed (satisfied) or unreadable (fail-open)
|
|
23
|
+
let names = [];
|
|
24
|
+
try { names = typeof issueLabels === "function" ? ((await issueLabels(d)) ?? []) : []; } catch { names = []; }
|
|
25
|
+
(Array.isArray(names) && names.includes("needs-human") ? parked : pull).push(d);
|
|
26
|
+
}
|
|
27
|
+
return { pull, parked };
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
// Prerequisite pull-in (#5340).
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { openPrerequisites } from "./prereq.mjs";
|
|
7
|
+
|
|
8
|
+
const states = { 2: "OPEN", 3: "CLOSED", 4: "OPEN", 5: "OPEN", 6: "boom" };
|
|
9
|
+
const issueState = async (n) => { if (n === 6) throw new Error("gh down"); return states[n]; };
|
|
10
|
+
const issueLabels = async (n) => (n === 4 ? ["needs-human"] : []);
|
|
11
|
+
|
|
12
|
+
describe("openPrerequisites (#5340)", () => {
|
|
13
|
+
it("pulls open out-of-batch prerequisites; skips closed, in-batch, finished, parked and unreadable ones", async () => {
|
|
14
|
+
const r = await openPrerequisites({ deps: [2, 3, 4, 5, 6, 7, 2], inBatch: (d) => d === 5, results: new Map([[7, {}]]), issueState, issueLabels });
|
|
15
|
+
assert.deepEqual(r, { pull: [2], parked: [4] });
|
|
16
|
+
});
|
|
17
|
+
it("without a state probe nothing is known to be open", async () => {
|
|
18
|
+
assert.deepEqual(await openPrerequisites({ deps: [2], inBatch: () => false }), { pull: [], parked: [] });
|
|
19
|
+
});
|
|
20
|
+
});
|
package/bin/lean/probe.mjs
CHANGED
|
@@ -41,13 +41,13 @@ const isForgeMarker = (body) => /^\s*<!--\s*FORGE:/.test(String(body ?? ""));
|
|
|
41
41
|
* a line of its own character at least as long; anything inside another fence (a quoted sample) or indented 4+ columns
|
|
42
42
|
* (an indented code block) is content, never a declaration. An unclosed fence yields nothing.
|
|
43
43
|
*/
|
|
44
|
-
function
|
|
44
|
+
export function fencedBlocks(text, tag = "forge-probe") {
|
|
45
45
|
const blocks = [];
|
|
46
46
|
let open = null;
|
|
47
47
|
for (const line of text.split("\n")) {
|
|
48
48
|
const m = FENCE_RE.exec(line);
|
|
49
49
|
if (!open) {
|
|
50
|
-
if (m && !(m[1][0] === "`" && m[2].includes("`"))) open = { ch: m[1][0], len: m[1].length, lines: m[2].trim() ===
|
|
50
|
+
if (m && !(m[1][0] === "`" && m[2].includes("`"))) open = { ch: m[1][0], len: m[1].length, lines: m[2].trim() === tag ? [] : null };
|
|
51
51
|
} else if (m && m[1][0] === open.ch && m[1].length >= open.len && !m[2].trim()) {
|
|
52
52
|
if (open.lines) blocks.push(open.lines.join("\n"));
|
|
53
53
|
open = null;
|
|
@@ -56,6 +56,8 @@ function probeBlocks(text) {
|
|
|
56
56
|
return blocks;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
const probeBlocks = (text) => fencedBlocks(text, "forge-probe");
|
|
60
|
+
|
|
59
61
|
/** The last top-level ```forge-probe block of `text`: {run, pass, timeoutS}, or null when absent or malformed. */
|
|
60
62
|
export function parseProbe(text) {
|
|
61
63
|
const blocks = probeBlocks(noComments(String(text ?? ""), " ").replace(/\r\n?/g, "\n"));
|