forgedock 1.67.0 → 1.68.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 -0
- package/bin/engine/outcome-codes.mjs +1 -0
- package/bin/engine-cli.mjs +99 -12
- package/bin/engine.mjs +10 -0
- package/bin/forgedock.mjs +17 -1
- package/bin/help-text.mjs +1 -0
- package/bin/lean/admission.mjs +21 -0
- package/bin/lean/admission.test.mjs +30 -0
- package/bin/lean/advisory.test.mjs +25 -10
- package/bin/lean/amendment-schema.mjs +3 -4
- package/bin/lean/attempts.mjs +34 -31
- package/bin/lean/attempts.test.mjs +33 -19
- package/bin/lean/basered.mjs +26 -0
- package/bin/lean/batch-health.mjs +17 -12
- package/bin/lean/batch-health.test.mjs +39 -11
- package/bin/lean/batch.test.mjs +51 -2
- package/bin/lean/ci-gate.mjs +2 -90
- package/bin/lean/ci-gate.test.mjs +1 -127
- package/bin/lean/ci-precheck.mjs +25 -8
- package/bin/lean/ci-precheck.test.mjs +24 -0
- package/bin/lean/clear-breaker.test.mjs +4 -3
- package/bin/lean/commentstate.mjs +10 -5
- package/bin/lean/commentstate.test.mjs +12 -1
- package/bin/lean/conformance.e2e.test.mjs +9 -6
- package/bin/lean/conformance.mjs +56 -196
- package/bin/lean/conformance.test.mjs +40 -376
- package/bin/lean/depcache.mjs +100 -10
- package/bin/lean/depcache.test.mjs +105 -0
- package/bin/lean/docsgate.mjs +0 -32
- package/bin/lean/docsgate.test.mjs +2 -23
- package/bin/lean/effects-cap.test.mjs +9 -1
- package/bin/lean/effects-killtree.test.mjs +35 -0
- package/bin/lean/effects.mjs +42 -24
- package/bin/lean/engine-readmit.test.mjs +35 -0
- package/bin/lean/envgap.mjs +93 -0
- package/bin/lean/envgap.test.mjs +53 -0
- package/bin/lean/execution.mjs +10 -4
- package/bin/lean/execution.test.mjs +12 -0
- package/bin/lean/failure-census.mjs +170 -0
- package/bin/lean/failure-census.test.mjs +59 -0
- package/bin/lean/guardgate.test.mjs +2 -3
- package/bin/lean/heavy.mjs +33 -4
- package/bin/lean/heavy.test.mjs +38 -6
- package/bin/lean/hotarea.mjs +0 -36
- package/bin/lean/hotarea.test.mjs +1 -22
- package/bin/lean/issuewatch-verify.mjs +19 -4
- package/bin/lean/issuewatch.mjs +21 -4
- package/bin/lean/issuewatch.test.mjs +48 -1
- package/bin/lean/lane-audit-gap.mjs +66 -0
- package/bin/lean/lane-audit-gap.test.mjs +59 -0
- package/bin/lean/lane-audit-llm.mjs +5 -0
- package/bin/lean/lane-audit-query.mjs +47 -0
- package/bin/lean/lane-audit-query.test.mjs +44 -0
- package/bin/lean/lane-audit-signatures.mjs +33 -0
- package/bin/lean/lane-audit.mjs +110 -0
- package/bin/lean/lane-audit.test.mjs +97 -0
- package/bin/lean/lane-recovery.test.mjs +33 -0
- package/bin/lean/lanecheck.mjs +5 -3
- package/bin/lean/lanecheck.test.mjs +6 -0
- package/bin/lean/lean.mjs +206 -148
- package/bin/lean/lean.test.mjs +406 -190
- package/bin/lean/limits.mjs +17 -0
- package/bin/lean/limits.test.mjs +15 -1
- package/bin/lean/live-execution.mjs +21 -2
- package/bin/lean/live-execution.test.mjs +39 -0
- package/bin/lean/orchestrate-attempts.test.mjs +17 -9
- package/bin/lean/orchestrate-envhold.test.mjs +47 -0
- package/bin/lean/orchestrate-heldroot.test.mjs +72 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +59 -1
- package/bin/lean/orchestrate-overload-recovery.test.mjs +37 -0
- package/bin/lean/orchestrate-pause.test.mjs +53 -1
- package/bin/lean/orchestrate-reconcile.test.mjs +17 -0
- package/bin/lean/orchestrate-relaunch-gates.test.mjs +57 -0
- package/bin/lean/orchestrate-stacking.test.mjs +10 -0
- package/bin/lean/orchestrate.mjs +188 -33
- package/bin/lean/postdeploy-check.test.mjs +1 -3
- package/bin/lean/precheck.mjs +20 -0
- package/bin/lean/preflight.mjs +100 -11
- package/bin/lean/preflight.test.mjs +44 -4
- package/bin/lean/prompts.mjs +10 -21
- package/bin/lean/recurrence.mjs +6 -148
- package/bin/lean/recurrence.test.mjs +11 -147
- package/bin/lean/release-flakes.mjs +14 -2
- package/bin/lean/release-flakes.test.mjs +17 -1
- package/bin/lean/release-ledger.mjs +19 -1
- package/bin/lean/release-ledger.test.mjs +23 -0
- package/bin/lean/release-preflight.mjs +28 -0
- package/bin/lean/release-preflight.test.mjs +42 -1
- package/bin/lean/release-review.mjs +40 -5
- package/bin/lean/release-review.test.mjs +43 -2
- package/bin/lean/release.mjs +43 -14
- package/bin/lean/release.test.mjs +32 -0
- package/bin/lean/retry.mjs +1 -1
- package/bin/lean/retry.test.mjs +6 -1
- package/bin/lean/rotator.mjs +9 -0
- package/bin/lean/rotator.test.mjs +11 -1
- package/bin/lean/sandbox-remote.mjs +16 -9
- package/bin/lean/schedd.mjs +11 -6
- package/bin/lean/schedd.test.mjs +65 -5
- package/bin/lean/selfreview.mjs +1 -1
- package/bin/lean/statuscomment.mjs +4 -1
- package/bin/lean/validate-catalog.mjs +108 -0
- package/bin/lean/validate-catalog.test.mjs +46 -1
- package/bin/lean/verify.mjs +1 -1
- package/bin/pool/affinity.test.mjs +91 -0
- package/bin/pool/agent.mjs +143 -9
- package/bin/pool/cache-sweep.mjs +31 -10
- package/bin/pool/ci-autoscale.mjs +160 -0
- package/bin/pool/cli.mjs +37 -8
- package/bin/pool/docker.mjs +3 -0
- package/bin/pool/engine-placement.test.mjs +94 -0
- package/bin/pool/lane-target.mjs +41 -0
- package/bin/pool/lane-tools.mjs +7 -2
- package/bin/pool/lane-tools.test.mjs +9 -0
- package/bin/pool/mirror-seed.mjs +15 -11
- package/bin/pool/router.mjs +88 -32
- package/bin/pool/version.mjs +29 -2
- package/bin/review-staging.mjs +11 -3
- package/bin/runner.mjs +59 -11
- package/bin/stats/release.mjs +7 -0
- package/bin/stats/release.test.mjs +20 -0
- package/bin/stats/scorecard.mjs +187 -0
- package/bin/stats/scorecard.test.mjs +89 -0
- package/docs/CONFIG.md +41 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/STATS.md +17 -0
- package/package.json +1 -1
- package/pool/image/Dockerfile +14 -2
- package/pool/image/manifest.json +25 -0
- package/pool/image/mirror.sh +11 -2
- package/pool/install/install-agent.ps1 +11 -4
- package/scripts/ci-local/adapters/github-actions.mjs +8 -0
- package/scripts/ci-local/cli.mjs +1 -1
- package/scripts/ci-local/plan.mjs +3 -2
- package/scripts/ci-local.test.sh +11 -0
- package/scripts/failure-census.mjs +67 -0
- package/scripts/review-finalize.sh +5 -5
- package/scripts/review-finalize.test.sh +8 -1
- package/scripts/verify-phase-trail.sh +11 -0
- package/scripts/verify-phase-trail.test.sh +9 -0
package/bin/lean/hotarea.mjs
CHANGED
|
@@ -35,39 +35,3 @@ export async function acquireHotArea({ gitCommonDir, areas = [], owner, waitMs =
|
|
|
35
35
|
}
|
|
36
36
|
return { ok: true, release, areas: [...new Set(areas)].sort() };
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Each counter's match count at `ref` (git grep -c -E; no checkout). `git(args)` returns stdout and throws on a non-zero
|
|
41
|
-
* exit: git grep exits 1 on no match, so a throw counts as 0.
|
|
42
|
-
* @returns {Promise<Record<string, number>>}
|
|
43
|
-
*/
|
|
44
|
-
export async function countCounters({ git, ref = "HEAD", counters = [] }) {
|
|
45
|
-
const out = {};
|
|
46
|
-
for (const c of counters ?? []) {
|
|
47
|
-
let n = 0;
|
|
48
|
-
try {
|
|
49
|
-
const txt = String(await git(["grep", "-c", "-E", "-e", c.pattern, ref, "--", ...(c.paths?.length ? c.paths : ["."])]));
|
|
50
|
-
for (const line of txt.split("\n")) { const m = /:(\d+)\s*$/.exec(line); if (m) n += Number(m[1]); }
|
|
51
|
-
} catch { n = 0; }
|
|
52
|
-
out[c.name] = n;
|
|
53
|
-
}
|
|
54
|
-
return out;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const okRe = (name) => new RegExp(`counter-ok:\\s*${String(name).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s+\\S`, "i");
|
|
58
|
-
/** True when the contract decisions (or a result decision amendment) carry `counter-ok: <name> <reason>`. */
|
|
59
|
-
export function counterExempt(name, contract, result = null) {
|
|
60
|
-
const re = okRe(name);
|
|
61
|
-
const texts = [...(contract?.decisions ?? []).flatMap((d) => [d?.choice, d?.justification, d?.why]),
|
|
62
|
-
...(Array.isArray(result?.amendments) ? result.amendments : []).filter((a) => a?.kind === "decision").flatMap((a) => [a?.decision?.choice, a?.why])];
|
|
63
|
-
return texts.some((t) => typeof t === "string" && re.test(t));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Failures for every counter that grew from `before` to `after` without an explicit decision. */
|
|
67
|
-
export function counterGrowth({ before = null, after = null, contract = null, result = null } = {}) {
|
|
68
|
-
if (!before || !after) return [];
|
|
69
|
-
return Object.keys(after)
|
|
70
|
-
.filter((name) => Number.isFinite(before[name]) && Number(after[name]) > Number(before[name]) && !counterExempt(name, contract, result))
|
|
71
|
-
.map((name) => ({ code: C.MAINTENANCE_COUNTER_GROWTH, kind: "counter_growth",
|
|
72
|
-
detail: `counter ${name} grew from ${before[name]} to ${after[name]} without a contract decision "counter-ok: ${name} <reason>"` }));
|
|
73
|
-
}
|
|
@@ -4,7 +4,7 @@ import { describe, it } from "node:test";
|
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { existsSync, readdirSync, writeFileSync, mkdirSync } from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
|
-
import { areaOf, acquireHotArea
|
|
7
|
+
import { areaOf, acquireHotArea } from "./hotarea.mjs";
|
|
8
8
|
import { LOCK_DIR } from "./branchlock.mjs";
|
|
9
9
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
10
10
|
|
|
@@ -50,24 +50,3 @@ describe("hot areas (#5751)", () => {
|
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
describe("named counters (#5751)", () => {
|
|
54
|
-
it("countCounters sums git grep -c at a ref; no match counts 0", async () => {
|
|
55
|
-
const calls = [];
|
|
56
|
-
const git = async (a) => { calls.push(a); if (a.includes("NONE")) throw new Error("exit 1"); return "origin/main:src/a.js:3\norigin/main:src/b.js:2\n"; };
|
|
57
|
-
const c = await countCounters({ git, ref: "origin/main", counters: [{ name: "flags", pattern: "FLAG_", paths: ["src/**"] }, { name: "none", pattern: "NONE", paths: [] }] });
|
|
58
|
-
assert.deepEqual(c, { flags: 5, none: 0 });
|
|
59
|
-
assert.deepEqual(calls[0], ["grep", "-c", "-E", "-e", "FLAG_", "origin/main", "--", "src/**"]);
|
|
60
|
-
assert.deepEqual(calls[1].slice(-2), ["--", "."]);
|
|
61
|
-
});
|
|
62
|
-
it("growth fails without a decision and passes with a counter-ok decision", () => {
|
|
63
|
-
const f = counterGrowth({ before: { flags: 5 }, after: { flags: 6 }, contract: { decisions: [] } });
|
|
64
|
-
assert.equal(f.length, 1);
|
|
65
|
-
assert.equal(f[0].code, "maintenance.counter_growth");
|
|
66
|
-
assert.equal(counterGrowth({ before: { flags: 5 }, after: { flags: 6 }, contract: { decisions: [{ choice: "counter-ok: flags one rollout flag, removed in #9" }] } }).length, 0);
|
|
67
|
-
assert.equal(counterGrowth({ before: { flags: 5 }, after: { flags: 6 }, result: { amendments: [{ kind: "decision", decision: { choice: "counter-ok: flags needed" }, why: "x" }] } }).length, 0);
|
|
68
|
-
assert.equal(counterExempt("flags", { decisions: [{ choice: "counter-ok: flags" }] }), false, "a reason is required");
|
|
69
|
-
assert.equal(counterExempt("flags", { decisions: [{ choice: "counter-ok: flagsx because" }] }), false, "another counter's decision does not exempt");
|
|
70
|
-
assert.equal(counterGrowth({ before: { flags: 5 }, after: { flags: 5 } }).length, 0);
|
|
71
|
-
assert.equal(counterGrowth({ before: null, after: { flags: 9 } }).length, 0);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* `CONFORMS`, shadow `would PASS`, or a `review.trigger` skip; an enforced NONCONFORMING/BLOCK/FAIL fails; a shadow
|
|
8
8
|
* `would BLOCK` is advisory, as its label says: the lane merges by design, so it is recorded in the evidence, not reopened); every required check of the
|
|
9
9
|
* lane is green on the merged head; the merge commit is on the lane; no check on the merge commit failed
|
|
10
|
-
* (`forgedock/verify` is report-only; a `cancelled`/`stale` check, superseded by a newer run, is resolved against the newest
|
|
10
|
+
* (a check also red on the first parent is base-red, noted and not blamed on the PR; `forgedock/verify` is report-only; a `cancelled`/`stale` check, superseded by a newer run, is resolved against the newest
|
|
11
11
|
* descendant run of the same check on the lane). A failure reopens the issue with `needs-human` and the evidence; nothing is
|
|
12
12
|
* reverted, a human decides. No LLM calls.
|
|
13
13
|
*/
|
|
@@ -95,7 +95,10 @@ export async function verifyMerge({ gh, repo, lane, issue, comments, requiredChe
|
|
|
95
95
|
ev.push(`PR #${pr.number} merged into ${pr.baseRefName} at ${sha.slice(0, 12) || "?"}`);
|
|
96
96
|
if (pr.baseRefName !== lane) return fail(`PR #${pr.number} targets ${pr.baseRefName}, not ${lane}`, { pr: pr.number });
|
|
97
97
|
if (labelNames(pr).has("review-degraded")) return fail(`PR #${pr.number} merged with an incomplete review (review-degraded)`, { pr: pr.number });
|
|
98
|
-
|
|
98
|
+
let verdict = reviewVerdict(comments);
|
|
99
|
+
if (verdict === null) { // no trusted issue-level record: the PR's own review record (FORGE:REVIEW incl. the trigger-skip note), best effort
|
|
100
|
+
try { verdict = reviewVerdict(JSON.parse(String(await gh(["pr", "view", String(pr.number), "-R", repo, "--json", "comments"])) || "{}").comments ?? []); } catch { verdict = null; }
|
|
101
|
+
}
|
|
99
102
|
if (verdict !== "pass" && verdict !== "shadow-block") return fail(verdict === "block" ? "the latest FORGE:REVIEW did not pass (enforced NONCONFORMING)" : "no trusted FORGE:REVIEW on the issue", { pr: pr.number });
|
|
100
103
|
ev.push(verdict === "pass" ? "FORGE:REVIEW passed" : "FORGE:REVIEW shadow `would BLOCK` (advisory: shadow mode does not enforce; see the review comment)");
|
|
101
104
|
let required = [];
|
|
@@ -122,13 +125,25 @@ export async function verifyMerge({ gh, repo, lane, issue, comments, requiredChe
|
|
|
122
125
|
ev.push(`merge commit is on ${lane}`);
|
|
123
126
|
const post = (await checkStates({ gh, repo, sha })).filter((x) => !REPORT_ONLY_CHECKS.has(x.name));
|
|
124
127
|
const red = post.filter((x) => !OK_STATES.has(x.state) && x.state !== "pending" && !SUPERSEDED_STATES.has(x.state));
|
|
125
|
-
|
|
128
|
+
const baseRed = [];
|
|
129
|
+
if (red.length) { // red on the merge commit counts against the PR only when it was green or absent on the first parent
|
|
130
|
+
let parent = "";
|
|
131
|
+
try { parent = String(await gh(["api", `repos/${repo}/commits/${sha}`, "--jq", ".parents[0].sha"])).trim(); } catch { parent = ""; }
|
|
132
|
+
const before = parent ? await checkStates({ gh, repo, sha: parent }) : [];
|
|
133
|
+
for (const x of red) {
|
|
134
|
+
const b = before.find((c) => c.name === x.name);
|
|
135
|
+
if (b && !OK_STATES.has(b.state) && b.state !== "pending" && !SUPERSEDED_STATES.has(b.state)) baseRed.push(`${x.name}=${x.state} (also ${b.state} on the first parent ${parent.slice(0, 12)})`);
|
|
136
|
+
}
|
|
137
|
+
const own = red.filter((x) => !baseRed.some((l) => l.startsWith(`${x.name}=`)));
|
|
138
|
+
if (own.length) return fail(`${lane} CI red on the merge commit: ${own.map((x) => `${x.name}=${x.state}`).join(", ")}`, { pr: pr.number, sha });
|
|
139
|
+
ev.push(`base-red, not blamed on the PR: ${baseRed.join(", ")}`);
|
|
140
|
+
}
|
|
126
141
|
const sup = await resolveSuperseded({ gh, repo, lane, sha, names: post.filter((x) => SUPERSEDED_STATES.has(x.state)).map((x) => x.name) });
|
|
127
142
|
if (sup.red.length) return fail(`${lane} CI red: a cancelled check on the merge commit was superseded by a failing run: ${sup.red.join(", ")}`, { pr: pr.number, sha });
|
|
128
143
|
ev.push(...sup.green);
|
|
129
144
|
const pending = [...post.filter((x) => x.state === "pending"), ...sup.pending.map((name) => ({ name }))];
|
|
130
145
|
if (pending.length) return { status: "pending", evidence: [...ev, `${lane} CI pending: ${pending.map((x) => x.name).join(", ")}`], pr: pr.number, sha };
|
|
131
|
-
ev.push(post.length ? `${lane} CI green on the merge commit (${post.length} check(s))` : "no CI ran on the merge commit");
|
|
146
|
+
ev.push(baseRed.length ? `${lane} CI otherwise green on the merge commit (${post.length - baseRed.length} check(s))` : post.length ? `${lane} CI green on the merge commit (${post.length} check(s))` : "no CI ran on the merge commit");
|
|
132
147
|
return { status: "verified", evidence: ev, pr: pr.number, sha };
|
|
133
148
|
}
|
|
134
149
|
|
package/bin/lean/issuewatch.mjs
CHANGED
|
@@ -29,6 +29,7 @@ import { APP_SLUG } from "../init-repo.mjs";
|
|
|
29
29
|
import { noComments } from "./render.mjs";
|
|
30
30
|
import { listAssociations } from "./gh-assoc.mjs";
|
|
31
31
|
import { verifyMerge, verifyComment } from "./issuewatch-verify.mjs";
|
|
32
|
+
import { percentile } from "./efficiency.mjs";
|
|
32
33
|
import { DEFAULT_SKIP_LABELS, isPullRequest, searchesPullRequests, skipLabelHit, closingPrIssues, releaseInFlight, watchLiveness, alertDeadWatches, resolveOnPath } from "./issuewatch-parity.mjs";
|
|
33
34
|
|
|
34
35
|
const WATCH_KEYS = ["milestone", "labels", "exclude_labels", "search", "title_regex", "since", "version", "lane", "max_issues", "max_inflight", "until", "mode", "parallel", "include_followups", "postdeploy_rollup", "threshold", "immediate", "max_release_issues", "theme_map", "tracker", "sweep_needs_human", "max_launches", "trust_app", "trust_app_labels", "skip_labels", "release_pause", "max_remediations", "triage.max_per_hour", "triage"];
|
|
@@ -39,7 +40,16 @@ const readFile = (f) => readFileSync(f, "utf8");
|
|
|
39
40
|
const JUDGE_TIMEOUT_MS = 120_000; // a hung `claude --print` must not stall the watch round
|
|
40
41
|
const CLAUDE_MAX_BUFFER = 8 * 1024 * 1024;
|
|
41
42
|
const PENDING_START_MS = 10 * 60000; // #5425: how long a slow `orchestrate` start may take to create its batch before the claims are released
|
|
42
|
-
const VERIFY_WAIT_MS = 60 * 60000; // how long a merge commit's CI may stay pending before verification fails
|
|
43
|
+
const VERIFY_WAIT_MS = 60 * 60000; // floor and fallback of how long a merge commit's CI may stay pending before verification fails
|
|
44
|
+
const VERIFY_WAIT_CAP_MS = 6 * 60 * 60000;
|
|
45
|
+
const VERIFY_WAIT_FACTOR = 3; // window = p90 of recent CI run minutes x this
|
|
46
|
+
|
|
47
|
+
/** Verify window (ms) from recent CI run durations in minutes: p90 x 3, floored at 60 min, capped at 6 h; no history = 60 min. */
|
|
48
|
+
export function verifyWindowMs(minutes) {
|
|
49
|
+
const sorted = (Array.isArray(minutes) ? minutes : []).map(Number).filter((m) => Number.isFinite(m) && m > 0).sort((a, b) => a - b);
|
|
50
|
+
const p90 = percentile(sorted, 0.9);
|
|
51
|
+
return p90 === null ? VERIFY_WAIT_MS : Math.min(VERIFY_WAIT_CAP_MS, Math.max(VERIFY_WAIT_MS, Math.round(p90 * VERIFY_WAIT_FACTOR * 60000)));
|
|
52
|
+
}
|
|
43
53
|
const readJson = (f) => { try { return JSON.parse(readFileSync(f, "utf8")); } catch { return null; } };
|
|
44
54
|
|
|
45
55
|
// ── config ───────────────────────────────────────────────────────────────────────────────────────────────────
|
|
@@ -288,15 +298,18 @@ export function claimIssue(rdir, issue, name) {
|
|
|
288
298
|
} finally { rmdirSync(lock); }
|
|
289
299
|
}
|
|
290
300
|
|
|
291
|
-
/** Verify closed issue `n` (see tick); a pending result waits up to
|
|
301
|
+
/** Verify closed issue `n` (see tick); a pending result waits up to the CI-derived window (verifyWindowMs) from the first attempt. */
|
|
292
302
|
async function verifyClosed({ n, repo, io, state, now, lane }) {
|
|
293
303
|
const comments = JSON.parse(String(await io.gh(["issue", "view", String(n), "-R", repo, "--json", "comments"]))).comments ?? [];
|
|
294
304
|
let r = await verifyMerge({ gh: io.gh, repo, lane, issue: n, comments, ...(io.requiredChecks ? { requiredChecks: io.requiredChecks } : {}) });
|
|
295
305
|
state.verifyFrom = { ...(state.verifyFrom ?? {}) };
|
|
296
306
|
state.verifyFrom[n] ??= now;
|
|
297
307
|
if (r.status === "pending") {
|
|
298
|
-
|
|
299
|
-
|
|
308
|
+
let minutes = null;
|
|
309
|
+
try { minutes = (await io.ciDurations?.(repo, lane)) ?? null; } catch { minutes = null; } // best effort: unreadable = the 60 min floor
|
|
310
|
+
const wait = verifyWindowMs(minutes);
|
|
311
|
+
if (now - state.verifyFrom[n] < wait) return;
|
|
312
|
+
r = { ...r, status: "failed", evidence: [...r.evidence, `FAIL: still unverified after ${Math.round(wait / 60000)} min${wait === VERIFY_WAIT_MS ? "" : " (window from recent CI run p90)"}`] };
|
|
300
313
|
}
|
|
301
314
|
// Side effects first, state last: a failed gh call throws with the issue still closed and in pendingVerify, so the next tick
|
|
302
315
|
// resumes (state.escalation records the finished steps). Reopen is last because only closed issues are revisited.
|
|
@@ -631,6 +644,10 @@ function realIo(repo, env = process.env) {
|
|
|
631
644
|
const gh = ghRunner(execFileSync, (l) => console.error(l));
|
|
632
645
|
const root = batchRoot(env), findNew = (before) => listBatches(root).find((b) => !before.includes(b)) ?? null;
|
|
633
646
|
return { env, gh, now: () => Date.now(), sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
647
|
+
ciDurations: async (r, lane) => { // minutes of the lane's recent completed Actions runs, for the verify window
|
|
648
|
+
const out = String(await gh(["api", `repos/${r}/actions/runs?per_page=100&status=completed&branch=${encodeURIComponent(lane)}`, "--jq", ".workflow_runs[] | [.run_started_at // .created_at, .updated_at] | @tsv"]));
|
|
649
|
+
return out.split("\n").filter(Boolean).map((l) => { const [a, b] = l.split("\t"); return (Date.parse(b) - Date.parse(a)) / 60000; }).filter((m) => m > 0);
|
|
650
|
+
},
|
|
634
651
|
classify: (issues, themes) => { // the one LLM judgment of release mode: issues no theme_map rule classifies
|
|
635
652
|
const prompt = `Classify each GitHub issue into exactly one theme of [${themes.join(", ")}], or "general" when none fits. Reply with only a JSON object {"<number>": "<theme>"}.\n\n${issues.map((i) => `#${i.number} ${i.title}\n${String(i.body ?? "").slice(0, 600)}`).join("\n---\n")}`;
|
|
636
653
|
return JSON.parse(/\{[\s\S]*\}/.exec(execFileSync("claude", ["--print"], { input: prompt, encoding: "utf8", maxBuffer: 8 * 1024 * 1024 }))[0]);
|
|
@@ -22,17 +22,21 @@ const REVIEW_PASS = { author: { login: "rapiercraft-forgedock" }, authorAssociat
|
|
|
22
22
|
* issue has a merged `feat/issue-N-lean` PR into staging with a passing review and green CI unless `prs[n]` / `comments[n]` /
|
|
23
23
|
* `checks[sha]` / `compare` say otherwise.
|
|
24
24
|
*/
|
|
25
|
-
function fakeIo(env, issues, { closed = new Set(), exit = () => 0, bodies = {}, prs = {}, comments = {}, checks = {}, compare = "behind", descendants = {}, failGh = () => false } = {}) {
|
|
25
|
+
function fakeIo(env, issues, { closed = new Set(), exit = () => 0, bodies = {}, prs = {}, comments = {}, prComments = {}, parents = {}, ciDurations = null, checks = {}, compare = "behind", descendants = {}, failGh = () => false } = {}) {
|
|
26
26
|
const calls = [], launched = [], batchOps = [];
|
|
27
27
|
let clock = Date.parse("2026-10-30T00:00:00Z"), nb = 0;
|
|
28
28
|
const io = { env: { FORGEDOCK_WATCH_DIR: env }, calls, launched, batchOps, closed, bodies, prs, comments, checks, tickClock: (ms) => { clock += ms; }, now: () => clock, sleep: async () => {},
|
|
29
29
|
requiredChecks: async () => [],
|
|
30
|
+
...(ciDurations ? { ciDurations: async () => ciDurations } : {}),
|
|
30
31
|
gh: async (a) => {
|
|
31
32
|
calls.push(a);
|
|
32
33
|
if (failGh(a)) throw new Error("gh transient");
|
|
33
34
|
const desc = a[0] === "api" && /\/compare\/([0-9a-f]+)\.\.\.staging/.exec(a[1]); // descendants of a commit, oldest first
|
|
34
35
|
if (desc) return (descendants[desc[1]] ?? []).join("\n");
|
|
35
36
|
if (a[0] === "api" && /\/compare\//.test(a[1])) return compare;
|
|
37
|
+
const par = a[0] === "api" && /\/commits\/([0-9a-f]+)$/.exec(a[1]);
|
|
38
|
+
if (par) return parents[par[1]] ?? "";
|
|
39
|
+
if (a[0] === "pr" && a[1] === "view" && a.includes("comments")) return JSON.stringify({ comments: prComments[a[2]] ?? [] });
|
|
36
40
|
if (a[0] === "api" && /\/commits\/([0-9a-f]+)\/check-runs/.test(a.join(" "))) { const sha = /commits\/([0-9a-f]+)/.exec(a.join(" "))[1]; return (checks[sha] ?? []).map(([n, st, c], i) => `${i + 1}\t${n}\t${st}\t${c ?? ""}`).join("\n"); }
|
|
37
41
|
if (a[0] === "api" && /\/commits\/[0-9a-f]+\/status/.test(a[1])) return "";
|
|
38
42
|
if (a[0] === "api") return issues.filter((i) => !closed.has(i.number)).map((i) => `${i.number}\t${i.authorAssociation}`).join("\n"); // #4859: REST association list
|
|
@@ -400,6 +404,49 @@ test("verify: a review comment from an untrusted author does not count", async (
|
|
|
400
404
|
assert.match(r.posted[0], /no trusted FORGE:REVIEW/);
|
|
401
405
|
});
|
|
402
406
|
|
|
407
|
+
test("verify: base-red check red on first parent and merge commit verifies with base-red evidence", async () => {
|
|
408
|
+
const r = await settleOne({ parents: { bb1: "ee1" }, checks: { bb1: [["lint", "completed", "failure"], ["test", "completed", "success"]], ee1: [["lint", "completed", "failure"]] } });
|
|
409
|
+
assert.deepEqual(r.state.verified, [1]);
|
|
410
|
+
assert.equal(r.reopened || r.escalated, false);
|
|
411
|
+
assert.match(r.posted[0], /merge verified[\s\S]*base-red, not blamed on the PR: lint=failure \(also failure on the first parent ee1\)/);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
test("verify: red on the merge commit but green, absent or unreadable on the first parent still fails", async () => {
|
|
415
|
+
for (const opts of [
|
|
416
|
+
{ parents: { bb1: "ee1" }, checks: { bb1: [["lint", "completed", "failure"]], ee1: [["lint", "completed", "success"]] } },
|
|
417
|
+
{ parents: { bb1: "ee1" }, checks: { bb1: [["lint", "completed", "failure"]], ee1: [["other", "completed", "failure"]] } },
|
|
418
|
+
{ checks: { bb1: [["lint", "completed", "failure"]] } },
|
|
419
|
+
]) {
|
|
420
|
+
const r = await settleOne(opts);
|
|
421
|
+
assert.deepEqual(r.state.unverified, [1]);
|
|
422
|
+
assert.ok(r.reopened && r.escalated);
|
|
423
|
+
assert.match(r.posted[0], /staging CI red on the merge commit: lint=failure/);
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test("verify: no issue FORGE:REVIEW but the PR carries the trigger-skip record verifies; an enforced block there still fails", async () => {
|
|
428
|
+
const skip = { ...REVIEW_PASS, body: "<!-- FORGE:REVIEW -->\n## Conformance Review\n**Skipped by `review.trigger: enforce`:** no risk path." };
|
|
429
|
+
const ok = await settleOne({ comments: { 1: [] }, prComments: { 1001: [skip] } });
|
|
430
|
+
assert.deepEqual(ok.state.verified, [1]);
|
|
431
|
+
assert.equal(ok.reopened, false);
|
|
432
|
+
const bad = await settleOne({ comments: { 1: [] }, prComments: { 1001: [{ ...REVIEW_PASS, body: "<!-- FORGE:REVIEW -->\n**Verdict:** NONCONFORMING" }] } });
|
|
433
|
+
assert.deepEqual(bad.state.unverified, [1]);
|
|
434
|
+
assert.match(bad.posted[0], /did not pass/);
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
test("verify: a slow-but-green run verifies inside the CI-derived window; without history the 60 min fail stays", async () => {
|
|
438
|
+
const r = await settleOne({ checks: { bb1: [["test", "in_progress"]] }, ciDurations: Array(10).fill(40) }, { ticks: 2, gap: 90 * 60000 });
|
|
439
|
+
assert.deepEqual(r.state.pendingVerify, [1]); // 90 min > 60 but < p90 40 x 3 = 120
|
|
440
|
+
r.io.checks.bb1 = [["test", "completed", "success"]];
|
|
441
|
+
await tick({ watch: W({ max_issues: "1" }), repo: "o/r", io: r.io, state: r.state, handles: new Map() });
|
|
442
|
+
assert.deepEqual(r.state.verified, [1]);
|
|
443
|
+
const none = await settleOne({ checks: { bb1: [["test", "in_progress"]] } }, { ticks: 3, gap: 30 * 60000 });
|
|
444
|
+
assert.deepEqual(none.state.unverified, [1]);
|
|
445
|
+
const late = await settleOne({ checks: { bb1: [["test", "in_progress"]] }, ciDurations: Array(10).fill(40) }, { ticks: 3, gap: 60 * 60000 });
|
|
446
|
+
assert.deepEqual(late.state.unverified, [1]);
|
|
447
|
+
assert.match(late.posted.at(-1), /still unverified after 120 min \(window from recent CI run p90\)/);
|
|
448
|
+
});
|
|
449
|
+
|
|
403
450
|
test("verify: review-degraded, wrong base, missing required check, merge commit off the lane, red lane CI each fail", async () => {
|
|
404
451
|
const pr = (o) => ({ 1: [{ number: 1001, baseRefName: "staging", headRefOid: "aa1", mergeCommit: { oid: "bb1" }, labels: [], ...o }] });
|
|
405
452
|
const cases = [
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Gap audit of an active pipeline/env/pool failure (#6078): opt-in (forge.yaml orchestrate.lane_audit.file_gaps, default off) engine-gap issue per signature with a count and the affected lanes.
|
|
2
|
+
export const GAP_CLASSES = Object.freeze(["pipeline", "env", "pool"]);
|
|
3
|
+
export const DEFAULT_GAP = Object.freeze({ fileGaps: false, repo: "RapierCraftStudios/ForgeDock", label: "engine-gap" });
|
|
4
|
+
|
|
5
|
+
/** forge.yaml (parsed) -> gap config; the parser may nest (`orchestrate.lane_audit.x`) or flatten. Only the string "true" enables. */
|
|
6
|
+
export function parseGapConfig(yaml) {
|
|
7
|
+
const o = yaml?.orchestrate && typeof yaml.orchestrate === "object" ? yaml.orchestrate : {};
|
|
8
|
+
const s = { ...o, ...(o.lane_audit && typeof o.lane_audit === "object" ? o.lane_audit : {}) };
|
|
9
|
+
const out = { ...DEFAULT_GAP };
|
|
10
|
+
const f = s.file_gaps ?? s.lane_audit_file_gaps;
|
|
11
|
+
out.fileGaps = f !== undefined && String(f).trim().toLowerCase() === "true";
|
|
12
|
+
const repo = String(s.repo ?? s.lane_audit_repo ?? "").trim();
|
|
13
|
+
if (/^[\w.-]+\/[\w.-]+$/.test(repo)) out.repo = repo;
|
|
14
|
+
const label = String(s.label ?? s.lane_audit_label ?? "").trim();
|
|
15
|
+
if (/^[\w. :-]+$/.test(label)) out.label = label;
|
|
16
|
+
return out;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const esc = (s) => String(s).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
20
|
+
|
|
21
|
+
/** Strip what must not reach the engine repo (#6020): the lane's own repo, any owner/name, absolute paths. */
|
|
22
|
+
export function redactGap(text, { repo = "" } = {}) {
|
|
23
|
+
let t = String(text ?? "");
|
|
24
|
+
const [, name] = String(repo).split("/");
|
|
25
|
+
if (repo) t = t.replace(new RegExp(esc(repo), "gi"), "<repo>");
|
|
26
|
+
if (name && name.length > 2) t = t.replace(new RegExp(`(?<![\\w.-])${esc(name)}(?![\\w.-])`, "gi"), "<repo>");
|
|
27
|
+
t = t.replace(/(?:[A-Za-z]:\\|~\/|\/)[\w.@+~-]+(?:[\\/][\w.@+~ -]*)+/g, "<path>");
|
|
28
|
+
t = t.replace(/(?<![\w.-])[\w.-]+\/[\w.-]+(?![\w.-])/g, "<repo>");
|
|
29
|
+
return t;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const lanesOf = (body) => [...new Set([...(/Affected lanes:\s*([^\n]*)/.exec(body)?.[1] ?? "").matchAll(/#(\d+)/g)].map((m) => Number(m[1])))];
|
|
33
|
+
const render = ({ sig, c, count, lanes, version, repo }) => `<!-- forge-gap: ${sig} -->\n**Engine gap** \`${sig}\`\n\n- Class: ${redactGap(c.class, { repo })}\n- Owner: ${redactGap(c.owner ?? "-", { repo })}\n- Action: ${redactGap(c.action ?? "-", { repo })}\n- Engine version: ${redactGap(version ?? "-", { repo })}\n- Occurrences: ${count}\n- Affected lanes: ${lanes.map((n) => `#${n}`).join(", ")}\n`;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Build the gap seam for runLaneAudit: async (bundle, classified) -> {issue, count, action} | null. Never throws.
|
|
37
|
+
* @param {{gh: Function, cfg?: object, repo?: string}} o
|
|
38
|
+
*/
|
|
39
|
+
export function makeGapAuditor({ gh, cfg = DEFAULT_GAP, repo = "" } = {}) {
|
|
40
|
+
return async (bundle, classified = null) => {
|
|
41
|
+
try {
|
|
42
|
+
const c = classified;
|
|
43
|
+
if (!cfg?.fileGaps || typeof gh !== "function" || !c || !c.active || c.fixed_in_later || !GAP_CLASSES.includes(c.class) || !c.signature) return null;
|
|
44
|
+
const sig = String(c.signature), marker = `<!-- forge-gap: ${sig} -->`, lane = Number(bundle?.issue);
|
|
45
|
+
if (!Number.isSafeInteger(lane)) return null;
|
|
46
|
+
const version = bundle?.stamp?.engine_version ?? null;
|
|
47
|
+
const list = JSON.parse(String(await gh(["issue", "list", "--repo", cfg.repo, "--label", cfg.label, "--state", "open", "--search", `"${sig}" in:body`, "--json", "number,body"])) || "[]");
|
|
48
|
+
const found = list.find((i) => String(i.body ?? "").includes(marker));
|
|
49
|
+
if (found) {
|
|
50
|
+
const lanes = lanesOf(String(found.body));
|
|
51
|
+
if (lanes.includes(lane)) return { issue: found.number, count: lanes.length, action: "unchanged" };
|
|
52
|
+
lanes.push(lane);
|
|
53
|
+
await gh(["issue", "edit", String(found.number), "--repo", cfg.repo, "--body", render({ sig, c, count: lanes.length, lanes, version, repo })]);
|
|
54
|
+
return { issue: found.number, count: lanes.length, action: "update" };
|
|
55
|
+
}
|
|
56
|
+
const out = String(await gh(["issue", "create", "--repo", cfg.repo, "--label", cfg.label, "--title", `engine-gap: ${redactGap(sig, { repo })} (${c.class})`, "--body", render({ sig, c, count: 1, lanes: [lane], version, repo })]));
|
|
57
|
+
const n = Number(out.match(/(\d+)\s*$/)?.[1]);
|
|
58
|
+
return Number.isSafeInteger(n) ? { issue: n, count: 1, action: "create" } : null;
|
|
59
|
+
} catch { return null; }
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Default seam: no gap finding. @param {object} bundle the evidence bundle of lane-audit.mjs @param {object} [classified] the signature match, when any */
|
|
64
|
+
export async function auditGap(bundle, classified = null) { // eslint-disable-line no-unused-vars
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { makeGapAuditor, parseGapConfig, redactGap, auditGap } from "./lane-audit-gap.mjs";
|
|
6
|
+
import { runLaneAudit } from "./lane-audit.mjs";
|
|
7
|
+
|
|
8
|
+
const ON = parseGapConfig({ orchestrate: { lane_audit: { file_gaps: "true" } } });
|
|
9
|
+
const C = { signature: "gh-network-text", class: "env", owner: "engine", action: "retry", fixed_in_later: false, active: true };
|
|
10
|
+
const fakeGh = () => { const issues = [], calls = []; return { issues, calls, gh: async (a) => { calls.push(a);
|
|
11
|
+
if (a[1] === "list") return JSON.stringify(issues.map((i) => ({ number: i.number, body: i.body })));
|
|
12
|
+
if (a[1] === "create") { const i = { number: 90 + issues.length, body: a[a.indexOf("--body") + 1] }; issues.push(i); return `https://github.com/x/y/issues/${i.number}\n`; }
|
|
13
|
+
if (a[1] === "edit") { issues.find((i) => String(i.number) === a[2]).body = a[a.indexOf("--body") + 1]; return ""; }
|
|
14
|
+
return ""; } }; };
|
|
15
|
+
const run = (g, issue, c = C, cfg = ON, repo = "acme/secret-app") => makeGapAuditor({ gh: g.gh, cfg, repo })({ issue, stamp: { engine_version: "1.2.0" } }, c);
|
|
16
|
+
|
|
17
|
+
describe("#6078 gap audit", () => {
|
|
18
|
+
it("is off by default and only the string true enables", async () => {
|
|
19
|
+
assert.equal(parseGapConfig({}).fileGaps, false);
|
|
20
|
+
assert.equal(parseGapConfig({ orchestrate: { lane_audit: { file_gaps: "yes" } } }).fileGaps, false);
|
|
21
|
+
const g = fakeGh();
|
|
22
|
+
assert.equal(await run(g, 1, C, parseGapConfig({})), null);
|
|
23
|
+
assert.equal(g.calls.length, 0);
|
|
24
|
+
assert.equal(await auditGap({}, C), null);
|
|
25
|
+
});
|
|
26
|
+
it("creates one issue, then updates it for a second lane without a second create", async () => {
|
|
27
|
+
const g = fakeGh();
|
|
28
|
+
assert.deepEqual(await run(g, 11), { issue: 90, count: 1, action: "create" });
|
|
29
|
+
assert.deepEqual(await run(g, 12), { issue: 90, count: 2, action: "update" });
|
|
30
|
+
assert.equal(g.calls.filter((a) => a[1] === "create").length, 1);
|
|
31
|
+
assert.match(g.issues[0].body, /Occurrences: 2/); assert.match(g.issues[0].body, /#11, #12/);
|
|
32
|
+
assert.match(g.issues[0].body, /<!-- forge-gap: gh-network-text -->/);
|
|
33
|
+
});
|
|
34
|
+
it("does not double count the same lane", async () => {
|
|
35
|
+
const g = fakeGh(); await run(g, 11);
|
|
36
|
+
assert.deepEqual(await run(g, 11), { issue: 90, count: 1, action: "unchanged" });
|
|
37
|
+
assert.equal(g.calls.filter((a) => a[1] === "edit").length, 0);
|
|
38
|
+
});
|
|
39
|
+
it("files nothing for fixed_in_later, inactive or genuine classes", async () => {
|
|
40
|
+
const g = fakeGh();
|
|
41
|
+
for (const c of [{ ...C, fixed_in_later: true }, { ...C, active: false }, { ...C, class: "genuine" }, { ...C, class: "spec" }, null]) assert.equal(await run(g, 1, c), null);
|
|
42
|
+
assert.equal(g.calls.length, 0);
|
|
43
|
+
});
|
|
44
|
+
it("redacts repo names and paths from the body", async () => {
|
|
45
|
+
const g = fakeGh();
|
|
46
|
+
await run(g, 5, { ...C, action: "see acme/secret-app at /home/bob/work/secret-app/x.mjs" });
|
|
47
|
+
assert.doesNotMatch(g.issues[0].body, /acme|secret-app|\/home/);
|
|
48
|
+
assert.equal(redactGap("acme/secret-app /tmp/x/y", { repo: "acme/secret-app" }), "<repo> <path>");
|
|
49
|
+
assert.equal(redactGap("version 1.2.0 ok", { repo: "a/b" }), "version 1.2.0 ok");
|
|
50
|
+
});
|
|
51
|
+
it("returns null without throwing when gh fails", async () => {
|
|
52
|
+
assert.equal(await run({ gh: async () => { throw new Error("boom"); } }, 1), null);
|
|
53
|
+
});
|
|
54
|
+
it("runLaneAudit stores the gap in the audit", async () => {
|
|
55
|
+
const g = fakeGh(), posts = [];
|
|
56
|
+
const r = await runLaneAudit({ issue: 7, reason: "needs-human", code: "x", detail: "gh: error connecting to api.github.com", comments: [], post: async (m, b) => { posts.push(b); }, gap: makeGapAuditor({ gh: g.gh, cfg: ON, repo: "o/r" }), stamp: { engine_version: "0.0.1", attempt: 1 } });
|
|
57
|
+
assert.equal(r.posted, true); assert.equal(r.audit.gap?.action, "create");
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Seam for the LLM classification of evidence no signature matched (#6079 fills this in). Until then a no-op: null means "unclassified".
|
|
2
|
+
/** @param {object} bundle the evidence bundle of lane-audit.mjs */
|
|
3
|
+
export async function classifyWithLlm(bundle) { // eslint-disable-line no-unused-vars
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Pure query helpers over parsed FORGE:LANE_AUDIT audits (#6077, child of #6072). Read-only consumers of lane-audit.mjs.
|
|
2
|
+
import { compareAuditVersions } from "./lane-audit.mjs";
|
|
3
|
+
|
|
4
|
+
const ver = (a) => a?.stamp?.engine_version ?? null;
|
|
5
|
+
|
|
6
|
+
/** Audits matching every given filter: version (exact), sinceVersion (>=), signature, class (exact). */
|
|
7
|
+
export function filterAudits(audits, { version, sinceVersion, signature, class: cls } = {}) {
|
|
8
|
+
return (audits ?? []).filter((a) => {
|
|
9
|
+
if (version != null && ver(a) !== version) return false;
|
|
10
|
+
if (sinceVersion != null && !(compareAuditVersions(ver(a), sinceVersion) >= 0)) return false;
|
|
11
|
+
if (signature != null && a.signature !== signature) return false;
|
|
12
|
+
if (cls != null && a.class !== cls) return false;
|
|
13
|
+
return true;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The highest engine_version among the audits (null when none is a version). */
|
|
18
|
+
export function highestVersion(audits) {
|
|
19
|
+
let best = null;
|
|
20
|
+
for (const a of audits ?? []) {
|
|
21
|
+
const v = ver(a);
|
|
22
|
+
if (compareAuditVersions(v, v) === null) continue;
|
|
23
|
+
if (best === null || compareAuditVersions(v, best) === 1) best = v;
|
|
24
|
+
}
|
|
25
|
+
return best;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Active findings of the current version, per signature: [{signature, class, count, lanes}] (lanes = issue numbers). */
|
|
29
|
+
export function summarizeActive(audits, { currentVersion = highestVersion(audits) } = {}) {
|
|
30
|
+
const by = new Map();
|
|
31
|
+
for (const a of audits ?? []) {
|
|
32
|
+
if (!a.active || a.fixed_in_later) continue;
|
|
33
|
+
if (currentVersion == null || ver(a) !== currentVersion) continue;
|
|
34
|
+
const g = by.get(a.signature) ?? { signature: a.signature, class: a.class ?? null, count: 0, lanes: [] };
|
|
35
|
+
g.count++;
|
|
36
|
+
if (a.issue != null && !g.lanes.includes(a.issue)) g.lanes.push(a.issue);
|
|
37
|
+
by.set(a.signature, g);
|
|
38
|
+
}
|
|
39
|
+
return [...by.values()].sort((x, y) => y.count - x.count || String(x.signature).localeCompare(String(y.signature)));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Text output for either rows (audits) or an active summary. */
|
|
43
|
+
export function formatAudits(rows, { active = false } = {}) {
|
|
44
|
+
if (!rows.length) return active ? "no active audits" : "no audits";
|
|
45
|
+
if (active) return rows.map((g) => `${g.signature} [${g.class ?? "-"}] count=${g.count} lanes: ${g.lanes.map((n) => `#${n}`).join(", ") || "-"}`).join("\n");
|
|
46
|
+
return rows.map((a) => `#${a.issue ?? "?"} ${a.signature} [${a.class ?? "-"}] ${ver(a) ?? "-"}${a.fixed_in_later ? " fixed-in-later" : a.active ? " active" : ""}`).join("\n");
|
|
47
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { filterAudits, summarizeActive, highestVersion } from "./lane-audit-query.mjs";
|
|
4
|
+
import { auditsFromCli } from "../engine-cli.mjs";
|
|
5
|
+
import { renderAudit } from "./lane-audit.mjs";
|
|
6
|
+
|
|
7
|
+
const mk = (issue, signature, v, extra = {}) => ({ key: `${issue}:0:${signature}`, issue, signature, class: "pipeline", active: true, fixed_in_later: false, status: "proposed", stamp: { engine_version: v }, ...extra });
|
|
8
|
+
const A = [
|
|
9
|
+
mk(1, "s1", "1.2.0"), mk(2, "s1", "1.2.0"), mk(3, "s2", "1.2.0", { class: "env" }),
|
|
10
|
+
mk(4, "s1", "1.2.0", { active: false, fixed_in_later: true }), mk(5, "s1", "1.1.0"),
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
test("filters", () => {
|
|
14
|
+
assert.equal(filterAudits(A, { version: "1.1.0" }).length, 1);
|
|
15
|
+
assert.equal(filterAudits(A, { sinceVersion: "1.2.0" }).length, 4);
|
|
16
|
+
assert.equal(filterAudits(A, { signature: "s2" }).length, 1);
|
|
17
|
+
assert.equal(filterAudits(A, { class: "env" })[0].issue, 3);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("active summary excludes fixed_in_later and older versions", () => {
|
|
21
|
+
assert.equal(highestVersion(A), "1.2.0");
|
|
22
|
+
assert.deepEqual(summarizeActive(A), [
|
|
23
|
+
{ signature: "s1", class: "pipeline", count: 2, lanes: [1, 2] },
|
|
24
|
+
{ signature: "s2", class: "env", count: 1, lanes: [3] },
|
|
25
|
+
]);
|
|
26
|
+
assert.equal(summarizeActive(A, { currentVersion: "1.1.0" })[0].lanes[0], 5);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const cm = (a, o = {}) => JSON.stringify({ body: `<!-- FORGE:LANE_AUDIT -->\n${renderAudit(a)}`, user: { login: "bot", type: "Bot" }, author_association: "OWNER", issue_url: `https://api.github.com/repos/o/r/issues/${a.issue}`, ...o });
|
|
30
|
+
|
|
31
|
+
test("auditsFromCli: json, active, skips malformed and untrusted", async () => {
|
|
32
|
+
const lines = [...A.map((a) => cm(a)), "not json", cm(mk(9, "s1", "9.9.9"), { author_association: "NONE", user: { login: "rando", type: "User" } }), JSON.stringify({ body: "<!-- FORGE:LANE_AUDIT -->\nno json", author_association: "OWNER" })].join("\n");
|
|
33
|
+
const exec = async () => lines;
|
|
34
|
+
const logs = [];
|
|
35
|
+
const orig = console.log; console.log = (s) => logs.push(s);
|
|
36
|
+
try {
|
|
37
|
+
const r = await auditsFromCli(["--repo", "o/r", "--active", "--json"], { exec });
|
|
38
|
+
assert.deepEqual(r.rows.map((g) => [g.signature, g.count]), [["s1", 2], ["s2", 1]]);
|
|
39
|
+
assert.deepEqual(JSON.parse(logs[0])[0].lanes, [1, 2]);
|
|
40
|
+
const r2 = await auditsFromCli(["--repo", "o/r", "--signature", "s1"], { exec });
|
|
41
|
+
assert.equal(r2.rows.length, 4);
|
|
42
|
+
} finally { console.log = orig; }
|
|
43
|
+
await assert.rejects(() => auditsFromCli(["--bogus"], { exec }), /usage/);
|
|
44
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Known failure signatures for FORGE:LANE_AUDIT (#6076, seeded from the failure classes of #6072).
|
|
2
|
+
// {id, class: genuine|pipeline|spec|env|pool, owner, action, match(evidence) -> boolean, introduced_in, fixed_in}
|
|
3
|
+
// `evidence.text` is the lower-noise concatenation of detail, park rows, stderr and run-log tail. introduced_in / fixed_in are engine
|
|
4
|
+
// versions (null = unknown / not fixed yet); a lane on an engine older than fixed_in is classified fixed_in_later, not active.
|
|
5
|
+
const t = (e) => String(e?.text ?? "");
|
|
6
|
+
const re = (r) => (e) => r.test(t(e));
|
|
7
|
+
const sig = (id, klass, owner, action, match, extra = {}) => ({ id, class: klass, owner, action, match, introduced_in: null, fixed_in: null, ...extra });
|
|
8
|
+
|
|
9
|
+
export const SIGNATURES = [
|
|
10
|
+
sig("gh-network-text", "pipeline", "#6068", "treat a gh network error text as transient and retry, not as a blocker",
|
|
11
|
+
re(/error connecting to api\.github\.com|could not resolve host:? ?(api\.)?github\.com|dial tcp .*github|tls handshake timeout.*github|econnreset.*github/i)),
|
|
12
|
+
sig("unguarded-status-post", "pipeline", "#6045", "guard the status post so a failed comment cannot kill the lane",
|
|
13
|
+
re(/status (post|comment|edit) (failed|threw)|unguarded status post|writeStatus.*(failed|threw)/i)),
|
|
14
|
+
sig("no-status-rows", "pipeline", "#6058", "write the status rows before the terminal so the park cites them",
|
|
15
|
+
(e) => /no[- ]status rows|status rows? (missing|absent)/i.test(t(e)) || (e?.parkRows?.length === 0 && e?.reason === "needs-human" && /parked/i.test(t(e)))),
|
|
16
|
+
sig("contract-deferred-judged-omission", "pipeline", "#6051", "a narrowing backed by a cited frozen decision is not an omission",
|
|
17
|
+
re(/omission[\s\S]{0,200}(defer(red)?|narrow(ed|ing)?)[\s\S]{0,200}(contract|decision)|(defer(red)?|narrow(ed|ing)?)[\s\S]{0,120}(contract|decision)[\s\S]{0,200}omission/i)),
|
|
18
|
+
sig("decision-not-reaching-reviewer", "pipeline", "#6051", "carry the free-text decision to the reviewer",
|
|
19
|
+
re(/free[- ]text decision[\s\S]{0,80}(not|never)[\s\S]{0,40}(reach|seen|passed)[\s\S]{0,40}review/i)),
|
|
20
|
+
sig("amendment-syntax", "pipeline", "#6018", "fix the amendment shape (typed kind, one requirement id per row)",
|
|
21
|
+
re(/unknown amendment kind|amendment[s]? (rejected|invalid|malformed)|amendment .*not a (typed|valid)/i)),
|
|
22
|
+
sig("remote-sandbox-tool-gap", "env", "#6017", "the remote sandbox lacks a tool the lane needs; provision it in the image",
|
|
23
|
+
re(/(command not found|not found in (the )?(remote )?sandbox|enoent).*(sandbox|remote)|remote sandbox.*(missing|lacks|without).*(tool|binary)/i)),
|
|
24
|
+
sig("mirror-seed-conflict", "pool", "#6065", "reseed the mirror once; a 409/422 on seed is not a lane failure",
|
|
25
|
+
re(/mirror[\s\S]{0,80}seed[\s\S]{0,120}\b(409|422)\b|\b(409|422)\b[\s\S]{0,80}mirror[\s\S]{0,40}seed/i)),
|
|
26
|
+
sig("genuine-credentials", "genuine", "human", "a human provides the credential", re(/\b(credentials?|api[- ]key|secret|token) (is |are )?(needed|required|missing)|need creds|needs? credentials/i)),
|
|
27
|
+
sig("genuine-spend", "genuine", "human", "a human approves the spend", re(/approv(e|al)( of)? (the )?(spend|budget|purchase|payment)|paid (plan|account) (is )?required|billing/i)),
|
|
28
|
+
sig("genuine-product-decision", "genuine", "human", "the owner makes the product decision", re(/product decision|which (behaviou?r|option) (do you|should)|owner (must|should) (choose|decide)/i)),
|
|
29
|
+
sig("genuine-customer", "genuine", "human", "a human contacts or answers the customer", re(/customer (data|input|confirmation|must)|ask the customer|waiting for (the )?customer/i)),
|
|
30
|
+
sig("genuine-prod-access", "genuine", "human", "a human with production access acts", re(/production access|prod(uction)? (credentials|database|console) (is |are )?(needed|required)|requires? access to prod/i)),
|
|
31
|
+
sig("spec-two-features", "spec", "author", "split the issue: it asks for two features",
|
|
32
|
+
re(/two (separate |independent |distinct )?features|bundles? (two|2) (features|changes)|split (this|the) issue/i)),
|
|
33
|
+
];
|