forgedock 1.61.2 → 1.62.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 +10 -1
- package/bin/engine/outcome-codes.mjs +4 -0
- package/bin/engine-cli.mjs +159 -17
- package/bin/env/env.mjs +6 -4
- package/bin/forge-home-check.mjs +91 -0
- package/bin/forgedock.mjs +50 -7
- package/bin/gc.mjs +2 -0
- package/bin/hooks/pre-tool-use.mjs +4 -0
- package/bin/journey.mjs +55 -5
- package/bin/lean/admission.mjs +16 -5
- package/bin/lean/batch-health.mjs +55 -16
- package/bin/lean/batch-health.test.mjs +67 -1
- package/bin/lean/batch.mjs +8 -0
- package/bin/lean/batch.test.mjs +5 -0
- package/bin/lean/ceiling.mjs +20 -0
- package/bin/lean/ceiling.test.mjs +33 -2
- package/bin/lean/ci-gate.mjs +240 -0
- package/bin/lean/ci-gate.test.mjs +227 -0
- package/bin/lean/ci-precheck.mjs +178 -0
- package/bin/lean/ci-precheck.test.mjs +149 -0
- package/bin/lean/conformance.mjs +85 -9
- package/bin/lean/conformance.test.mjs +155 -3
- package/bin/lean/context.test.mjs +7 -6
- package/bin/lean/dag.mjs +128 -0
- package/bin/lean/dag.test.mjs +131 -0
- package/bin/lean/decisions.mjs +5 -4
- package/bin/lean/decisions.test.mjs +11 -0
- package/bin/lean/delguard.mjs +84 -0
- package/bin/lean/delguard.test.mjs +104 -0
- package/bin/lean/depcache.mjs +125 -17
- package/bin/lean/depcache.test.mjs +111 -0
- package/bin/lean/design-gate.mjs +5 -5
- package/bin/lean/design-gate.test.mjs +14 -0
- package/bin/lean/effects.mjs +72 -4
- package/bin/lean/execution.mjs +41 -7
- package/bin/lean/execution.test.mjs +99 -3
- package/bin/lean/forgedock-lane-workflow.test.mjs +35 -0
- package/bin/lean/guardgate.mjs +30 -7
- package/bin/lean/guardgate.test.mjs +44 -1
- package/bin/lean/guards.test.mjs +1 -1
- package/bin/lean/heavy.test.mjs +87 -0
- package/bin/lean/hotarea.mjs +73 -0
- package/bin/lean/hotarea.test.mjs +73 -0
- package/bin/lean/issuewatch-reconcile.mjs +20 -1
- package/bin/lean/issuewatch-reconcile.test.mjs +30 -0
- package/bin/lean/lanecheck.mjs +27 -3
- package/bin/lean/lanecheck.test.mjs +47 -5
- package/bin/lean/laneconfine.mjs +83 -0
- package/bin/lean/laneconfine.test.mjs +113 -0
- package/bin/lean/lean.mjs +376 -79
- package/bin/lean/lean.test.mjs +710 -22
- package/bin/lean/live-reconcile.mjs +169 -0
- package/bin/lean/live-reconcile.test.mjs +176 -0
- package/bin/lean/orchestrate-envhold.test.mjs +245 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +39 -0
- package/bin/lean/orchestrate.mjs +207 -17
- package/bin/lean/outcomeevidence.mjs +104 -0
- package/bin/lean/outcomeevidence.test.mjs +78 -0
- package/bin/lean/page-capture.mjs +68 -0
- package/bin/lean/page-capture.test.mjs +44 -0
- package/bin/lean/pagegate.mjs +46 -7
- package/bin/lean/pagegate.test.mjs +66 -1
- package/bin/lean/postdeploy-check.mjs +18 -4
- package/bin/lean/postdeploy-check.test.mjs +32 -1
- package/bin/lean/prefilter.mjs +36 -4
- package/bin/lean/prefilter.test.mjs +31 -1
- package/bin/lean/preflight.mjs +22 -0
- package/bin/lean/preflight.test.mjs +19 -1
- package/bin/lean/probe.mjs +18 -0
- package/bin/lean/probe.test.mjs +40 -0
- package/bin/lean/prompts.mjs +40 -3
- package/bin/lean/recovery.test.mjs +20 -0
- package/bin/lean/recurrence.mjs +133 -0
- package/bin/lean/recurrence.test.mjs +99 -0
- package/bin/lean/release-config.mjs +2 -1
- package/bin/lean/release-config.test.mjs +18 -0
- package/bin/lean/release-control.mjs +4 -2
- package/bin/lean/release-control.test.mjs +15 -0
- package/bin/lean/release-merge-hold.mjs +65 -0
- package/bin/lean/release-merge-hold.test.mjs +69 -0
- package/bin/lean/release-review.mjs +26 -9
- package/bin/lean/release-review.test.mjs +53 -0
- package/bin/lean/release-status.mjs +3 -1
- package/bin/lean/release-status.test.mjs +11 -0
- package/bin/lean/release.test.mjs +26 -1
- package/bin/lean/render.mjs +8 -7
- package/bin/lean/routing.mjs +49 -0
- package/bin/lean/routing.test.mjs +54 -1
- package/bin/lean/run-issue-placement.test.mjs +30 -1
- package/bin/lean/sandbox-actions.mjs +121 -0
- package/bin/lean/sandbox-actions.test.mjs +94 -0
- package/bin/lean/sandbox-provider.contract.test.mjs +22 -1
- package/bin/lean/sandbox-remote.mjs +3 -1
- package/bin/lean/schedd-health.mjs +14 -2
- package/bin/lean/schedd-health.test.mjs +13 -0
- package/bin/lean/schedd.mjs +43 -17
- package/bin/lean/schedd.test.mjs +61 -1
- package/bin/lean/toolchain.mjs +16 -6
- package/bin/lean/toolplace.mjs +12 -0
- package/bin/lean/weakguard.mjs +105 -0
- package/bin/lean/weakguard.test.mjs +59 -0
- package/bin/lean/winspawn.mjs +61 -0
- package/bin/lean/winspawn.test.mjs +45 -0
- package/bin/lean/worktree.mjs +3 -1
- package/bin/lean/worktree.test.mjs +11 -0
- package/bin/pool/agent.mjs +210 -14
- package/bin/pool/cache-sweep.mjs +74 -0
- package/bin/pool/cli.mjs +11 -3
- package/bin/pool/docker.mjs +33 -2
- package/bin/pool/health.mjs +38 -0
- package/bin/pool/lane-tools.mjs +23 -4
- package/bin/pool/lane-tools.test.mjs +12 -1
- package/bin/pool/router.mjs +21 -3
- package/bin/runner.mjs +37 -0
- package/bin/splash-scene.mjs +356 -0
- package/bin/win-hide-children.mjs +114 -0
- package/commands/orchestrate.md +18 -27
- package/commands/review-pr-agents/infra.md +1 -0
- package/commands/review-pr-staging.md +2 -2
- package/docs/CONFIG.md +60 -3
- package/docs/OUTCOME-CODES.md +3 -0
- package/package.json +1 -1
- package/plugins/forgedock-splash/.claude-plugin/plugin.json +1 -1
- package/plugins/forgedock-splash/README.md +1 -1
- package/plugins/forgedock-splash/hooks/scene.ts +142 -8
- package/pool/README.md +6 -0
- package/pool/image/entrypoint.sh +1 -0
- package/scripts/check-spec-size.sh +3 -1
- package/scripts/gen-splash-scene.mjs +24 -0
- package/scripts/review-staging-pre.sh +8 -3
- package/scripts/review-staging-pre.test.sh +2 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { parseOutcomeEvidenceConfig, touchedAreas, outcomeEvidenceFailures, rawChecksAt } from "./outcomeevidence.mjs";
|
|
6
|
+
|
|
7
|
+
const cfg = parseOutcomeEvidenceConfig({ paths: { triage: "[src/triage/**, src/classify.ts]" }, corpus: { triage: ["corpus/triage/**"] } });
|
|
8
|
+
const have = new Set(["corpus/triage/replay.jsonl"]);
|
|
9
|
+
const exists = (p) => have.has(p);
|
|
10
|
+
const good = { area: "triage", metric: "precision", corpus: "corpus/triage/replay.jsonl", before: 0.81, after: 0.86, better: "higher" };
|
|
11
|
+
const run = (o) => outcomeEvidenceFailures({ cfg, files: ["src/triage/rules.ts"], exists, ...o });
|
|
12
|
+
|
|
13
|
+
test("config: absent, empty or path-less sections are off; globs parse from strings and arrays", () => {
|
|
14
|
+
assert.equal(parseOutcomeEvidenceConfig(undefined), null);
|
|
15
|
+
assert.equal(parseOutcomeEvidenceConfig({}), null);
|
|
16
|
+
assert.equal(parseOutcomeEvidenceConfig({ corpus: { a: "c/**" } }), null);
|
|
17
|
+
assert.deepEqual(cfg, { paths: { triage: ["src/triage/**", "src/classify.ts"] }, corpus: { triage: ["corpus/triage/**"] } });
|
|
18
|
+
assert.deepEqual(outcomeEvidenceFailures({ cfg: null, files: ["src/triage/rules.ts"] }), []);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("an untouched area, a test-only or corpus-only change passes", () => {
|
|
22
|
+
assert.deepEqual(outcomeEvidenceFailures({ cfg, files: ["src/other.ts"], exists }), []);
|
|
23
|
+
assert.deepEqual(outcomeEvidenceFailures({ cfg, files: ["src/triage/rules.test.ts", "corpus/triage/replay.jsonl"], exists }), []);
|
|
24
|
+
assert.deepEqual(touchedAreas(cfg, ["src/classify.ts", "src/x.ts"]), { triage: ["src/classify.ts"] });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("a touched area with no result row fails with the area, files and required shape", () => {
|
|
28
|
+
const f = run({ result: {} });
|
|
29
|
+
assert.equal(f.length, 1);
|
|
30
|
+
assert.equal(f[0].code, "conformance.unimplemented");
|
|
31
|
+
assert.equal(f[0].kind, "outcome_evidence_missing");
|
|
32
|
+
assert.match(f[0].detail, /'triage'/);
|
|
33
|
+
assert.match(f[0].detail, /src\/triage\/rules\.ts/);
|
|
34
|
+
assert.match(f[0].detail, /result\.outcome_evidence/);
|
|
35
|
+
assert.match(f[0].detail, /corpus\/triage\/\*\*/);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("bad rows fail as invalid: no metric, undeclared or absent corpus, non-numeric values, unknown better", () => {
|
|
39
|
+
const kinds = (row) => run({ result: { outcome_evidence: [{ ...good, ...row }] } }).map((x) => `${x.kind}: ${x.detail}`);
|
|
40
|
+
assert.match(kinds({ metric: "" })[0], /outcome_evidence_invalid: .*metric is missing/);
|
|
41
|
+
assert.match(kinds({ corpus: "test/mocks/fake.json" })[0], /not a declared corpus/);
|
|
42
|
+
assert.match(kinds({ corpus: "corpus/triage/missing.jsonl" })[0], /does not exist/);
|
|
43
|
+
assert.match(kinds({ corpus: "" })[0], /corpus is missing/);
|
|
44
|
+
assert.match(kinds({ before: "n/a" })[0], /must be numbers/);
|
|
45
|
+
assert.match(kinds({ after: null })[0], /must be numbers/);
|
|
46
|
+
assert.match(kinds({ better: "up" })[0], /better must be/);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("a worse after fails as regressed; lower-is-better is honoured", () => {
|
|
50
|
+
const f = run({ result: { outcome_evidence: [{ ...good, after: 0.7 }] } });
|
|
51
|
+
assert.deepEqual(f.map((x) => x.kind), ["outcome_evidence_regressed"]);
|
|
52
|
+
assert.match(f[0].detail, /before 0\.81, after 0\.7/);
|
|
53
|
+
assert.deepEqual(run({ result: { outcome_evidence: [{ ...good, metric: "p95_ms", before: 120, after: 90, better: "lower" }] } }), []);
|
|
54
|
+
assert.equal(run({ result: { outcome_evidence: [{ ...good, metric: "p95_ms", before: 90, after: 120, better: "lower" }] } })[0].kind, "outcome_evidence_regressed");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("a good row passes", () => {
|
|
58
|
+
assert.deepEqual(run({ result: { outcome_evidence: [good] } }), []);
|
|
59
|
+
assert.deepEqual(run({ result: { outcome_evidence: [{ ...good, before: "0.5", after: "0.5" }] } }), [], "numeric strings and an unchanged value pass");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("a post-deploy check for a touched area needs a metric baseline, not a string match", () => {
|
|
63
|
+
const contract = { requirements: [{ id: "R3", disposition: "post-deploy", check: "triage-rate" }] };
|
|
64
|
+
const base = { result: { outcome_evidence: [good] }, contract };
|
|
65
|
+
const f = run({ ...base, checks: { "triage-rate": { run: "curl x", pass: "/ok/" } } });
|
|
66
|
+
assert.deepEqual(f.map((x) => x.kind), ["outcome_evidence_baseline_missing"]);
|
|
67
|
+
assert.match(f[0].detail, /R3 post-deploy check 'triage-rate'.*baseline/);
|
|
68
|
+
assert.equal(run({ ...base, checks: { "triage-rate": { run: "x", baseline: { metric: "precision", value: "high" } } } }).length, 1);
|
|
69
|
+
assert.deepEqual(run({ ...base, checks: { "triage-rate": { run: "x", baseline: { metric: "precision", value: 0.81, better: "higher" } } } }), []);
|
|
70
|
+
assert.deepEqual(run({ ...base, checks: {} }), [], "an unknown check id is check_unknown's finding");
|
|
71
|
+
assert.deepEqual(outcomeEvidenceFailures({ cfg, files: ["src/other.ts"], contract, checks: { "triage-rate": { run: "x" } } }), [], "untouched area: no baseline demand");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("rawChecksAt keeps the baseline field and lets later refs win", async () => {
|
|
75
|
+
const files = { base: JSON.stringify({ a: { run: "x" } }), HEAD: JSON.stringify({ a: { run: "y", baseline: { metric: "m", value: 1 } }, b: "z" }) };
|
|
76
|
+
const git = async ([, spec]) => { const ref = spec.split(":")[0]; if (!files[ref]) throw new Error("none"); return files[ref]; };
|
|
77
|
+
assert.deepEqual(await rawChecksAt(git, ["base", "HEAD", "missing"]), { a: { run: "y", baseline: { metric: "m", value: 1 } }, b: { run: "z" } });
|
|
78
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* #5770: the engine-run visual check for public pages. The builder may not install browsers and GitHub has no PR image upload, so after the
|
|
5
|
+
* build the engine runs forge.yaml `pages.capture` (a command on a host or sandbox that already has a browser) for the changed routes, checks
|
|
6
|
+
* every route x viewport file exists and is not blank, uploads them to an engine-owned orphan `forge-visual` ref and returns raw links.
|
|
7
|
+
* The command gets FORGE_PAGE_ROUTES, FORGE_PAGE_VIEWPORTS and FORGE_CAPTURE_DIR and must write `<dir>/<slug>-<viewport>.png`
|
|
8
|
+
* (slug: "/" -> home, "/a/b" -> a-b). All effects (run, stat, git) are injected.
|
|
9
|
+
*/
|
|
10
|
+
import { designOnlyFiles, pageFiles, pageRouteOf } from "./pagegate.mjs";
|
|
11
|
+
|
|
12
|
+
export const VISUAL_REF = "refs/heads/forge-visual";
|
|
13
|
+
export const MIN_SHOT_BYTES = 1000; // a smaller PNG is a blank page
|
|
14
|
+
|
|
15
|
+
export const routeSlug = (route) => String(route).replace(/^\/+|\/+$/g, "").replace(/[^A-Za-z0-9._-]+/g, "-") || "home";
|
|
16
|
+
|
|
17
|
+
/** The URL paths of the changed public pages and design_only pages (#5793); only Next app-router page files have a route. */
|
|
18
|
+
export function changedRoutes(files, cfg, { readFile = null } = {}) {
|
|
19
|
+
return [...new Set([...pageFiles(files, cfg, { readFile }), ...designOnlyFiles(files, cfg)].map(pageRouteOf).filter(Boolean))];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Commit the capture files in `dir` as an orphan tree on VISUAL_REF with git plumbing on a throwaway index (no checkout touched), push it and
|
|
24
|
+
* return {name: rawUrl}. `run({command})` -> {rc, output} is the injected shell; `slug` is owner/repo.
|
|
25
|
+
*/
|
|
26
|
+
export async function publishToRef({ run, dir, files, slug, runId }) {
|
|
27
|
+
const sh = (v) => `'${String(v).replace(/'/g, `'\\''`)}'`;
|
|
28
|
+
const adds = files.map((f) => `GIT_INDEX_FILE="$IDX" git update-index --add --cacheinfo 100644,$(git hash-object -w ${sh(`${dir}/${f.name}`)}),${sh(`${runId}/${f.name}`)}`).join(" && ");
|
|
29
|
+
const command = `set -e; IDX=$(mktemp -u); trap 'rm -f "$IDX"' EXIT; ${adds}; T=$(GIT_INDEX_FILE="$IDX" git write-tree); C=$(git commit-tree "$T" -m ${sh(`visual check ${runId}`)}); git push --force origin "$C:${VISUAL_REF}" >&2; echo "$C"`;
|
|
30
|
+
const r = await run({ command }).then((x) => x?.r ?? x);
|
|
31
|
+
const sha = String(r?.output ?? "").trim().split("\n").pop();
|
|
32
|
+
if (r?.rc !== 0 || !/^[0-9a-f]{40}$/.test(sha)) throw new Error(`git publish exited ${r?.rc}: ${String(r?.output ?? "").trim().split("\n").slice(-2).join(" | ")}`);
|
|
33
|
+
return Object.fromEntries(files.map((f) => [f.name, `https://raw.githubusercontent.com/${slug}/${sha}/${runId}/${f.name}`]));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Capture the visual check. `run({command, env})` -> {rc, output}; `read(path)` -> Buffer|null; `publish(files)` -> {name: url}.
|
|
38
|
+
* Returns {screenshots: [url], errors: [{route, viewport, error}], rows: [{route, urls: {vp: url}}]}.
|
|
39
|
+
*/
|
|
40
|
+
export async function captureVisualCheck({ cfg, routes, dir, run, read, publish }) {
|
|
41
|
+
const vps = cfg?.viewports ?? [390, 1440], out = { screenshots: [], errors: [], rows: [] };
|
|
42
|
+
if (!cfg?.capture || !routes.length) return out;
|
|
43
|
+
const fail = (route, viewport, error) => out.errors.push({ route, viewport, error: String(error).slice(0, 300) });
|
|
44
|
+
let r;
|
|
45
|
+
try { r = await run({ command: cfg.capture, env: { FORGE_PAGE_ROUTES: routes.join(","), FORGE_PAGE_VIEWPORTS: vps.join(","), FORGE_CAPTURE_DIR: dir } }); r = r?.r ?? r; } catch (e) { r = { rc: 127, output: String(e?.message ?? e) }; }
|
|
46
|
+
if (r?.rc !== 0) { fail(null, null, `capture command exited ${r?.rc ?? "?"}: ${String(r?.output ?? "").trim().split("\n").slice(-3).join(" | ")}`); return out; }
|
|
47
|
+
const files = [];
|
|
48
|
+
for (const route of routes) for (const vp of vps) {
|
|
49
|
+
const name = `${routeSlug(route)}-${vp}.png`, buf = await read(`${dir}/${name}`);
|
|
50
|
+
if (!buf) fail(route, vp, "render error: the capture command wrote no screenshot");
|
|
51
|
+
else if (buf.length < MIN_SHOT_BYTES) fail(route, vp, `blank page: screenshot is ${buf.length} bytes`);
|
|
52
|
+
else files.push({ route, vp, name, content: buf });
|
|
53
|
+
}
|
|
54
|
+
if (out.errors.length || !files.length) return out;
|
|
55
|
+
let urls;
|
|
56
|
+
try { urls = await publish(files); } catch (e) { fail(null, null, `upload to ${VISUAL_REF} failed: ${e?.message ?? e}`); return out; }
|
|
57
|
+
for (const route of routes) out.rows.push({ route, urls: Object.fromEntries(files.filter((f) => f.route === route).map((f) => [f.vp, urls[f.name]])) });
|
|
58
|
+
out.screenshots = files.map((f) => urls[f.name]).filter(Boolean);
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The engine-written PR body section; "" without captures. */
|
|
63
|
+
export function visualMarkdown(c, viewports = [390, 1440]) {
|
|
64
|
+
if (!c?.rows?.length) return "";
|
|
65
|
+
const head = `| Route | ${viewports.map((v) => `${v}px`).join(" | ")} |\n| --- | ${viewports.map(() => "---").join(" | ")} |`;
|
|
66
|
+
const rows = c.rows.map((r) => `| \`${r.route}\` | ${viewports.map((v) => (r.urls[v] ? `[${v}px](${r.urls[v]})` : "n/a")).join(" | ")} |`);
|
|
67
|
+
return `## Visual check\nCaptured by the engine (not the builder) at ${viewports.join("px, ")}px.\n\n${head}\n${rows.join("\n")}`;
|
|
68
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, it } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { captureVisualCheck, changedRoutes, routeSlug, visualMarkdown } from "./page-capture.mjs";
|
|
4
|
+
|
|
5
|
+
const cfg = { capture: "pw-shots", viewports: [390, 1440] };
|
|
6
|
+
const big = Buffer.alloc(5000, 1);
|
|
7
|
+
const mk = (files, rc = 0) => {
|
|
8
|
+
const calls = [];
|
|
9
|
+
return { calls, run: async (a) => { calls.push(a); return { rc, output: "boom" }; }, read: (p) => files[p.split("/").pop()] ?? null, publish: async (fs) => Object.fromEntries(fs.map((f) => [f.name, `https://x/${f.name}`])) };
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
describe("page-capture (#5770)", () => {
|
|
13
|
+
it("slugs routes and finds changed routes", () => {
|
|
14
|
+
assert.equal(routeSlug("/"), "home");
|
|
15
|
+
assert.equal(routeSlug("/site/removal"), "site-removal");
|
|
16
|
+
assert.deepEqual(changedRoutes(["web/app/bot/page.tsx", "src/a.ts"], { routes: [], exclude: [], design_only: [], generated: [], rewrite_threshold: 0.6 }), ["/bot"]);
|
|
17
|
+
});
|
|
18
|
+
it("#5793: design_only app pages are captured; excluded, test and non-app routes-glob files are not", () => {
|
|
19
|
+
const c = { routes: ["src/routes/**"], exclude: ["web/app/x/**"], design_only: ["web/app/dash/**", "web/app/x/**"], generated: [], rewrite_threshold: 0.6 };
|
|
20
|
+
assert.deepEqual(changedRoutes(["web/app/dash/page.tsx", "web/app/dash/page.test.tsx", "web/app/x/page.tsx", "src/routes/a.tsx"], c), ["/dash"]);
|
|
21
|
+
});
|
|
22
|
+
it("captures every route x viewport, publishes and renders markdown", async () => {
|
|
23
|
+
const m = mk({ "bot-390.png": big, "bot-1440.png": big });
|
|
24
|
+
const c = await captureVisualCheck({ cfg, routes: ["/bot"], dir: "/d", ...m });
|
|
25
|
+
assert.deepEqual(c.errors, []);
|
|
26
|
+
assert.deepEqual(c.screenshots, ["https://x/bot-390.png", "https://x/bot-1440.png"]);
|
|
27
|
+
assert.match(m.calls[0].env.FORGE_PAGE_ROUTES, /\/bot/);
|
|
28
|
+
assert.match(visualMarkdown(c), /## Visual check[\s\S]*\[390px\]\(https:\/\/x\/bot-390\.png\)/);
|
|
29
|
+
});
|
|
30
|
+
it("reports a missing render, a blank page, a failing command and a failed upload as errors", async () => {
|
|
31
|
+
const miss = await captureVisualCheck({ cfg, routes: ["/bot"], dir: "/d", ...mk({ "bot-390.png": big }) });
|
|
32
|
+
assert.match(miss.errors[0].error, /render error/);
|
|
33
|
+
const blank = await captureVisualCheck({ cfg, routes: ["/bot"], dir: "/d", ...mk({ "bot-390.png": Buffer.alloc(10), "bot-1440.png": big }) });
|
|
34
|
+
assert.match(blank.errors[0].error, /blank page/);
|
|
35
|
+
const rc = await captureVisualCheck({ cfg, routes: ["/bot"], dir: "/d", ...mk({}, 1) });
|
|
36
|
+
assert.match(rc.errors[0].error, /exited 1/);
|
|
37
|
+
const up = await captureVisualCheck({ cfg, routes: ["/bot"], dir: "/d", ...mk({ "bot-390.png": big, "bot-1440.png": big }), publish: async () => { throw new Error("no push"); } });
|
|
38
|
+
assert.match(up.errors[0].error, /upload.*no push/);
|
|
39
|
+
assert.equal(visualMarkdown(up), "");
|
|
40
|
+
});
|
|
41
|
+
it("is inert without pages.capture", async () => {
|
|
42
|
+
assert.deepEqual((await captureVisualCheck({ cfg: { viewports: [390] }, routes: ["/a"], dir: "/d", ...mk({}) })).errors, []);
|
|
43
|
+
});
|
|
44
|
+
});
|
package/bin/lean/pagegate.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* #5428: the page gate. A diff that adds or changes a public page needs an approved design (FORGE:DESIGN_SPEC), an SEO intent/ICP brief
|
|
5
5
|
* and a GEO brief in the contract (`page_gate`), and passes deterministic checks (sitemap, metadata, canonical, structured data, internal
|
|
6
6
|
* links, forbidden raw-JSON/null-sample patterns). forge.yaml `pages: {enabled, routes, icp_doc, require, sitemap, metadata_patterns,
|
|
7
|
-
* canonical_patterns, structured_data_patterns, forbid_patterns, lint}`. On by default only for repos with Next `app/**\/page.*` files;
|
|
7
|
+
* canonical_patterns, structured_data_patterns, forbid_patterns, lint, capture, viewports}`. On by default only for repos with Next `app/**\/page.*` files;
|
|
8
8
|
* `enabled: false` or no pages = off. Deterministic, 0 LLM calls; core stays repo-agnostic (#1347), like docsgate.mjs.
|
|
9
9
|
*/
|
|
10
10
|
import { OUTCOME_CODES } from "../engine/outcome-codes.mjs";
|
|
@@ -42,6 +42,9 @@ export function parsePagesConfig(raw, { hasAppPages = false } = {}) {
|
|
|
42
42
|
sitemap: pick(obj.sitemap, DEFAULTS.sitemap).map(norm), metadata_patterns: pick(obj.metadata_patterns, DEFAULTS.metadata),
|
|
43
43
|
canonical_patterns: pick(obj.canonical_patterns, DEFAULTS.canonical), structured_data_patterns: pick(obj.structured_data_patterns, DEFAULTS.structured),
|
|
44
44
|
forbid_patterns: pick(obj.forbid_patterns, DEFAULTS.forbid), lint: typeof obj.lint === "string" && obj.lint.trim() ? obj.lint.trim() : null,
|
|
45
|
+
// #5770: the engine-run capture command (renders the changed routes on a browser host) and the viewports it must cover
|
|
46
|
+
capture: typeof obj.capture === "string" && obj.capture.trim() ? obj.capture.trim() : null,
|
|
47
|
+
viewports: (() => { const v = [...new Set(list(obj.viewports).map(Number).filter((n) => Number.isInteger(n) && n > 0))]; return v.length ? v : [390, 1440]; })(),
|
|
45
48
|
};
|
|
46
49
|
}
|
|
47
50
|
|
|
@@ -81,12 +84,39 @@ function changedByFile(diff) {
|
|
|
81
84
|
return out;
|
|
82
85
|
}
|
|
83
86
|
|
|
87
|
+
/** Added and removed lines per file, kept apart (in diff order). */
|
|
88
|
+
function signedByFile(diff) {
|
|
89
|
+
const out = {}; let cur = null;
|
|
90
|
+
for (const line of String(diff ?? "").split("\n")) {
|
|
91
|
+
if (line.startsWith("+++ ")) { cur = line.replace(/^\+\+\+ (?:b\/)?/, "").trim(); if (cur === "/dev/null") cur = null; continue; }
|
|
92
|
+
if (line.startsWith("--- ")) continue;
|
|
93
|
+
if (cur && (line.startsWith("+") || line.startsWith("-"))) (out[cur] ??= { add: [], del: [] })[line[0] === "+" ? "add" : "del"].push(line.slice(1));
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
const VALUE_ATTR_RE = /\b(href|src|alt|target|rel|title|aria-[\w-]+)\s*=\s*(?:"[^"]*"|'[^']*'|\{[^{}]*\})/g;
|
|
98
|
+
const skeleton = (l) => l.replace(VALUE_ATTR_RE, "$1=_").replace(/\s+/g, " ").trim();
|
|
99
|
+
/** #5729: true when every markup line changed only the VALUE of an href/src/alt/target/rel/title/aria-* attribute (same tags, same classes, no import/export). */
|
|
100
|
+
const tagsOf = (l) => (l.match(/<\/?[A-Za-z][\w.]*|\/>/g) ?? []).join(" ");
|
|
101
|
+
/** `bugFix` (the issue is labelled bug/P0/P1): any attribute edit, class and style included, counts while no tag is added or removed. */
|
|
102
|
+
function attributeValueOnly(c, bugFix = false) {
|
|
103
|
+
const a = (c?.add ?? []).filter((l) => MARKUP_RE.test(l)), d = (c?.del ?? []).filter((l) => MARKUP_RE.test(l));
|
|
104
|
+
if (!a.length || a.length !== d.length || [...a, ...d].some((l) => /^\s*(?:import|export)\b/.test(l))) return false;
|
|
105
|
+
return a.every((l, i) => (bugFix ? tagsOf(l) === tagsOf(d[i]) : skeleton(l) === skeleton(d[i])));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** #5729: true when every row is a spec or visual-evidence row a builder resume cannot satisfy (needs /design or a browser the builder may not install). */
|
|
109
|
+
export function specOnlyFailures(rows) {
|
|
110
|
+
const kinds = ["page_design_missing", "design_spec_missing", "page_visual_missing"];
|
|
111
|
+
return Array.isArray(rows) && rows.length > 0 && rows.every((r) => kinds.includes(r?.kind));
|
|
112
|
+
}
|
|
113
|
+
|
|
84
114
|
/**
|
|
85
115
|
* #5648: how a diff touches a page file: "generated" (exempt: a generated/ path, a `pages.generated` glob or an @generated header),
|
|
86
116
|
* "new" (added, or unknown: no `added` list or no diff for the file fails closed), "rewrite" (a markup/style/import change, or churn at
|
|
87
117
|
* or over `threshold` of the file) or "copy" (only text or data lines changed: takes the visual-check path, no design spec).
|
|
88
118
|
*/
|
|
89
|
-
export function pageChange(file, { added = null, diff = "", threshold = 0.6, generated = [], readFile = null } = {}) {
|
|
119
|
+
export function pageChange(file, { added = null, diff = "", threshold = 0.6, generated = [], readFile = null, bugFix = false } = {}) {
|
|
90
120
|
const f = norm(file);
|
|
91
121
|
if (GENERATED_RE.test(f) || anyGlob(generated ?? [], f)) return "generated";
|
|
92
122
|
let src = "";
|
|
@@ -95,7 +125,7 @@ export function pageChange(file, { added = null, diff = "", threshold = 0.6, gen
|
|
|
95
125
|
if (!Array.isArray(added) || added.map(norm).includes(f)) return "new";
|
|
96
126
|
const lines = changedByFile(diff)[f];
|
|
97
127
|
if (!lines?.length) return "new";
|
|
98
|
-
if (lines.some((l) => MARKUP_RE.test(l))) return "rewrite";
|
|
128
|
+
if (lines.some((l) => MARKUP_RE.test(l)) && !attributeValueOnly(signedByFile(diff)[f], bugFix)) return "rewrite"; // #5729: an href/prop value edit keeps the tag skeleton: copy
|
|
99
129
|
const total = src ? src.split("\n").length : 0;
|
|
100
130
|
return total && lines.length / total >= threshold ? "rewrite" : "copy";
|
|
101
131
|
}
|
|
@@ -152,6 +182,12 @@ export function addedByFile(diff) {
|
|
|
152
182
|
return out;
|
|
153
183
|
}
|
|
154
184
|
|
|
185
|
+
const SHOT_RE = /^(?:https?:\/\/\S+|[\w@~./+-]+\.(?:png|jpe?g|webp|gif))$/i;
|
|
186
|
+
/** #5770: a screenshot entry is an http(s) link or an image path (never free text); a path must exist when `exists` is given. */
|
|
187
|
+
export const isShotRef = (s, exists = null) => SHOT_RE.test(s) && (/^https?:/i.test(s) || !exists || Boolean(exists(s)));
|
|
188
|
+
/** The configured viewports no valid screenshot entry names. */
|
|
189
|
+
export const viewportsMissing = (shots, viewports, exists = null) => viewports.filter((v) => !shots.some((s) => isShotRef(s, exists) && new RegExp(`(?:^|\\D)${v}(?:\\D|$)`).test(s)));
|
|
190
|
+
|
|
155
191
|
/** URL path served by a Next page file, or null. */
|
|
156
192
|
export function pageRouteOf(file) {
|
|
157
193
|
const m = /(?:^|\/)app\/(?:(.*)\/)?page\.[cm]?[jt]sx?$/.exec(String(file ?? ""));
|
|
@@ -164,9 +200,9 @@ const LINK_RE = /href\s*=\s*\{?\s*["'`](\/[^"'`#?\s{}$]*)/g;
|
|
|
164
200
|
* Blocking failures (conformance.unimplemented) for the pages a diff adds or changes. `readFile(path)` returns worktree content or "";
|
|
165
201
|
* `tracked` the repo's files; `designApproved` true/false/null (unknown skips); `run({command})` -> {rc, output} for `pages.lint`.
|
|
166
202
|
*/
|
|
167
|
-
export async function pageFailures({ cfg, files = [], diff = "", result = null, readFile = () => "", tracked = null, designApproved = null, run = null, added = null }) {
|
|
203
|
+
export async function pageFailures({ cfg, files = [], diff = "", result = null, readFile = () => "", tracked = null, designApproved = null, run = null, added = null, captures = null, exists = null, bugFix = false, remoteNoCapture = false }) {
|
|
168
204
|
// #5648: generated pages are exempt; a modified copy-only page takes the visual-check path (no spec, no new-page briefs)
|
|
169
|
-
const kind = (f) => pageChange(f, { added, diff, threshold: cfg?.rewrite_threshold, generated: cfg?.generated, readFile });
|
|
205
|
+
const kind = (f) => pageChange(f, { added, diff, threshold: cfg?.rewrite_threshold, generated: cfg?.generated, readFile, bugFix });
|
|
170
206
|
const pages = pageFiles(files, cfg, { readFile }).filter((f) => kind(f) !== "generated"), dOnly = designOnlyFiles(files, cfg).filter((f) => kind(f) !== "generated"), uiFiles = [...pages, ...dOnly];
|
|
171
207
|
if (!cfg || !uiFiles.length) return [];
|
|
172
208
|
const specFiles = uiFiles.filter((f) => kind(f) !== "copy"), briefPages = pages.filter((f) => kind(f) !== "copy");
|
|
@@ -174,8 +210,11 @@ export async function pageFailures({ cfg, files = [], diff = "", result = null,
|
|
|
174
210
|
const row = (kind, detail) => out.push({ code: C, kind, detail });
|
|
175
211
|
if (cfg.require.includes("design")) {
|
|
176
212
|
if (designApproved === false && specFiles.length) row("page_design_missing", `${specFiles.slice(0, 3).join(", ")} is a public page but the issue has no approved FORGE:DESIGN_SPEC: run /design before building`);
|
|
177
|
-
|
|
178
|
-
|
|
213
|
+
// #5770: the engine's capture (screenshots it produced and uploaded) counts like builder evidence; entries must be links or existing paths
|
|
214
|
+
const vps = cfg.viewports?.length ? cfg.viewports : [390, 1440], shots = [...list(j.screenshots), ...list(captures?.screenshots)];
|
|
215
|
+
if (captures?.errors?.length) row("page_visual_failed", `${uiFiles.slice(0, 3).join(", ")}: the engine's visual capture failed: ${captures.errors.slice(0, 5).map((e) => `${e.route ?? "?"}${e.viewport ? `@${e.viewport}` : ""}: ${e.error}`).join("; ")}`);
|
|
216
|
+
// #5729: a remote sandbox with no engine capture cannot render (builders may not install browsers): the shots are the CI/staging render's (`ci` evidence), not a builder claim
|
|
217
|
+
else if (viewportsMissing(shots, vps, exists).length && !(remoteNoCapture && !captures)) row("page_visual_missing", `${uiFiles.slice(0, 3).join(", ")}: page_gate.screenshots must be links or existing paths to a ${vps.join("px and a ")}px visual check attached to the PR (free text does not count)`);
|
|
179
218
|
}
|
|
180
219
|
const all = [...new Set([...(tracked ?? []), ...files].map(norm))];
|
|
181
220
|
if (briefPages.length && cfg.require.includes("seo_intent")) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { parsePagesConfig, pageChange, pageFiles, designOnlyFiles, contractBriefProblems, pageFailures, designSpecApproved, designHold, designLabelApproved } from "./pagegate.mjs";
|
|
5
|
+
import { parsePagesConfig, pageChange, specOnlyFailures, pageFiles, designOnlyFiles, contractBriefProblems, pageFailures, designSpecApproved, designHold, designLabelApproved, isShotRef } from "./pagegate.mjs";
|
|
6
6
|
import { pagePlanNote, domainChecksBlock } from "./prompts.mjs";
|
|
7
7
|
import { pathDomains } from "./review-trigger.mjs";
|
|
8
8
|
import { validateContract, precheck } from "./conformance.mjs";
|
|
@@ -22,6 +22,8 @@ describe("page gate (#5428)", () => {
|
|
|
22
22
|
assert.deepEqual(pageFiles(["web/app/a/page.tsx", "web/app/a/page.test.tsx", "web/app/api/x/route.ts"], cfg), ["web/app/a/page.tsx"]);
|
|
23
23
|
assert.equal(pagePlanNote(null), "");
|
|
24
24
|
assert.match(pagePlanNote(cfg), /page_gate/);
|
|
25
|
+
assert.match(pagePlanNote({ ...cfg, capture: "pw" }), /app\/\*\*\/page[^]*page_gate\.screenshots/);
|
|
26
|
+
assert.doesNotMatch(pagePlanNote(cfg), /engine captures/);
|
|
25
27
|
});
|
|
26
28
|
it("replay at contract time: a page deliverable with no design spec, ICP or GEO brief fails validateContract", () => {
|
|
27
29
|
const c = { deliverables: [{ id: "D1", path: storeFiles[0], change: "x", requirements: ["R1"] }] };
|
|
@@ -149,4 +151,67 @@ describe("copy-only edits to existing pages (#5648)", () => {
|
|
|
149
151
|
assert.deepEqual(contractBriefProblems(c, cfg, { baseFiles: [docs, mig, gen] }), []);
|
|
150
152
|
assert.deepEqual(contractBriefProblems({ deliverables: [{ path: gen }] }, cfg), []);
|
|
151
153
|
});
|
|
154
|
+
it("#5770: free text is not a screenshot; engine-captured links pass with no builder screenshots; a failed capture is page_visual_failed", async () => {
|
|
155
|
+
const o = { cfg, files, diff, readFile: body, tracked: files, added: [], designApproved: true };
|
|
156
|
+
assert.deepEqual(kinds(await pageFailures({ ...o, result: { page_gate: { screenshots: ["390/1440 per spec"] } } })), ["page_visual_missing"]);
|
|
157
|
+
assert.deepEqual(kinds(await pageFailures({ ...o, result: { page_gate: { screenshots: ["a-390.png", "a-1440.png"] } }, exists: () => false })), ["page_visual_missing"]);
|
|
158
|
+
const captures = { screenshots: ["https://raw.githubusercontent.com/o/r/abc/1/a-390.png", "https://raw.githubusercontent.com/o/r/abc/1/a-1440.png"], errors: [] };
|
|
159
|
+
assert.deepEqual(await pageFailures({ ...o, result: {}, captures }), []);
|
|
160
|
+
const f = await pageFailures({ ...o, result: {}, captures: { screenshots: [], errors: [{ route: "/a", viewport: 390, error: "blank page" }] } });
|
|
161
|
+
assert.deepEqual(kinds(f), ["page_visual_failed"]);
|
|
162
|
+
assert.match(f[0].detail, /blank page/);
|
|
163
|
+
assert.equal(isShotRef("see PR"), false);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe("attribute-only page edits and spec-only failures (#5729)", () => {
|
|
168
|
+
const page = "web/src/app/(site)/contact/page.tsx";
|
|
169
|
+
const body = () => Array.from({ length: 60 }, (_, i) => `line ${i}`).join("\n");
|
|
170
|
+
const d = (del, add) => `+++ b/${page}\n${del.flatMap((l) => l.split("\n")).map((l) => `-${l}`).join("\n")}\n${add.flatMap((l) => l.split("\n")).map((l) => `+${l}`).join("\n")}\n`;
|
|
171
|
+
const o = (diff) => ({ added: [], diff, readFile: body });
|
|
172
|
+
const link = (href, extra = "") => ` <Link href="${href}"${extra} className="btn">Book a demo</Link>`;
|
|
173
|
+
it("href-only edit on a JSX line classifies copy for 5729", () => {
|
|
174
|
+
assert.equal(pageChange(page, o(d([link("https://calendly.com/x")], [link("/contact")]))), "copy");
|
|
175
|
+
assert.equal(pageChange(page, o(d([link("/a", ' target="_self"')], [link("/b", ' target="_blank"')]))), "copy");
|
|
176
|
+
});
|
|
177
|
+
it("a tag, className, attribute or import change stays rewrite", () => {
|
|
178
|
+
assert.equal(pageChange(page, o(d([link("/a")], [`${link("/a")}\n <Badge />`]))), "rewrite");
|
|
179
|
+
assert.equal(pageChange(page, o(d([link("/a")], [link("/a").replace("btn", "btn-lg")]))), "rewrite");
|
|
180
|
+
assert.equal(pageChange(page, o(d([link("/a")], [link("/a", " download")]))), "rewrite");
|
|
181
|
+
assert.equal(pageChange(page, o(d(['import a from "a"'], ['import a from "b"']))), "rewrite");
|
|
182
|
+
});
|
|
183
|
+
it("href-only edit needs no spec", async () => {
|
|
184
|
+
const diff = d([link("/a")], [link("/b")]);
|
|
185
|
+
const f = await pageFailures({ cfg, files: [page], diff, readFile: body, tracked: [page], added: [], designApproved: false });
|
|
186
|
+
assert.ok(!f.some((x) => x.kind === "page_design_missing"));
|
|
187
|
+
});
|
|
188
|
+
it("rewrite with no spec yields one spec failure for 5729", async () => {
|
|
189
|
+
const diff = d([link("/a")], [`${link("/a")}\n <Badge />`]);
|
|
190
|
+
const pf = await pageFailures({ cfg, files: [page], diff, readFile: body, tracked: [page], added: [], designApproved: false });
|
|
191
|
+
const { designFailures } = await import("./design-gate.mjs");
|
|
192
|
+
const dcfg = { system: [], routes: ["web/src/app/**/page.tsx"], exclude: [], gate: "blocking", specLabel: "design:approved", neededLabel: "design:needed", viewports: [390, 1440], requireVisual: true };
|
|
193
|
+
const df = designFailures({ cfg: dcfg, files: [page], added: [], diff, readFile: body, covered: [page] });
|
|
194
|
+
const all = [...pf, ...df];
|
|
195
|
+
assert.equal(all.filter((x) => x.kind === "page_design_missing" || x.kind === "design_spec_missing").length, 1);
|
|
196
|
+
});
|
|
197
|
+
it("spec-only failure rows include page_visual_missing without capture for 5729", async () => {
|
|
198
|
+
const diff = d([link("/a")], [`${link("/a")}\n <Badge />`]);
|
|
199
|
+
const pf = await pageFailures({ cfg, files: [page], diff, readFile: body, tracked: [page], added: [], designApproved: false });
|
|
200
|
+
assert.ok(pf.some((x) => x.kind === "page_visual_missing"));
|
|
201
|
+
assert.equal(specOnlyFailures(pf.filter((x) => ["page_design_missing", "page_visual_missing"].includes(x.kind))), true);
|
|
202
|
+
assert.equal(specOnlyFailures([{ kind: "page_design_missing" }, { kind: "page_metadata_missing" }]), false);
|
|
203
|
+
assert.equal(specOnlyFailures([]), false);
|
|
204
|
+
});
|
|
205
|
+
it("a bug-labelled issue treats a className edit as copy, but never an added tag", () => {
|
|
206
|
+
const cls = d([link("/a")], [link("/a").replace("btn", "btn-lg")]);
|
|
207
|
+
assert.equal(pageChange(page, o(cls)), "rewrite");
|
|
208
|
+
assert.equal(pageChange(page, { ...o(cls), bugFix: true }), "copy");
|
|
209
|
+
assert.equal(pageChange(page, { ...o(d([link("/a")], [`${link("/a")}\n <Badge />`])), bugFix: true }), "rewrite");
|
|
210
|
+
});
|
|
211
|
+
it("a remote sandbox with no engine capture does not demand a builder screenshot claim; a failed capture still fails", async () => {
|
|
212
|
+
const diff = d([link("/a")], [link("/b")]), a = { cfg, files: [page], diff, readFile: body, tracked: [page], added: [], designApproved: true };
|
|
213
|
+
assert.ok((await pageFailures(a)).some((x) => x.kind === "page_visual_missing"));
|
|
214
|
+
assert.ok(!(await pageFailures({ ...a, remoteNoCapture: true })).some((x) => x.kind === "page_visual_missing"));
|
|
215
|
+
assert.ok((await pageFailures({ ...a, remoteNoCapture: true, captures: { screenshots: [], errors: [{ route: "/contact", error: "blank" }] } })).some((x) => x.kind === "page_visual_failed"));
|
|
216
|
+
});
|
|
152
217
|
});
|
|
@@ -25,8 +25,10 @@ const ITEM_RE = /^\s*[-*]\s+\[[ xX]\]\s+(.*)$/;
|
|
|
25
25
|
const CHECK_TOKEN_RE = /^`[^`]*`\s+(?:\*\*known-flaw\*\*\s+)?[—-]+\s*post-deploy:\s*\[check:\s*([^\]\s]*)\s*\]/;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* The checks file's runnable entries `{id: {run, pass, timeoutS, forMs?, everyMs?}}`; malformed input or entries are dropped.
|
|
28
|
+
* The checks file's runnable entries `{id: {run, pass, timeoutS, forMs?, everyMs?, expect?}}`; malformed input or entries are dropped.
|
|
29
29
|
* `for` (a window such as "7d") makes the check windowed (#4627); `every` (default 6h) is its cadence and needs a `for`.
|
|
30
|
+
* #5704: `expect` (optional) is a positive-evidence command that must also exit 0, so an "absence of alert" `run` also proves
|
|
31
|
+
* the new rule or config is loaded; a non-string or blank `expect` drops the entry.
|
|
30
32
|
*/
|
|
31
33
|
export function parseChecks(text) {
|
|
32
34
|
let j;
|
|
@@ -48,7 +50,8 @@ export function parseChecks(text) {
|
|
|
48
50
|
const win = spec.for == null ? null : parseMinAge(spec.for);
|
|
49
51
|
const cad = spec.every == null ? null : parseMinAge(spec.every);
|
|
50
52
|
if ((spec.for != null && !win) || (spec.every != null && !cad) || (spec.every != null && spec.for == null)) continue;
|
|
51
|
-
|
|
53
|
+
if (spec.expect != null && (typeof spec.expect !== "string" || !spec.expect.trim())) continue;
|
|
54
|
+
out[id] = { run: spec.run.trim(), pass, timeoutS: t == null ? null : Math.min(Math.floor(t) || 1, MAX_TIMEOUT_S), ...(win ? { forMs: win, everyMs: cad ?? DEFAULT_EVERY_MS } : {}), ...(spec.expect != null ? { expect: spec.expect.trim() } : {}) };
|
|
52
55
|
}
|
|
53
56
|
return out;
|
|
54
57
|
}
|
|
@@ -70,11 +73,22 @@ export async function checksAt(git, refs, cwd) {
|
|
|
70
73
|
|
|
71
74
|
const fenced = (s) => { const f = "`".repeat(Math.max(3, ...[...String(s).matchAll(/`+/g)].map((m) => m[0].length + 1))); return `${f}\n${String(s).trim() || "(no output)"}\n${f}`; };
|
|
72
75
|
|
|
73
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Run each distinct check id with the probe runner (minimal env, timeout, masked output): `[{id, result, exit, ms, output}]`.
|
|
78
|
+
* #5704: an entry with `expect` runs it after a passing `run` (exit 0 required); a failing `expect` fails the check with its output.
|
|
79
|
+
*/
|
|
74
80
|
export async function runNamedChecks({ ids, checks, cwd, config, env, spawn }) {
|
|
75
81
|
const rows = [];
|
|
82
|
+
const opts = () => ({ cwd, env: probeEnv(config.env, env), mask: config.env.map((k) => env[k]), timeoutS: config.timeoutS, ...(spawn ? { spawn } : {}) });
|
|
76
83
|
for (const id of [...new Set(ids)]) {
|
|
77
|
-
const r = await runProbe(checks[id],
|
|
84
|
+
const r = await runProbe(checks[id], opts());
|
|
85
|
+
if (r.result === "pass" && checks[id]?.expect) {
|
|
86
|
+
const e = await runProbe({ run: checks[id].expect, pass: { kind: "exit" }, timeoutS: checks[id].timeoutS }, opts());
|
|
87
|
+
if (e.result !== "pass") { rows.push({ id, result: "fail", exit: e.exit, ms: r.ms + e.ms, output: `expect (positive evidence) failed:
|
|
88
|
+
${e.output}`.slice(-OUTPUT_TAIL) }); continue; }
|
|
89
|
+
rows.push({ id, ...r, ms: r.ms + e.ms });
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
78
92
|
rows.push({ id, ...r });
|
|
79
93
|
}
|
|
80
94
|
return rows;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { e2eCheckFor, mergeCheckEntries, parseChecks, itemCheckIds, measureFollowup, monitorRecord, CHECK_ID_RE, tickItems } from "./postdeploy-check.mjs";
|
|
5
|
+
import { e2eCheckFor, mergeCheckEntries, parseChecks, itemCheckIds, measureFollowup, monitorRecord, CHECK_ID_RE, tickItems, runNamedChecks } from "./postdeploy-check.mjs";
|
|
6
6
|
import { postDeployOnly } from "./prefilter.mjs";
|
|
7
7
|
import { validateContract, applyAmendments, precheck, followupItems } from "./conformance.mjs";
|
|
8
8
|
import { PROBE_MARKER } from "./probe.mjs";
|
|
@@ -335,3 +335,34 @@ describe("generated e2e checks (#5468)", () => {
|
|
|
335
335
|
assert.ok(merged.smoke && merged[a.id]);
|
|
336
336
|
});
|
|
337
337
|
});
|
|
338
|
+
|
|
339
|
+
describe("post-deploy check expect field (#5704)", () => {
|
|
340
|
+
const cfg = { env: [], timeoutS: 30 };
|
|
341
|
+
const spawnBy = (codes, seen = []) => async ({ run }) => { seen.push(run); return { code: codes[run] ?? 0, stdout: `out:${run}`, stderr: "", timedOut: false }; };
|
|
342
|
+
|
|
343
|
+
it("parses an optional expect; entries without it are unchanged; a blank or non-string expect drops the entry", () => {
|
|
344
|
+
const c = parseChecks(JSON.stringify({ quiet: { run: "./no-alert.sh", expect: " ./rule-loaded.sh " }, plain: { run: "./x" }, bad: { run: "./y", expect: "" }, bad2: { run: "./z", expect: 3 } }));
|
|
345
|
+
assert.equal(c.quiet.expect, "./rule-loaded.sh");
|
|
346
|
+
assert.deepEqual(c.plain, { run: "./x", pass: { kind: "exit" }, timeoutS: null });
|
|
347
|
+
assert.ok(!c.bad && !c.bad2);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("a passing run with a failing expect is a fail carrying the expect output; both passing is a pass", async () => {
|
|
351
|
+
const checks = parseChecks(JSON.stringify({ quiet: { run: "./no-alert.sh", expect: "./rule-loaded.sh" } }));
|
|
352
|
+
const seen = [];
|
|
353
|
+
const [f] = await runNamedChecks({ ids: ["quiet"], checks, cwd: "/tmp", config: cfg, env: {}, spawn: spawnBy({ "./rule-loaded.sh": 1 }, seen) });
|
|
354
|
+
assert.equal(f.result, "fail");
|
|
355
|
+
assert.match(f.output, /expect \(positive evidence\) failed[\s\S]*out:\.\/rule-loaded\.sh/);
|
|
356
|
+
assert.deepEqual(seen, ["./no-alert.sh", "./rule-loaded.sh"]);
|
|
357
|
+
const [p] = await runNamedChecks({ ids: ["quiet"], checks, cwd: "/tmp", config: cfg, env: {}, spawn: spawnBy({}) });
|
|
358
|
+
assert.equal(p.result, "pass");
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("a failing run never runs expect; an entry without expect runs once", async () => {
|
|
362
|
+
const seen = [];
|
|
363
|
+
const checks = parseChecks(JSON.stringify({ quiet: { run: "./no-alert.sh", expect: "./rule-loaded.sh" }, plain: "./x" }));
|
|
364
|
+
const rows = await runNamedChecks({ ids: ["quiet", "plain"], checks, cwd: "/tmp", config: cfg, env: {}, spawn: spawnBy({ "./no-alert.sh": 2 }, seen) });
|
|
365
|
+
assert.deepEqual(rows.map((r) => r.result), ["fail", "pass"]);
|
|
366
|
+
assert.deepEqual(seen, ["./no-alert.sh", "./x"]);
|
|
367
|
+
});
|
|
368
|
+
});
|
package/bin/lean/prefilter.mjs
CHANGED
|
@@ -79,6 +79,33 @@ export async function resolveOwnLogins(gh) {
|
|
|
79
79
|
}
|
|
80
80
|
return { logins: [...out], resolved };
|
|
81
81
|
}
|
|
82
|
+
// #5734: the markers whose comments may record a post-deploy outcome, and the wording that says the fix failed in production
|
|
83
|
+
const PROD_MARKER_RE = /FORGE:(?:DECISION|VERIFIED|PROBE)\b/;
|
|
84
|
+
const PROD_RE = /\b(?:prod(?:uction)?|live|deployed|deploy)\b/i;
|
|
85
|
+
const PROD_FAIL_RE = /\b(?:fail(?:s|ed|ing|ures?)?|broken|not\s+fixed|ineffective|regress(?:ed|ion)?|did(?:\s+not|n['’]t)\s+(?:hold|work|fix)|does(?:\s+not|n['’]t)\s+work|still\s+(?:fail\w*|broken|happen\w*|reproduc\w*|occur\w*))\b|(?:^|[^\d.])(?:~\s*)?0(?:\.0+)?\s?%/i;
|
|
86
|
+
const PROD_OK_RE = /\b(?:no\s+longer\s+(?:fail\w*|broken|reproduc\w*)|not\s+failing|(?:fix|issue)\s+(?:holds|held))\b/i;
|
|
87
|
+
/**
|
|
88
|
+
* #5734: the latest trusted (or `own`) comment carrying a FORGE:DECISION, FORGE:VERIFIED or FORGE:PROBE marker that records
|
|
89
|
+
* the fix failing in production (a failed probe, or production wording plus failure wording), unless a later trusted
|
|
90
|
+
* FORGE:VERIFIED without failure wording or a passing probe cleared it. {why, url, excerpt} or null. Deterministic: no agent.
|
|
91
|
+
*/
|
|
92
|
+
export function prodFailureSignal(comments, own = [bareLogin(APP_SLUG)]) {
|
|
93
|
+
const mine = new Set((own ?? []).map(bareLogin));
|
|
94
|
+
let hit = null;
|
|
95
|
+
for (const c of comments ?? []) {
|
|
96
|
+
const body = String(c?.body ?? "");
|
|
97
|
+
if (!PROD_MARKER_RE.test(body) || !(trusted(c) || mine.has(bareLogin(loginOf(c))))) continue;
|
|
98
|
+
const probe = probeResultOf(body);
|
|
99
|
+
const text = noComments(body, " ");
|
|
100
|
+
const failed = probe ? probe.result === "fail" : PROD_RE.test(text) && PROD_FAIL_RE.test(text) && !PROD_OK_RE.test(text);
|
|
101
|
+
if (failed) {
|
|
102
|
+
const line = text.split("\n").map((l) => l.trim()).find((l) => PROD_FAIL_RE.test(l)) ?? text.trim();
|
|
103
|
+
const kind = probe ? "FORGE:PROBE" : /FORGE:VERIFIED/.test(body) ? "FORGE:VERIFIED" : "FORGE:DECISION";
|
|
104
|
+
hit = { why: `${kind} comment by ${loginOf(c) || "unknown"} records the fix failing in production`, url: c?.url ?? null, excerpt: line.replace(/\s+/g, " ").slice(0, 200) };
|
|
105
|
+
} else if (probe?.result === "pass" || (!probe && /FORGE:VERIFIED/.test(body))) hit = null;
|
|
106
|
+
}
|
|
107
|
+
return hit;
|
|
108
|
+
}
|
|
82
109
|
/**
|
|
83
110
|
* #4305: why one green run is no proof for this issue, without an API call: flaky wording or a `flaky` label, or an
|
|
84
111
|
* earlier pre-filter close by the pipeline (the issue is open again, so an operator reopened it). {reason, why} or null.
|
|
@@ -91,11 +118,14 @@ export function flakyReason(iss, own = [bareLogin(APP_SLUG)]) {
|
|
|
91
118
|
// #4399: the latest pipeline FORGE:PROBE result is a fail: the fix did not hold in production, so no already-fixed close
|
|
92
119
|
const probe = (iss.comments ?? []).filter((c) => probeResultOf(c?.body) && (trusted(c) || mine.has(bareLogin(loginOf(c))))).at(-1);
|
|
93
120
|
if (probe && probeResultOf(probe.body).result === "fail") return { reason: "probe-failed", why: "acceptance probe failed after promotion" };
|
|
121
|
+
// #5734: a trusted decision/verification recording the fix failing in production: ancestry is no proof, so no already-fixed close
|
|
122
|
+
const prod = prodFailureSignal(iss.comments, own);
|
|
123
|
+
if (prod) return { reason: "prod-failed", why: prod.why };
|
|
94
124
|
if ((iss.comments ?? []).some((c) => isMarked(c) && (trusted(c) || mine.has(bareLogin(loginOf(c)))))) return { reason: "reopened", why: "reopened after a pre-filter close" };
|
|
95
125
|
return null;
|
|
96
126
|
}
|
|
97
127
|
/** The own logins, looked up only when an otherwise-untrusted marker comment needs them (no call for most issues). */
|
|
98
|
-
const ownFor = async (iss, resolve) => ((iss.comments ?? []).some((c) => (isMarked(c) || probeResultOf(c?.body)) && !trusted(c)) ? resolve() : undefined);
|
|
128
|
+
const ownFor = async (iss, resolve) => ((iss.comments ?? []).some((c) => (isMarked(c) || probeResultOf(c?.body) || PROD_MARKER_RE.test(String(c?.body ?? ""))) && !trusted(c)) ? resolve() : undefined);
|
|
99
129
|
const selfResolver = (selfLogins, gh) => (typeof selfLogins === "function" ? selfLogins : selfLogins ? async () => selfLogins : () => ownLogins(gh));
|
|
100
130
|
|
|
101
131
|
const PATH_RE = /(?:^|[\s`'"(\[])((?:\.{0,2}\/)?(?:[\w@.-]+\/)+[\w@.-]+\.[A-Za-z0-9]{1,8})(?::\d+(?:-\d+)?)?(?=$|[\s`'"),.:;\]])/gm;
|
|
@@ -450,9 +480,11 @@ export async function prefilterIssue({ issue, repo, lane, cwd, io, model = DEFAU
|
|
|
450
480
|
}
|
|
451
481
|
if (gateOnly) return { ...out, detail: "not a gated follow-up" };
|
|
452
482
|
// #4399: an issue reopened by a failed acceptance probe goes to a lane, never back to an already-fixed close
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
483
|
+
// #5734: so does one whose trusted FORGE:DECISION/FORGE:VERIFIED records the merged fix failing in production
|
|
484
|
+
if ((iss.comments ?? []).some((c) => probeResultOf(c?.body)?.result === "fail" || PROD_MARKER_RE.test(String(c?.body ?? "")))) {
|
|
485
|
+
const fr = flakyReason({ comments: iss.comments }, await ownFor(iss, selfResolver(selfLogins, io.gh)));
|
|
486
|
+
if (fr?.reason === "probe-failed") return { ...out, detail: "acceptance probe failed after promotion (FORGE:PROBE): no already-fixed close; lane" };
|
|
487
|
+
if (fr?.reason === "prod-failed") return { ...out, detail: `production failure recorded after the fix (${fr.why}): no already-fixed close; lane` };
|
|
456
488
|
}
|
|
457
489
|
const sig = await collectSignals({ iss, repo, lane, io, cwd, selfLogins });
|
|
458
490
|
// #5152: `completed` for a delivered outcome (CI green again, ALREADY-FIXED); only an INVALID verdict is dropped scope
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { prefilterIssue, flakyReason, makePrefilter, postDeployGate, postDeployOnly, deferredFrom, formatParkedLine, lazyDefaultBranch, ownLogins, resolveOwnLogins, formatPrefilterSummary, claimsFix, ciFailureRun, namedPaths, isTrustedIssueComment, DEFAULT_PREFILTER_MODEL, parseMinAge, itemWindowsMs, landedAt, itemDueMs, hasDecisionItem, deferredFromAll, itemDueAnchors } from "./prefilter.mjs";
|
|
5
|
+
import { prefilterIssue, flakyReason, prodFailureSignal, makePrefilter, postDeployGate, postDeployOnly, deferredFrom, formatParkedLine, lazyDefaultBranch, ownLogins, resolveOwnLogins, formatPrefilterSummary, claimsFix, ciFailureRun, namedPaths, isTrustedIssueComment, DEFAULT_PREFILTER_MODEL, parseMinAge, itemWindowsMs, landedAt, itemDueMs, hasDecisionItem, deferredFromAll, itemDueAnchors } from "./prefilter.mjs";
|
|
6
6
|
import { writeFileSync } from "node:fs";
|
|
7
7
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
8
8
|
import { execFileSync } from "node:child_process";
|
|
@@ -92,6 +92,36 @@ describe("pre-filter (#4123)", () => {
|
|
|
92
92
|
assert.equal(w.runner.length, 0); assert.deepEqual(w.closed, []); assert.deepEqual(w.comments, []);
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
+
it("#5734 a trusted decision recording the merged fix failing in prod blocks the already-fixed close (AlterLab#40650 sequence)", async () => {
|
|
96
|
+
const bot = { author: { login: "rapiercraft-forgedock" }, authorAssociation: "CONTRIBUTOR" };
|
|
97
|
+
const owner = { author: { login: "op" }, authorAssociation: "OWNER" };
|
|
98
|
+
const decision = { ...owner, url: "https://github.com/o/r/issues/12#issuecomment-3",
|
|
99
|
+
body: "<!-- FORGE:DECISION -->\n## Requeue\nPR #90 went live, but Reddit success is still ~0% in production; verified failing in prod. Requeue for a real fix." };
|
|
100
|
+
const verified = (text) => ({ ...bot, body: `<!-- FORGE:VERIFIED abc1234 -->\n${text}` });
|
|
101
|
+
const probe = (result) => ({ ...bot, body: `<!-- FORGE:PROBE -->\n## Acceptance probe: ${result}\n${JSON.stringify({ fix: "abc1234", default_sha: "d", result, exit: result === "pass" ? 0 : 1, ms: 5 })}` });
|
|
102
|
+
// the AlterLab#40650 comment sequence: trajectory of the merged fix, then the requeue decision recording 0% prod success
|
|
103
|
+
const comments = [{ ...bot, body: "<!-- FORGE:TRAJECTORY -->\nmerged at `abc1234`" }, decision];
|
|
104
|
+
const sig = prodFailureSignal(comments);
|
|
105
|
+
assert.ok(sig); assert.match(sig.why, /FORGE:DECISION comment by op records the fix failing in production/); assert.equal(sig.url, decision.url); assert.match(sig.excerpt, /0%/);
|
|
106
|
+
assert.equal(flakyReason({ comments }).reason, "prod-failed");
|
|
107
|
+
// cleared by a later FORGE:VERIFIED or a passing probe; an untrusted author is ignored; a non-failure decision is no signal
|
|
108
|
+
assert.equal(prodFailureSignal([...comments, verified("Deployed probe passed in production.")]), null);
|
|
109
|
+
assert.equal(prodFailureSignal([...comments, probe("pass")]), null);
|
|
110
|
+
assert.ok(prodFailureSignal([...comments, verified("ok"), verified("verified failing in production again")]));
|
|
111
|
+
assert.ok(prodFailureSignal([probe("fail")]));
|
|
112
|
+
assert.equal(prodFailureSignal([{ ...decision, author: { login: "rando" }, authorAssociation: "NONE" }]), null);
|
|
113
|
+
assert.ok(prodFailureSignal([{ ...decision, author: { login: "me" }, authorAssociation: "NONE" }], ["me"]), "an own login is trusted");
|
|
114
|
+
assert.equal(prodFailureSignal([{ ...owner, body: "<!-- FORGE:DECISION -->\nKeep the retry budget at 3." }]), null);
|
|
115
|
+
assert.equal(prodFailureSignal([{ ...owner, body: "Verified failing in prod" }]), null, "no marker, no signal");
|
|
116
|
+
assert.equal(prodFailureSignal([{ ...owner, body: "<!-- FORGE:DECISION -->\nThe fix holds in production; no longer failing." }]), null);
|
|
117
|
+
const w = world({ issues: { 12: { title: "reddit scrape success rate", body: "Acceptance: Reddit success rate above 90% in prod", comments } },
|
|
118
|
+
prs: [{ number: 90, title: "fix: reddit fetch", body: "Fixes #12", url: "https://github.com/o/r/pull/90" }],
|
|
119
|
+
verdict: { verdict: "ALREADY-FIXED", summary: "PR #90 is an ancestor", evidence: ["src/reddit.js:3"] } });
|
|
120
|
+
const r = await pf(w, 12);
|
|
121
|
+
assert.equal(r.closed, false); assert.match(r.detail, /production failure recorded after the fix .*: no already-fixed close; lane/);
|
|
122
|
+
assert.equal(w.runner.length, 0); assert.deepEqual(w.closed, []); assert.deepEqual(w.comments, []);
|
|
123
|
+
});
|
|
124
|
+
|
|
95
125
|
it("a candidate the validator CONFIRMS (or answers without evidence) is not closed", async () => {
|
|
96
126
|
const mk = (verdict) => world({ issues: { 12: { body: "x" } }, prs: [{ number: 90, title: "fix (#12)", body: "" }], verdict });
|
|
97
127
|
for (const v of [{ verdict: "CONFIRMED", evidence: ["src/foo.js:3 still derefs"] }, { verdict: "ALREADY-FIXED", evidence: [] }, null]) {
|