forgedock 1.59.2 → 1.60.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/bin/engine/outcome-codes.mjs +3 -3
- package/bin/engine-cli.mjs +50 -10
- package/bin/labels.json +5 -0
- package/bin/lean/batch.mjs +21 -2
- package/bin/lean/batch.test.mjs +116 -1
- package/bin/lean/conformance.mjs +19 -6
- package/bin/lean/conformance.test.mjs +37 -3
- package/bin/lean/depcache.mjs +34 -15
- package/bin/lean/depcache.test.mjs +100 -1
- package/bin/lean/design-gate.mjs +15 -10
- package/bin/lean/design-gate.test.mjs +21 -0
- package/bin/lean/effects.mjs +18 -2
- package/bin/lean/execution.mjs +23 -5
- package/bin/lean/execution.test.mjs +81 -1
- package/bin/lean/gatewatch.test.mjs +5 -5
- package/bin/lean/issuewatch-triage.mjs +68 -0
- package/bin/lean/issuewatch-triage.test.mjs +98 -0
- package/bin/lean/issuewatch.mjs +34 -6
- package/bin/lean/issuewatch.test.mjs +11 -0
- package/bin/lean/lanelock.mjs +5 -4
- package/bin/lean/lean.mjs +144 -21
- package/bin/lean/lean.test.mjs +180 -6
- package/bin/lean/orchestrate-cancel.test.mjs +33 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +41 -0
- package/bin/lean/orchestrate-recovering.test.mjs +42 -0
- package/bin/lean/orchestrate.mjs +23 -10
- package/bin/lean/pagegate.mjs +50 -12
- package/bin/lean/pagegate.test.mjs +38 -1
- package/bin/lean/phaseledger.mjs +65 -2
- package/bin/lean/phaseledger.test.mjs +70 -2
- package/bin/lean/preflight.mjs +67 -3
- package/bin/lean/preflight.test.mjs +37 -1
- package/bin/lean/prompts.mjs +2 -1
- package/bin/lean/recovery.test.mjs +11 -6
- package/bin/lean/release-classify.mjs +143 -0
- package/bin/lean/release-classify.test.mjs +130 -0
- package/bin/lean/release-conductor.mjs +163 -0
- package/bin/lean/release-conductor.test.mjs +194 -0
- package/bin/lean/release-config.mjs +60 -8
- package/bin/lean/release-config.test.mjs +43 -1
- package/bin/lean/release-control.mjs +22 -5
- package/bin/lean/release-control.test.mjs +22 -0
- package/bin/lean/release-credentials.mjs +40 -0
- package/bin/lean/release-credentials.test.mjs +42 -0
- package/bin/lean/release-deploy.mjs +3 -3
- package/bin/lean/release-deploy.test.mjs +8 -0
- package/bin/lean/release-docs.test.mjs +93 -0
- package/bin/lean/release-fence.mjs +2 -0
- package/bin/lean/release-gate.mjs +88 -0
- package/bin/lean/release-gate.test.mjs +116 -0
- package/bin/lean/release-gates.mjs +5 -1
- package/bin/lean/release-ledger.mjs +47 -1
- package/bin/lean/release-ledger.test.mjs +33 -1
- package/bin/lean/release-mergeback.mjs +148 -0
- package/bin/lean/release-mergeback.test.mjs +129 -0
- package/bin/lean/release-p0.mjs +193 -0
- package/bin/lean/release-p0.test.mjs +127 -0
- package/bin/lean/release-plan.mjs +267 -0
- package/bin/lean/release-plan.test.mjs +202 -0
- package/bin/lean/release-preflight.mjs +16 -0
- package/bin/lean/release-regate.mjs +141 -0
- package/bin/lean/release-regate.test.mjs +149 -0
- package/bin/lean/release-review.mjs +5 -3
- package/bin/lean/release-rollback.mjs +277 -0
- package/bin/lean/release-rollback.test.mjs +245 -0
- package/bin/lean/release-snapshot.mjs +48 -9
- package/bin/lean/release-snapshot.test.mjs +43 -1
- package/bin/lean/release-start.mjs +164 -0
- package/bin/lean/release-start.test.mjs +171 -0
- package/bin/lean/release-status.mjs +6 -2
- package/bin/lean/release-train.mjs +159 -0
- package/bin/lean/release-train.test.mjs +139 -0
- package/bin/lean/release.mjs +127 -5
- package/bin/lean/release.test.mjs +80 -0
- package/bin/lean/sandbox-remote.mjs +2 -0
- package/bin/lean/schedd-load.test.mjs +82 -0
- package/bin/lean/schedd.mjs +67 -31
- package/bin/lean/schedd.test.mjs +80 -1
- package/bin/lean/validate-catalog.mjs +110 -0
- package/bin/lean/validate-catalog.test.mjs +55 -0
- package/bin/pool/agent.mjs +12 -1
- package/bin/pool/lane-tools.mjs +146 -0
- package/bin/pool/lane-tools.test.mjs +26 -0
- package/bin/pool/router.mjs +3 -1
- package/bin/pool/warm.mjs +14 -3
- package/docs/CONFIG.md +225 -1
- package/docs/ISSUE-WATCH.md +1 -0
- package/docs/design/visual-gate.md +10 -0
- package/docs/eval/adversarial-bench.md +1 -0
- package/package.json +1 -1
- package/pool/README.md +2 -0
- package/scripts/acceptance-red-green.sh +5 -2
- package/scripts/acceptance-red-green.test.sh +11 -0
- package/scripts/bench-adversarial.mjs +4 -0
- package/scripts/bench-lightlane.mjs +2 -1
- package/templates/github-actions/forge-conductor.scopes.json +7 -0
- package/templates/github-actions/forge-conductor.yml +57 -0
package/bin/lean/pagegate.mjs
CHANGED
|
@@ -37,7 +37,7 @@ export function parsePagesConfig(raw, { hasAppPages = false } = {}) {
|
|
|
37
37
|
const req = list(obj.require).map((k) => k.toLowerCase()).filter((k) => PAGE_REQUIRE.includes(k));
|
|
38
38
|
const pick = (v, d) => { const l = list(v); return l.length ? l : d; };
|
|
39
39
|
return {
|
|
40
|
-
routes, exclude: list(obj.exclude).map(norm), design_only: list(obj.design_only).map(norm), icp_doc: typeof obj.icp_doc === "string" && obj.icp_doc.trim() ? obj.icp_doc.trim() : null,
|
|
40
|
+
routes, exclude: list(obj.exclude).map(norm), design_only: list(obj.design_only).map(norm), generated: list(obj.generated).map(norm), rewrite_threshold: Number(obj.rewrite_threshold) > 0 && Number(obj.rewrite_threshold) <= 1 ? Number(obj.rewrite_threshold) : 0.6, icp_doc: typeof obj.icp_doc === "string" && obj.icp_doc.trim() ? obj.icp_doc.trim() : null,
|
|
41
41
|
require: raw && obj.require !== undefined && req.length ? [...new Set(req)] : [...PAGE_REQUIRE],
|
|
42
42
|
sitemap: pick(obj.sitemap, DEFAULTS.sitemap).map(norm), metadata_patterns: pick(obj.metadata_patterns, DEFAULTS.metadata),
|
|
43
43
|
canonical_patterns: pick(obj.canonical_patterns, DEFAULTS.canonical), structured_data_patterns: pick(obj.structured_data_patterns, DEFAULTS.structured),
|
|
@@ -68,12 +68,47 @@ export function designOnlyFiles(files, cfg) {
|
|
|
68
68
|
return [...new Set((files ?? []).map(norm).filter((f) => f && !TEST_RE.test(f) && anyGlob(cfg.design_only, f) && !anyGlob(cfg.exclude ?? [], f)))];
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
const GENERATED_RE = /(?:^|\/)(?:__generated__|generated)(?:\/|$)/;
|
|
72
|
+
const MARKUP_RE = /<\/?[A-Za-z][\w.]*|\/>|\b(?:className|style|class)\s*=|^\s*(?:import|export)\b/;
|
|
73
|
+
/** Added and removed lines per file from a unified diff. */
|
|
74
|
+
function changedByFile(diff) {
|
|
75
|
+
const out = {}; let cur = null;
|
|
76
|
+
for (const line of String(diff ?? "").split("\n")) {
|
|
77
|
+
if (line.startsWith("+++ ")) { cur = line.replace(/^\+\+\+ (?:b\/)?/, "").trim(); if (cur === "/dev/null") cur = null; continue; }
|
|
78
|
+
if (line.startsWith("--- ")) continue;
|
|
79
|
+
if (cur && (line.startsWith("+") || line.startsWith("-"))) (out[cur] ??= []).push(line.slice(1));
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* #5648: how a diff touches a page file: "generated" (exempt: a generated/ path, a `pages.generated` glob or an @generated header),
|
|
86
|
+
* "new" (added, or unknown: no `added` list or no diff for the file fails closed), "rewrite" (a markup/style/import change, or churn at
|
|
87
|
+
* or over `threshold` of the file) or "copy" (only text or data lines changed: takes the visual-check path, no design spec).
|
|
88
|
+
*/
|
|
89
|
+
export function pageChange(file, { added = null, diff = "", threshold = 0.6, generated = [], readFile = null } = {}) {
|
|
90
|
+
const f = norm(file);
|
|
91
|
+
if (GENERATED_RE.test(f) || anyGlob(generated ?? [], f)) return "generated";
|
|
92
|
+
let src = "";
|
|
93
|
+
try { src = typeof readFile === "function" ? String(readFile(f) ?? "") : ""; } catch { /* unreadable: no header, no churn */ }
|
|
94
|
+
if (/@generated|auto-?generated/i.test(src.split("\n").slice(0, 5).join("\n"))) return "generated";
|
|
95
|
+
if (!Array.isArray(added) || added.map(norm).includes(f)) return "new";
|
|
96
|
+
const lines = changedByFile(diff)[f];
|
|
97
|
+
if (!lines?.length) return "new";
|
|
98
|
+
if (lines.some((l) => MARKUP_RE.test(l))) return "rewrite";
|
|
99
|
+
const total = src ? src.split("\n").length : 0;
|
|
100
|
+
return total && lines.length / total >= threshold ? "rewrite" : "copy";
|
|
101
|
+
}
|
|
102
|
+
|
|
71
103
|
const present = (o, ks) => ks.filter((k) => blank(o?.[k]));
|
|
72
104
|
|
|
73
105
|
/** Contract-time problems: a deliverable that is a page needs `page_gate` {design_spec, seo, geo} per `pages.require`. [] when off or no page deliverable. */
|
|
74
|
-
export function contractBriefProblems(contract, cfg, { readFile = null } = {}) {
|
|
106
|
+
export function contractBriefProblems(contract, cfg, { readFile = null, baseFiles = null } = {}) {
|
|
75
107
|
const paths = (contract?.deliverables ?? []).map((d) => d?.path);
|
|
76
|
-
|
|
108
|
+
// #5648: a page already on the base is modified, not new: pageFailures judges rewrite vs copy from the diff; generated pages are exempt
|
|
109
|
+
const onBase = new Set(Array.isArray(baseFiles) ? baseFiles.map(norm) : []);
|
|
110
|
+
const gen = (f) => GENERATED_RE.test(f) || anyGlob(cfg?.generated ?? [], f);
|
|
111
|
+
const pages = pageFiles(paths, cfg, { readFile }).filter((f) => !onBase.has(f) && !gen(f)), dOnly = designOnlyFiles(paths, cfg).filter((f) => !onBase.has(f) && !gen(f));
|
|
77
112
|
if (!pages.length && !dOnly.length) return [];
|
|
78
113
|
if (!pages.length) {
|
|
79
114
|
const g = contract?.page_gate;
|
|
@@ -129,38 +164,41 @@ const LINK_RE = /href\s*=\s*\{?\s*["'`](\/[^"'`#?\s{}$]*)/g;
|
|
|
129
164
|
* Blocking failures (conformance.unimplemented) for the pages a diff adds or changes. `readFile(path)` returns worktree content or "";
|
|
130
165
|
* `tracked` the repo's files; `designApproved` true/false/null (unknown skips); `run({command})` -> {rc, output} for `pages.lint`.
|
|
131
166
|
*/
|
|
132
|
-
export async function pageFailures({ cfg, files = [], diff = "", result = null, readFile = () => "", tracked = null, designApproved = null, run = null }) {
|
|
133
|
-
|
|
167
|
+
export async function pageFailures({ cfg, files = [], diff = "", result = null, readFile = () => "", tracked = null, designApproved = null, run = null, added = null }) {
|
|
168
|
+
// #5648: generated pages are exempt; a modified copy-only page takes the visual-check path (no spec, no new-page briefs)
|
|
169
|
+
const kind = (f) => pageChange(f, { added, diff, threshold: cfg?.rewrite_threshold, generated: cfg?.generated, readFile });
|
|
170
|
+
const pages = pageFiles(files, cfg, { readFile }).filter((f) => kind(f) !== "generated"), dOnly = designOnlyFiles(files, cfg).filter((f) => kind(f) !== "generated"), uiFiles = [...pages, ...dOnly];
|
|
134
171
|
if (!cfg || !uiFiles.length) return [];
|
|
172
|
+
const specFiles = uiFiles.filter((f) => kind(f) !== "copy"), briefPages = pages.filter((f) => kind(f) !== "copy");
|
|
135
173
|
const C = OUTCOME_CODES.CONFORMANCE_UNIMPLEMENTED, out = [], j = result?.page_gate ?? {};
|
|
136
174
|
const row = (kind, detail) => out.push({ code: C, kind, detail });
|
|
137
175
|
if (cfg.require.includes("design")) {
|
|
138
|
-
if (designApproved === false) row("page_design_missing", `${
|
|
176
|
+
if (designApproved === false && specFiles.length) row("page_design_missing", `${specFiles.slice(0, 3).join(", ")} is a public page but the issue has no approved FORGE:DESIGN_SPEC: run /design before building`);
|
|
139
177
|
const shots = list(j.screenshots).join(" ");
|
|
140
178
|
if (!/390/.test(shots) || !/1440/.test(shots)) row("page_visual_missing", `${uiFiles.slice(0, 3).join(", ")}: the result's page_gate.screenshots must name a 390px and a 1440px visual check attached to the PR`);
|
|
141
179
|
}
|
|
142
180
|
const all = [...new Set([...(tracked ?? []), ...files].map(norm))];
|
|
143
|
-
if (
|
|
181
|
+
if (briefPages.length && cfg.require.includes("seo_intent")) {
|
|
144
182
|
const meta = regexes(cfg.metadata_patterns), canon = regexes(cfg.canonical_patterns), sd = regexes(cfg.structured_data_patterns);
|
|
145
|
-
for (const f of
|
|
183
|
+
for (const f of briefPages) {
|
|
146
184
|
const dir = f.split("/").slice(0, -1);
|
|
147
185
|
const ctx = [f, ...all.filter((p) => /(?:^|\/)layout\.[cm]?[jt]sx?$/.test(p) && (p.split("/").slice(0, -1).join("/") === "" || dir.join("/").startsWith(p.split("/").slice(0, -1).join("/"))))].map((p) => String(readFile(p) ?? "")).join("\n");
|
|
148
186
|
if (!meta.some((r) => r.test(ctx))) row("page_metadata_missing", `${f} has no title/description metadata (forge.yaml pages.metadata_patterns)`);
|
|
149
187
|
if (!canon.some((r) => r.test(ctx))) row("page_canonical_missing", `${f} declares no canonical URL (pages.canonical_patterns)`);
|
|
150
188
|
if (!sd.some((r) => r.test(ctx))) row("page_structured_data_missing", `${f} emits no structured data / JSON-LD (pages.structured_data_patterns)`);
|
|
151
189
|
}
|
|
152
|
-
if (!files.map(norm).some((f) => anyGlob(cfg.sitemap, f)) && blank(j.sitemap_justification)) row("page_sitemap_missing", `${
|
|
190
|
+
if (!files.map(norm).some((f) => anyGlob(cfg.sitemap, f)) && blank(j.sitemap_justification)) row("page_sitemap_missing", `${briefPages.slice(0, 3).join(", ")} needs a sitemap entry (a change under ${cfg.sitemap.join(", ")}) or page_gate.sitemap_justification in the result (a generated sitemap)`);
|
|
153
191
|
}
|
|
154
|
-
const
|
|
192
|
+
const addedLines = addedByFile(diff), forbid = regexes(cfg.forbid_patterns);
|
|
155
193
|
for (const f of pages) {
|
|
156
|
-
const lines =
|
|
194
|
+
const lines = addedLines[f] ?? [];
|
|
157
195
|
const hit = forbid.find((r) => lines.some((l) => r.test(l)));
|
|
158
196
|
if (hit) row("page_forbidden_pattern", `${f} adds content matching /${hit.source}/ (null sample, raw JSON or dead-end state on a public page; forge.yaml pages.forbid_patterns)`);
|
|
159
197
|
}
|
|
160
198
|
if (tracked) {
|
|
161
199
|
const routes = all.map(pageRouteOf).concat(all.map(routePathOf)).filter(Boolean).map(routeRe);
|
|
162
200
|
const bad = new Set();
|
|
163
|
-
for (const f of pages) for (const l of
|
|
201
|
+
for (const f of pages) for (const l of addedLines[f] ?? []) for (const m of l.matchAll(LINK_RE)) {
|
|
164
202
|
const p = m[1].replace(/\/+$/, "") || "/";
|
|
165
203
|
if (!routes.some((r) => r.test(p)) && !all.includes(`public${p}`) && !all.some((a) => a.endsWith(`/public${p}`))) bad.add(p);
|
|
166
204
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { parsePagesConfig, pageFiles, designOnlyFiles, contractBriefProblems, pageFailures, designSpecApproved, designHold, designLabelApproved } from "./pagegate.mjs";
|
|
5
|
+
import { parsePagesConfig, pageChange, pageFiles, designOnlyFiles, contractBriefProblems, pageFailures, designSpecApproved, designHold, designLabelApproved } from "./pagegate.mjs";
|
|
6
6
|
import { pagePlanNote, domainChecksBlock } from "./prompts.mjs";
|
|
7
7
|
import { pathDomains } from "./review-trigger.mjs";
|
|
8
8
|
import { validateContract, precheck } from "./conformance.mjs";
|
|
@@ -113,3 +113,40 @@ describe("page gate exclusions (#5585)", () => {
|
|
|
113
113
|
assert.deepEqual(f.map((x) => x.kind).sort(), ["page_design_missing", "page_visual_missing"]);
|
|
114
114
|
});
|
|
115
115
|
});
|
|
116
|
+
|
|
117
|
+
describe("copy-only edits to existing pages (#5648)", () => {
|
|
118
|
+
const docs = "web/src/app/(site)/docs/api/search/page.tsx", mig = "docs/migrations/search-to-serp/page.tsx", gen = "docs/api/generated/search/page.tsx";
|
|
119
|
+
const copyDiff = (f) => `+++ b/${f}\n- Searches Google and Bing.\n+ Searches the web.\n`;
|
|
120
|
+
const body = (f) => (f === docs || f === mig ? Array.from({ length: 40 }, (_, i) => `line ${i}`).join("\n") : "");
|
|
121
|
+
const files = [docs, mig, gen], diff = files.map(copyDiff).join("");
|
|
122
|
+
const kinds = (f) => f.map((x) => x.kind).sort();
|
|
123
|
+
it("pageChange: new, copy, rewrite, generated; unknown fails closed", () => {
|
|
124
|
+
const o = { added: [], diff, readFile: body };
|
|
125
|
+
assert.equal(pageChange(docs, o), "copy");
|
|
126
|
+
assert.equal(pageChange(gen, o), "generated");
|
|
127
|
+
assert.equal(pageChange(docs, { ...o, added: [docs] }), "new");
|
|
128
|
+
assert.equal(pageChange(docs, { ...o, added: null }), "new");
|
|
129
|
+
assert.equal(pageChange(docs, { ...o, diff: "" }), "new");
|
|
130
|
+
assert.equal(pageChange(docs, { ...o, diff: `+++ b/${docs}\n+<div className="x">hi</div>\n` }), "rewrite");
|
|
131
|
+
assert.equal(pageChange(docs, { ...o, threshold: 0.01 }), "rewrite");
|
|
132
|
+
});
|
|
133
|
+
it("copy-only modified pages need a visual check, not a design spec; generated pages need nothing", async () => {
|
|
134
|
+
const f = await pageFailures({ cfg, files, diff, readFile: body, tracked: files, added: [], designApproved: false });
|
|
135
|
+
assert.deepEqual(kinds(f), ["page_visual_missing"]);
|
|
136
|
+
assert.ok(!f.some((x) => x.detail.includes("generated")));
|
|
137
|
+
const shots = { page_gate: { screenshots: ["a-390.png", "a-1440.png"] } };
|
|
138
|
+
assert.deepEqual(await pageFailures({ cfg, files, diff, readFile: body, tracked: files, added: [], designApproved: false, result: shots }), []);
|
|
139
|
+
});
|
|
140
|
+
it("a new page, a markup rewrite, or unknown change info still needs the design spec", async () => {
|
|
141
|
+
assert.ok(kinds(await pageFailures({ cfg, files: [docs], diff, readFile: body, tracked: [docs], added: [docs], designApproved: false })).includes("page_design_missing"));
|
|
142
|
+
assert.ok(kinds(await pageFailures({ cfg, files: [docs], diff, readFile: body, tracked: [docs], designApproved: false })).includes("page_design_missing"));
|
|
143
|
+
const md = `+++ b/${docs}\n+<section className="grid">x</section>\n`;
|
|
144
|
+
assert.ok(kinds(await pageFailures({ cfg, files: [docs], diff: md, readFile: body, tracked: [docs], added: [], designApproved: false })).includes("page_design_missing"));
|
|
145
|
+
});
|
|
146
|
+
it("contract: on-base page deliverables skip the new-page briefs, generated ones too", () => {
|
|
147
|
+
const c = { deliverables: files.map((path) => ({ path })) };
|
|
148
|
+
assert.equal(contractBriefProblems(c, cfg).length, 1);
|
|
149
|
+
assert.deepEqual(contractBriefProblems(c, cfg, { baseFiles: [docs, mig, gen] }), []);
|
|
150
|
+
assert.deepEqual(contractBriefProblems({ deliverables: [{ path: gen }] }, cfg), []);
|
|
151
|
+
});
|
|
152
|
+
});
|
package/bin/lean/phaseledger.mjs
CHANGED
|
@@ -9,9 +9,14 @@
|
|
|
9
9
|
* `phase_<id>_ms|_model_ms|_usd|_wait_<cause>_ms` keys for it and `unflattenPhases` reads them back.
|
|
10
10
|
* #5349: `wait` is the phase's non-model time by cause (WAIT_CAUSES); what no typed wait explains is `command` (`sandbox` in
|
|
11
11
|
* sandbox_start), so model_ms + the wait causes close to ms.
|
|
12
|
+
* #5649: `contract` (contract authoring and corrections) and `fix` (review/CI fix rounds) are their own phases; the batch summary
|
|
13
|
+
* compares each phase's median/p75 with the previous 7 days of batches (`comparePhases`, `readBaselineRows`).
|
|
12
14
|
*/
|
|
15
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { homedir } from "node:os";
|
|
13
18
|
|
|
14
|
-
export const LANE_PHASES = Object.freeze(["queue_wait", "sandbox_start", "deps_install", "validate", "plan", "implement", "precheck", "review", "ci_wait", "base_sync", "merge"]);
|
|
19
|
+
export const LANE_PHASES = Object.freeze(["queue_wait", "sandbox_start", "deps_install", "validate", "plan", "contract", "implement", "precheck", "review", "fix", "ci_wait", "base_sync", "merge"]);
|
|
15
20
|
/** 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
21
|
export const WAIT_CAUSES = Object.freeze(["heavy_queue", "host_load", "rate_limit", "sandbox", "command"]);
|
|
17
22
|
const isNum = (x) => typeof x === "number" && Number.isFinite(x);
|
|
@@ -125,7 +130,7 @@ export function summarizePhases(list) {
|
|
|
125
130
|
if (!by[id]) continue;
|
|
126
131
|
const sum = by[id].reduce((a, b) => a + b, 0);
|
|
127
132
|
total += sum;
|
|
128
|
-
phases[id] = { n: by[id].length, p50: pct(by[id], 50), p90: pct(by[id], 90), sum };
|
|
133
|
+
phases[id] = { n: by[id].length, p50: pct(by[id], 50), p75: pct(by[id], 75), p90: pct(by[id], 90), sum };
|
|
129
134
|
}
|
|
130
135
|
let largest = null;
|
|
131
136
|
for (const [id, v] of Object.entries(phases)) if (!largest || v.sum > phases[largest].sum) largest = id;
|
|
@@ -163,6 +168,64 @@ export function formatLedgerSummary(rows) {
|
|
|
163
168
|
} catch { return "phases (wall time): n/a"; }
|
|
164
169
|
}
|
|
165
170
|
|
|
171
|
+
const DAY_MS = 86400000, GROWTH = 0.25;
|
|
172
|
+
const merged = (r) => r?.outcome === "merged";
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* #5649: per phase the current median/p75 and the baseline's, with the median delta (ratio - 1, null without a baseline), plus
|
|
176
|
+
* the lane wall time (merged rows' `minutes`) the same way. `prevRows` null/empty (no prior batches) gives `prev: null` everywhere.
|
|
177
|
+
* Pure; rows without a ledger are skipped; a phase on one side only keeps the other side null.
|
|
178
|
+
*/
|
|
179
|
+
export function comparePhases(curRows, prevRows) {
|
|
180
|
+
const side = (rows) => ({ s: summarizePhases((rows ?? []).map((r) => r?.phases)), wall: (rows ?? []).filter(merged).map((r) => r.minutes).filter(isNum).map((m) => m * 60000) });
|
|
181
|
+
const c = side(curRows), p = side(prevRows);
|
|
182
|
+
const stat = (v) => (v ? { median: v.p50, p75: v.p75, n: v.n } : null);
|
|
183
|
+
const delta = (cur, prev) => (cur && prev && prev.median > 0 ? cur.median / prev.median - 1 : null);
|
|
184
|
+
const phases = {};
|
|
185
|
+
for (const id of LANE_PHASES) {
|
|
186
|
+
const cur = stat(c.s.phases[id]), prev = stat(p.s.phases[id]);
|
|
187
|
+
if (cur || prev) phases[id] = { cur, prev, delta: delta(cur, prev) };
|
|
188
|
+
}
|
|
189
|
+
const w = (a) => (a.length ? { median: pct(a, 50), p75: pct(a, 75), n: a.length } : null);
|
|
190
|
+
const wall = { cur: w(c.wall), prev: w(p.wall) };
|
|
191
|
+
wall.delta = delta(wall.cur, wall.prev);
|
|
192
|
+
return { phases, wall, baseline: Boolean(p.s.n || p.wall.length) };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* #5649: the lane rows of the batches under `root` (default `~/.forge/batches`) whose last progress is within the previous
|
|
197
|
+
* `days` days, excluding batch `excludeId`; the last row per issue of each batch. Read-only; null when it cannot be read.
|
|
198
|
+
*/
|
|
199
|
+
export function readBaselineRows({ root = process.env.FORGEDOCK_BATCH_DIR || join(homedir(), ".forge", "batches"), excludeId = null, now = Date.now(), days = 7 } = {}) {
|
|
200
|
+
try {
|
|
201
|
+
const out = [];
|
|
202
|
+
for (const id of readdirSync(root)) {
|
|
203
|
+
if (id === excludeId) continue;
|
|
204
|
+
try {
|
|
205
|
+
const f = join(root, id, "log.jsonl");
|
|
206
|
+
if (now - statSync(f).mtimeMs > days * DAY_MS) continue;
|
|
207
|
+
const last = new Map();
|
|
208
|
+
for (const l of readFileSync(f, "utf8").split("\n")) { try { const r = l && JSON.parse(l); if (r && r.issue != null) last.set(r.issue, r); } catch { /* skip */ } }
|
|
209
|
+
out.push(...last.values());
|
|
210
|
+
} catch { /* a batch without a log */ }
|
|
211
|
+
}
|
|
212
|
+
return out;
|
|
213
|
+
} catch { return null; }
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** #5649: one line per phase, `<phase> median Xm (prev7d Ym) p75 Xm (prev7d Ym)`, `!` after a median that grew over 25%; then lane wall. */
|
|
217
|
+
export function formatPhaseComparison(curRows, prevRows) {
|
|
218
|
+
try {
|
|
219
|
+
const c = comparePhases(curRows, prevRows);
|
|
220
|
+
const m = (v, k) => (v ? min(v[k]) : "n/a");
|
|
221
|
+
const wm = (v, k) => (v ? `${v[k].toFixed(1)}m` : "n/a");
|
|
222
|
+
const line = (id, v, f) => `${id} median ${f(v.cur, "median")} (prev7d ${f(v.prev, "median")}) p75 ${f(v.cur, "p75")} (prev7d ${f(v.prev, "p75")})${v.delta != null && v.delta > GROWTH ? ` ! median +${Math.round(v.delta * 100)}%` : ""}`;
|
|
223
|
+
const lines = Object.entries(c.phases).map(([id, v]) => line(id, v, m));
|
|
224
|
+
if (c.wall.cur || c.wall.prev) lines.push(line("lane wall (merged)", { ...c.wall, cur: c.wall.cur && { median: c.wall.cur.median / 60000, p75: c.wall.cur.p75 / 60000 }, prev: c.wall.prev && { median: c.wall.prev.median / 60000, p75: c.wall.prev.p75 / 60000 } }, wm));
|
|
225
|
+
return lines.length ? lines : ["phases vs prev7d: n/a"];
|
|
226
|
+
} catch { return ["phases vs prev7d: n/a"]; }
|
|
227
|
+
}
|
|
228
|
+
|
|
166
229
|
/** #5435: the local `sandbox_start` budget (issue: p50 <= 3 s on the bench corpus). */
|
|
167
230
|
export const SANDBOX_START_P50_BUDGET_MS = 3000;
|
|
168
231
|
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
+
import { mkdirSync, writeFileSync, utimesSync } from "node:fs";
|
|
6
|
+
import { tmpDir } from "../tests/_tmp.mjs";
|
|
7
|
+
import { join } from "node:path";
|
|
5
8
|
import { phasesOf } from "./orchestrate.mjs";
|
|
6
9
|
import { aggregate } from "../stats/aggregate.mjs";
|
|
7
|
-
import { LANE_PHASES, createLedger, laneSum, withinWall, flattenPhases, unflattenPhases, summarizePhases, formatLedgerSummary, WAIT_CAUSES, summarizeWaits } from "./phaseledger.mjs";
|
|
10
|
+
import { LANE_PHASES, createLedger, laneSum, withinWall, flattenPhases, unflattenPhases, summarizePhases, formatLedgerSummary, WAIT_CAUSES, summarizeWaits, comparePhases, formatPhaseComparison, readBaselineRows } from "./phaseledger.mjs";
|
|
8
11
|
|
|
9
12
|
const clock = () => { let t = 1000; const f = () => t; f.tick = (ms) => { t += ms; }; return f; };
|
|
10
13
|
|
|
@@ -53,7 +56,7 @@ describe("phase ledger (#4908)", () => {
|
|
|
53
56
|
assert.match(line, /largest: implement/);
|
|
54
57
|
assert.equal(formatLedgerSummary([{ issue: 1 }]), "phases (wall time): n/a");
|
|
55
58
|
assert.equal(formatLedgerSummary(null), "phases (wall time): n/a");
|
|
56
|
-
assert.equal(LANE_PHASES.length,
|
|
59
|
+
assert.equal(LANE_PHASES.length, 13);
|
|
57
60
|
});
|
|
58
61
|
|
|
59
62
|
it("the batch row adds queue_wait to the lane ledger and stays null without one (#4908)", () => {
|
|
@@ -99,3 +102,68 @@ describe("phase ledger (#4908)", () => {
|
|
|
99
102
|
assert.deepEqual(q.phases.plan.pct.heavy_queue, { p50: 2500, p90: 4000 });
|
|
100
103
|
});
|
|
101
104
|
});
|
|
105
|
+
|
|
106
|
+
describe("phase comparison vs previous 7 days (#5649)", () => {
|
|
107
|
+
const row = (phases, minutes, outcome = "merged", issue = 1) => ({ issue, outcome, minutes, phases });
|
|
108
|
+
const M = 60000;
|
|
109
|
+
|
|
110
|
+
it("contract and fix are ledger phases that keep the lane sum, rows without them still summarise", async () => {
|
|
111
|
+
const now = clock(), t0 = now(), L = createLedger(now);
|
|
112
|
+
now.tick(1000); L.enter("plan"); now.tick(2000);
|
|
113
|
+
await L.during("contract", async () => { now.tick(3000); });
|
|
114
|
+
now.tick(4000); L.enter("review"); now.tick(5000);
|
|
115
|
+
await L.during("fix", async () => { now.tick(6000); });
|
|
116
|
+
now.tick(7000); L.enter("merge"); now.tick(1000);
|
|
117
|
+
const p = L.snapshot();
|
|
118
|
+
assert.deepEqual(Object.keys(p), ["sandbox_start", "plan", "contract", "review", "fix", "merge"]);
|
|
119
|
+
assert.equal(p.contract.ms, 3000); assert.equal(p.fix.ms, 6000);
|
|
120
|
+
assert.ok(withinWall(p, now() - t0));
|
|
121
|
+
assert.equal(unflattenPhases(flattenPhases(p)).fix.ms, 6000);
|
|
122
|
+
const s = summarizePhases([p, { plan: { ms: 10 } }]);
|
|
123
|
+
assert.equal(s.n, 2); assert.equal(s.phases.plan.n, 2); assert.equal(s.phases.fix.n, 1);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("summarizePhases carries p75", () => {
|
|
127
|
+
const s = summarizePhases([1, 2, 3, 4].map((x) => ({ plan: { ms: x * 1000 } })));
|
|
128
|
+
assert.equal(s.phases.plan.p75, 3000);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("comparePhases: no prior batches, rows without ledgers, one-sided phases", () => {
|
|
132
|
+
const cur = [row({ plan: { ms: 4 * M }, fix: { ms: M } }, 20), row(undefined, 30, "merged", 2)];
|
|
133
|
+
const none = comparePhases(cur, null);
|
|
134
|
+
assert.equal(none.baseline, false);
|
|
135
|
+
assert.equal(none.phases.plan.prev, null); assert.equal(none.phases.plan.delta, null);
|
|
136
|
+
assert.deepEqual([none.wall.cur.median, none.wall.cur.p75], [25 * M, 30 * M]);
|
|
137
|
+
const c = comparePhases(cur, [row({ plan: { ms: 2 * M }, merge: { ms: M } }, 10), row({}, 0, "failed")]);
|
|
138
|
+
assert.equal(c.baseline, true);
|
|
139
|
+
assert.equal(c.phases.plan.delta, 1);
|
|
140
|
+
assert.equal(c.phases.fix.prev, null); assert.equal(c.phases.merge.cur, null);
|
|
141
|
+
assert.equal(c.wall.prev.median, 10 * M);
|
|
142
|
+
assert.doesNotThrow(() => comparePhases(undefined, undefined));
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("formatPhaseComparison prints the line form, marks >25% growth and the lane wall", () => {
|
|
146
|
+
const out = formatPhaseComparison([row({ plan: { ms: 3 * M }, merge: { ms: M } }, 20)], [row({ plan: { ms: 2 * M }, merge: { ms: M } }, 10)]);
|
|
147
|
+
assert.equal(out[0], "plan median 3.0m (prev7d 2.0m) p75 3.0m (prev7d 2.0m) ! median +50%");
|
|
148
|
+
assert.equal(out[1], "merge median 1.0m (prev7d 1.0m) p75 1.0m (prev7d 1.0m)");
|
|
149
|
+
assert.equal(out[2], "lane wall (merged) median 20.0m (prev7d 10.0m) p75 20.0m (prev7d 10.0m) ! median +100%");
|
|
150
|
+
assert.match(formatPhaseComparison([row({ plan: { ms: M } }, 5)], null)[0], /^plan median 1\.0m \(prev7d n\/a\)/);
|
|
151
|
+
assert.deepEqual(formatPhaseComparison([], []), ["phases vs prev7d: n/a"]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("readBaselineRows reads recent batches except the current one, last row per issue; null when unreadable", () => {
|
|
155
|
+
const root = tmpDir("bl-"), now = Date.now();
|
|
156
|
+
const mk = (id, rows, ageDays) => {
|
|
157
|
+
mkdirSync(join(root, id)); const f = join(root, id, "log.jsonl");
|
|
158
|
+
writeFileSync(f, rows.map((r) => JSON.stringify(r)).join("\n") + "\nnot json\n");
|
|
159
|
+
const t = (now - ageDays * 86400000) / 1000; utimesSync(f, t, t);
|
|
160
|
+
};
|
|
161
|
+
mk("a", [{ issue: 1, minutes: 1 }, { issue: 1, minutes: 2 }, { issue: 2, minutes: 3 }], 1);
|
|
162
|
+
mk("old", [{ issue: 9, minutes: 9 }], 10);
|
|
163
|
+
mk("cur", [{ issue: 5, minutes: 5 }], 0);
|
|
164
|
+
mkdirSync(join(root, "nolog"));
|
|
165
|
+
const rows = readBaselineRows({ root, excludeId: "cur", now });
|
|
166
|
+
assert.deepEqual(rows.map((r) => r.minutes).sort(), [2, 3]);
|
|
167
|
+
assert.equal(readBaselineRows({ root: join(root, "missing"), now }), null);
|
|
168
|
+
});
|
|
169
|
+
});
|
package/bin/lean/preflight.mjs
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { builtinModules } from "node:module";
|
|
13
13
|
import { existsSync } from "node:fs";
|
|
14
|
-
import { join, dirname, delimiter } from "node:path";
|
|
14
|
+
import { join, dirname, delimiter, relative } from "node:path";
|
|
15
15
|
import { missingTool } from "./conformance.mjs";
|
|
16
16
|
|
|
17
17
|
export const PREFLIGHT_CAP = 20;
|
|
@@ -280,6 +280,7 @@ export function depInstallFailures({ results = [], changedFiles = [] } = {}) {
|
|
|
280
280
|
if (r?.status !== "failed") continue;
|
|
281
281
|
const label = `${r.eco ?? "dependencies"}${r.dir && r.dir !== "." ? ` in ${r.dir}` : ""}: ${r.reason ?? "install failed"}`;
|
|
282
282
|
const rx = SRC_BY_ECO(r.eco);
|
|
283
|
+
if (r.code === "env.tool_missing") { block.push({ code: "env.tool_missing", kind: "dep_install", tool: r.eco ?? "python", detail: `dependency install stopped (${label}) (environment, not the change)` }); continue; } // #5651
|
|
283
284
|
const hit = r.eco ? changedFiles.find((f) => rx.test(f) && underDir(r.dir, f) && (r.dir && r.dir !== "." ? true : !dirs.some((d) => underDir(d, f)))) : null;
|
|
284
285
|
if (hit) block.push({ code: "env.tool_missing", kind: "dep_install", tool: r.eco, detail: `dependency install failed (${label}) for a package the changed file ${hit} imports (environment, not the change)` });
|
|
285
286
|
else logged.push(`Dependency install failed, unrelated to the changed files: ${label}`);
|
|
@@ -313,9 +314,11 @@ export function declaredEnv(contract) {
|
|
|
313
314
|
|
|
314
315
|
/** #5590: pytest's built-in fixtures, never host executables. */
|
|
315
316
|
const PYTEST_FIXTURES = new Set(["caplog", "capsys", "capfd", "capsysbinary", "capfdbinary", "monkeypatch", "tmp_path", "tmp_path_factory", "tmpdir", "tmpdir_factory", "request", "recwarn", "pytestconfig", "mocker", "doctest_namespace", "cache", "testdir"]);
|
|
316
|
-
/**
|
|
317
|
+
/** A file name (`depcache.test.mjs`, `conftest.py`) in `env` is a test file, not a host tool; versioned executables (`python3.12`) still pass. */
|
|
318
|
+
const SOURCE_FILE_RE = /\.(?:[cm]?[jt]sx?|py|rb|go|rs|java|kt|sh|bash|json|ya?ml|toml|md|txt|lock|cfg|ini)$/;
|
|
319
|
+
/** #5590: `env` lists executables only; CamelCase (a class such as FakeRedis), snake_case, pytest-fixture and source-file names are libraries/fixtures/tests, not host tools. Pure. */
|
|
317
320
|
export function isExecutableName(t) {
|
|
318
|
-
return !/[A-Z]/.test(t) && !t.includes("_") && !PYTEST_FIXTURES.has(t);
|
|
321
|
+
return !/[A-Z]/.test(t) && !t.includes("_") && !PYTEST_FIXTURES.has(t) && !SOURCE_FILE_RE.test(t);
|
|
319
322
|
}
|
|
320
323
|
|
|
321
324
|
/**
|
|
@@ -342,3 +345,64 @@ export function projectBinDirs(wt, files = [], { exists = existsSync, cap = 24 }
|
|
|
342
345
|
|
|
343
346
|
/** #5592: `base` PATH with the project-local executable dirs appended (never ahead of what the lane already resolves). */
|
|
344
347
|
export const withLocalBins = (base, dirs) => [...String(base ?? "").split(delimiter).filter(Boolean), ...dirs.filter((d) => !String(base ?? "").split(delimiter).includes(d))].join(delimiter);
|
|
348
|
+
|
|
349
|
+
const PY_MANIFESTS = new Set(["pyproject.toml", "poetry.lock", "uv.lock", "requirements.txt"]);
|
|
350
|
+
const normPy = (n) => String(n).toLowerCase().replace(/[-_.]+/g, "-");
|
|
351
|
+
const reEsc = (n) => String(n).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
352
|
+
/** #5683: does manifest text `text` (package.json, pyproject.toml, a requirements file) declare `name` as a dependency? */
|
|
353
|
+
function manifestDeclares(base, text, name) {
|
|
354
|
+
if (base === "package.json") {
|
|
355
|
+
try { const j = JSON.parse(text); return ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].some((k) => j?.[k] && Object.hasOwn(j[k], name)); } catch { return false; }
|
|
356
|
+
}
|
|
357
|
+
const n = reEsc(normPy(name)).replace(/-/g, "[-_.]+");
|
|
358
|
+
if (base === "pyproject.toml") return new RegExp(`["']\\s*${n}(?:\\[[^\\]]*\\])?\\s*(?:[<>=!~;@ ,]|["'])|^\\s*${n}\\s*=`, "im").test(text);
|
|
359
|
+
return new RegExp(`^\\s*${n}(?:\\[[^\\]]*\\])?\\s*(?:[<>=!~;@#]|$)`, "im").test(text);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* #5683: the sub-project dir whose tracked manifest (package.json deps/devDeps/peerDeps, pyproject dependencies, a requirements
|
|
363
|
+
* file) declares `name`, or null. A declared test-plan env name that has an owner is a project dependency the lane prepares
|
|
364
|
+
* (deps.prepare), never a host tool or a lane_tools recipe. `files`: tracked paths; `readFile(path)`: manifest text. Pure.
|
|
365
|
+
*/
|
|
366
|
+
export function manifestDepOwner(name, files = [], readFile = () => "") {
|
|
367
|
+
for (const f of files) {
|
|
368
|
+
const parts = String(f).split("/"), base = parts[parts.length - 1];
|
|
369
|
+
if (parts.includes("node_modules") || !(base === "package.json" || base === "pyproject.toml" || /^requirements[\w.-]*\.txt$/.test(base))) continue;
|
|
370
|
+
let text = ""; try { text = String(readFile(f) ?? ""); } catch { continue; }
|
|
371
|
+
if (manifestDeclares(base.startsWith("requirements") ? "requirements.txt" : base, text, name)) return dirname(f);
|
|
372
|
+
}
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** nearest ancestor dir (of `dir`, up to the root ".") holding a tracked Python manifest, or null. */
|
|
377
|
+
function nearestPyProject(dir, files) {
|
|
378
|
+
const have = new Set(files.filter((f) => PY_MANIFESTS.has(String(f).split("/").pop()) || /(^|\/)requirements[\w.-]*\.txt$/.test(f)).map((f) => dirname(f)));
|
|
379
|
+
for (let d = dir; ; d = dirname(d)) { if (have.has(d)) return d; if (d === "." || d === "/") return null; }
|
|
380
|
+
}
|
|
381
|
+
const PYTEST_SEG = /^(\s*(?:[A-Za-z_]\w*=\S*\s+)*)(?:python3?(?:\.\d+)?\s+-m\s+pytest|pytest)\b/;
|
|
382
|
+
/**
|
|
383
|
+
* #5683: a bare `python -m pytest` / `pytest` in a sub-project that has a tracked Python manifest and an in-project `.venv`
|
|
384
|
+
* runs through that venv's interpreter. The sub-project is the `cd X &&` directory, else the nearest manifest of the first
|
|
385
|
+
* test path, else the root. `exists(rel)`: repo-relative path check. Unchanged when no manifest or venv applies. Pure.
|
|
386
|
+
*/
|
|
387
|
+
export function venvPythonRewrite(command, files = [], exists = () => false) {
|
|
388
|
+
const parts = String(command ?? "").split(/(&&|\|\||;|\||\n)/);
|
|
389
|
+
let cwd = ".", changed = false;
|
|
390
|
+
const out = parts.map((seg, i) => {
|
|
391
|
+
if (i % 2) return seg;
|
|
392
|
+
const cd = /^\s*cd\s+(?:"([^"]+)"|'([^']+)'|(\S+))\s*$/.exec(seg);
|
|
393
|
+
if (cd) { const t = (cd[1] ?? cd[2] ?? cd[3]).replace(/^\.\//, "").replace(/\/+$/, ""); cwd = t.startsWith("/") || t.startsWith("$") || t.startsWith("..") ? "?" : join(cwd === "?" ? "." : cwd, t) || "."; return seg; }
|
|
394
|
+
const m = PYTEST_SEG.exec(seg);
|
|
395
|
+
if (!m || cwd === "?") return seg;
|
|
396
|
+
const rest = seg.slice(m[0].length);
|
|
397
|
+
const tp = rest.split(/\s+/).map((x) => x.replace(/::.*$/, "").replace(/^\.\//, "")).find((x) => x && !x.startsWith("-") && /[\w-]\/|\.py$/.test(x) && !x.startsWith("/"));
|
|
398
|
+
const origin = cwd !== "." ? cwd : tp ? dirname(tp) : ".";
|
|
399
|
+
const proj = nearestPyProject(origin, files);
|
|
400
|
+
if (proj === null) return seg;
|
|
401
|
+
const venv = join(proj, ".venv/bin/python");
|
|
402
|
+
if (!exists(venv)) return seg;
|
|
403
|
+
const rel = cwd === "." ? venv : relative(cwd, venv);
|
|
404
|
+
changed = true;
|
|
405
|
+
return `${m[1]}${rel} -m pytest${rest}`;
|
|
406
|
+
});
|
|
407
|
+
return changed ? out.join("") : String(command ?? "");
|
|
408
|
+
}
|
|
@@ -4,7 +4,7 @@ import { describe, it } from "node:test";
|
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
|
-
import { testRunnerProblems, shellSegments, pythonImports, nodeImports, preflightProbes, preflightProblems, runProbeMiss, unsetEnvVars, runPreflight, knownToContract, contractCommands, depInstallFailures, testRunSummary, projectBinDirs, withLocalBins } from "./preflight.mjs";
|
|
7
|
+
import { manifestDepOwner, venvPythonRewrite, testRunnerProblems, shellSegments, pythonImports, nodeImports, preflightProbes, preflightProblems, runProbeMiss, unsetEnvVars, runPreflight, knownToContract, contractCommands, depInstallFailures, testRunSummary, projectBinDirs, withLocalBins } from "./preflight.mjs";
|
|
8
8
|
import { runCheckCommand } from "./effects.mjs";
|
|
9
9
|
import { repoTracks } from "./conformance.mjs";
|
|
10
10
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
@@ -146,6 +146,11 @@ describe("#5447 unrunnable tests: install classification and the Tests summary",
|
|
|
146
146
|
assert.deepEqual(depInstallFailures({ results, changedFiles: ["svc/a.py"] }).block, []);
|
|
147
147
|
assert.equal(depInstallFailures({ results, changedFiles: ["top.py"] }).block.length, 1);
|
|
148
148
|
});
|
|
149
|
+
it("#5651 a row coded env.tool_missing blocks without a changed-file match", () => {
|
|
150
|
+
const r = depInstallFailures({ results: [{ status: "failed", eco: "poetry", dir: ".", code: "env.tool_missing", reason: "no python satisfying the declared range" }], changedFiles: ["README.md"] });
|
|
151
|
+
assert.equal(r.block.length, 1);
|
|
152
|
+
assert.equal(r.block[0].code, "env.tool_missing");
|
|
153
|
+
});
|
|
149
154
|
it("testRunSummary counts declared, ran, red->green and skipped(reason)", () => {
|
|
150
155
|
const c = { validate: [{ id: "V1", command: "a" }, { id: "V2", command: "b" }], repro_test: { command: "c" } };
|
|
151
156
|
const t = testRunSummary({ contract: c, failures: [{ kind: "validate_env", detail: "validate V2 (`b`) could not run" }], repro: { base: "FAILED", head: "RAN" } });
|
|
@@ -161,6 +166,8 @@ describe("#5447 declaredEnv", () => {
|
|
|
161
166
|
assert.deepEqual(declaredEnv({}), []);
|
|
162
167
|
// #5590: fixtures and libraries are not executables
|
|
163
168
|
assert.deepEqual(declaredEnv({ test_plan: { env: ["pytest", "caplog", "FakeRedis", "tmp_path", "node", "psql"] } }), ["pytest", "node", "psql"]);
|
|
169
|
+
// a test file named in env is not a host tool (#5651 parked env.tool_missing on depcache.test.mjs)
|
|
170
|
+
assert.deepEqual(declaredEnv({ test_plan: [{ requirement: "R1", env: ["depcache.test.mjs", "conftest.py", "node", "python3.12"] }] }), ["node", "python3.12"]);
|
|
164
171
|
});
|
|
165
172
|
});
|
|
166
173
|
|
|
@@ -187,3 +194,32 @@ describe("project-local executables (#5592 3d/9)", () => {
|
|
|
187
194
|
assert.equal(withLocalBins("/a:/b", ["/c", "/a"]), "/a:/b:/c");
|
|
188
195
|
});
|
|
189
196
|
});
|
|
197
|
+
|
|
198
|
+
describe("#5683 sub-project manifest deps and venv python", () => {
|
|
199
|
+
const files = ["package.json", "web/package.json", "services/api/pyproject.toml", "shared/content/pyproject.toml", "tools/requirements-dev.txt"];
|
|
200
|
+
const texts = { "web/package.json": JSON.stringify({ devDependencies: { vitest: "^1", vite: "^5" } }), "services/api/pyproject.toml": 'dependencies = ["Fast_Api>=1", "httpx"]\n[dependency-groups]\ndev = ["pytest>=8"]', "tools/requirements-dev.txt": "# dev\nruff==0.4\nblack[jupyter]>=24\n" };
|
|
201
|
+
const read = (f) => texts[f] ?? "";
|
|
202
|
+
it("manifestDepOwner resolves vitest to web", () => {
|
|
203
|
+
assert.equal(manifestDepOwner("vitest", files, read), "web");
|
|
204
|
+
assert.equal(manifestDepOwner("vite", files, read), "web");
|
|
205
|
+
assert.equal(manifestDepOwner("pytest", files, read), "services/api");
|
|
206
|
+
assert.equal(manifestDepOwner("fast-api", files, read), "services/api");
|
|
207
|
+
assert.equal(manifestDepOwner("black", files, read), "tools");
|
|
208
|
+
});
|
|
209
|
+
it("manifestDepOwner null for host tools", () => {
|
|
210
|
+
for (const t of ["psql", "promtool", "ruf"]) assert.equal(manifestDepOwner(t, files, read), null);
|
|
211
|
+
assert.equal(manifestDepOwner("vitest", ["web/node_modules/x/package.json"], () => texts["web/package.json"]), null);
|
|
212
|
+
});
|
|
213
|
+
const exists = (p) => ["services/api/.venv/bin/python", "shared/content/.venv/bin/python"].includes(p);
|
|
214
|
+
it("venvPythonRewrite uses sub-project venv", () => {
|
|
215
|
+
assert.equal(venvPythonRewrite("pytest -q", ["pyproject.toml"], (p) => p === ".venv/bin/python"), ".venv/bin/python -m pytest -q");
|
|
216
|
+
assert.equal(venvPythonRewrite("python -m pytest tests/x.py", files, exists), "python -m pytest tests/x.py");
|
|
217
|
+
assert.equal(venvPythonRewrite("cd services/api && .venv/bin/python -m pytest t.py", files, exists), "cd services/api && .venv/bin/python -m pytest t.py");
|
|
218
|
+
assert.equal(venvPythonRewrite("cd services/api && python -m pytest t.py", files, () => false), "cd services/api && python -m pytest t.py");
|
|
219
|
+
});
|
|
220
|
+
it("venvPythonRewrite cd prefix and nearest manifest", () => {
|
|
221
|
+
assert.equal(venvPythonRewrite("cd services/api && python -m pytest tests/x.py -q", files, exists), "cd services/api && .venv/bin/python -m pytest tests/x.py -q");
|
|
222
|
+
assert.equal(venvPythonRewrite("python3 -m pytest shared/content/tests/t.py::a", files, exists), "shared/content/.venv/bin/python -m pytest shared/content/tests/t.py::a");
|
|
223
|
+
assert.equal(venvPythonRewrite("cd web && pytest", files, exists), "cd web && pytest");
|
|
224
|
+
});
|
|
225
|
+
});
|
package/bin/lean/prompts.mjs
CHANGED
|
@@ -176,6 +176,7 @@ ${HOST_RULES}${toolchainRule(toolchain)}${sparseRule(sparse)}${factsRule(facts)}
|
|
|
176
176
|
### Recommendation
|
|
177
177
|
### Related Issues
|
|
178
178
|
### Test plan (bug issues: per deliver requirement, see the contract test_plan)
|
|
179
|
+
${LEAN_DIR}/classification.json{type,severity,exists_in,flag,exists_in_evidence:{cite,repro:{command,red_on_live,green_after}}}
|
|
179
180
|
|
|
180
181
|
If the issue is already fixed or invalid, write ${RESULT_FILE} {"status":"already-fixed|invalid","summary":"one line","evidence":["file:line ..."]} and stop. A feature already reachable (another name, or a stdlib or wrapped dependency function) is a duplicate: INVALID, naming the equivalent and its path; its deprecation counts against an alias. If it is blocked, write {"status":"blocked","summary":"",...} with a typed "block" (rules below) and stop.
|
|
181
182
|
|
|
@@ -288,7 +289,7 @@ export function buildOpeningNote({ paths = [], tests = [], packFiles = [] } = {}
|
|
|
288
289
|
/** #4857: validate-command rules for the plan prompt (the implement session resumes it), kept out of the shared templates (their token caps are guarded). */
|
|
289
290
|
export function unrunnableValidateNote(testRunners = null) {
|
|
290
291
|
const map = testRunners && typeof testRunners === "object" ? Object.entries(testRunners).map(([k, v]) => `${k}/ -> ${v}`).join("; ") : "";
|
|
291
|
-
return `\n\nValidate and repro commands must pass bash -n (no prose notes), select tests that exist, and run from the right cwd (never combine \`poetry -C <dir>\` or \`uv run --project <dir>\` with repo-root-relative paths: use \`cd <dir> && poetry run pytest <dir-relative paths>\`)${map ? ` (forge.yaml verification.test_runners: ${map})` : ""}. An unrunnable validate (missing tool, wrong cwd, no tests selected) is never a block or "human" product-decision: run an equivalent through the repo's toolchain and record {"kind":"substitute-validate","validate":"V#","command":"<runnable equivalent>","why":""} in ${RESULT_FILE} amendments. A post-deploy requirement needs a registered check id; one that is a manual or production-credential action with no runnable check is disposition "defer" with bucket "owner:<action>" only when it needs credentials, spend, an account, a third party or a customer; read-only prod data is "host". forge.yaml validate.recipes rewrite matching commands at freeze.`;
|
|
292
|
+
return `\n\nValidate and repro commands must pass bash -n (no prose notes), select tests that exist, and run from the right cwd (never combine \`poetry -C <dir>\` or \`uv run --project <dir>\` with repo-root-relative paths: use \`cd <dir> && poetry run pytest <dir-relative paths>\`)${map ? ` (forge.yaml verification.test_runners: ${map})` : ""}. An unrunnable validate (missing tool, wrong cwd, no tests selected) is never a block or "human" product-decision: run an equivalent through the repo's toolchain and record {"kind":"substitute-validate","validate":"V#","command":"<runnable equivalent>","why":""} in ${RESULT_FILE} amendments. A post-deploy requirement needs a registered check id; one that is a manual or production-credential action with no runnable check is disposition "defer" with bucket "owner:<action>" only when it needs credentials, spend, an account, a third party or a customer; read-only prod data is "host". forge.yaml validate.recipes rewrite matching commands at freeze, and the engine rewrites an unrunnable command from the repo's CI-derived command catalogue: prefer the repo's own CI test commands over free-form paths. A substitute that runs the same test ids with the same result is recorded, not failed. A criterion only time or production can show (a 14-day metric, a corpus re-run, a published scorecard) is post-deploy or defer with a bucket: never narrow it into something the lane can observe.`;
|
|
292
293
|
}
|
|
293
294
|
|
|
294
295
|
/** #5419: the R-docs rule for the planner; "" when forge.yaml docs.required_for is unset. */
|
|
@@ -106,16 +106,16 @@ describe("in-batch recovery of mechanical needs-human (#4267)", () => {
|
|
|
106
106
|
assert.ok(formatOutcomeLists(rows).some((l) => /^unrecovered: #1 \(budget\.exceeded: Implement turn budget spent/.test(l)));
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
-
it("conformance gaps are recoverable: one recovery lane each,
|
|
110
|
-
const codes = ["conformance.unimplemented", "conformance.omission", "conformance.unjustified_deferral"];
|
|
109
|
+
it("conformance gaps are recoverable: one recovery lane each, guard_broken/e2e_unverified stay terminal, notes name the defer route", async () => {
|
|
110
|
+
const codes = ["conformance.unimplemented", "conformance.omission", "conformance.unjustified_deferral", "conformance.regression", "conformance.scope_creep"];
|
|
111
111
|
for (const c of codes) {
|
|
112
112
|
assert.equal(classifyNeedsHuman({ outcome: "needs-human", code: c }), "recoverable", c);
|
|
113
113
|
assert.ok(RECOVERABLE_CODES.includes(c) && RECOVER_HOW[c], c);
|
|
114
114
|
}
|
|
115
|
-
for (const c of ["conformance.
|
|
115
|
+
for (const c of ["conformance.guard_broken", "conformance.e2e_unverified"]) {
|
|
116
116
|
assert.equal(classifyNeedsHuman({ outcome: "needs-human", code: c }), "terminal", c);
|
|
117
117
|
}
|
|
118
|
-
for (const c of codes.slice(1)) assert.match(RECOVER_HOW[c], /`defer`[\s\S]*why|why[\s\S]*follow-up/i);
|
|
118
|
+
for (const c of codes.slice(1, 3)) assert.match(RECOVER_HOW[c], /`defer`[\s\S]*why|why[\s\S]*follow-up/i);
|
|
119
119
|
assert.match(RECOVER_HOW["conformance.omission"], /add-requirement/);
|
|
120
120
|
const { rows, calls } = await batch({ 1: [NH("conformance.omission", "R2 not covered", { branch: "feat/issue-1-lean" }), NH("conformance.omission", "again")] });
|
|
121
121
|
assert.deepEqual(calls.filter((c) => c.n === 1).map((c) => c.recover?.code ?? null), [null, "conformance.omission"]);
|
|
@@ -128,7 +128,7 @@ describe("in-batch recovery of mechanical needs-human (#4267)", () => {
|
|
|
128
128
|
1: [NH("builder.blocked", "Builder is blocked (product-decision): pick a pricing model")],
|
|
129
129
|
2: [],
|
|
130
130
|
3: [NH("builder.blocked", "Builder is blocked (spend): needs a paid plan")],
|
|
131
|
-
4: [NH("conformance.
|
|
131
|
+
4: [NH("conformance.guard_broken", "R2 broke")],
|
|
132
132
|
5: [{ terminalReason: "merged" }] }, { 2: "**Depends on**: #1" });
|
|
133
133
|
const r = byIssue(rows);
|
|
134
134
|
assert.equal(calls.filter((c) => c.n === 1).length, 1); assert.equal(calls.filter((c) => c.n === 3).length, 1);
|
|
@@ -141,7 +141,7 @@ describe("in-batch recovery of mechanical needs-human (#4267)", () => {
|
|
|
141
141
|
assert.match(esc, /#1 \(builder\.blocked\): Builder is blocked \(product-decision\)/);
|
|
142
142
|
assert.match(esc, /#3 \(builder\.blocked\): Builder is blocked \(spend\)/);
|
|
143
143
|
assert.doesNotMatch(esc, /#4/, "the needs-human list holds only human codes");
|
|
144
|
-
assert.ok(lines.some((l) => /^unrecovered: #4 \(conformance\.
|
|
144
|
+
assert.ok(lines.some((l) => /^unrecovered: #4 \(conformance\.guard_broken: R2 broke\)$/.test(l)));
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
it("base.conflict: a recovery base-sync with a clean result re-queues the issue; the report lists recovered issues separately", async () => {
|
|
@@ -167,6 +167,11 @@ describe("in-batch recovery of mechanical needs-human (#4267)", () => {
|
|
|
167
167
|
assert.equal(byIssue(rows)[2].recovered, "contract.invalid"); assert.equal(byIssue(rows)[2].outcome, "merged"); assert.equal(calls.filter((c) => c.n === 2).length, 2);
|
|
168
168
|
});
|
|
169
169
|
|
|
170
|
+
it("#5644: conformance.regression gets one recovery lane", async () => {
|
|
171
|
+
const { rows, calls } = await batch({ 1: [NH("conformance.regression"), { terminalReason: "merged" }] });
|
|
172
|
+
assert.equal(byIssue(rows)[1].recovered, "conformance.regression"); assert.equal(byIssue(rows)[1].outcome, "merged"); assert.equal(calls.filter((c) => c.n === 1).length, 2);
|
|
173
|
+
});
|
|
174
|
+
|
|
170
175
|
it("relabelNeedsHuman (SPEC-7/8): only a recovery that ends final engine-error/deferred relabels; invalid/merged never; a requeued deferred waits", async () => {
|
|
171
176
|
const relabels = [];
|
|
172
177
|
const rl = { relabelNeedsHuman: async (x) => { relabels.push(x); }, pollMs: 5 };
|