forgedock 1.56.0 → 1.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/config-schema.mjs +1 -1
- package/bin/engine/outcome-codes.mjs +2 -1
- package/bin/engine/phases.mjs +4 -3
- package/bin/engine-cli.mjs +48 -12
- package/bin/forgedock.mjs +52 -3
- package/bin/gc.mjs +43 -6
- package/bin/help-text.mjs +4 -2
- package/bin/lean/batch-health.mjs +5 -1
- package/bin/lean/batch-health.test.mjs +7 -1
- package/bin/lean/batch.mjs +7 -2
- package/bin/lean/batch.test.mjs +45 -0
- package/bin/lean/conformance.e2e.test.mjs +3 -2
- package/bin/lean/conformance.mjs +118 -20
- package/bin/lean/conformance.test.mjs +172 -3
- package/bin/lean/decisions.mjs +98 -1
- package/bin/lean/decisions.test.mjs +30 -1
- package/bin/lean/depcache.mjs +124 -13
- package/bin/lean/depcache.test.mjs +121 -3
- package/bin/lean/design-gate.mjs +144 -0
- package/bin/lean/design-gate.test.mjs +169 -0
- package/bin/lean/effects-cap.test.mjs +17 -0
- package/bin/lean/effects.mjs +58 -13
- package/bin/lean/heavy.mjs +25 -8
- package/bin/lean/hostload.test.mjs +28 -0
- package/bin/lean/intake.mjs +97 -0
- package/bin/lean/intake.test.mjs +105 -0
- package/bin/lean/interfaces.mjs +181 -0
- package/bin/lean/interfaces.test.mjs +192 -0
- package/bin/lean/issuewatch-install.mjs +52 -12
- package/bin/lean/issuewatch-install.test.mjs +50 -0
- package/bin/lean/issuewatch-parity.mjs +16 -3
- package/bin/lean/issuewatch-parity.test.mjs +32 -0
- package/bin/lean/issuewatch-reconcile.mjs +29 -1
- package/bin/lean/issuewatch-reconcile.test.mjs +21 -0
- package/bin/lean/issuewatch.mjs +34 -3
- package/bin/lean/issuewatch.test.mjs +49 -1
- package/bin/lean/lanecheck.test.mjs +15 -4
- package/bin/lean/lean.mjs +110 -24
- package/bin/lean/lean.test.mjs +183 -4
- package/bin/lean/orchestrate-blocked.test.mjs +18 -2
- package/bin/lean/orchestrate-owned.test.mjs +14 -5
- package/bin/lean/orchestrate.mjs +26 -4
- package/bin/lean/orphan-pr.mjs +3 -2
- package/bin/lean/orphan-pr.test.mjs +8 -1
- package/bin/lean/pagegate.mjs +35 -12
- package/bin/lean/pagegate.test.mjs +39 -1
- package/bin/lean/preflight.mjs +35 -1
- package/bin/lean/preflight.test.mjs +27 -1
- package/bin/lean/prompts.mjs +2 -1
- package/bin/lean/reap.test.mjs +39 -0
- package/bin/lean/recovery.test.mjs +28 -3
- package/bin/lean/release-config.mjs +169 -0
- package/bin/lean/release-config.test.mjs +132 -0
- package/bin/lean/release-control.mjs +171 -0
- package/bin/lean/release-control.test.mjs +167 -0
- package/bin/lean/release-deploy.mjs +209 -0
- package/bin/lean/release-deploy.test.mjs +217 -0
- package/bin/lean/release-fence.mjs +50 -0
- package/bin/lean/release-fence.test.mjs +105 -0
- package/bin/lean/release-flakes.mjs +139 -0
- package/bin/lean/release-flakes.test.mjs +116 -0
- package/bin/lean/release-gates.mjs +230 -0
- package/bin/lean/release-gates.test.mjs +146 -0
- package/bin/lean/release-ledger.mjs +176 -0
- package/bin/lean/release-ledger.test.mjs +226 -0
- package/bin/lean/release-minutes.mjs +102 -0
- package/bin/lean/release-minutes.test.mjs +107 -0
- package/bin/lean/release-nightly.mjs +75 -0
- package/bin/lean/release-nightly.test.mjs +48 -0
- package/bin/lean/release-postmerge.mjs +8 -2
- package/bin/lean/release-review.e2e.test.mjs +1 -0
- package/bin/lean/release-review.mjs +54 -7
- package/bin/lean/release-review.test.mjs +76 -7
- package/bin/lean/release-status.mjs +300 -0
- package/bin/lean/release-status.test.mjs +220 -0
- package/bin/lean/release-unitmap.mjs +35 -0
- package/bin/lean/release-unitmap.test.mjs +41 -0
- package/bin/lean/release-verify.mjs +221 -0
- package/bin/lean/release-verify.test.mjs +176 -0
- package/bin/lean/release.mjs +244 -22
- package/bin/lean/release.test.mjs +44 -0
- package/bin/lean/render.mjs +3 -1
- package/bin/lean/run-issue-placement.test.mjs +82 -0
- package/bin/lean/sandbox-remote.mjs +16 -0
- package/bin/lean/schedd.mjs +1 -1
- package/bin/lean/seam.mjs +115 -0
- package/bin/lean/seam.test.mjs +118 -0
- package/bin/lean/selftest-journey.mjs +40 -2
- package/bin/lean/selftest-journey.test.mjs +43 -3
- package/bin/lean/statuscomment.mjs +168 -0
- package/bin/lean/statuscomment.test.mjs +133 -0
- package/bin/lean/ui-quality.mjs +57 -0
- package/bin/lean/ui-quality.test.mjs +55 -0
- package/bin/lean/visual-gate.test.mjs +63 -0
- package/bin/pool/agent.mjs +16 -2
- package/bin/pool/router.mjs +5 -1
- package/bin/review-staging.mjs +5 -3
- package/bin/stats/card.mjs +117 -0
- package/bin/stats/card.test.mjs +109 -0
- package/bin/stats/conformance-outcomes.test.mjs +2 -1
- package/bin/stats/depth.mjs +1 -1
- package/bin/stats/gh-retry.test.mjs +152 -0
- package/bin/stats/github-source.mjs +147 -14
- package/bin/stats/index.mjs +35 -2
- package/bin/stats/stats.test.mjs +31 -3
- package/bin/vendor/js-yaml/LICENSE +21 -0
- package/bin/vendor/js-yaml/PIN.md +7 -0
- package/bin/vendor/js-yaml/js-yaml.mjs +3851 -0
- package/commands/design-render-critique-loop.md +2 -0
- package/commands/design.md +2 -0
- package/commands/issue.md +1 -1
- package/commands/milestone.md +1 -1
- package/commands/review-pr-agents/frontend.md +1 -0
- package/commands/review-pr-staging.md +5 -0
- package/docs/CONFIG.md +95 -2
- package/docs/ISSUE-WATCH.md +7 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/STATS.md +10 -0
- package/docs/design/visual-gate.md +25 -0
- package/docs/eval/adversarial-bench.md +2 -2
- package/docs/eval/corpus/adversarial-v1.json +3 -3
- package/docs/site/start-a-new-project.md +7 -0
- package/docs/spec/forge-protocol-v1.md +31 -0
- package/package.json +1 -1
- package/pool/README.md +2 -0
- package/scripts/acceptance-red-green.sh +15 -1
- package/scripts/acceptance-red-green.test.sh +12 -0
- package/scripts/bench-adversarial.mjs +4 -0
- package/scripts/bench-lightlane.mjs +4 -1
- package/scripts/bootstrap-create.mjs +8 -2
- package/scripts/ci-local/scoping.mjs +19 -0
- package/scripts/ci-local.test.sh +16 -3
- package/scripts/fixtures/ci-local/gha-dorny/.github/workflows/ci.yml +4 -0
- package/scripts/plan-validate-live.mjs +9 -6
- package/scripts/review-prepare.sh +7 -1
- package/scripts/review-roster.sh +5 -2
- package/scripts/review-roster.test.sh +9 -0
- package/scripts/visual-gate.mjs +64 -0
- package/templates/bootstrap/technical-spike.md +17 -0
- package/templates/contracts/seam-check.mjs +236 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Design gate (#5330). Opt-in per repo through forge.yaml `design:`; a repo without `design.routes` is never gated.
|
|
5
|
+
* - routing (lane time): a predicted page entry (page.tsx|jsx, .vue, .svelte) under `design.routes` is routed to /design, or the
|
|
6
|
+
* lane is blocked pending a FORGE:DESIGN_SPEC (or the `spec_label` label) with `design.gate: blocking`, never built from a
|
|
7
|
+
* functional spec alone (designGate, designGateNote, specApproved);
|
|
8
|
+
* - visual gate (one gate, two call sites): visualGate() judges every new or changed user-visible route. The lane precheck calls it
|
|
9
|
+
* through designFailures() (spec + deterministic source critique); review-pr-staging calls it through scripts/visual-gate.mjs
|
|
10
|
+
* (#5369) with the rendered screenshots and the design-render-critique-loop verdict as evidence;
|
|
11
|
+
* - critiqueMarkup(): the deterministic floor of the render critique (empty boxes, placeholder text, a text-only hero), 0 LLM calls.
|
|
12
|
+
* Keys: system, routes, exclude, gate (blocking|advisory), spec_label, needed_label, directions_param, viewports,
|
|
13
|
+
* require_visual_check. Pure: no I/O, no model calls.
|
|
14
|
+
*/
|
|
15
|
+
import { OUTCOME_CODES } from "../engine/outcome-codes.mjs";
|
|
16
|
+
import { globToRegex } from "../../scripts/ci-local/lib.mjs";
|
|
17
|
+
import { designSpecApproved, pageRouteOf } from "./pagegate.mjs";
|
|
18
|
+
|
|
19
|
+
export const DEFAULT_VIEWPORTS = Object.freeze([390, 1440]);
|
|
20
|
+
const PAGE_ENTRY_RE = /(?:^|\/)page\.[cm]?[jt]sx?$|\.(?:vue|svelte)$/i;
|
|
21
|
+
const LAYOUT_RE = /(?:^|\/)layout\.[cm]?[jt]sx?$/i;
|
|
22
|
+
const TEST_RE = /(?:^|\/)(?:__tests__|tests?|e2e)\/|\.(?:test|spec|stories)\.[cm]?[jt]sx?$/i;
|
|
23
|
+
const norm = (p) => String(p ?? "").trim().replace(/^\.\//, "");
|
|
24
|
+
const list = (v) => (Array.isArray(v) ? v : typeof v === "string" ? v.replace(/^\s*\[|\]\s*$/g, "").split(",") : v == null ? [] : [v]).map((x) => String(x).trim().replace(/^(["'])(.*)\1$/, "$2")).filter(Boolean);
|
|
25
|
+
const truthy = (v, d) => (v === undefined || v === null || v === "" ? d : v === true || /^(?:true|yes|on|1)$/i.test(String(v).trim()));
|
|
26
|
+
const str = (v, d) => (typeof v === "string" && v.trim() ? v.trim() : d);
|
|
27
|
+
|
|
28
|
+
/** forge.yaml design block -> config, or null when there is no block. `routes: []` means the gate is off (system still read). */
|
|
29
|
+
export function parseDesignConfig(raw) {
|
|
30
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
31
|
+
const vp = list(raw.viewports).map(Number).filter((n) => Number.isInteger(n) && n > 0);
|
|
32
|
+
return {
|
|
33
|
+
system: list(raw.system), routes: list(raw.routes).map(norm), exclude: list(raw.exclude).map(norm),
|
|
34
|
+
gate: String(raw.gate ?? "").trim().toLowerCase() === "blocking" ? "blocking" : "advisory",
|
|
35
|
+
specLabel: str(raw.spec_label, "design:approved"), neededLabel: str(raw.needed_label, "design:needed"), directionsParam: str(raw.directions_param, null),
|
|
36
|
+
viewports: vp.length ? [...new Set(vp)] : [...DEFAULT_VIEWPORTS], requireVisual: truthy(raw.require_visual_check, true),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** The gate is on only when design.routes names at least one glob. */
|
|
40
|
+
export const designOn = (cfg) => Boolean(cfg && Array.isArray(cfg.routes) && cfg.routes.length);
|
|
41
|
+
|
|
42
|
+
const anyGlob = (globs, f) => globs.some((g) => globToRegex(g).test(f));
|
|
43
|
+
/** Non-test files under design.routes and outside design.exclude: every user-visible route file (pages and layouts). */
|
|
44
|
+
export function designFiles(files = [], cfg = null) {
|
|
45
|
+
if (!designOn(cfg)) return [];
|
|
46
|
+
return [...new Set((Array.isArray(files) ? files : []).map(norm).filter((f) => f && !TEST_RE.test(f) && anyGlob(cfg.routes, f) && !anyGlob(cfg.exclude ?? [], f)))];
|
|
47
|
+
}
|
|
48
|
+
/** Page entry points among designFiles (what routing keys on). */
|
|
49
|
+
export const designPages = (files, cfg) => designFiles(files, cfg).filter((f) => PAGE_ENTRY_RE.test(f));
|
|
50
|
+
/** URL path a route file serves (Next app router), else its directory. */
|
|
51
|
+
export function routeOf(file) {
|
|
52
|
+
const f = norm(file);
|
|
53
|
+
return pageRouteOf(f) ?? pageRouteOf(f.replace(LAYOUT_RE, (m) => m.replace(/layout/, "page"))) ?? `/${f.replace(/\.[^.]+$/, "")}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** True when an issue comment carries a non-draft FORGE:DESIGN_SPEC, or the issue has the design.spec_label label. */
|
|
57
|
+
export function specApproved({ comments = [], labels = [], cfg = null } = {}) {
|
|
58
|
+
const label = cfg?.specLabel ?? "design:approved";
|
|
59
|
+
return designSpecApproved(comments) || (labels ?? []).some((l) => (typeof l === "string" ? l : l?.name) === label);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Lane-time routing: { route, blocked, pages, reason }. route when a predicted page matches design.routes and has no spec; blocked only with gate: blocking. */
|
|
63
|
+
export function designGate({ files = [], cfg = null, comments = [], labels = [] } = {}) {
|
|
64
|
+
const pages = designPages(files, cfg);
|
|
65
|
+
if (!pages.length || specApproved({ comments, labels, cfg })) return { route: false, blocked: false, pages, reason: "" };
|
|
66
|
+
return { route: true, blocked: cfg.gate === "blocking", pages, reason: `page ${pages.slice(0, 3).join(", ")} is under design.routes and the issue has no FORGE:DESIGN_SPEC (label ${cfg.specLabel}); route it to /design before building` };
|
|
67
|
+
}
|
|
68
|
+
/** Builder prompt note for a routed lane; "" otherwise. */
|
|
69
|
+
export const designGateNote = (g) => (g?.route ? `\n\nDesign gate: ${g.reason}. Do not build a user-visible page straight from a functional spec; ${g.blocked ? "stop with a block asking for /design (design.gate: blocking)" : "reference a /design spec in the contract and in implementation.md's Visual Check"}.` : "");
|
|
70
|
+
|
|
71
|
+
// ---- deterministic render-critique floor ----
|
|
72
|
+
const BOX = /\b(?:rounded|shadow|card|panel|tile)\b|\bborder\b(?!-[tblrxy]\b)|\brounded-/i;
|
|
73
|
+
const BOX_TAGS = "div|section|article|aside|li|Card|CardContent|Box|Panel|Tile";
|
|
74
|
+
const PLACEHOLDER = /lorem ipsum|\bTBD\b|\bTODO\b|coming soon|placeholder (?:text|content|image)|\[\[null\]\]|\bundefined\b\s*<|>\s*null\s*</i;
|
|
75
|
+
const GENERIC_CTA = /^(?:get access|learn more|click here|read more|sign up|submit|more|go)$/i;
|
|
76
|
+
const VISUAL = /<(?:img|svg|video|picture|canvas|iframe|Image|Lottie)\b|bg-(?:gradient|\[url)|background(?:Image)?\s*[:=]|<(?!Link\b|Fragment\b|Suspense\b|Head\b|Script\b)[A-Z][A-Za-z0-9.]*/;
|
|
77
|
+
|
|
78
|
+
/** Findings [{id, severity: "block"|"warn", detail}] for one page's markup/JSX source. Heuristic floor; the rendered critique is the vision judge. */
|
|
79
|
+
export function critiqueMarkup(src) {
|
|
80
|
+
// Comments are stripped for analysis only (never emitted); repeat until stable so nested/overlapping markers leave nothing behind.
|
|
81
|
+
let code = String(src ?? ""), prev;
|
|
82
|
+
do { prev = code; code = code.replace(/\{\/\*[\s\S]*?\*\/\}|<!--[\s\S]*?-->/g, ""); } while (code !== prev);
|
|
83
|
+
const out = [];
|
|
84
|
+
let empties = 0;
|
|
85
|
+
for (const m of code.matchAll(new RegExp(`<(${BOX_TAGS})\\b([^>]*?)(?:/>|>\\s*</\\1\\s*>)`, "g"))) {
|
|
86
|
+
if (BOX.test(m[2]) && !/aria-hidden|animate-|skeleton|role=["']presentation/i.test(m[2])) empties++;
|
|
87
|
+
}
|
|
88
|
+
for (const m of code.matchAll(new RegExp(`<(${BOX_TAGS})\\b([^>]*)>\\s*<(?:h[2-6]|CardTitle|strong|dt)\\b[^>]*>[^<{]{1,60}</(?:h[2-6]|CardTitle|strong|dt)>\\s*</\\1\\s*>`, "g"))) {
|
|
89
|
+
if (/\bp[xy]?-\d|card|panel/i.test(m[2])) empties++;
|
|
90
|
+
}
|
|
91
|
+
if (empties) out.push({ id: "empty_box", severity: "block", detail: `${empties} box(es) with no content or only a label (empty cards/panels)` });
|
|
92
|
+
if (PLACEHOLDER.test(code)) out.push({ id: "placeholder_text", severity: "block", detail: "placeholder copy or a null/undefined sample is rendered" });
|
|
93
|
+
if (/<h1\b/.test(code) && !VISUAL.test(code)) out.push({ id: "plain_text_hero", severity: "block", detail: "the page is text only: an h1 and prose with no component, media, icon or background" });
|
|
94
|
+
const anchors = [...code.matchAll(/<a\b[^>]*>([^<{]{1,40})<\/a>/gi)].map((m) => m[1].trim());
|
|
95
|
+
if (anchors.length && anchors.every((t) => GENERIC_CTA.test(t)) && !/<(?:button|Button)\b/.test(code)) out.push({ id: "bare_cta", severity: "warn", detail: `the only calls to action are bare links (${[...new Set(anchors)].join(", ")})` });
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const hasShot = (shots, vp) => (shots ?? []).some((s) => new RegExp(`(?:^|[^0-9])${vp}(?:[^0-9]|$)`).test(String(s)));
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The visual gate over the user-visible route files in `files`.
|
|
103
|
+
* `specs`: boolean | { [route]: boolean }; `sources`: { [file]: source text } for the deterministic critique;
|
|
104
|
+
* `evidence`: { [route]: { screenshots: [paths], verdict: "PASS"|"ITERATE"|"BUDGET-EXHAUSTED" } } from the render critique, consulted only with `rendered: true`.
|
|
105
|
+
* -> { gate, verdict: "SKIP"|"PASS"|"ADVISORY"|"FAIL", routes, rows: [{kind, route, detail}] }. Rows are failures when gate is blocking, warnings otherwise.
|
|
106
|
+
*/
|
|
107
|
+
export function visualGate({ cfg = null, files = [], specs = false, sources = {}, evidence = {}, rendered = false } = {}) {
|
|
108
|
+
if (!designOn(cfg)) return { gate: null, verdict: "SKIP", routes: [], rows: [], reason: "design.routes is unset" };
|
|
109
|
+
const routeFiles = designFiles(files, cfg);
|
|
110
|
+
const routes = routeFiles.map((file) => ({ file, route: routeOf(file), page: PAGE_ENTRY_RE.test(file) }));
|
|
111
|
+
const rows = [], add = (kind, route, detail) => rows.push({ kind, route, detail });
|
|
112
|
+
for (const r of routes) {
|
|
113
|
+
const spec = typeof specs === "object" && specs !== null ? Boolean(specs[r.route] ?? specs[r.file]) : Boolean(specs);
|
|
114
|
+
if (r.page && !spec) add("design_spec_missing", r.route, `${r.file} has no approved FORGE:DESIGN_SPEC (label ${cfg.specLabel}): run /design first`);
|
|
115
|
+
if (r.page && sources[r.file] != null) {
|
|
116
|
+
for (const f of critiqueMarkup(sources[r.file])) if (f.severity === "block") add("visual_critique_failed", r.route, `${r.file}: ${f.id}: ${f.detail}`);
|
|
117
|
+
}
|
|
118
|
+
if (rendered && cfg.requireVisual) {
|
|
119
|
+
const ev = evidence[r.route] ?? evidence[r.file];
|
|
120
|
+
const missing = cfg.viewports.filter((vp) => !hasShot(ev?.screenshots, vp));
|
|
121
|
+
if (missing.length) add("visual_screenshots_missing", r.route, `${r.route}: no screenshot at ${missing.join(", ")}px`);
|
|
122
|
+
const v = String(ev?.verdict ?? "").trim().toUpperCase();
|
|
123
|
+
if (!v) add("visual_critique_missing", r.route, `${r.route}: no design-render-critique-loop verdict`);
|
|
124
|
+
else if (v !== "PASS") add("visual_critique_failed", r.route, `${r.route}: render critique verdict ${v}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const verdict = !rows.length ? "PASS" : cfg.gate === "blocking" ? "FAIL" : "ADVISORY";
|
|
128
|
+
return { gate: cfg.gate, verdict, routes, rows, viewports: cfg.viewports };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Lane precheck rows (conformance.unimplemented) for the diff's user-visible routes; [] unless design.routes is set and gate is blocking. */
|
|
132
|
+
export function designFailures({ cfg = null, files = [], specs = false, readFile = () => "" } = {}) {
|
|
133
|
+
if (!designOn(cfg) || cfg.gate !== "blocking") return [];
|
|
134
|
+
const sources = {};
|
|
135
|
+
for (const f of designPages(files, cfg)) sources[f] = String(readFile(f) ?? "");
|
|
136
|
+
return visualGate({ cfg, files, specs, sources }).rows.map((r) => ({ code: OUTCOME_CODES.CONFORMANCE_UNIMPLEMENTED, kind: r.kind, detail: r.detail }));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Markdown for the FORGE:VISUAL_GATE comment (review-pr-staging). Rendered screenshots are listed by path. */
|
|
140
|
+
export function visualGateComment(g, evidence = {}) {
|
|
141
|
+
const rows = (g.routes ?? []).map((r) => `| \`${r.route}\` | \`${r.file}\` | ${(evidence[r.route]?.screenshots ?? []).map((s) => `\`${s}\``).join(", ") || "none"} | ${String(evidence[r.route]?.verdict ?? "n/a")} |`);
|
|
142
|
+
const probs = (g.rows ?? []).map((r) => `- ${r.kind}: ${r.detail}`);
|
|
143
|
+
return `<!-- FORGE:VISUAL_GATE -->\n## Visual gate: ${g.verdict} (design.gate: ${g.gate ?? "off"})\n\n| Route | File | Screenshots | Critique |\n| --- | --- | --- | --- |\n${rows.join("\n") || "| none | | | |"}\n${probs.length ? `\n${g.gate === "blocking" ? "Blocking" : "Advisory"} findings:\n${probs.join("\n")}\n` : ""}`;
|
|
144
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
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 { parseDesignConfig, designOn, designFiles, designPages, routeOf, specApproved, designGate, designGateNote, critiqueMarkup, visualGate, designFailures, visualGateComment } from "./design-gate.mjs";
|
|
6
|
+
import { precheck } from "./conformance.mjs";
|
|
7
|
+
import { parseForgeYaml } from "../forge-utils.mjs";
|
|
8
|
+
|
|
9
|
+
// The AlterLab block as filed on #5330 (2026-11-10): these exact keys are consumed.
|
|
10
|
+
const YAML = `design:
|
|
11
|
+
gate: blocking
|
|
12
|
+
routes: ["web/src/app/(site)/**/page.tsx", "web/src/app/(site)/**/layout.tsx"]
|
|
13
|
+
exclude: ["web/src/app/(site)/api/**"]
|
|
14
|
+
system: [web/src/components/marketing/home, web/src/components/dashboard, web/src/components/ui]
|
|
15
|
+
spec_label: design:approved
|
|
16
|
+
needed_label: design:needed
|
|
17
|
+
directions_param: dir
|
|
18
|
+
viewports: [390, 1440]
|
|
19
|
+
require_visual_check: true
|
|
20
|
+
`;
|
|
21
|
+
const cfg = parseDesignConfig(parseForgeYaml(YAML).design);
|
|
22
|
+
|
|
23
|
+
/** The regression fixture: Hands 2026-11-09, a plain-text hero, empty Needs/Evidence/Action boxes, a bare "Get access" link. */
|
|
24
|
+
const HANDS_BAD = `export default function Page() {
|
|
25
|
+
return (
|
|
26
|
+
<main>
|
|
27
|
+
<h1>AlterLab Hands</h1>
|
|
28
|
+
<p>Delegate any task to a person.</p>
|
|
29
|
+
<div className="rounded border p-4"><h3>Needs</h3></div>
|
|
30
|
+
<div className="rounded border p-4"></div>
|
|
31
|
+
<div className="rounded border p-4" />
|
|
32
|
+
<a href="/signup">Get access</a>
|
|
33
|
+
</main>
|
|
34
|
+
);
|
|
35
|
+
}`;
|
|
36
|
+
const HANDS_GOOD = `import { Hero } from "@/components/marketing/home/Hero";
|
|
37
|
+
import { NeedCard } from "@/components/marketing/home/NeedCard";
|
|
38
|
+
export default function Page() {
|
|
39
|
+
return (
|
|
40
|
+
<main>
|
|
41
|
+
<Hero title="AlterLab Hands" />
|
|
42
|
+
<section className="grid">
|
|
43
|
+
<NeedCard title="Needs" body="A named task with an owner." />
|
|
44
|
+
<div className="rounded border p-4"><h3>Evidence</h3><p>Receipts and photos.</p></div>
|
|
45
|
+
</section>
|
|
46
|
+
<Button asChild><a href="/signup">Get access</a></Button>
|
|
47
|
+
</main>
|
|
48
|
+
);
|
|
49
|
+
}`;
|
|
50
|
+
|
|
51
|
+
describe("design config (#5330 R15)", () => {
|
|
52
|
+
it("parses the AlterLab keys exactly", () => {
|
|
53
|
+
assert.equal(cfg.gate, "blocking");
|
|
54
|
+
assert.deepEqual(cfg.routes, ["web/src/app/(site)/**/page.tsx", "web/src/app/(site)/**/layout.tsx"]);
|
|
55
|
+
assert.deepEqual(cfg.exclude, ["web/src/app/(site)/api/**"]);
|
|
56
|
+
assert.equal(cfg.system.length, 3);
|
|
57
|
+
assert.equal(cfg.specLabel, "design:approved"); assert.equal(cfg.neededLabel, "design:needed"); assert.equal(cfg.directionsParam, "dir");
|
|
58
|
+
assert.deepEqual(cfg.viewports, [390, 1440]); assert.equal(cfg.requireVisual, true);
|
|
59
|
+
assert.ok(designOn(cfg));
|
|
60
|
+
});
|
|
61
|
+
it("defaults: advisory, 390/1440, label design:approved, rendered check required", () => {
|
|
62
|
+
const c = parseDesignConfig({ routes: ["web/app/**"], gate: "bogus" });
|
|
63
|
+
assert.deepEqual([c.gate, c.viewports, c.specLabel, c.requireVisual], ["advisory", [390, 1440], "design:approved", true]);
|
|
64
|
+
assert.equal(parseDesignConfig({ routes: "web/app/**, other/**", require_visual_check: "false" }).requireVisual, false);
|
|
65
|
+
});
|
|
66
|
+
it("opt-in: no design block or no design.routes means the gate is off and nothing is routed", () => {
|
|
67
|
+
for (const c of [null, undefined, parseDesignConfig(undefined), parseDesignConfig({ system: ["docs/ds.md"] }), parseDesignConfig({ gate: "blocking" })]) {
|
|
68
|
+
assert.equal(designOn(c), false);
|
|
69
|
+
assert.deepEqual(designGate({ files: ["web/app/x/page.tsx"], cfg: c }), { route: false, blocked: false, pages: [], reason: "" });
|
|
70
|
+
assert.equal(designGateNote(designGate({ files: ["web/app/x/page.tsx"], cfg: c })), "");
|
|
71
|
+
assert.deepEqual(designFailures({ cfg: c, files: ["web/app/x/page.tsx"], readFile: () => HANDS_BAD }), []);
|
|
72
|
+
assert.equal(visualGate({ cfg: c, files: ["web/app/x/page.tsx"] }).verdict, "SKIP");
|
|
73
|
+
}
|
|
74
|
+
assert.deepEqual(parseDesignConfig({ system: ["docs/ds.md"] }).system, ["docs/ds.md"]); // system is still read for UI lanes
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("design routing (#5330 R11)", () => {
|
|
79
|
+
const P = "web/src/app/(site)/hands/page.tsx";
|
|
80
|
+
it("selects user-visible route files, minus exclude and tests", () => {
|
|
81
|
+
const files = [P, "web/src/app/(site)/layout.tsx", "web/src/app/(site)/api/x/page.tsx", "web/src/app/(site)/hands/page.test.tsx", "web/src/app/dashboard/page.tsx", "services/api/x.py"];
|
|
82
|
+
assert.deepEqual(designFiles(files, cfg), [P, "web/src/app/(site)/layout.tsx"]);
|
|
83
|
+
assert.deepEqual(designPages(files, cfg), [P]);
|
|
84
|
+
assert.equal(routeOf(P), "/hands"); assert.equal(routeOf("web/src/app/(site)/layout.tsx"), "/");
|
|
85
|
+
});
|
|
86
|
+
it("a predicted new page.tsx under design.routes with no spec is routed to /design and blocked with gate: blocking", () => {
|
|
87
|
+
const g = designGate({ files: [P, "src/a.mjs"], cfg });
|
|
88
|
+
assert.deepEqual([g.route, g.blocked, g.pages], [true, true, [P]]);
|
|
89
|
+
assert.match(g.reason, /\/design/); assert.match(designGateNote(g), /stop with a block asking for \/design/);
|
|
90
|
+
});
|
|
91
|
+
it("advisory routes without blocking", () => {
|
|
92
|
+
const g = designGate({ files: [P], cfg: { ...cfg, gate: "advisory" } });
|
|
93
|
+
assert.deepEqual([g.route, g.blocked], [true, false]); assert.match(designGateNote(g), /reference a \/design spec/);
|
|
94
|
+
});
|
|
95
|
+
it("a FORGE:DESIGN_SPEC comment or the spec label clears it; a draft spec does not", () => {
|
|
96
|
+
assert.equal(designGate({ files: [P], cfg, comments: [{ body: "<!-- FORGE:DESIGN_SPEC -->\nok" }] }).route, false);
|
|
97
|
+
assert.equal(designGate({ files: [P], cfg, labels: [{ name: "design:approved" }] }).route, false);
|
|
98
|
+
assert.equal(designGate({ files: [P], cfg, comments: [{ body: '<!-- FORGE:DESIGN_SPEC {"status":"draft"} -->' }] }).route, true);
|
|
99
|
+
assert.equal(specApproved({ labels: ["design:approved"], cfg }), true);
|
|
100
|
+
});
|
|
101
|
+
it("a change that adds no page entry (a component, an excluded api route) is not routed", () => {
|
|
102
|
+
assert.equal(designGate({ files: ["web/src/components/ui/button.tsx", "web/src/app/(site)/api/x/page.tsx"], cfg }).route, false);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("deterministic render critique floor (#5330 R14)", () => {
|
|
107
|
+
const ids = (src) => critiqueMarkup(src).map((f) => f.id);
|
|
108
|
+
it("flags the plain-text hero page with empty boxes", () => {
|
|
109
|
+
const f = ids(HANDS_BAD);
|
|
110
|
+
assert.ok(f.includes("empty_box")); assert.ok(f.includes("plain_text_hero")); assert.ok(f.includes("bare_cta"));
|
|
111
|
+
});
|
|
112
|
+
it("passes a page with components, filled cards and a real button", () => assert.deepEqual(critiqueMarkup(HANDS_GOOD), []));
|
|
113
|
+
it("placeholder copy and null samples block", () => {
|
|
114
|
+
assert.ok(ids("<main><Hero/><p>Lorem ipsum dolor</p></main>").includes("placeholder_text"));
|
|
115
|
+
assert.ok(ids("<main><Hero/><p>[[null]]</p></main>").includes("placeholder_text"));
|
|
116
|
+
});
|
|
117
|
+
it("decorative dividers, skeletons and commented-out boxes are not empty boxes", () => {
|
|
118
|
+
assert.deepEqual(ids('<main><Hero/><div className="border-t" /><div className="rounded animate-pulse" /><div aria-hidden className="rounded border" />{/* <div className="rounded border"></div> */}</main>'), []);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe("visual gate (#5330 R12, R14; shared with #5369)", () => {
|
|
123
|
+
const P = "web/src/app/(site)/hands/page.tsx";
|
|
124
|
+
const shots = { "/hands": { screenshots: ["shots/hands-390.png", "shots/hands-1440.png"], verdict: "PASS" } };
|
|
125
|
+
it("regression fixture: a bundle adding the plain-text hero page with empty boxes fails the gate", () => {
|
|
126
|
+
const g = visualGate({ cfg, files: [P], specs: true, sources: { [P]: HANDS_BAD } });
|
|
127
|
+
assert.equal(g.verdict, "FAIL");
|
|
128
|
+
assert.ok(g.rows.some((r) => r.kind === "visual_critique_failed" && /empty_box/.test(r.detail)));
|
|
129
|
+
assert.ok(g.rows.some((r) => /plain_text_hero/.test(r.detail)));
|
|
130
|
+
});
|
|
131
|
+
it("the same bundle through the lane precheck is a conformance.unimplemented failure", () => {
|
|
132
|
+
const rows = designFailures({ cfg, files: [P], specs: true, readFile: () => HANDS_BAD });
|
|
133
|
+
assert.ok(rows.length >= 2); assert.ok(rows.every((r) => r.code === "conformance.unimplemented"));
|
|
134
|
+
const p = precheck({ contract: { requirements: [], deliverables: [{ id: "D1", path: P }] }, result: { status: "fixed" }, changedFiles: [P], pageFailures: rows });
|
|
135
|
+
assert.ok(JSON.stringify(p).includes("visual_critique_failed"));
|
|
136
|
+
});
|
|
137
|
+
it("blocking: a missing spec yields a failure; a good page with a spec, screenshots at both viewports and a PASS verdict passes", () => {
|
|
138
|
+
assert.equal(visualGate({ cfg, files: [P], specs: false, sources: { [P]: HANDS_GOOD } }).rows[0].kind, "design_spec_missing");
|
|
139
|
+
const g = visualGate({ cfg, files: [P], specs: true, sources: { [P]: HANDS_GOOD }, evidence: shots, rendered: true });
|
|
140
|
+
assert.deepEqual([g.verdict, g.rows], ["PASS", []]);
|
|
141
|
+
});
|
|
142
|
+
it("rendered evidence is required: a missing viewport, a missing verdict or a non-PASS verdict fails", () => {
|
|
143
|
+
const run = (evidence) => visualGate({ cfg, files: [P], specs: true, sources: { [P]: HANDS_GOOD }, evidence, rendered: true });
|
|
144
|
+
assert.match(run({ "/hands": { screenshots: ["a-1440.png"], verdict: "PASS" } }).rows[0].detail, /390px/);
|
|
145
|
+
assert.equal(run({}).rows.map((r) => r.kind).join(), "visual_screenshots_missing,visual_critique_missing");
|
|
146
|
+
assert.match(run({ "/hands": { ...shots["/hands"], verdict: "BUDGET-EXHAUSTED" } }).rows[0].detail, /BUDGET-EXHAUSTED/);
|
|
147
|
+
assert.equal(visualGate({ cfg: { ...cfg, requireVisual: false }, files: [P], specs: true, rendered: true }).verdict, "PASS");
|
|
148
|
+
});
|
|
149
|
+
it("advisory reports the same rows but never fails; lane precheck returns no rows", () => {
|
|
150
|
+
const a = { ...cfg, gate: "advisory" };
|
|
151
|
+
const g = visualGate({ cfg: a, files: [P], specs: false, sources: { [P]: HANDS_BAD } });
|
|
152
|
+
assert.equal(g.verdict, "ADVISORY"); assert.ok(g.rows.length >= 2);
|
|
153
|
+
assert.deepEqual(designFailures({ cfg: a, files: [P], readFile: () => HANDS_BAD }), []);
|
|
154
|
+
});
|
|
155
|
+
it("per-route specs: only the route without a spec is flagged", () => {
|
|
156
|
+
const Q = "web/src/app/(site)/pricing/page.tsx";
|
|
157
|
+
const g = visualGate({ cfg, files: [P, Q], specs: { "/hands": true } });
|
|
158
|
+
assert.deepEqual(g.rows.map((r) => r.route), ["/pricing"]);
|
|
159
|
+
});
|
|
160
|
+
it("nothing user-visible in the bundle: PASS with no routes", () => {
|
|
161
|
+
const g = visualGate({ cfg, files: ["services/api/x.py"] });
|
|
162
|
+
assert.deepEqual([g.verdict, g.routes.length], ["PASS", 0]);
|
|
163
|
+
});
|
|
164
|
+
it("the comment lists each route with its screenshots and the verdict", () => {
|
|
165
|
+
const g = visualGate({ cfg, files: [P], specs: true, sources: { [P]: HANDS_GOOD }, evidence: shots, rendered: true });
|
|
166
|
+
const c = visualGateComment(g, shots);
|
|
167
|
+
assert.match(c, /FORGE:VISUAL_GATE/); assert.match(c, /Visual gate: PASS/); assert.match(c, /hands-390\.png/);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
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 { execCapped } from "./effects.mjs";
|
|
6
|
+
|
|
7
|
+
describe("#5592 a huge git/gh output never crashes the lane", () => {
|
|
8
|
+
it("output past the cap is truncated with a marker, not a maxBuffer error", async () => {
|
|
9
|
+
const out = await execCapped(process.execPath, ["-e", "process.stdout.write('x'.repeat(3e6))"], { cap: 1_000_000 });
|
|
10
|
+
assert.ok(out.startsWith("xxxx") && out.length < 1_000_200);
|
|
11
|
+
assert.match(out, /output truncated at 1000000 bytes/);
|
|
12
|
+
});
|
|
13
|
+
it("normal output passes through; a failing child rejects with stderr", async () => {
|
|
14
|
+
assert.equal(await execCapped(process.execPath, ["-e", "process.stdout.write('hi')"]), "hi");
|
|
15
|
+
await assert.rejects(execCapped(process.execPath, ["-e", "console.error('boom');process.exit(3)"]), (e) => e.code === 3 && /boom/.test(e.stderr) && /boom/.test(e.message));
|
|
16
|
+
});
|
|
17
|
+
});
|
package/bin/lean/effects.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { homedir, hostname, freemem, loadavg, cpus, tmpdir } from "node:os";
|
|
|
8
8
|
import { promises as fsp } from "node:fs";
|
|
9
9
|
import { dirname, join, resolve, sep } from "node:path";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { randomBytes } from "node:crypto";
|
|
11
12
|
import { runCliBackendAsync, resolveClaudeCliBinary, getClaudeCliCapabilities, buildLeanSessionFlags, buildReadOnlyToolFlags, sanitizeCliModel } from "../runner.mjs";
|
|
12
13
|
import { makeIo, readSubagentModel } from "../engine-cli.mjs";
|
|
13
14
|
import { makeProjector } from "../engine/projector.mjs";
|
|
@@ -113,12 +114,13 @@ export const leanSettingsFlags = ({ subagentModel = null, reread = false, guard
|
|
|
113
114
|
};
|
|
114
115
|
|
|
115
116
|
export function makeLeanRunner({ runCli = runCliBackendAsync, probe = systemdRunAvailable, subagentModel = null, sandboxed = inSandbox() } = {}) {
|
|
116
|
-
return async ({ role, issue, cwd, model, resume, system, prompt, readOnly = false, noTools = false, rereadNudge = false, maxTurns = null, agents = null, env = null, idleMs = 0, maxMs = 0, laneLimits = null, control = null, onSpawn = null, session = null, contextMax = 0, turnMax = 0, busy = null, busyMs = 0, onIdleExtend = null, bin: pinnedBin = null }) => {
|
|
117
|
+
return async ({ role, issue, cwd, model, resume, system, prompt, readOnly = false, noTools = false, rereadNudge = false, maxTurns = null, agents = null, env = null, idleMs = 0, maxMs = 0, laneLimits = null, control = null, onSpawn = null, session = null, contextMax = 0, turnMax = 0, busy = null, busyMs = 0, onIdleExtend = null, bin: pinnedBin = null, fullSession = false }) => {
|
|
117
118
|
// #5205: a rotation relaunch pins the real claude past the tokenbaton shim; absent, the usual resolution
|
|
118
119
|
const bin = pinnedBin || resolveClaudeCliBinary(cwd) || "claude";
|
|
119
120
|
const caps = getClaudeCliCapabilities(cwd);
|
|
120
121
|
// #4391: custom subagents (the explorer) for the builder session; null leaves argv unchanged
|
|
121
|
-
|
|
122
|
+
// #5516: fullSession keeps slash commands/Skill/Task (the release test gate invokes /test-gate); otherwise the lean minimal group
|
|
123
|
+
const flags = [...(fullSession ? [] : buildLeanSessionFlags(caps)), ...(noTools ? noToolFlags(caps) : readOnly ? buildReadOnlyToolFlags(caps) : []), ...(agents ? ["--agents", JSON.stringify(agents)] : [])];
|
|
122
124
|
// #4843 owned models, in extraArgs so FORGEDOCK_FULL_SESSION=1 (which drops sessionFlags) keeps them (#4848 BUG-1);
|
|
123
125
|
// #4456 re-read hooks: builder sessions only, and like the other session flags not in a full session
|
|
124
126
|
const settings = leanSettingsFlags({ subagentModel, reread: rereadNudge && !readOnly && !noTools && process.env.FORGEDOCK_FULL_SESSION !== "1", guard: sandboxed });
|
|
@@ -295,25 +297,68 @@ export async function requiredChecksRead({ gh, repo, lane }) {
|
|
|
295
297
|
|
|
296
298
|
export const requiredChecksFor = async (opts) => (await requiredChecksRead(opts)).checks;
|
|
297
299
|
|
|
300
|
+
/** #5592: stdout cap of a lane-path git/gh/docker call; output past it is cut, never an error. */
|
|
301
|
+
export const EXEC_CAPPED_BYTES = 100 * 1024 * 1024;
|
|
302
|
+
/**
|
|
303
|
+
* #5592: like `execFile` resolving stdout, but a child that prints more than `cap` bytes is stopped and its output
|
|
304
|
+
* truncated (marker appended) instead of failing with `stdout maxBuffer length exceeded`: a commit that removes a
|
|
305
|
+
* 485 MB archive made `git diff base...HEAD` kill the lane after it had pushed. A non-zero exit rejects with
|
|
306
|
+
* {stdout, stderr, code} like execFile, unless the exit came from our own stop (then the capped text is the result).
|
|
307
|
+
*/
|
|
308
|
+
export function execCapped(bin, args, { cwd, env, timeout = 120000, cap = EXEC_CAPPED_BYTES, spawnFn = spawn } = {}) {
|
|
309
|
+
return new Promise((res, rej) => {
|
|
310
|
+
const child = spawnFn(bin, args, { cwd, ...(env ? { env } : {}), stdio: ["ignore", "pipe", "pipe"] });
|
|
311
|
+
const chunks = []; let size = 0, cut = false, err = "", timedOut = false;
|
|
312
|
+
const timer = timeout > 0 ? setTimeout(() => { timedOut = true; try { child.kill("SIGKILL"); } catch { /* gone */ } }, timeout) : null;
|
|
313
|
+
child.stdout.on("data", (b) => {
|
|
314
|
+
if (cut) return;
|
|
315
|
+
const room = cap - size;
|
|
316
|
+
if (b.length > room) { if (room > 0) chunks.push(b.subarray(0, room)); size = cap; cut = true; try { child.kill("SIGTERM"); } catch { /* gone */ } return; }
|
|
317
|
+
chunks.push(b); size += b.length;
|
|
318
|
+
});
|
|
319
|
+
child.stderr.on("data", (b) => { if (err.length < 64000) err += String(b); });
|
|
320
|
+
child.on("error", (e) => { if (timer) clearTimeout(timer); rej(e); });
|
|
321
|
+
child.on("close", (code, signal) => {
|
|
322
|
+
if (timer) clearTimeout(timer);
|
|
323
|
+
const out = Buffer.concat(chunks).toString("utf8") + (cut ? `\n[forgedock: output truncated at ${cap} bytes]\n` : "");
|
|
324
|
+
if (cut || code === 0) return res(out);
|
|
325
|
+
const e = new Error(`Command failed: ${bin} ${args.join(" ")}${timedOut ? " (timed out)" : ""}\n${err}`);
|
|
326
|
+
Object.assign(e, { code: timedOut ? null : code, signal, killed: timedOut, stdout: out, stderr: err });
|
|
327
|
+
rej(e);
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
298
332
|
/** Combined stdout+stderr kept per declared check command (tail). */
|
|
299
333
|
const CHECK_OUTPUT_CAP = 64000;
|
|
300
334
|
/** #4240: run a forge.yaml declared check command locally (no gh, no Actions); {rc, output}, rc 124 on timeout. `env` (#4323) is merged over process.env. */
|
|
301
|
-
|
|
302
|
-
|
|
335
|
+
/** #5598: best-effort removal of the containers a check started (labelled by the docker shim); never throws. */
|
|
336
|
+
export async function reapContainers(label, { timeoutMs = 20000, env = process.env } = {}) {
|
|
337
|
+
try {
|
|
338
|
+
const ids = String((await pexec("docker", ["ps", "-aq", "--filter", `label=${label}`], { timeout: timeoutMs, env })).stdout ?? "").split(/\s+/).filter(Boolean);
|
|
339
|
+
if (ids.length) await pexec("docker", ["rm", "-f", ...ids], { timeout: timeoutMs, env });
|
|
340
|
+
return ids;
|
|
341
|
+
} catch { return []; }
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export function runCheckCommand({ command, cwd, timeoutMs = 300000, env = null, graceMs = 2000 }) {
|
|
345
|
+
const reapLabel = `forgedock.reap=${randomBytes(8).toString("hex")}`;
|
|
346
|
+
const inner = new Promise((finish) => {
|
|
303
347
|
let out = "", timedOut = false, child;
|
|
304
348
|
const add = (b) => { out += String(b); if (out.length > 2 * CHECK_OUTPUT_CAP) out = out.slice(-CHECK_OUTPUT_CAP); };
|
|
305
|
-
try { child = spawn("bash", ["-c", String(command)], { cwd, detached: true, windowsHide: true, stdio: ["ignore", "pipe", "pipe"],
|
|
306
|
-
catch (e) {
|
|
307
|
-
const kill = () => { try { process.kill(-child.pid,
|
|
308
|
-
const timer = setTimeout(() => { timedOut = true; kill(); }, timeoutMs);
|
|
349
|
+
try { child = spawn("bash", ["-c", String(command)], { cwd, detached: true, windowsHide: true, stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, ...(env ?? {}), FORGE_REAP_LABEL: reapLabel } }); }
|
|
350
|
+
catch (e) { finish({ rc: 127, output: String(e?.message ?? e) }); return; }
|
|
351
|
+
const kill = (sig) => { try { process.kill(-child.pid, sig); } catch { try { child.kill(sig); } catch { /* gone */ } } };
|
|
352
|
+
const timer = setTimeout(() => { timedOut = true; kill("SIGTERM"); setTimeout(() => kill("SIGKILL"), graceMs).unref(); }, timeoutMs);
|
|
309
353
|
child.stdout.on("data", add); child.stderr.on("data", add);
|
|
310
|
-
child.on("error", (e) => { clearTimeout(timer);
|
|
354
|
+
child.on("error", (e) => { clearTimeout(timer); finish({ rc: 127, output: `${out}${String(e?.message ?? e)}`.slice(-CHECK_OUTPUT_CAP) }); });
|
|
311
355
|
child.on("close", (code) => {
|
|
312
356
|
clearTimeout(timer);
|
|
313
357
|
const tail = out.slice(-CHECK_OUTPUT_CAP);
|
|
314
|
-
|
|
358
|
+
finish(timedOut ? { rc: 124, output: `${tail}\n(timed out after ${Math.round(timeoutMs / 1000)}s)` } : { rc: Number.isInteger(code) ? code : 1, output: tail });
|
|
315
359
|
});
|
|
316
360
|
});
|
|
361
|
+
return inner.then(async (r) => { await reapContainers(reapLabel, { env: { ...process.env, ...(env ?? {}) } }); return r; });
|
|
317
362
|
}
|
|
318
363
|
|
|
319
364
|
/**
|
|
@@ -344,7 +389,7 @@ export function makeGhCache({ root = null, tmp = tmpdir() } = {}) {
|
|
|
344
389
|
export function makeLeanIo({ repo, subagentModel = readSubagentModel() }) {
|
|
345
390
|
const base = makeIo();
|
|
346
391
|
const seqLeaseIo = makeSequenceLeaseIo(); // #5340: one instance: sequence leases, surface leases and declarations
|
|
347
|
-
const run = (bin) => async (args, opts = {}) => (
|
|
392
|
+
const run = (bin) => async (args, opts = {}) => execCapped(bin, args, { cwd: opts.cwd, timeout: 120000, ...(opts.env ? { env: { ...process.env, ...opts.env } } : {}) });
|
|
348
393
|
/** #5235: paths the other open PRs on `lane` carry (gh only, no fetch); [] on any failure. */
|
|
349
394
|
const openPrFiles = async (cwd, lane) => {
|
|
350
395
|
try {
|
|
@@ -509,8 +554,8 @@ export function makeLeanIo({ repo, subagentModel = readSubagentModel() }) {
|
|
|
509
554
|
async redGreen({ cwd, base, command, timeoutSec = 300, env = null }) {
|
|
510
555
|
const args = [script("acceptance-red-green.sh"), "--repo-path", cwd, "--base-ref", base, "--test-cmd", command, "--timeout", String(timeoutSec)];
|
|
511
556
|
try {
|
|
512
|
-
const m = /BASE=(\w+) HEAD=(\w+)
|
|
513
|
-
return m ? { base: m[1], head: m[2] } : null;
|
|
557
|
+
const m = /BASE=(\w+) HEAD=(\w+)(?: PRISTINE=(\w+))?/.exec(String((await pexec("bash", args, { cwd, timeout: (timeoutSec * 2 + 60) * 1000, maxBuffer: 4 * 1024 * 1024, ...(env ? { env: { ...process.env, ...env } } : {}) })).stdout ?? ""));
|
|
558
|
+
return m ? { base: m[1], head: m[2], ...(m[3] ? { pristine: m[3] } : {}) } : null; // #5544: pristine only when the base's own test version failed
|
|
514
559
|
} catch { return null; }
|
|
515
560
|
},
|
|
516
561
|
/**
|
package/bin/lean/heavy.mjs
CHANGED
|
@@ -317,23 +317,31 @@ export function sumWaits(text, waits = {}) {
|
|
|
317
317
|
return { waits, queueMax };
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
+
/** #5592: the real command a ForgeDock heavy shim (`exec node heavy.mjs run --name n -- 'real' "$@"`) was written for, or null when `text` is no shim. */
|
|
321
|
+
export function shimTarget(text) {
|
|
322
|
+
const t = String(text ?? "");
|
|
323
|
+
if (!t.startsWith(SHIM_HEADER)) return null;
|
|
324
|
+
const m = /--\s+'((?:[^']|'\\'')*)'\s+"\$@"/.exec(t);
|
|
325
|
+
return m ? m[1].replace(/'\\''/g, "'") : null;
|
|
326
|
+
}
|
|
327
|
+
|
|
320
328
|
/**
|
|
321
|
-
* Admission-time form of the guardChain loop (#4866):
|
|
322
|
-
*
|
|
329
|
+
* Admission-time form of the guardChain loop (#4866): PATH dirs where a heavy shim of ours for a tool execs a pass-through
|
|
330
|
+
* wrapper (its own `command -v` lands back on the shim). Returns [{name, dir}].
|
|
331
|
+
* #5592: a pass-through wrapper with no real binary on PATH behind it is NOT a loop: writeHeavyShims writes no shim over such
|
|
332
|
+
* a wrapper (it skips the name with a warning), so the wrapper runs unshimmed. Only a shim that already points at one loops;
|
|
333
|
+
* a wrapper the shim already covers (real binary found past it, or a shim on PATH) never does.
|
|
323
334
|
*/
|
|
324
335
|
export function findShimLoops(path, { names = HEAVY_BINS, find = which, read = head, skip = [] } = {}) {
|
|
325
336
|
const out = [];
|
|
326
337
|
const dirs = String(path ?? "").split(delimiter).filter(Boolean);
|
|
327
338
|
for (const name of names) {
|
|
328
|
-
const wrappers = [];
|
|
329
339
|
for (const d of dirs) {
|
|
330
340
|
if (skip.includes(d)) continue;
|
|
331
341
|
const f = find(name, d, []);
|
|
332
|
-
|
|
342
|
+
const target = f ? shimTarget(read(f)) : null;
|
|
343
|
+
if (target && isPassThroughWrapper(read(target), name)) out.push({ name, dir: d });
|
|
333
344
|
}
|
|
334
|
-
if (!wrappers.length) continue;
|
|
335
|
-
const real = find(name, path, [...skip, ...wrappers]);
|
|
336
|
-
if (!real) for (const dir of wrappers) out.push({ name, dir });
|
|
337
345
|
}
|
|
338
346
|
return out;
|
|
339
347
|
}
|
|
@@ -364,6 +372,15 @@ export function guardChain(name, cmd, env, read = head) {
|
|
|
364
372
|
return { cmd, env: { ...env, FORGE_HEAVY_DEPTH: String(depth + 1), FORGE_HEAVY_CHAIN: [...chain, `${name}:${cmd}`].join("|") } };
|
|
365
373
|
}
|
|
366
374
|
|
|
375
|
+
/** #5598: `docker run|create` gets `--label <FORGE_REAP_LABEL>` so the validate runner can remove the container when it kills a timed-out step. */
|
|
376
|
+
export function labelDockerArgs(name, args, env = {}) {
|
|
377
|
+
const label = env.FORGE_REAP_LABEL;
|
|
378
|
+
if (!label || name !== "docker") return args;
|
|
379
|
+
const i = args.findIndex((a) => !a.startsWith("-"));
|
|
380
|
+
if (i < 0 || !(args[i] === "run" || args[i] === "create") || args.includes(label)) return args;
|
|
381
|
+
return [...args.slice(0, i + 1), "--label", label, ...args.slice(i + 1)];
|
|
382
|
+
}
|
|
383
|
+
|
|
367
384
|
/**
|
|
368
385
|
* CLI body: `run --name <n> -- <real> args...`. Pass-through when FORGE_HEAVY_HELD is set or the step is llm; else
|
|
369
386
|
* acquire, run with FORGE_HEAVY_HELD=1 and FORGE_HOST_PARALLELISM from live holders, release, propagate the exit.
|
|
@@ -378,7 +395,7 @@ export async function runWrapped(argv, { env: env0 = process.env, open = openHea
|
|
|
378
395
|
const c = heavyConfig({}, env);
|
|
379
396
|
const g0 = guardChain(name, cmd, env);
|
|
380
397
|
if (g0.error) { process.stderr.write(`${g0.error}\n`); return { code: 126, signal: null }; }
|
|
381
|
-
cmd = g0.cmd; env = g0.env;
|
|
398
|
+
cmd = g0.cmd; env = g0.env; args = labelDockerArgs(name, args, env);
|
|
382
399
|
if (env.FORGE_HEAVY_HELD || env.FORGE_HEAVY_DISABLED === "1" || classifyStep(name, args) === "llm") return run(cmd, args, env);
|
|
383
400
|
const hostP = host ?? defaultHost();
|
|
384
401
|
const h = open(env.FORGEDOCK_SCHED_DIR || schedDir(env), { env, host: hostP });
|
|
@@ -114,4 +114,32 @@ describe("#5174 hostload", () => {
|
|
|
114
114
|
assert.deepEqual(out.map((r) => r.outcome), ["merged"]);
|
|
115
115
|
assert.equal(probes, 0, "the remote placement never consults the overload gate");
|
|
116
116
|
});
|
|
117
|
+
|
|
118
|
+
it("#5592: a pool capacity 503 never falls back to an overloaded host; the lane keeps retrying the pool", async () => {
|
|
119
|
+
const c = { t: 1_000_000 };
|
|
120
|
+
const csleep = async (ms) => { await new Promise((r) => setImmediate(r)); c.t += ms; };
|
|
121
|
+
const where = [];
|
|
122
|
+
let tries = 0;
|
|
123
|
+
const rows = await orchestrate({ issues: [1], parallel: 1, now: () => c.t, sleep: csleep, pollMs: 1, readBody: async () => "",
|
|
124
|
+
overload: () => ({ overloaded: true, perCore: 5, threshold: 2 }),
|
|
125
|
+
remote: { max: 1, isRemote: () => true, capacity: () => ({ free: null, online: 1, at: 1 }), offlineFallback: true, capacityFallbackAfter: 2, headroom: () => ({ ok: true }) },
|
|
126
|
+
runOne: async (n, _ln, ctx = {}) => {
|
|
127
|
+
where.push(ctx.placement?.where ?? "remote");
|
|
128
|
+
tries++;
|
|
129
|
+
return tries >= 6 ? { terminalReason: "merged", pr: 1 } : { terminalReason: "deferred", code: "sandbox.capacity", retryInSeconds: 1, detail: "HTTP 503 capacity" };
|
|
130
|
+
} });
|
|
131
|
+
assert.equal(rows[0].outcome, "merged");
|
|
132
|
+
assert.equal(tries, 6);
|
|
133
|
+
assert.ok(where.every((w) => w === "remote"), where.join());
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("#5592: a local issue held by host overload does not block a remote issue behind it", async () => {
|
|
137
|
+
const started = [], seen = [];
|
|
138
|
+
const rows = await orchestrate({ issues: [1, 2], parallel: 2, pollMs: 1, sleep, readBody: async () => "",
|
|
139
|
+
overload: () => { seen.push([...started]); return { overloaded: !started.includes(2), perCore: 5, threshold: 2 }; },
|
|
140
|
+
remote: { max: 2, isRemote: (n) => n === 2 },
|
|
141
|
+
runOne: async (n) => { started.push(n); return { terminalReason: "merged", pr: n }; } });
|
|
142
|
+
assert.deepEqual(started, [2, 1], "#2 (remote) starts while #1 (local) is held; #1 follows once the host clears");
|
|
143
|
+
assert.equal(rows.length, 2);
|
|
144
|
+
});
|
|
117
145
|
});
|