forgedock 1.55.1 → 1.57.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 +1 -0
- package/bin/engine/phases.mjs +4 -3
- package/bin/engine-cli.mjs +58 -10
- package/bin/forgedock.mjs +52 -3
- package/bin/gc.mjs +43 -6
- package/bin/help-text.mjs +3 -1
- 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 +88 -17
- package/bin/lean/conformance.test.mjs +98 -3
- package/bin/lean/decisions.mjs +86 -1
- package/bin/lean/decisions.test.mjs +21 -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 +12 -2
- package/bin/lean/issuewatch-parity.test.mjs +26 -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 +80 -25
- package/bin/lean/lean.test.mjs +149 -3
- 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 +125 -0
- package/bin/lean/orphan-pr.test.mjs +145 -0
- 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 +25 -0
- package/bin/lean/release-config.mjs +158 -0
- package/bin/lean/release-config.test.mjs +109 -0
- package/bin/lean/release-control.mjs +148 -0
- package/bin/lean/release-control.test.mjs +143 -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-ledger.mjs +160 -0
- package/bin/lean/release-ledger.test.mjs +226 -0
- package/bin/lean/release-minutes.mjs +92 -0
- package/bin/lean/release-minutes.test.mjs +99 -0
- package/bin/lean/release-nightly.mjs +75 -0
- package/bin/lean/release-nightly.test.mjs +48 -0
- package/bin/lean/release-postmerge.mjs +45 -21
- 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-unitmap.mjs +35 -0
- package/bin/lean/release-unitmap.test.mjs +41 -0
- package/bin/lean/release.mjs +177 -19
- package/bin/lean/release.test.mjs +80 -16
- 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 +8 -5
- 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/incident-response.md +4 -0
- package/commands/issue.md +1 -1
- package/commands/milestone.md +1 -1
- package/commands/pipeline-status.md +13 -0
- package/commands/review-pr-agents/frontend.md +1 -0
- package/commands/review-pr-staging.md +5 -0
- package/docs/CONFIG.md +75 -1
- 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.test.sh +3 -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
package/bin/lean/depcache.mjs
CHANGED
|
@@ -34,6 +34,8 @@ const pidAlive = (pid) => { try { process.kill(pid, 0); return true; } catch (e)
|
|
|
34
34
|
* Error text for a reason: pnpm prints its ERR_PNPM_* errors on stdout (#4522), so the first such line from either
|
|
35
35
|
* stream leads, then the last lines of stderr and stdout; the message only when both streams are empty.
|
|
36
36
|
*/
|
|
37
|
+
/** #5592: poetry cannot install the project itself (not package-mode: no package dir, no `package-mode = false`). */
|
|
38
|
+
const NO_ROOT_RE = /--no-root|current project could not be installed|No file\/folder found for package|does not contain any element/i;
|
|
37
39
|
const msg = (e) => {
|
|
38
40
|
const lines = (s) => String(s ?? "").split("\n").map((l) => l.trim()).filter(Boolean);
|
|
39
41
|
const err = lines(e?.stderr), out = lines(e?.stdout);
|
|
@@ -102,16 +104,55 @@ function serviceLocks(fs, wt) {
|
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
const JS = new Set(["pnpm", "npm", "yarn"]);
|
|
107
|
+
const PY = new Set(["uv", "poetry"]);
|
|
108
|
+
/** Files a finished install leaves at the top of node_modules (npm, yarn classic, yarn berry, pnpm). */
|
|
109
|
+
const JS_MARKERS = [".package-lock.json", ".yarn-integrity", ".yarn-state.yml", ".modules.yaml"];
|
|
110
|
+
|
|
111
|
+
/** #5590: the project's declared Python range (`[project] requires-python` / `[tool.poetry.dependencies] python`), null when absent. */
|
|
112
|
+
export function pyRange(text, eco) {
|
|
113
|
+
let section = "", poetry = null, pep = null;
|
|
114
|
+
for (const raw of String(text).split("\n")) {
|
|
115
|
+
const line = raw.trim();
|
|
116
|
+
const h = /^\[([^\]]+)\]$/.exec(line);
|
|
117
|
+
if (h) { section = h[1].trim(); continue; }
|
|
118
|
+
let m;
|
|
119
|
+
if (section === "project" && (m = /^requires-python\s*=\s*["']([^"']+)["']/.exec(line))) pep = m[1];
|
|
120
|
+
else if (section === "tool.poetry.dependencies" && (m = /^python\s*=\s*["']([^"']+)["']/.exec(line))) poetry = m[1];
|
|
121
|
+
}
|
|
122
|
+
return eco === "poetry" ? poetry ?? pep : pep ?? poetry;
|
|
123
|
+
}
|
|
124
|
+
const cmpVer = (a, b) => { for (let i = 0; i < 3; i++) { const d = (a[i] ?? 0) - (b[i] ?? 0); if (d) return d; } return 0; };
|
|
125
|
+
const prefixOf = (v, n) => n.every((x, i) => v[i] === x);
|
|
126
|
+
function clauseOk(clause, v) {
|
|
127
|
+
const m = /^(\^|~=|~|==|!=|>=|<=|>|<)?v?(\d+(?:\.\d+)*)(\.\*)?$/.exec(clause);
|
|
128
|
+
if (!m) return true; // unparseable: never constrain
|
|
129
|
+
const op = m[1] ?? "==", n = m[2].split(".").map(Number), wild = Boolean(m[3]) || (op === "==" && n.length < 3) || (op === "!=" && n.length < 3);
|
|
130
|
+
switch (op) {
|
|
131
|
+
case "==": return wild ? prefixOf(v, n) : cmpVer(v, n) === 0;
|
|
132
|
+
case "!=": return wild ? !prefixOf(v, n) : cmpVer(v, n) !== 0;
|
|
133
|
+
case ">=": return cmpVer(v, n) >= 0;
|
|
134
|
+
case ">": return cmpVer(v, n) > 0;
|
|
135
|
+
case "<=": return cmpVer(v, n) <= 0;
|
|
136
|
+
case "<": return cmpVer(v, n) < 0;
|
|
137
|
+
case "^": { let i = n.findIndex((x) => x !== 0); if (i < 0) i = n.length - 1; const up = n.slice(0, i + 1); up[i] += 1; return cmpVer(v, n) >= 0 && cmpVer(v, up) < 0; }
|
|
138
|
+
default: { const up = (op === "~=" ? n.length === 2 : n.length === 1) ? [n[0] + 1] : [n[0], (n[1] ?? 0) + 1]; return cmpVer(v, n) >= 0 && cmpVer(v, up) < 0; } // ~ / ~=
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/** #5590: does version `v` ([major, minor, patch]) satisfy the PEP 440 / poetry range `spec` ("||" alternatives, comma or space joined clauses)? */
|
|
142
|
+
export function pySatisfies(spec, v) {
|
|
143
|
+
return String(spec).split("||").some((grp) => grp.replace(/(\^|~=|~|==|!=|>=|<=|>|<)\s+/g, "$1").split(/[,\s]+/).filter(Boolean).every((c) => clauseOk(c, v)));
|
|
144
|
+
}
|
|
105
145
|
/** Full frozen install on a miss, and the warm no-op repair pass on a hit (null: nothing path-dependent to repair). */
|
|
106
|
-
function commands(d) {
|
|
146
|
+
function commands(d, py = null) {
|
|
147
|
+
const use = py ? [["poetry", ["env", "use", py.cmd]]] : [];
|
|
107
148
|
switch (d.eco) {
|
|
108
149
|
case "pnpm": return { install: [["pnpm", ["install", "--frozen-lockfile"]]], repair: [["pnpm", ["install", "--frozen-lockfile", "--offline"]]] };
|
|
109
150
|
// npm/yarn node_modules hold only relative links; npm's hidden lockfile is rewritten in place, which the read-only
|
|
110
151
|
// snapshot (correctly) refuses, so they get no repair pass.
|
|
111
152
|
case "npm": return { install: [["npm", ["ci", "--no-audit", "--no-fund"]]], repair: null };
|
|
112
153
|
case "yarn": return { install: [["yarn", ["install", d.berry ? "--immutable" : "--frozen-lockfile"]]], repair: null };
|
|
113
|
-
case "uv": return { install: [["uv", ["venv", "--relocatable", ".venv"]], ["uv", ["sync", "--frozen"]]], repair: [["uv", ["sync", "--frozen"]]] };
|
|
114
|
-
case "poetry": return { install: [["poetry", ["install", "--sync"]]], repair: [["poetry", ["install", "--sync"]]] };
|
|
154
|
+
case "uv": return { install: [["uv", ["venv", "--relocatable", ...(py ? ["--python", py.cmd] : []), ".venv"]], ["uv", ["sync", "--frozen"]]], repair: [["uv", ["sync", "--frozen"]]] };
|
|
155
|
+
case "poetry": return { install: [...use, ["poetry", ["install", "--sync"]]], repair: [...use, ["poetry", ["install", "--sync"]]] };
|
|
115
156
|
default: return null;
|
|
116
157
|
}
|
|
117
158
|
}
|
|
@@ -147,10 +188,39 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
147
188
|
return ["package.json"];
|
|
148
189
|
}
|
|
149
190
|
|
|
150
|
-
|
|
191
|
+
/**
|
|
192
|
+
* #5590: for a Python project whose pyproject declares a range the host's default python3 is outside of, the interpreter that
|
|
193
|
+
* does satisfy it ({cmd, version}: pythonX.Y on PATH, then `uv python find`); null keeps the default (no range, default in range, none found).
|
|
194
|
+
*/
|
|
195
|
+
async function pythonFor(wt, d) {
|
|
196
|
+
if (!PY.has(d.eco)) return null;
|
|
197
|
+
let range = null;
|
|
198
|
+
try { range = pyRange(String(fs.readFileSync(join(wt, "pyproject.toml"))), d.eco); } catch { /* no pyproject */ }
|
|
199
|
+
if (!range) return null;
|
|
200
|
+
const probe = async (cmd) => {
|
|
201
|
+
try {
|
|
202
|
+
const version = String(await exec(cmd, ["--version"], { timeoutMs: 30000 })).trim();
|
|
203
|
+
const m = /(\d+)\.(\d+)(?:\.(\d+))?/.exec(version);
|
|
204
|
+
return m ? { cmd, version, v: [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] } : null;
|
|
205
|
+
} catch { return null; }
|
|
206
|
+
};
|
|
207
|
+
const def = await probe("python3");
|
|
208
|
+
if (def && pySatisfies(range, def.v)) return null;
|
|
209
|
+
const minors = [14, 13, 12, 11, 10, 9, 8];
|
|
210
|
+
for (const x of minors) { const c = await probe(`python3.${x}`); if (c && pySatisfies(range, c.v)) return c; }
|
|
211
|
+
for (const x of minors) {
|
|
212
|
+
let path = "";
|
|
213
|
+
try { path = String(await exec("uv", ["python", "find", `3.${x}`], { timeoutMs: 30000 })).trim().split("\n")[0]; } catch { break; } // no uv
|
|
214
|
+
const c = path ? await probe(path) : null;
|
|
215
|
+
if (c && pySatisfies(range, c.v)) return c;
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function keyOf(wt, d, pkgs, py = null) {
|
|
151
221
|
const h = createHash("sha256").update(`v1\0${d.eco}\0${process.platform}-${process.arch}\0`);
|
|
152
222
|
if (d.dir) h.update(`${d.dir}\0`);
|
|
153
|
-
h.update(await runtime(JS.has(d.eco) ? "node" : "python3")).update("\0");
|
|
223
|
+
h.update(py ? py.version : await runtime(JS.has(d.eco) ? "node" : "python3")).update("\0");
|
|
154
224
|
const files = JS.has(d.eco) ? [d.lock, ...pkgs, "pnpm-workspace.yaml", ".npmrc", ".yarnrc.yml"] : [d.lock, "pyproject.toml", ".python-version"];
|
|
155
225
|
for (const f of files) {
|
|
156
226
|
h.update(`${f}\0`);
|
|
@@ -196,6 +266,12 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
196
266
|
fs.chmodSync(dp, fs.statSync(sp).mode & 0o7777);
|
|
197
267
|
}
|
|
198
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Package-manager state at the top of a node_modules tree (pnpm's .modules.yaml, .pnpm/lock.yaml, workspace state; npm's and
|
|
271
|
+
* yarn's hidden lockfiles) that the repair pass rewrites in place (#5574): lanes get a writable copy, never the read-only
|
|
272
|
+
* shared inode, or the open-for-write fails with EACCES and the lane falls back to a full install.
|
|
273
|
+
*/
|
|
274
|
+
const mutableState = (rel, name) => (rel === "" && /^\.(modules\.yaml|pnpm-workspace-state.*\.json|package-lock\.json|yarn-state\.yml)$/.test(name)) || (rel === ".pnpm" && name === "lock.yaml");
|
|
199
275
|
/** Hardlink `src` into `dst` (copy on EXDEV); symlinks recreated; files in bin dirs that name `from` are copied with `to` instead. */
|
|
200
276
|
function linkTree(src, dst, { from = null, to = null, binDir = () => false } = {}) {
|
|
201
277
|
const re = from && to && from !== to ? boundary(from) : null;
|
|
@@ -215,7 +291,10 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
215
291
|
continue;
|
|
216
292
|
}
|
|
217
293
|
}
|
|
218
|
-
|
|
294
|
+
if (mutableState(rel, ent.name)) {
|
|
295
|
+
fs.copyFileSync(sp, dp);
|
|
296
|
+
fs.chmodSync(dp, fs.statSync(sp).mode & 0o7777 | 0o200);
|
|
297
|
+
} else linkOrCopy(sp, dp);
|
|
219
298
|
}
|
|
220
299
|
}
|
|
221
300
|
};
|
|
@@ -234,6 +313,20 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
234
313
|
const binDirFor = (d) => (JS.has(d.eco) ? (rel) => rel.split("/").includes(".bin") : (rel) => rel === "bin");
|
|
235
314
|
const rmTrees = (wt, trees) => { for (const t of trees) { try { fs.rmSync(join(wt, t), { recursive: true, force: true }); } catch { /* best effort */ } } };
|
|
236
315
|
|
|
316
|
+
/** #5590: the existing trees an install did not finish (no marker, a declared dependency missing, a venv without a working python). */
|
|
317
|
+
function brokenTrees(wt, d, trees) {
|
|
318
|
+
return trees.filter((t) => {
|
|
319
|
+
const p = join(wt, t);
|
|
320
|
+
try {
|
|
321
|
+
if (!JS.has(d.eco)) return !fs.existsSync(join(p, "pyvenv.cfg")) || !fs.existsSync(join(p, "bin", "python"));
|
|
322
|
+
if (!JS_MARKERS.some((m) => fs.existsSync(join(p, m)))) return true;
|
|
323
|
+
const pj = JSON.parse(String(fs.readFileSync(join(wt, dirname(t), "package.json"))));
|
|
324
|
+
return Object.keys({ ...pj.dependencies, ...pj.devDependencies }).some((n) => !fs.existsSync(join(p, n)));
|
|
325
|
+
} catch { return true; }
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
const present = (p) => { try { fs.lstatSync(p); return true; } catch { return false; } };
|
|
329
|
+
|
|
237
330
|
function publish(wt, d, key, trees, snap) {
|
|
238
331
|
const tmp = `${snap}.tmp-${pid}`;
|
|
239
332
|
try {
|
|
@@ -255,24 +348,42 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
255
348
|
|
|
256
349
|
async function prepareOne(wt, keyRoot, d, laneEnv) {
|
|
257
350
|
const t0 = now();
|
|
258
|
-
|
|
351
|
+
let repaired = null;
|
|
352
|
+
const done = (status, extra = {}) => ({ status, eco: d.eco, key: extra.key ?? null, ms: now() - t0, reason: extra.reason ?? repaired, ...(extra.published === undefined ? {} : { published: extra.published }) });
|
|
259
353
|
if (d.skip) return done("skipped", { reason: d.skip });
|
|
260
354
|
const pkgs = JS.has(d.eco) ? await manifests(wt) : [];
|
|
261
|
-
const
|
|
355
|
+
const py = await pythonFor(wt, d);
|
|
356
|
+
const key = await keyOf(wt, d, pkgs, py);
|
|
262
357
|
const snap = join(keyRoot, `${d.eco}-${key}`);
|
|
263
|
-
const cmds = commands(d);
|
|
358
|
+
const cmds = commands(d, py);
|
|
264
359
|
const expected = JS.has(d.eco) ? [...new Set(pkgs.map((p) => (dirname(p) === "." ? "node_modules" : `${dirname(p)}/node_modules`)))] : [".venv"];
|
|
265
|
-
const existing = expected.filter((t) =>
|
|
266
|
-
if (existing.length)
|
|
360
|
+
const existing = expected.filter((t) => present(join(wt, t)));
|
|
361
|
+
if (existing.length) {
|
|
362
|
+
const broken = brokenTrees(wt, d, existing);
|
|
363
|
+
if (!broken.length) return done("skipped", { key, reason: `${existing[0]} already exists in the worktree` });
|
|
364
|
+
// #5590: an interrupted or borrowed install is rebuilt, not trusted (the trees go together: a snapshot links all of them).
|
|
365
|
+
rmTrees(wt, existing);
|
|
366
|
+
repaired = `repaired incomplete ${broken[0]}`;
|
|
367
|
+
}
|
|
267
368
|
fs.mkdirSync(keyRoot, { recursive: true, mode: 0o700 });
|
|
268
369
|
|
|
370
|
+
// #5592: `poetry install` fails on a project that is not package-mode (root package not installable): retry once with --no-root (dependencies only).
|
|
371
|
+
const runList = async (list) => {
|
|
372
|
+
for (const [c, a] of list) {
|
|
373
|
+
try { await run(c, a, wt, laneEnv); } catch (e) {
|
|
374
|
+
if (c !== "poetry" || a[0] !== "install" || a.includes("--no-root") || !NO_ROOT_RE.test(`${msg(e)}\n${e?.stderr ?? ""}\n${e?.stdout ?? ""}`)) throw e;
|
|
375
|
+
await run(c, [...a, "--no-root"], wt, laneEnv);
|
|
376
|
+
repaired = repaired ?? "poetry install --no-root (project is not package-mode)";
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
};
|
|
269
380
|
const materialize = async () => {
|
|
270
381
|
let man;
|
|
271
382
|
try { man = JSON.parse(String(fs.readFileSync(join(snap, "manifest.json")))); } catch { return null; }
|
|
272
383
|
const created = [];
|
|
273
384
|
try {
|
|
274
385
|
for (const t of man.trees ?? []) { created.push(t); linkTree(join(snap, t), join(wt, t), { from: man.prefix, to: wt, binDir: binDirFor(d) }); }
|
|
275
|
-
|
|
386
|
+
await runList(cmds.repair ?? []);
|
|
276
387
|
try { fs.writeFileSync(join(snap, "last-used"), String(now())); } catch { /* best effort */ }
|
|
277
388
|
return done("hit", { key });
|
|
278
389
|
} catch (e) {
|
|
@@ -282,7 +393,7 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
282
393
|
}
|
|
283
394
|
};
|
|
284
395
|
const install = async () => {
|
|
285
|
-
try {
|
|
396
|
+
try { await runList(cmds.install); } catch (e) {
|
|
286
397
|
rmTrees(wt, expected);
|
|
287
398
|
return { failed: done("failed", { key, reason: `${e?.code === "ENOENT" ? "tool not found" : "install failed"}: ${msg(e)}` }) };
|
|
288
399
|
}
|
|
@@ -38,7 +38,7 @@ const FIXTURES = {
|
|
|
38
38
|
const LOCKFILE = { pnpm: "pnpm-lock.yaml", npm: "package-lock.json", uv: "uv.lock", poetry: "poetry.lock" };
|
|
39
39
|
|
|
40
40
|
/** Fake package managers: write what a real install leaves behind, including the absolute paths that need rewriting. */
|
|
41
|
-
function fakeExec({ failInstall = false, failRepair = false, installDelayMs = 0 } = {}) {
|
|
41
|
+
function fakeExec({ failInstall = false, failRepair = false, installDelayMs = 0, rewriteState = false, pythons = null } = {}) {
|
|
42
42
|
const calls = [];
|
|
43
43
|
const venv = (cwd, lock) => {
|
|
44
44
|
const v = join(cwd, ".venv");
|
|
@@ -59,6 +59,12 @@ function fakeExec({ failInstall = false, failRepair = false, installDelayMs = 0
|
|
|
59
59
|
walk(cwd);
|
|
60
60
|
return out.join("\0");
|
|
61
61
|
}
|
|
62
|
+
if (pythons && /^python/.test(cmd)) {
|
|
63
|
+
if (args[0] === "--version" && pythons[cmd]) return `Python ${pythons[cmd]}\n`;
|
|
64
|
+
throw Object.assign(new Error(`spawn ${cmd} ENOENT`), { code: "ENOENT" });
|
|
65
|
+
}
|
|
66
|
+
if (cmd === "uv" && args[0] === "python") throw Object.assign(new Error("spawn uv ENOENT"), { code: "ENOENT" });
|
|
67
|
+
if (cmd === "poetry" && args[0] === "env") return "";
|
|
62
68
|
if (args[0] === "--version") return cmd === "node" ? "v22.1.0\n" : "Python 3.12.3\n";
|
|
63
69
|
const full = (cmd === "pnpm" && args.includes("--frozen-lockfile") && !args.includes("--offline")) || (cmd === "npm" && args[0] === "ci")
|
|
64
70
|
|| (cmd === "uv" && args[0] === "venv") || (cmd === "poetry" && !existsSync(join(cwd, ".venv")));
|
|
@@ -69,12 +75,18 @@ function fakeExec({ failInstall = false, failRepair = false, installDelayMs = 0
|
|
|
69
75
|
// pnpm prints its errors on stdout; execFile's error then carries an empty stderr (#4522).
|
|
70
76
|
throw Object.assign(new Error("Command failed: pnpm install --frozen-lockfile --offline"), { stderr: "", stdout: "Lockfile is up to date\n ERR_PNPM_TEST_REPAIR some cause\n" });
|
|
71
77
|
}
|
|
72
|
-
if (args.includes("--offline"))
|
|
78
|
+
if (args.includes("--offline")) {
|
|
79
|
+
// The real repair rewrites its state files in place (#5574); a read-only hardlinked inode fails with EACCES.
|
|
80
|
+
if (rewriteState) for (const f of ["node_modules/.modules.yaml", "node_modules/.pnpm/lock.yaml", "packages/a/node_modules/.modules.yaml"]) if (existsSync(join(cwd, f))) writeFileSync(join(cwd, f), "layoutVersion: 5\nrepaired: true\n");
|
|
81
|
+
return ""; // warm repair pass: nothing else to do
|
|
82
|
+
}
|
|
73
83
|
const lock = readFileSync(join(cwd, "pnpm-lock.yaml"), "utf8");
|
|
74
84
|
put(join(cwd, "node_modules/.pnpm/lodash@4/node_modules/lodash/index.js"), `module.exports = ${JSON.stringify(lock)};\n`);
|
|
75
85
|
symlinkSync(".pnpm/lodash@4/node_modules/lodash", join(cwd, "node_modules/lodash"));
|
|
76
86
|
put(join(cwd, "node_modules/.bin/lodash"), `#!/bin/sh\nexport NODE_PATH="${cwd}/node_modules/.pnpm/node_modules"\nexec node "$basedir/../lodash/cli.js"\n`, 0o755);
|
|
77
87
|
put(join(cwd, "node_modules/.modules.yaml"), "layoutVersion: 5\n");
|
|
88
|
+
put(join(cwd, "node_modules/.pnpm/lock.yaml"), "lockfileVersion: 9\n");
|
|
89
|
+
put(join(cwd, "packages/a/node_modules/.modules.yaml"), "layoutVersion: 5\n");
|
|
78
90
|
mkdirSync(join(cwd, "packages/a/node_modules"), { recursive: true });
|
|
79
91
|
symlinkSync("../../../node_modules/.pnpm/lodash@4/node_modules/lodash", join(cwd, "packages/a/node_modules/lodash"));
|
|
80
92
|
return "";
|
|
@@ -227,6 +239,28 @@ describe("depcache (#4220): shared dependency installs keyed by lock hash", () =
|
|
|
227
239
|
assert.equal(r.published, true, "the stale lock was replaced");
|
|
228
240
|
});
|
|
229
241
|
|
|
242
|
+
it("#5574 state files the repair rewrites in place are writable copies; the snapshot and package files stay read-only", async () => {
|
|
243
|
+
const s = setup("pnpm");
|
|
244
|
+
const f2 = fakeExec({ rewriteState: true });
|
|
245
|
+
const cache = makeDepCache({ root: s.root, exec: f2.exec, env: {}, pollMs: 5 });
|
|
246
|
+
const [ra] = await cache.prepare({ wt: s.lane("a"), repoKey: "r" });
|
|
247
|
+
assert.equal(ra.status, "miss-installed", ra.reason);
|
|
248
|
+
const [snap] = snapDirs(s.root, "pnpm");
|
|
249
|
+
const before = snapshotOf(snap);
|
|
250
|
+
const wt = s.lane("b");
|
|
251
|
+
const [rb] = await cache.prepare({ wt, repoKey: "r" });
|
|
252
|
+
assert.equal(rb.status, "hit", rb.reason);
|
|
253
|
+
for (const f of ["node_modules/.modules.yaml", "node_modules/.pnpm/lock.yaml", "packages/a/node_modules/.modules.yaml"]) {
|
|
254
|
+
assert.match(readFileSync(join(wt, f), "utf8"), /repaired: true/, f);
|
|
255
|
+
assert.notEqual(statSync(join(wt, f)).ino, statSync(join(snap, f)).ino, `${f} is a copy, not the snapshot inode`);
|
|
256
|
+
}
|
|
257
|
+
const after = snapshotOf(snap);
|
|
258
|
+
delete before["last-used"]; delete after["last-used"];
|
|
259
|
+
assert.deepEqual(after, before, "the snapshot is untouched");
|
|
260
|
+
const pkg = join(wt, "node_modules/.pnpm/lodash@4/node_modules/lodash/index.js");
|
|
261
|
+
assert.equal(statSync(pkg).ino, statSync(join(snap, "node_modules/.pnpm/lodash@4/node_modules/lodash/index.js")).ino, "package files stay hardlinks");
|
|
262
|
+
});
|
|
263
|
+
|
|
230
264
|
it("#4522 a snapshot whose repair fails falls back to a fresh install outside the lock, keeps the snapshot and records pnpm's stdout error", async () => {
|
|
231
265
|
const s = setup("pnpm");
|
|
232
266
|
const [ra] = await s.cache.prepare({ wt: s.lane("a"), repoKey: "r" });
|
|
@@ -309,7 +343,7 @@ describe("depcache (#4220): shared dependency installs keyed by lock hash", () =
|
|
|
309
343
|
assert.deepEqual((await s.cache.prepare({ wt: empty, repoKey: "r" })).map((r) => [r.status, r.reason]), [["skipped", "no lockfile"]]);
|
|
310
344
|
const y = join(s.base, "yarn"); put(join(y, "package.json"), "{}"); put(join(y, "yarn.lock"), "# yarn"); put(join(y, ".yarnrc.yml"), "yarnPath: x\n");
|
|
311
345
|
assert.equal((await s.cache.prepare({ wt: y, repoKey: "r" }))[0].status, "skipped");
|
|
312
|
-
const pre = s.lane("pre"); put(join(pre, "node_modules/keep.js"), "mine");
|
|
346
|
+
const pre = s.lane("pre"); put(join(pre, "node_modules/keep.js"), "mine"); put(join(pre, "node_modules/.modules.yaml"), "layoutVersion: 5\n"); // a finished install (#5590)
|
|
313
347
|
const [r] = await s.cache.prepare({ wt: pre, repoKey: "r" });
|
|
314
348
|
assert.equal(r.status, "skipped");
|
|
315
349
|
assert.equal(readFileSync(join(pre, "node_modules/keep.js"), "utf8"), "mine");
|
|
@@ -471,3 +505,87 @@ describe("depcache (#5423): nested JS lockfiles", () => {
|
|
|
471
505
|
assert.equal(r.reason, "no lockfile");
|
|
472
506
|
});
|
|
473
507
|
});
|
|
508
|
+
|
|
509
|
+
describe("depcache (#5590): incomplete installs are repaired, Python follows the project's range", () => {
|
|
510
|
+
it("a truncated node_modules is rebuilt; a complete one is still skipped", async () => {
|
|
511
|
+
const { cache, base, f } = setup("pnpm");
|
|
512
|
+
const wt = join(base, "wt", "trunc");
|
|
513
|
+
mkdirSync(wt, { recursive: true });
|
|
514
|
+
FIXTURES.pnpm(wt);
|
|
515
|
+
put(join(wt, "package.json"), '{"name":"web","devDependencies":{"vitest":"1"}}');
|
|
516
|
+
put(join(wt, "node_modules/.modules.yaml"), "layoutVersion: 5\n"); // marker but vitest never landed
|
|
517
|
+
const [r] = await cache.prepare({ wt, repoKey: "repo-trunc" });
|
|
518
|
+
assert.notEqual(r.status, "skipped", JSON.stringify(r));
|
|
519
|
+
assert.match(r.reason ?? "", /repaired incomplete node_modules/);
|
|
520
|
+
assert.ok(f.installs().length > 0, "a repair pass or install ran");
|
|
521
|
+
assert.ok(existsSync(join(wt, "node_modules/lodash")), "tree rebuilt");
|
|
522
|
+
put(join(wt, "node_modules/vitest/package.json"), "{}");
|
|
523
|
+
const calls = f.installs().length;
|
|
524
|
+
const [r2] = await cache.prepare({ wt, repoKey: "repo-trunc" });
|
|
525
|
+
assert.equal(r2.status, "skipped", JSON.stringify(r2));
|
|
526
|
+
assert.equal(f.installs().length, calls, "a complete tree runs nothing");
|
|
527
|
+
});
|
|
528
|
+
it("a venv with a dangling python is rebuilt", async () => {
|
|
529
|
+
const { cache, base } = setup("poetry");
|
|
530
|
+
const wt = join(base, "wt", "venv");
|
|
531
|
+
mkdirSync(wt, { recursive: true });
|
|
532
|
+
FIXTURES.poetry(wt);
|
|
533
|
+
put(join(wt, ".venv/pyvenv.cfg"), "home = /gone\n");
|
|
534
|
+
mkdirSync(join(wt, ".venv/bin"), { recursive: true });
|
|
535
|
+
symlinkSync("/nonexistent/python3", join(wt, ".venv/bin/python"));
|
|
536
|
+
const [r] = await cache.prepare({ wt, repoKey: "repo-venv" });
|
|
537
|
+
assert.notEqual(r.status, "skipped", JSON.stringify(r));
|
|
538
|
+
assert.ok(existsSync(join(wt, ".venv/bin/python")));
|
|
539
|
+
});
|
|
540
|
+
it("poetry uses the pythonX.Y that satisfies the range, before install, and the key follows it", async () => {
|
|
541
|
+
const pythons = { python3: "3.9.18", "python3.12": "3.12.3" };
|
|
542
|
+
const a = setup("poetry", { pythons }), b = setup("poetry", { pythons: { python3: "3.9.18", "python3.11": "3.11.8" } });
|
|
543
|
+
const res = [];
|
|
544
|
+
for (const s of [a, b]) {
|
|
545
|
+
const wt = s.lane("x");
|
|
546
|
+
put(join(wt, "pyproject.toml"), '[tool.poetry.dependencies]\npython = "^3.11"\n');
|
|
547
|
+
res.push((await s.cache.prepare({ wt, repoKey: "repo-py" }))[0]);
|
|
548
|
+
}
|
|
549
|
+
const cmds = a.f.installs().map((c) => `${c.cmd} ${c.args.join(" ")}`);
|
|
550
|
+
assert.deepEqual(cmds.slice(0, 2), ["poetry env use python3.12", "poetry install --sync"]);
|
|
551
|
+
assert.notEqual(res[0].key, res[1].key, "the chosen interpreter is part of the key");
|
|
552
|
+
});
|
|
553
|
+
it("a default python3 inside the range, or no declared range, changes nothing", async () => {
|
|
554
|
+
const { cache, lane, f } = setup("poetry", { pythons: { python3: "3.12.3" } });
|
|
555
|
+
const wt = lane("in");
|
|
556
|
+
put(join(wt, "pyproject.toml"), '[project]\nrequires-python = ">=3.11,<3.13"\n');
|
|
557
|
+
await cache.prepare({ wt, repoKey: "repo-in" });
|
|
558
|
+
assert.ok(!f.calls.some((c) => c.args[0] === "env"));
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
describe("depcache (#5592 3c): poetry --no-root fallback", () => {
|
|
563
|
+
it("a poetry install that cannot install the root package is retried with --no-root", async () => {
|
|
564
|
+
const f = fakeExec();
|
|
565
|
+
const tried = [];
|
|
566
|
+
const exec = async (cmd, args, o) => {
|
|
567
|
+
if (cmd === "poetry" && args[0] === "install") {
|
|
568
|
+
tried.push(args.join(" "));
|
|
569
|
+
if (!args.includes("--no-root")) throw Object.assign(new Error("failed"), { stderr: "Error: The current project could not be installed: No file/folder found for package proj\nIf you do not want to install the current project use --no-root." });
|
|
570
|
+
}
|
|
571
|
+
return f.exec(cmd, args, o);
|
|
572
|
+
};
|
|
573
|
+
const base = scratch(), wt = join(base, "wt"); mkdirSync(wt, { recursive: true }); FIXTURES.poetry(wt);
|
|
574
|
+
const cache = makeDepCache({ root: join(base, "cache"), exec, env: {}, pollMs: 5 });
|
|
575
|
+
const [r] = await cache.prepare({ wt, repoKey: "repo-noroot" });
|
|
576
|
+
assert.equal(r.status, "miss-installed", JSON.stringify(r));
|
|
577
|
+
assert.deepEqual(tried, ["install --sync", "install --sync --no-root"]);
|
|
578
|
+
});
|
|
579
|
+
it("an unrelated poetry failure is not retried", async () => {
|
|
580
|
+
const tried = [];
|
|
581
|
+
const exec = async (cmd, args) => {
|
|
582
|
+
if (cmd === "poetry" && args[0] === "install") { tried.push(args.join(" ")); throw Object.assign(new Error("failed"), { stderr: "SolverProblemError: no matching version" }); }
|
|
583
|
+
if (args[0] === "--version") return "Python 3.12.3\n";
|
|
584
|
+
return "";
|
|
585
|
+
};
|
|
586
|
+
const base = scratch(), wt = join(base, "wt"); mkdirSync(wt, { recursive: true }); FIXTURES.poetry(wt);
|
|
587
|
+
const [r] = await makeDepCache({ root: join(base, "cache"), exec, env: {}, pollMs: 5 }).prepare({ wt, repoKey: "repo-noroot2" });
|
|
588
|
+
assert.equal(r.status, "failed");
|
|
589
|
+
assert.deepEqual(tried, ["install --sync"]);
|
|
590
|
+
});
|
|
591
|
+
});
|
|
@@ -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
|
+
}
|