forgedock 1.52.0 → 1.54.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/.claude-plugin/marketplace.json +51 -0
- package/README.md +8 -2
- package/bin/auth/app-manifest.mjs +89 -0
- package/bin/auth/app-manifest.test.mjs +75 -0
- package/bin/auth/app-token.mjs +256 -0
- package/bin/auth/app-token.test.mjs +232 -0
- package/bin/brand.mjs +7 -0
- package/bin/config-history.mjs +151 -0
- package/bin/config-schema.mjs +115 -0
- package/bin/demo.mjs +65 -11
- package/bin/engine/outcome-codes.mjs +9 -3
- package/bin/engine/telemetry-seam.mjs +11 -3
- package/bin/engine/telemetry-seam.test.mjs +17 -0
- package/bin/engine-cli.mjs +110 -36
- package/bin/experiment.mjs +58 -6
- package/bin/first-run.mjs +122 -0
- package/bin/forge-utils.mjs +6 -2
- package/bin/forgedock.mjs +138 -142
- package/bin/help-text.mjs +144 -0
- package/bin/hooks/pre-tool-use.mjs +7 -0
- package/bin/journey.mjs +82 -83
- package/bin/lean/acceptance.mjs +313 -0
- package/bin/lean/acceptance.test.mjs +215 -0
- package/bin/lean/account-watch.mjs +28 -0
- package/bin/lean/account-watch.test.mjs +30 -0
- package/bin/lean/activation.mjs +38 -0
- package/bin/lean/activation.test.mjs +36 -1
- package/bin/lean/basered.mjs +115 -0
- package/bin/lean/basered.test.mjs +66 -0
- package/bin/lean/batch-health.mjs +114 -7
- package/bin/lean/batch-health.test.mjs +87 -1
- package/bin/lean/batch.mjs +41 -2
- package/bin/lean/batch.test.mjs +115 -11
- package/bin/lean/branchlock.mjs +54 -0
- package/bin/lean/branchlock.test.mjs +49 -0
- package/bin/lean/ceiling.mjs +72 -0
- package/bin/lean/ceiling.test.mjs +54 -0
- package/bin/lean/checkpoint-reconcile.mjs +43 -0
- package/bin/lean/checkpoint-reconcile.test.mjs +95 -0
- package/bin/lean/ci-budget.mjs +366 -0
- package/bin/lean/ci-budget.test.mjs +167 -0
- package/bin/lean/conformance.e2e.test.mjs +8 -1
- package/bin/lean/conformance.mjs +269 -38
- package/bin/lean/conformance.test.mjs +280 -7
- package/bin/lean/context.mjs +35 -6
- package/bin/lean/context.test.mjs +27 -1
- package/bin/lean/depcache.mjs +25 -1
- package/bin/lean/depcache.test.mjs +26 -0
- package/bin/lean/e2e.mjs +18 -2
- package/bin/lean/e2e.test.mjs +26 -1
- package/bin/lean/effects.mjs +47 -14
- package/bin/lean/execution.mjs +19 -3
- package/bin/lean/execution.test.mjs +63 -0
- package/bin/lean/facts.mjs +3 -3
- package/bin/lean/facts.test.mjs +5 -0
- package/bin/lean/findinglabel.mjs +16 -0
- package/bin/lean/findinglabel.test.mjs +39 -0
- package/bin/lean/fixround.mjs +14 -0
- package/bin/lean/fixround.test.mjs +25 -2
- package/bin/lean/gh-assoc.test.mjs +2 -1
- package/bin/lean/integration.mjs +100 -9
- package/bin/lean/integration.test.mjs +98 -0
- package/bin/lean/issuewatch-parity.mjs +64 -0
- package/bin/lean/issuewatch-parity.test.mjs +127 -0
- package/bin/lean/issuewatch-release.mjs +6 -2
- package/bin/lean/issuewatch-release.test.mjs +17 -1
- package/bin/lean/issuewatch.mjs +45 -6
- package/bin/lean/issuewatch.test.mjs +3 -2
- package/bin/lean/lanelock.mjs +14 -0
- package/bin/lean/lean.mjs +473 -100
- package/bin/lean/lean.test.mjs +686 -33
- package/bin/lean/light.mjs +48 -7
- package/bin/lean/light.test.mjs +37 -3
- package/bin/lean/limits.test.mjs +142 -9
- package/bin/lean/mechfix.mjs +124 -0
- package/bin/lean/mechfix.test.mjs +75 -0
- package/bin/lean/orchestrate-cancel.test.mjs +143 -0
- package/bin/lean/orchestrate.mjs +116 -28
- package/bin/lean/phaseledger.mjs +47 -5
- package/bin/lean/phaseledger.test.mjs +30 -1
- package/bin/lean/postdeploy-check.test.mjs +39 -0
- package/bin/lean/precheck.mjs +23 -4
- package/bin/lean/precheck.test.mjs +14 -1
- package/bin/lean/prereq.mjs +28 -0
- package/bin/lean/prereq.test.mjs +20 -0
- package/bin/lean/probe.mjs +4 -2
- package/bin/lean/prodparity.mjs +52 -0
- package/bin/lean/prodparity.test.mjs +67 -0
- package/bin/lean/prompts.mjs +77 -19
- package/bin/lean/quota.mjs +39 -0
- package/bin/lean/recovery.test.mjs +11 -1
- package/bin/lean/relaxation.mjs +73 -0
- package/bin/lean/relaxation.test.mjs +54 -0
- package/bin/lean/release-io.test.mjs +42 -0
- package/bin/lean/release-postmerge.mjs +125 -0
- package/bin/lean/release-preflight.mjs +58 -0
- package/bin/lean/release-preflight.test.mjs +114 -0
- package/bin/lean/release-rehearsal.mjs +64 -0
- package/bin/lean/release-rehearsal.test.mjs +93 -0
- package/bin/lean/release-review.e2e.test.mjs +77 -0
- package/bin/lean/release-review.mjs +254 -0
- package/bin/lean/release-review.test.mjs +307 -0
- package/bin/lean/release-snapshot.mjs +188 -0
- package/bin/lean/release-snapshot.test.mjs +190 -0
- package/bin/lean/release.mjs +296 -0
- package/bin/lean/release.test.mjs +387 -0
- package/bin/lean/render.mjs +1 -1
- package/bin/lean/replan.mjs +184 -0
- package/bin/lean/replan.test.mjs +110 -0
- package/bin/lean/resume.mjs +9 -7
- package/bin/lean/resume.test.mjs +16 -0
- package/bin/lean/rotator.mjs +150 -31
- package/bin/lean/rotator.test.mjs +105 -2
- package/bin/lean/sandbox-remote.mjs +9 -2
- package/bin/lean/schedd.mjs +83 -5
- package/bin/lean/schedd.test.mjs +108 -7
- package/bin/lean/selfreview.mjs +94 -0
- package/bin/lean/selfreview.test.mjs +58 -1
- package/bin/lean/selftest-gate.mjs +22 -0
- package/bin/lean/selftest-gate.test.mjs +18 -1
- package/bin/lean/selftest-journey.mjs +234 -0
- package/bin/lean/selftest-journey.test.mjs +130 -0
- package/bin/lean/selftest-live.mjs +2 -1
- package/bin/lean/seqlease.mjs +35 -1
- package/bin/lean/seqlease.test.mjs +15 -0
- package/bin/lean/seqreserve.e2e.test.mjs +135 -0
- package/bin/lean/seqreserve.mjs +73 -0
- package/bin/lean/seqreserve.test.mjs +134 -0
- package/bin/lean/sequence.mjs +35 -6
- package/bin/lean/seqversioned.mjs +147 -0
- package/bin/lean/stagestamp.mjs +28 -0
- package/bin/lean/stagestamp.test.mjs +32 -0
- package/bin/lean/surfaces.mjs +75 -0
- package/bin/lean/surfaces.test.mjs +59 -0
- package/bin/lean/toolplace.mjs +28 -0
- package/bin/lean/toolplace.test.mjs +24 -0
- package/bin/lean/toolstats.mjs +3 -1
- package/bin/lean/toolstats.test.mjs +11 -0
- package/bin/lean/validatebest.mjs +28 -0
- package/bin/lean/validatebest.test.mjs +27 -0
- package/bin/lean/verifier.mjs +3 -2
- package/bin/lean/verify.mjs +2 -1
- package/bin/lean/verify.test.mjs +6 -0
- package/bin/pool/agent.mjs +27 -4
- package/bin/pool/docker.mjs +5 -0
- package/bin/pool/router.mjs +74 -28
- package/bin/prereqs.mjs +111 -0
- package/bin/replay-timelapse.mjs +149 -0
- package/bin/review-staging.mjs +123 -16
- package/bin/review-staging.test.mjs +18 -0
- package/bin/runner.mjs +43 -6
- package/bin/splash-install.mjs +157 -0
- package/bin/stats/aggregate.mjs +8 -1
- package/bin/stats/conformance-outcomes.mjs +289 -0
- package/bin/stats/conformance-outcomes.test.mjs +274 -0
- package/bin/stats/depth.mjs +275 -0
- package/bin/stats/depth.test.mjs +158 -0
- package/bin/stats/efficiency.mjs +26 -5
- package/bin/stats/efficiency.test.mjs +45 -1
- package/bin/stats/experiment.mjs +7 -5
- package/bin/stats/first-review.mjs +77 -0
- package/bin/stats/first-review.test.mjs +36 -0
- package/bin/stats/firstmerge.mjs +40 -0
- package/bin/stats/firstmerge.test.mjs +41 -0
- package/bin/stats/github-source.mjs +53 -15
- package/bin/stats/index.mjs +147 -9
- package/bin/stats/local-source.mjs +12 -0
- package/bin/stats/origin.mjs +80 -0
- package/bin/stats/origin.test.mjs +58 -0
- package/bin/stats/query.mjs +69 -0
- package/bin/stats/render.mjs +3 -1
- package/bin/stats/scoreboard.mjs +137 -0
- package/bin/stats/scoreboard.test.mjs +87 -0
- package/bin/stats/selffiled.mjs +52 -0
- package/bin/stats/selffiled.test.mjs +71 -0
- package/bin/stats/stats.test.mjs +80 -0
- package/bin/tui.mjs +3 -2
- package/commands/bootstrap.md +15 -14
- package/commands/deploy-pr.md +18 -3
- package/commands/forge-stats.md +1 -1
- package/commands/forgedock-ci-setup.md +28 -0
- package/commands/forgedock-init.md +4 -5
- package/commands/issue.md +2 -0
- package/commands/milestone.md +9 -1
- package/commands/orchestrate.md +1 -1
- package/commands/replay.md +2 -0
- package/commands/review-pr-agents/security.md +4 -0
- package/commands/review-pr-staging.md +6 -1
- package/commands/work-on/build.md +4 -6
- package/commands/work-on/close.md +8 -0
- package/docs/CONFIG.md +170 -18
- package/docs/ISSUE-WATCH.md +25 -0
- package/docs/OUTCOME-CODES.md +4 -0
- package/docs/REPLAY.md +9 -0
- package/docs/SELFTEST.md +11 -0
- package/docs/STATS.md +61 -0
- package/docs/TELEMETRY.md +1 -1
- package/docs/eval/README.md +6 -0
- package/docs/eval/adversarial-bench.md +68 -0
- package/docs/eval/corpus/adversarial-v1.json +285 -0
- package/docs/eval/feature-bench.md +42 -0
- package/docs/eval/feature-specs/crud-auth/journeys/notes-crud-isolated.mjs +21 -0
- package/docs/eval/feature-specs/crud-auth/journeys/register-login.mjs +12 -0
- package/docs/eval/feature-specs/crud-auth/spec.md +15 -0
- package/docs/site/start-a-new-project.md +2 -1
- package/package.json +5 -2
- package/plugins/forgedock-splash/.claude-plugin/plugin.json +10 -0
- package/plugins/forgedock-splash/README.md +27 -0
- package/plugins/forgedock-splash/hooks/hooks.json +1 -0
- package/plugins/forgedock-splash/hooks/register.tsx +74 -0
- package/plugins/forgedock-splash/hooks/scene.ts +222 -0
- package/plugins/forgedock-splash/types/index.d.ts +10 -0
- package/pool/README.md +1 -1
- package/pool/image/cs-cred +14 -1
- package/scripts/backfill-finding-labels.mjs +50 -0
- package/scripts/backfill-finding-labels.test.mjs +36 -0
- package/scripts/bench-adversarial.mjs +216 -0
- package/scripts/bench-feature.mjs +170 -0
- package/scripts/bench-lightlane.mjs +2 -2
- package/scripts/bootstrap-create.mjs +2 -2
- package/scripts/bootstrap-validate.mjs +35 -2
- package/scripts/check-spec-size.sh +4 -3
- package/scripts/check-spec-size.test.sh +3 -0
- package/scripts/doctor-pipeline-state.sh +21 -6
- package/scripts/file-deferred-followups.sh +59 -251
- package/scripts/file-deferred-followups.test.sh +85 -206
- package/scripts/followup-route.mjs +12 -0
- package/scripts/owner-route-parity.test.sh +17 -1
- package/scripts/plan-validate-live.mjs +40 -6
- package/scripts/review-pr-side-effects.test.sh +40 -0
- package/scripts/review-pr-staging-scope.test.sh +1 -1
- package/scripts/review-staging-post.sh +23 -0
- package/scripts/review-staging-post.test.sh +8 -0
|
@@ -0,0 +1,274 @@
|
|
|
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 { conformanceOutcomes, gatherConformanceOutcomes, renderConformanceOutcomes, replayPrs, renderReplay, prsOfPage, joinedNumbers, wilson, cites, reverts, sameHunks, warmSameHunks, OUTCOME_INSUFFICIENT, HIGHER, NOT_HIGHER, DEFAULT_OUTCOME_MIN_N } from "./conformance-outcomes.mjs";
|
|
6
|
+
import { conformanceVerdicts, verdictOf } from "./query.mjs";
|
|
7
|
+
import { summariseLog } from "./local-source.mjs";
|
|
8
|
+
import { buildReport, parseArgs, runStats } from "./index.mjs";
|
|
9
|
+
|
|
10
|
+
const DAY = 86400000;
|
|
11
|
+
const T0 = Date.parse("2026-10-01T00:00:00Z");
|
|
12
|
+
const at = (d) => new Date(T0 + d * DAY).toISOString();
|
|
13
|
+
const NOW = T0 + 60 * DAY;
|
|
14
|
+
const pr = (number, d, extra = {}) => ({ repo: "o/r", number, title: `feat: change ${number}`, body: "", mergedAt: at(d), mergeSha: `sha${number}`, closingIssues: [], ...extra });
|
|
15
|
+
const verdicts = (rows) => conformanceVerdicts({ records: rows.map(([prN, would, failures = [], mode = "shadow"]) => [
|
|
16
|
+
{ event: "run_terminal", issue: prN + 1000, pr: prN, reason: "merged", conformance_mode: mode, ...(would ? { shadow_would: would } : {}), ts: at(0) },
|
|
17
|
+
...(failures.length ? [{ event: "conformance_shadow", issue: prN + 1000, would, failures, ts: at(-0.1) }] : []),
|
|
18
|
+
]).flat() });
|
|
19
|
+
|
|
20
|
+
describe("conformance outcomes: join (#5210 R1)", () => {
|
|
21
|
+
it("joins each merged lane PR to its last verdict, mode and the four signals inside the window only", () => {
|
|
22
|
+
const prs = [
|
|
23
|
+
pr(1, 0, { closingIssues: [{ number: 1001, reopenedAt: [at(3)] }] }), // reopened in window
|
|
24
|
+
pr(2, 0), pr(3, 0), pr(4, 0), pr(5, 0),
|
|
25
|
+
pr(6, 0, { closingIssues: [{ number: 1006, reopenedAt: [at(9)] }] }), // reopened outside the 7d window
|
|
26
|
+
pr(20, 1, { title: "Revert \"feat: change 2\"", body: "Reverts o/r#2" }),
|
|
27
|
+
pr(21, 2, { title: "fix: handle null", body: "Fixes a regression from #3" }),
|
|
28
|
+
pr(22, 3, { title: "chore: tidy", body: "review-finding of PR #4" }),
|
|
29
|
+
pr(23, 4, { title: "fix: loop bound", body: "unrelated" }), // same-hunks fix for #5 via git
|
|
30
|
+
pr(24, 12, { title: "fix: late", body: "fix for #6" }), // outside window
|
|
31
|
+
pr(25, 1, { title: "docs: mention #5", body: "" }), // a mention, not a cause
|
|
32
|
+
];
|
|
33
|
+
const v = verdicts([[1, "conforms"], [2, "nonconforming", ["omission"]], [3, "conforms", [], "enforce"], [4, "nonconforming", ["scope_creep", "omission"]], [5, "conforms"], [6, "conforms"]]);
|
|
34
|
+
const git = { oldRanges: (sha) => (sha === "sha23" ? [{ file: "a.js", start: 1, end: 2 }] : []), blame: (rev, file) => (rev === "sha23^" && file === "a.js" ? ["sha5"] : []) };
|
|
35
|
+
const r = conformanceOutcomes({ prs, verdicts: v, now: NOW, git, minN: 1 });
|
|
36
|
+
const by = Object.fromEntries(r.prs.map((x) => [x.pr, x]));
|
|
37
|
+
assert.equal(r.sources.lane_prs, 6);
|
|
38
|
+
assert.equal(r.sources.unjoined, 6, "PRs without a verdict are not lane PRs");
|
|
39
|
+
assert.deepEqual(by[1].signals, { reverted: false, reopened: true, cited: false, same_hunks: false });
|
|
40
|
+
assert.equal(by[2].signals.reverted, true);
|
|
41
|
+
assert.deepEqual(by[2].kinds, ["omission"]);
|
|
42
|
+
assert.equal(by[3].signals.cited, true);
|
|
43
|
+
assert.equal(by[3].mode, "enforce");
|
|
44
|
+
assert.equal(by[4].signals.cited, true, "review-finding of PR #N");
|
|
45
|
+
assert.deepEqual(by[4].kinds, ["omission", "scope_creep"]);
|
|
46
|
+
assert.equal(by[5].signals.same_hunks, true);
|
|
47
|
+
assert.equal(by[5].signals.cited, false, "a docs mention is not a cause");
|
|
48
|
+
assert.deepEqual(by[6].signals, { reverted: false, reopened: false, cited: false, same_hunks: false }, "signals after the window do not count");
|
|
49
|
+
assert.equal(by[6].defect, false);
|
|
50
|
+
assert.equal(by[1].defect, true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("the latest verdict wins across batch rows, run logs and telemetry; a shadow run with no verdict has none", () => {
|
|
54
|
+
const v = conformanceVerdicts({
|
|
55
|
+
batchRows: [{ issue: 7, pr: 70, outcome: "merged", conformance: { mode: "shadow", would: "nonconforming", kinds: ["omission"] }, ts: "2026-10-01T00:00:00Z" }],
|
|
56
|
+
runs: [{ finished: true, issue: 7, pr: 70, reason: "merged", conformanceMode: "shadow", shadowWould: "conforms", conformanceFailures: [], endTs: "2026-10-02T00:00:00Z" }],
|
|
57
|
+
records: [{ event: "run_terminal", issue: 8, pr: 80, reason: "merged", conformance_mode: "shadow", ts: "2026-10-02T00:00:00Z" }],
|
|
58
|
+
});
|
|
59
|
+
assert.equal(v.get("pr:70").state, "conforms");
|
|
60
|
+
assert.equal(v.get("pr:70").source, "local");
|
|
61
|
+
assert.equal(v.get("pr:80"), undefined);
|
|
62
|
+
assert.deepEqual(verdictOf({ mode: "enforce", merged: true }), { mode: "enforce", state: "conforms", kinds: [] });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("a PR whose window is still open is pending, not counted", () => {
|
|
66
|
+
const r = conformanceOutcomes({ prs: [pr(1, 58)], verdicts: verdicts([[1, "conforms"]]), now: NOW, minN: 1 });
|
|
67
|
+
assert.equal(r.sources.pending, 1);
|
|
68
|
+
assert.equal(r.sources.lane_prs, 0);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("run logs expose pr, mode and the last verdict's failure codes", () => {
|
|
72
|
+
const s = summariseLog([{ event: "RUN_START", issue: 9, ts: at(0) }, { event: "CONFORMANCE", round: 1, state: "nonconforming", failures: ["regression"], mode: "shadow" },
|
|
73
|
+
{ event: "CONFORMANCE_SHADOW", would: "nonconforming", failures: ["omission"] }, { event: "RUN_TERMINAL", reason: "merged", pr: 90, conformance_mode: "shadow", shadow_would: "nonconforming", ts: at(1) }]);
|
|
74
|
+
assert.equal(s.pr, 90);
|
|
75
|
+
assert.equal(s.conformanceMode, "shadow");
|
|
76
|
+
assert.deepEqual(s.conformanceFailures, ["omission"]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("signal helpers", () => {
|
|
80
|
+
assert.equal(reverts({ title: "Revert \"x\"", body: "Reverts o/r#12" }, { number: 12 }, "o/r"), true);
|
|
81
|
+
assert.equal(reverts({ title: "fix: x", body: "Reverts o/r#12" }, { number: 12 }, "o/r"), false);
|
|
82
|
+
assert.equal(cites({ title: "fix(x): y", body: "Closes #120" }, { number: 12, closingIssues: [] }), false, "#120 is not #12");
|
|
83
|
+
assert.equal(cites({ title: "fix(x): y (#12)", body: "" }, { number: 12, closingIssues: [] }), true);
|
|
84
|
+
assert.equal(sameHunks({ mergeSha: "a" }, [{ mergeSha: "b" }], null), null, "no git: unresolved");
|
|
85
|
+
assert.equal(sameHunks({ mergeSha: "a" }, [], null), false, "no later fix: false");
|
|
86
|
+
assert.equal(sameHunks({ mergeSha: "a" }, [{ mergeSha: "b" }], { oldRanges: () => null, blame: () => [] }), null);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("conformance outcomes: 2x2 and conclusion (#5210 R2)", () => {
|
|
91
|
+
const many = (start, n, would, defects, failures = []) => Array.from({ length: n }, (_, i) => {
|
|
92
|
+
const num = start + i;
|
|
93
|
+
return { p: pr(num, 0, i < defects ? { closingIssues: [{ number: num + 1000, reopenedAt: [at(1)] }] } : {}), v: [num, would, failures] };
|
|
94
|
+
});
|
|
95
|
+
it("defaults to min n 20 per cell and prints insufficient data below it", () => {
|
|
96
|
+
const xs = [...many(1, 19, "nonconforming", 10, ["omission"]), ...many(100, 30, "conforms", 1)];
|
|
97
|
+
const r = conformanceOutcomes({ prs: xs.map((x) => x.p), verdicts: verdicts(xs.map((x) => x.v)), now: NOW });
|
|
98
|
+
assert.equal(r.min_n, DEFAULT_OUTCOME_MIN_N);
|
|
99
|
+
assert.equal(r.min_n, 20);
|
|
100
|
+
assert.equal(r.overall.nonconforming.n, 19);
|
|
101
|
+
assert.equal(r.overall.nonconforming.rate, null);
|
|
102
|
+
assert.equal(r.overall.nonconforming.insufficient, true);
|
|
103
|
+
assert.equal(r.conclusion, OUTCOME_INSUFFICIENT);
|
|
104
|
+
const text = renderConformanceOutcomes(r);
|
|
105
|
+
assert.match(text, /\| all \| 10\/19 n\/a \|/);
|
|
106
|
+
assert.match(text.split("\n").at(-1), /^conclusion: insufficient data$/);
|
|
107
|
+
});
|
|
108
|
+
it("per repo, per mode and per failure kind with n, rate and a Wilson interval; higher when the intervals separate", () => {
|
|
109
|
+
const xs = [...many(1, 25, "nonconforming", 15, ["omission"]), ...many(30, 22, "nonconforming", 1, ["scope_creep"]), ...many(100, 40, "conforms", 2)];
|
|
110
|
+
const r = conformanceOutcomes({ prs: xs.map((x) => x.p), verdicts: verdicts(xs.map((x) => x.v)), now: NOW });
|
|
111
|
+
const o = r.repos["o/r"];
|
|
112
|
+
assert.deepEqual([o.by_kind.omission.nonconforming.n, o.by_kind.omission.nonconforming.defects, o.by_kind.omission.nonconforming.rate], [25, 15, 0.6]);
|
|
113
|
+
assert.deepEqual(o.by_kind.omission.nonconforming.interval, wilson(15, 25));
|
|
114
|
+
assert.equal(o.by_kind.omission.conclusion, HIGHER);
|
|
115
|
+
assert.equal(o.by_kind.scope_creep.conclusion, NOT_HIGHER);
|
|
116
|
+
assert.equal(o.overall.conforming.n, 40);
|
|
117
|
+
assert.ok(o.by_mode.shadow);
|
|
118
|
+
assert.equal(r.conclusion, HIGHER);
|
|
119
|
+
const text = renderConformanceOutcomes(r);
|
|
120
|
+
assert.match(text, /## o\/r/);
|
|
121
|
+
assert.match(text, /\| kind omission \| 15\/25 60% \[/);
|
|
122
|
+
assert.equal(text.split("\n").at(-1), `conclusion: ${HIGHER}`);
|
|
123
|
+
});
|
|
124
|
+
it("wilson matches the closed form and stays inside [0, 1]", () => {
|
|
125
|
+
assert.deepEqual(wilson(0, 10), [0, 0.2775]);
|
|
126
|
+
assert.deepEqual(wilson(10, 10), [0.7225, 1]);
|
|
127
|
+
assert.equal(wilson(0, 0), null);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
/** gh stub: `api graphql` search pages over `total` merged PRs; records every call. */
|
|
132
|
+
function graphqlGh(total, calls = []) {
|
|
133
|
+
return async (args) => {
|
|
134
|
+
calls.push(args);
|
|
135
|
+
if (args[0] === "api" && args[1] === "graphql") {
|
|
136
|
+
const after = args.find((a) => a.startsWith("after="));
|
|
137
|
+
const start = after ? Number(after.slice(6)) : 0;
|
|
138
|
+
const nodes = Array.from({ length: Math.min(100, total - start) }, (_, i) => ({ number: start + i + 1, title: "t", body: "", mergedAt: at(0), mergeCommit: { oid: `s${start + i}` },
|
|
139
|
+
repository: { nameWithOwner: "o/r" }, closingIssuesReferences: { nodes: [] } }));
|
|
140
|
+
return JSON.stringify({ data: { search: { pageInfo: { hasNextPage: start + 100 < total, endCursor: String(start + 100) }, nodes } } });
|
|
141
|
+
}
|
|
142
|
+
return "[]";
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const isWrite = (args) => args.some((a) => /^(-X|--method)$/.test(a)) || args.some((a) => /^query=\s*mutation\b/.test(a)) || ["comment", "edit", "create", "close", "reopen", "merge"].includes(args[1]);
|
|
146
|
+
|
|
147
|
+
describe("conformance outcomes: read only (#5210 R3)", () => {
|
|
148
|
+
it("one GraphQL call per 100 PRs and no write", async () => {
|
|
149
|
+
const calls = [];
|
|
150
|
+
const out = await gatherConformanceOutcomes({ repo: "o/r", gh: graphqlGh(250, calls), since: at(0), now: NOW });
|
|
151
|
+
assert.equal(out.prs.length, 250);
|
|
152
|
+
assert.equal(out.graphqlCalls, 3);
|
|
153
|
+
assert.equal(calls.length, 3);
|
|
154
|
+
assert.ok(calls.every((a) => a[0] === "api" && a[1] === "graphql" && !isWrite(a)));
|
|
155
|
+
assert.ok(calls[0].includes("q=repo:o/r is:pr is:merged merged:>=2026-10-01"));
|
|
156
|
+
});
|
|
157
|
+
it("runStats --conformance-outcomes --json: GitHub reads only, the report under query.conformance_outcomes", async () => {
|
|
158
|
+
const calls = [];
|
|
159
|
+
const gh = graphqlGh(120, calls);
|
|
160
|
+
let out = "";
|
|
161
|
+
const w = process.stdout.write;
|
|
162
|
+
process.stdout.write = (t) => { out += t; return true; };
|
|
163
|
+
let code;
|
|
164
|
+
try {
|
|
165
|
+
code = await runStats(["--conformance-outcomes", "--repo", "o/r", "--since", "2026-10-01", "--window-days", "5", "--json", "--no-cache", "--no-local"],
|
|
166
|
+
{ gh, env: { HOME: "/nonexistent" }, now: () => NOW, git: null, releaseTimes: [], onProgress: () => {} });
|
|
167
|
+
} finally { process.stdout.write = w; }
|
|
168
|
+
assert.equal(code, 0);
|
|
169
|
+
const rep = JSON.parse(out).query.conformance_outcomes;
|
|
170
|
+
assert.equal(rep.window_days, 5);
|
|
171
|
+
assert.equal(rep.sources.merged_prs, 120);
|
|
172
|
+
assert.equal(rep.sources.graphql_calls, 2);
|
|
173
|
+
assert.equal(rep.conclusion, OUTCOME_INSUFFICIENT);
|
|
174
|
+
assert.equal(calls.filter((a) => a[1] === "graphql").length, 2);
|
|
175
|
+
assert.ok(calls.every((a) => !isWrite(a)), "no GitHub write");
|
|
176
|
+
});
|
|
177
|
+
it("buildReport bounds the crawl and uses min n 20 unless --min-n is passed", async () => {
|
|
178
|
+
const r = await buildReport({ ...parseArgs(["--conformance-outcomes", "--min-n", "3"]), repo: "o/r", cache: false, local: false },
|
|
179
|
+
{ gh: graphqlGh(0), env: {}, now: () => NOW, git: null, releaseTimes: [], onProgress: () => {} });
|
|
180
|
+
assert.equal(r.query.conformance_outcomes.min_n, 3);
|
|
181
|
+
});
|
|
182
|
+
it("a 502 at first=100 retries the same page smaller and completes (#5363)", async () => {
|
|
183
|
+
const calls = [];
|
|
184
|
+
const inner = graphqlGh(150, calls);
|
|
185
|
+
const gh = async (args) => {
|
|
186
|
+
if (args.includes("first=100")) throw new Error("gh: HTTP 502: Bad Gateway");
|
|
187
|
+
return inner(args);
|
|
188
|
+
};
|
|
189
|
+
const out = await gatherConformanceOutcomes({ repo: "o/r", gh, since: at(0), now: NOW });
|
|
190
|
+
assert.ok(out.prs.length > 0);
|
|
191
|
+
assert.ok(calls.some((a) => a.includes("first=50")));
|
|
192
|
+
});
|
|
193
|
+
it("a persistent 502 fails naming a narrower --since (#5363)", async () => {
|
|
194
|
+
await assert.rejects(gatherConformanceOutcomes({ repo: "o/r", gh: async () => { throw new Error("HTTP 502"); }, since: at(0), now: NOW }), /narrower --since/);
|
|
195
|
+
});
|
|
196
|
+
it("flag parsing", () => {
|
|
197
|
+
assert.equal(parseArgs(["--conformance-outcomes"]).conformanceOutcomes, true);
|
|
198
|
+
assert.equal(parseArgs(["--conformance-outcomes", "--window-days", "14"]).windowDays, 14);
|
|
199
|
+
assert.throws(() => parseArgs(["--window-days", "7"]), /needs --conformance-outcomes/);
|
|
200
|
+
assert.throws(() => parseArgs(["--conformance-outcomes", "--window-days", "0"]), /positive integer/);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
describe("conformance outcomes: surfaces and replay (#5283)", () => {
|
|
205
|
+
const stub = (files) => files.map((f) => (f.includes("migrations/") ? "domain:database" : f.includes("auth") ? "domain:auth" : f.endsWith(".tsx") ? "domain:frontend" : null)).filter(Boolean).sort();
|
|
206
|
+
const lane = (n, d, files) => pr(n, d, { files });
|
|
207
|
+
it("by_surface compares nonconforming vs conforming among PRs touching that surface; n/a under min n", () => {
|
|
208
|
+
const prs = [lane(1, 0, ["db/migrations/0543.sql"]), lane(2, 0, ["db/migrations/0544.sql"]), lane(3, 0, ["web/a.tsx"]), pr(4, 0)];
|
|
209
|
+
const v = verdicts([[1, "nonconforming", ["conformance.unimplemented"]], [2, "conforms"], [3, "conforms"], [4, "conforms"]]);
|
|
210
|
+
const r = conformanceOutcomes({ prs, verdicts: v, minN: 1, now: NOW, surfacesOf: stub });
|
|
211
|
+
const s = r.repos["o/r"].by_surface;
|
|
212
|
+
assert.deepEqual(Object.keys(s).sort(), ["domain:database", "domain:frontend"]);
|
|
213
|
+
assert.equal(s["domain:database"].nonconforming.n, 1);
|
|
214
|
+
assert.equal(s["domain:database"].conforming.n, 1);
|
|
215
|
+
assert.match(renderConformanceOutcomes(r), /surface domain:database/);
|
|
216
|
+
assert.equal(conformanceOutcomes({ prs, verdicts: v, minN: 5, now: NOW, surfacesOf: stub }).repos["o/r"].by_surface["domain:database"].nonconforming.rate, null);
|
|
217
|
+
});
|
|
218
|
+
it("replay: enforced when a configured surface is hit and the verdict is nonconforming, flagged when it would pass, none otherwise", () => {
|
|
219
|
+
const prs = [lane(1, 0, ["db/migrations/0543.sql"]), lane(2, 0, ["web/(site)/layout.tsx"]), lane(3, 0, ["docs/x.md"])];
|
|
220
|
+
const v = verdicts([[1, "nonconforming", ["conformance.unimplemented"]], [2, "conforms"], [3, "conforms"]]);
|
|
221
|
+
const r = replayPrs({ prs, verdicts: v, numbers: [1, 2, 3, 9], enforceDomains: "database,frontend", surfacesOf: stub });
|
|
222
|
+
assert.deepEqual(r.prs.map((x) => x.outcome), ["enforced", "flagged", "none"]);
|
|
223
|
+
assert.deepEqual(r.missing, [9]);
|
|
224
|
+
assert.equal(replayPrs({ prs, verdicts: v, numbers: [3], riskPaths: "docs/**", surfacesOf: stub }).prs[0].outcome, "flagged");
|
|
225
|
+
assert.match(renderReplay(r), /\| #2 \| shadow \| conforms \| domain:frontend \| flagged \|/);
|
|
226
|
+
});
|
|
227
|
+
it("buildReport wires --replay into the report (JSON) and reports PRs outside the fetched range as missing", async () => {
|
|
228
|
+
const r = await buildReport({ ...parseArgs(["--conformance-outcomes", "--replay", "1,99", "--enforce-domains", "frontend"]), repo: "o/r", cache: false, local: false },
|
|
229
|
+
{ gh: graphqlGh(0), env: {}, now: () => NOW, git: null, releaseTimes: [], onProgress: () => {} });
|
|
230
|
+
const rp = r.query.conformance_outcomes.replay;
|
|
231
|
+
assert.deepEqual(rp.enforce_domains, ["frontend"]);
|
|
232
|
+
assert.ok(rp.missing.includes(99));
|
|
233
|
+
});
|
|
234
|
+
it("prsOfPage keeps changed file paths; parseArgs validates --replay and its companions", () => {
|
|
235
|
+
const data = { data: { search: { nodes: [{ number: 5, mergedAt: at(0), files: { nodes: [{ path: "a.ts" }] } }] } } };
|
|
236
|
+
assert.deepEqual(prsOfPage(data, "o/r")[0].files, ["a.ts"]);
|
|
237
|
+
assert.deepEqual(parseArgs(["--conformance-outcomes", "--replay", "1,2", "--enforce-domains", "auth"]).replay, [1, 2]);
|
|
238
|
+
assert.throws(() => parseArgs(["--replay", "1"]), /need --conformance-outcomes/);
|
|
239
|
+
assert.throws(() => parseArgs(["--conformance-outcomes", "--enforce-domains", "auth"]), /need --replay/);
|
|
240
|
+
assert.throws(() => parseArgs(["--conformance-outcomes", "--replay", "x"]), /comma list/);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe("joinedNumbers (#5363)", () => {
|
|
245
|
+
it("lists each merged PR and its closing issues once, sorted", () => {
|
|
246
|
+
assert.deepEqual(joinedNumbers([{ number: 9, closingIssues: [{ number: 3 }, { number: 5 }] }, { number: 4, closingIssues: [{ number: 3 }] }]), [3, 4, 5, 9]);
|
|
247
|
+
assert.deepEqual(joinedNumbers(), []);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("same-hunks blames each fix PR once (#5372)", () => {
|
|
252
|
+
const at = (d) => new Date(Date.UTC(2026, 0, 1 + d)).toISOString();
|
|
253
|
+
const NOW2 = Date.parse(at(60));
|
|
254
|
+
const lanes = Array.from({ length: 10 }, (_, i) => ({ repo: "o/r", number: 100 + i, title: `feat: ${i}`, body: "", mergedAt: at(i), mergeSha: `lane${i}`, closingIssues: [{ number: 200 + i }] }));
|
|
255
|
+
const fixes = Array.from({ length: 3 }, (_, i) => ({ repo: "o/r", number: 300 + i, title: `fix: ${i}`, body: "", mergedAt: at(i + 3), mergeSha: `fix${i}`, closingIssues: [] }));
|
|
256
|
+
const calls = { ranges: 0, blame: 0 };
|
|
257
|
+
const git = { oldRanges: () => { calls.ranges++; return [{ file: "a", start: 1, end: 2 }, { file: "b", start: 1, end: 2 }]; }, blame: (rev) => { calls.blame++; return rev === "fix1^" ? ["lane0"] : []; } };
|
|
258
|
+
const verdicts = new Map(lanes.map((l, i) => [`pr:${l.number}`, { state: "conforms", issue: 200 + i, kinds: [] }]));
|
|
259
|
+
const events = [];
|
|
260
|
+
const r = conformanceOutcomes({ prs: [...lanes, ...fixes], verdicts, now: NOW2, git, minN: 1, onProgress: (e) => events.push(e) });
|
|
261
|
+
assert.equal(calls.ranges, 3, "oldRanges once per fix PR");
|
|
262
|
+
assert.equal(calls.blame, 6, "blame calls are fix PRs x hunks");
|
|
263
|
+
assert.equal(r.prs.find((x) => x.pr === 100).signals.same_hunks, true);
|
|
264
|
+
assert.equal(r.prs.find((x) => x.pr === 101).signals.same_hunks, false);
|
|
265
|
+
assert.deepEqual(events.map((e) => [e.phase, e.done, e.total]), [["same-hunks", 1, 3], ["same-hunks", 2, 3], ["same-hunks", 3, 3]]);
|
|
266
|
+
warmSameHunks(fixes, git);
|
|
267
|
+
assert.equal(calls.blame, 6, "a second warm reuses the memo");
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("same-hunks keeps a hit when another range of the fix PR is unresolved (#5372)", () => {
|
|
271
|
+
const git = { oldRanges: () => [{ file: "a", start: 1, end: 2 }, { file: "b", start: 1, end: 2 }], blame: (_r, f) => (f === "a" ? null : ["lane0"]) };
|
|
272
|
+
assert.equal(sameHunks({ mergeSha: "lane0" }, [{ mergeSha: "fixU" }], git), true);
|
|
273
|
+
assert.equal(sameHunks({ mergeSha: "other" }, [{ mergeSha: "fixU" }], git), null);
|
|
274
|
+
});
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* forge#5209: adaptive lane depth. `forgedock stats --depth` joins each lane's LIGHT_ELIGIBILITY verdict, reasons and
|
|
5
|
+
* signals (bin/lean/light.mjs) with its outcome: merged / needs-human, first pass, cost, wall and model time, review
|
|
6
|
+
* findings and conformance failures, and post-merge defect signals within 7 days: the conformance-outcomes set (#5364),
|
|
7
|
+
* reverted, reopened, cited, and same_hunks (a later fix PR's old-side lines blame to the lane's merge commit). It answers whether, for lanes the light gate would have taken, the plan and review steps
|
|
8
|
+
* caught anything or only added cost, and whether the #5052 light-lane promotion criterion is met:
|
|
9
|
+
* light-shaped lanes (light or upgraded) cost <= 1.2x eligible full lanes of the same size, wall <= 1.3x model time, and
|
|
10
|
+
* a defect rate no worse than those full lanes; any cell under min-n is "insufficient data".
|
|
11
|
+
* Flipping lean.light.mode stays a config decision. No model, no clock (`now` is injected), no network except the injected gh.
|
|
12
|
+
*
|
|
13
|
+
* Sources: the run logs (~/.forge/runs/<issue>.jsonl, every RUN_START..RUN_TERMINAL slice); GitHub only for defect signals.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { firstPassOf } from "../lean/fixround.mjs";
|
|
18
|
+
import { DEFAULT_MIN_N } from "./aggregate.mjs";
|
|
19
|
+
import { cacheDir } from "./cache.mjs";
|
|
20
|
+
import { cites, isFix, reverts, sameHunks } from "./conformance-outcomes.mjs";
|
|
21
|
+
import { sameRepo, WEEK_MS } from "./efficiency.mjs";
|
|
22
|
+
|
|
23
|
+
export const VERDICTS = Object.freeze(["eligible", "ambiguous", "ineligible"]);
|
|
24
|
+
export const PROMOTION = Object.freeze({ costRatio: 1.2, wallOverModel: 1.3 });
|
|
25
|
+
export const INSUFFICIENT = "insufficient data";
|
|
26
|
+
|
|
27
|
+
const num = (x) => (typeof x === "number" && Number.isFinite(x) ? x : null);
|
|
28
|
+
const costOf = (e) => num(e.cost_usd_delta) ?? num(e.cost_usd);
|
|
29
|
+
const r = (x, p = 1e4) => (num(x) == null ? null : Math.round(x * p) / p);
|
|
30
|
+
const per = (a, b) => (b > 0 ? a / b : null);
|
|
31
|
+
const ms = (ts) => { const t = Date.parse(ts ?? ""); return Number.isNaN(t) ? null : t; };
|
|
32
|
+
const median = (xs) => {
|
|
33
|
+
const v = xs.filter((x) => num(x) != null).sort((a, b) => a - b);
|
|
34
|
+
if (!v.length) return null;
|
|
35
|
+
const h = Math.floor(v.length / 2);
|
|
36
|
+
return v.length % 2 ? v[h] : (v[h - 1] + v[h]) / 2;
|
|
37
|
+
};
|
|
38
|
+
const codesOf = (xs) => [...new Set((Array.isArray(xs) ? xs : []).map((x) => String(x?.code ?? x ?? "").trim()).filter(Boolean))].sort();
|
|
39
|
+
|
|
40
|
+
function parseLog(text) {
|
|
41
|
+
const out = [];
|
|
42
|
+
for (const line of String(text ?? "").split("\n")) {
|
|
43
|
+
if (!line.trim()) continue;
|
|
44
|
+
try { const e = JSON.parse(line); if (e && typeof e === "object") out.push(e); } catch { /* torn line */ }
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* One row per RUN_START..RUN_TERMINAL slice of one run log that logged LIGHT_ELIGIBILITY. A slice whose repo is unknown is
|
|
51
|
+
* kept; `sinceMs` bounds the slice start (a slice without a start time is kept).
|
|
52
|
+
*/
|
|
53
|
+
export function depthRows(events, { repo = null, sinceMs = null, issue = null } = {}) {
|
|
54
|
+
const out = [];
|
|
55
|
+
let cur = null;
|
|
56
|
+
const close = () => { if (cur?.elig && cur.term) out.push(finish(cur)); cur = null; };
|
|
57
|
+
for (const e of Array.isArray(events) ? events : []) {
|
|
58
|
+
if (!e || typeof e !== "object") continue;
|
|
59
|
+
if (e.event === "RUN_START") { close(); cur = { start: e, elig: null, term: null, shape: "full", attempts: [], findings: 0, conf: 0, pr: null }; continue; }
|
|
60
|
+
if (!cur) continue;
|
|
61
|
+
if (e.event === "LIGHT_ELIGIBILITY") cur.elig = e;
|
|
62
|
+
else if (e.event === "LIGHT_DONE") cur.shape = "light";
|
|
63
|
+
else if (e.event === "LIGHT_UPGRADE") cur.shape = "upgraded";
|
|
64
|
+
else if (e.event === "PHASE_ATTEMPT_USAGE") cur.attempts.push(e);
|
|
65
|
+
else if (e.event === "CONFORMANCE") {
|
|
66
|
+
cur.findings += Array.isArray(e.failures) ? e.failures.length : 0;
|
|
67
|
+
if (typeof e.state === "string" && e.state !== "conforms") cur.conf++;
|
|
68
|
+
} else if (e.event === "VERIFIER") cur.findings += num(e.findings) ?? 0;
|
|
69
|
+
else if (e.event === "PR_OPENED" && Number.isSafeInteger(e.pr)) cur.pr = e.pr;
|
|
70
|
+
else if (e.event === "RUN_TERMINAL") { cur.term = e; close(); }
|
|
71
|
+
}
|
|
72
|
+
close();
|
|
73
|
+
function finish(s) {
|
|
74
|
+
const impl = s.attempts.filter((a) => a.phase === "implement");
|
|
75
|
+
const t = s.term;
|
|
76
|
+
return { issue: Number.isSafeInteger(s.start.issue) ? s.start.issue : issue, repo: s.start.repo ?? null, startTs: s.start.ts ?? null, endTs: t.ts ?? null,
|
|
77
|
+
verdict: String(s.elig.verdict ?? "unknown"), mode: s.elig.mode ?? null, reasons: codesOf(s.elig.reasons), signals: codesOf(s.elig.signals),
|
|
78
|
+
shape: s.shape, outcome: t.reason ?? null, merged: t.reason === "merged", needsHuman: t.reason === "needs-human",
|
|
79
|
+
firstPass: firstPassOf(impl.map((a) => ({ trigger: a.trigger ?? null, restart_of: a.restart_of ?? null }))),
|
|
80
|
+
cost: s.attempts.reduce((n, a) => n + (costOf(a) ?? 0), 0), wallMs: num(t.wall_ms), modelMs: num(t.model_ms),
|
|
81
|
+
size: ["S", "M", "L"].includes(t.turns?.size) ? t.turns.size : null, pr: Number.isSafeInteger(t.pr) ? t.pr : s.pr,
|
|
82
|
+
findings: s.findings, conformanceFailures: s.conf };
|
|
83
|
+
}
|
|
84
|
+
return out.filter((x) => (!repo || !x.repo || sameRepo(x.repo, repo)) && (sinceMs == null || ms(x.startTs) == null || ms(x.startTs) >= sinceMs));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const lines = (raw) => String(raw ?? "").split("\n").filter((l) => l.trim()).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean);
|
|
88
|
+
|
|
89
|
+
const DEFECT_CACHE_V = 2;
|
|
90
|
+
const CONCURRENCY = 4;
|
|
91
|
+
const defectCachePath = (repo, env) => join(cacheDir(repo, env), "depth-defects.json");
|
|
92
|
+
function loadDefectCache(repo, env) {
|
|
93
|
+
try { const c = JSON.parse(readFileSync(defectCachePath(repo, env), "utf8")); if (c?.v === DEFECT_CACHE_V) return { v: DEFECT_CACHE_V, defects: c.defects ?? {}, shas: c.shas ?? {} }; } catch { /* refetch */ }
|
|
94
|
+
return { v: DEFECT_CACHE_V, defects: {}, shas: {} };
|
|
95
|
+
}
|
|
96
|
+
function saveDefectCache(repo, env, c) {
|
|
97
|
+
try { mkdirSync(cacheDir(repo, env), { recursive: true }); writeFileSync(defectCachePath(repo, env), JSON.stringify(c)); } catch { /* a cache never fails the report */ }
|
|
98
|
+
}
|
|
99
|
+
/** Run `fn` over `items` with at most `n` in flight. */
|
|
100
|
+
async function mapLimit(items, n, fn) {
|
|
101
|
+
let next = 0;
|
|
102
|
+
await Promise.all(Array.from({ length: Math.min(n, items.length) }, async () => { while (next < items.length) await fn(items[next++]); }));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Post-merge defect signals of merged rows with a PR, over the injected gh: Map issue -> {reopen, revert, cited, same_hunks, defect}.
|
|
107
|
+
* The signals are those of conformance-outcomes.mjs (reverts, cites, sameHunks over the injected local `git` probes). same_hunks is
|
|
108
|
+
* null when git cannot resolve (no local clone); defect is then null (n/a) unless another signal is true.
|
|
109
|
+
* A gh failure gives the rows it could not read null fields (rendered n/a), never false.
|
|
110
|
+
* Bounded crawl (#5318): reopens are read per issue (not repo-wide), the PR search is limited to the rows' merge window,
|
|
111
|
+
* per-PR merge shas are fetched with bounded concurrency, and a row whose window has closed (`now` past its end + window)
|
|
112
|
+
* is cached under cacheDir(repo) with the PR merge shas, so a warm run makes no gh calls for it. `useCache` false skips
|
|
113
|
+
* the cache; `refresh` ignores what is stored. `onProgress({phase, done, total})` is called as rows are resolved.
|
|
114
|
+
*/
|
|
115
|
+
export async function gatherDefects({ repo, gh, rows = [], windowMs = WEEK_MS, now = null, env = process.env, useCache = false, refresh = false, onProgress = null, git = null } = {}) {
|
|
116
|
+
const out = new Map();
|
|
117
|
+
const merged = rows.filter((x) => x.merged && Number.isSafeInteger(x.pr) && ms(x.endTs) != null);
|
|
118
|
+
if (!gh || !repo || !merged.length) return out;
|
|
119
|
+
const cache = useCache && !refresh ? loadDefectCache(repo, env) : { v: DEFECT_CACHE_V, defects: {}, shas: {} };
|
|
120
|
+
const settled = (x) => now != null && ms(x.endTs) + windowMs < now;
|
|
121
|
+
const hit = (x) => { const c = cache.defects[`${x.issue}:${x.pr}`]; return c && c.endTs === x.endTs ? c.value : null; };
|
|
122
|
+
const todo = [];
|
|
123
|
+
for (const x of merged) { const v = settled(x) ? hit(x) : null; if (v) out.set(x.issue, v); else todo.push(x); }
|
|
124
|
+
const total = merged.length;
|
|
125
|
+
let done = total - todo.length;
|
|
126
|
+
onProgress?.({ phase: "defect signals (cached)", done, total });
|
|
127
|
+
if (!todo.length) return out;
|
|
128
|
+
try {
|
|
129
|
+
const from = new Date(Math.min(...todo.map((x) => ms(x.endTs)))).toISOString().slice(0, 10);
|
|
130
|
+
const to = new Date(Math.max(...todo.map((x) => ms(x.endTs))) + windowMs).toISOString().slice(0, 10);
|
|
131
|
+
const prs = lines(await gh(["api", "--paginate", `search/issues?q=${encodeURIComponent(`repo:${repo} is:pr is:merged merged:${from}..${to}`)}&per_page=100`,
|
|
132
|
+
"--jq", ".items[] | {number, title, body, labels: [.labels[].name], merged_at: .pull_request.merged_at}"]));
|
|
133
|
+
const shas = new Map(Object.entries(cache.shas).map(([k, v]) => [Number(k), v]));
|
|
134
|
+
const shaOf = async (n) => {
|
|
135
|
+
if (!shas.has(n)) shas.set(n, String(await gh(["api", `repos/${repo}/pulls/${n}`, "--jq", ".merge_commit_sha"])).trim() || null);
|
|
136
|
+
return shas.get(n);
|
|
137
|
+
};
|
|
138
|
+
await mapLimit(todo, CONCURRENCY, async (x) => {
|
|
139
|
+
const t0 = ms(x.endTs), inWin = (p) => p.number !== x.pr && ms(p.merged_at) != null && ms(p.merged_at) > t0 && ms(p.merged_at) <= t0 + windowMs;
|
|
140
|
+
const reopens = lines(await gh(["api", "--paginate", `repos/${repo}/issues/${x.issue}/events?per_page=100`, "--jq", '.[] | select(.event == "reopened") | {issue: .issue.number, ts: .created_at}']));
|
|
141
|
+
const reopen = reopens.some((e) => (e.issue ?? x.issue) === x.issue && (ms(e.ts) ?? 0) > t0);
|
|
142
|
+
const own = prs.find((p) => p.number === x.pr);
|
|
143
|
+
const lane = { repo, number: x.pr, title: own?.title ?? "", body: own?.body ?? "", closingIssues: [{ number: x.issue }] };
|
|
144
|
+
const later = prs.filter(inWin);
|
|
145
|
+
const revert = later.some((q) => reverts(q, lane, repo));
|
|
146
|
+
const cited = later.some((q) => cites(q, lane));
|
|
147
|
+
const fixes = later.filter(isFix);
|
|
148
|
+
let same_hunks = false;
|
|
149
|
+
if (fixes.length) {
|
|
150
|
+
lane.mergeSha = git ? await shaOf(x.pr) : null;
|
|
151
|
+
const withSha = lane.mergeSha ? await Promise.all(fixes.map(async (q) => ({ ...q, mergeSha: await shaOf(q.number) }))) : fixes;
|
|
152
|
+
same_hunks = sameHunks(lane, withSha, git);
|
|
153
|
+
}
|
|
154
|
+
const hit = reopen || revert || cited || same_hunks === true;
|
|
155
|
+
const value = { reopen, revert, cited, same_hunks, defect: hit ? true : same_hunks === null ? null : false };
|
|
156
|
+
out.set(x.issue, value);
|
|
157
|
+
if (settled(x)) cache.defects[`${x.issue}:${x.pr}`] = { endTs: x.endTs, value };
|
|
158
|
+
onProgress?.({ phase: "defect signals", done: ++done, total });
|
|
159
|
+
});
|
|
160
|
+
if (useCache) { cache.shas = Object.fromEntries(shas); saveDefectCache(repo, env, cache); }
|
|
161
|
+
} catch { // gh unavailable: the unread rows get null defect fields (n/a), never false
|
|
162
|
+
for (const x of merged) if (!out.has(x.issue)) out.set(x.issue, { reopen: null, revert: null, cited: null, same_hunks: null, defect: null });
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** The metrics of one group of rows; `defects` maps issue -> {defect}. */
|
|
168
|
+
export function depthCell(rows, defects = new Map()) {
|
|
169
|
+
const n = rows.length;
|
|
170
|
+
const fp = rows.filter((x) => typeof x.firstPass === "boolean");
|
|
171
|
+
const known = rows.filter((x) => x.merged && typeof defects.get(x.issue)?.defect === "boolean");
|
|
172
|
+
const ratios = rows.filter((x) => x.wallMs != null && x.modelMs > 0).map((x) => x.wallMs / x.modelMs);
|
|
173
|
+
return { n, merge_rate: r(per(rows.filter((x) => x.merged).length, n)), needs_human_rate: r(per(rows.filter((x) => x.needsHuman).length, n)),
|
|
174
|
+
first_pass_rate: r(per(fp.filter((x) => x.firstPass).length, fp.length)), median_cost_usd: r(median(rows.map((x) => x.cost)), 1e4),
|
|
175
|
+
median_wall_min: r(median(rows.map((x) => (x.wallMs == null ? null : x.wallMs / 60000))), 100), median_wall_over_model: r(median(ratios), 100),
|
|
176
|
+
findings_per_lane: r(per(rows.reduce((a, x) => a + x.findings, 0), n), 100), share_with_findings: r(per(rows.filter((x) => x.findings > 0).length, n)),
|
|
177
|
+
conformance_failure_rate: r(per(rows.filter((x) => x.conformanceFailures > 0).length, n)),
|
|
178
|
+
defects_n: known.length, defect_rate: known.length ? r(per(known.filter((x) => defects.get(x.issue).defect).length, known.length)) : null };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const check = (value, limit, nT, nC, minN, cmp) => {
|
|
182
|
+
if (nT < minN || (nC != null && nC < minN) || value == null) return { value: r(value, 100), limit, n_treatment: nT, ...(nC != null ? { n_control: nC } : {}), met: null, verdict: INSUFFICIENT };
|
|
183
|
+
const met = cmp(value, limit);
|
|
184
|
+
return { value: r(value, 100), limit, n_treatment: nT, ...(nC != null ? { n_control: nC } : {}), met, verdict: met ? "met" : "not met" };
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The #5052 promotion verdict: treatment = light-shaped lanes (light or upgraded: the true cost of trying light);
|
|
189
|
+
* control = full-shape lanes the gate rated eligible, in the size buckets both cohorts have (#4491 matched sizes).
|
|
190
|
+
*/
|
|
191
|
+
export function promotion(rows, defects = new Map(), minN = DEFAULT_MIN_N) {
|
|
192
|
+
const sz = (x) => x.size ?? "unknown";
|
|
193
|
+
const t0 = rows.filter((x) => x.shape === "light" || x.shape === "upgraded"), c0 = rows.filter((x) => x.shape === "full" && x.verdict === "eligible");
|
|
194
|
+
const sizes = [...new Set(t0.map(sz))].filter((s) => c0.some((x) => sz(x) === s)).sort();
|
|
195
|
+
const t = t0.filter((x) => sizes.includes(sz(x))), c = c0.filter((x) => sizes.includes(sz(x)));
|
|
196
|
+
const tc = depthCell(t, defects), cc = depthCell(c, defects);
|
|
197
|
+
const cost = check(tc.median_cost_usd != null && cc.median_cost_usd > 0 ? tc.median_cost_usd / cc.median_cost_usd : null, PROMOTION.costRatio, t.length, c.length, minN, (v, l) => v <= l);
|
|
198
|
+
const wallRows = t0.filter((x) => x.wallMs != null && x.modelMs > 0);
|
|
199
|
+
const wall = check(median(wallRows.map((x) => x.wallMs / x.modelMs)), PROMOTION.wallOverModel, wallRows.length, null, minN, (v, l) => v <= l);
|
|
200
|
+
const defect = tc.defect_rate != null && cc.defect_rate != null && tc.defects_n >= minN && cc.defects_n >= minN
|
|
201
|
+
? { value: tc.defect_rate, limit: cc.defect_rate, n_treatment: tc.defects_n, n_control: cc.defects_n, met: tc.defect_rate <= cc.defect_rate, verdict: tc.defect_rate <= cc.defect_rate ? "met" : "not met" }
|
|
202
|
+
: { value: tc.defect_rate, limit: cc.defect_rate, n_treatment: tc.defects_n, n_control: cc.defects_n, met: null, verdict: INSUFFICIENT };
|
|
203
|
+
const checks = { cost, wall, defects: defect };
|
|
204
|
+
const vs = Object.values(checks).map((x) => x.met);
|
|
205
|
+
const met = vs.includes(false) ? false : vs.every((x) => x === true) ? true : INSUFFICIENT;
|
|
206
|
+
return { met, sizes, n_treatment: t.length, n_control: c.length, min_n: minN, checks, note: "flipping lean.light.mode: on stays a config decision" };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The promotion recommendation from shadow data (#5318): eligible share of lanes, would-be saving (eligible full lanes x
|
|
211
|
+
* the median cost gap to light-shaped lanes) and the defect rate on eligible lanes. The decision follows promotion().met.
|
|
212
|
+
*/
|
|
213
|
+
export function recommendation(rows, defects, prom) {
|
|
214
|
+
const elig = rows.filter((x) => x.verdict === "eligible"), full = elig.filter((x) => x.shape === "full");
|
|
215
|
+
const light = rows.filter((x) => x.shape === "light" || x.shape === "upgraded");
|
|
216
|
+
const fullMed = median(full.map((x) => x.cost)), lightMed = median(light.map((x) => x.cost));
|
|
217
|
+
const saving = fullMed != null && lightMed != null ? r(full.length * (fullMed - lightMed), 100) : null;
|
|
218
|
+
const decision = prom.met === true ? "promote" : prom.met === false ? "do not promote" : INSUFFICIENT;
|
|
219
|
+
return { decision, eligible_share: r(per(elig.length, rows.length)), eligible_n: elig.length, would_be_saving_usd: saving, eligible_defect_rate: depthCell(elig, defects).defect_rate };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Pure report: per verdict, per reason/signal code, and the promotion verdict. */
|
|
223
|
+
export function depthReport({ rows = [], defects = new Map(), minN = DEFAULT_MIN_N, defectsSource = "github" } = {}) {
|
|
224
|
+
const byVerdict = {};
|
|
225
|
+
for (const v of [...VERDICTS, ...new Set(rows.map((x) => x.verdict).filter((v) => !VERDICTS.includes(v)))]) {
|
|
226
|
+
const xs = rows.filter((x) => x.verdict === v);
|
|
227
|
+
if (xs.length || VERDICTS.includes(v)) byVerdict[v] = depthCell(xs, defects);
|
|
228
|
+
}
|
|
229
|
+
const byCode = {};
|
|
230
|
+
for (const code of [...new Set(rows.flatMap((x) => [...x.reasons, ...x.signals]))].sort()) byCode[code] = depthCell(rows.filter((x) => x.reasons.includes(code) || x.signals.includes(code)), defects);
|
|
231
|
+
const prom = promotion(rows, defects, minN);
|
|
232
|
+
const unresolved = rows.filter((x) => x.merged && defects.get(x.issue)?.defect === null).length;
|
|
233
|
+
return { lanes: rows.length, min_n: minN, defects_source: defectsSource, defects_unresolved: unresolved, by_verdict: byVerdict, by_code: byCode, promotion: prom, recommendation: recommendation(rows, defects, prom) };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const pct = (x) => (x == null ? "n/a" : `${Math.round(x * 100)}%`);
|
|
237
|
+
const val = (x, unit = "") => (x == null ? "n/a" : `${x}${unit}`);
|
|
238
|
+
const cellLine = (label, c) => ` ${label}: n=${c.n}, merge ${pct(c.merge_rate)}, first-pass ${pct(c.first_pass_rate)}, needs-human ${pct(c.needs_human_rate)}, `
|
|
239
|
+
+ `median cost ${c.median_cost_usd == null ? "n/a" : `$${c.median_cost_usd.toFixed(4)}`}, wall ${val(c.median_wall_min, " min")}, findings/lane ${val(c.findings_per_lane)} `
|
|
240
|
+
+ `(${pct(c.share_with_findings)} with any), conformance failures ${pct(c.conformance_failure_rate)}, post-merge defects ${pct(c.defect_rate)} (n=${c.defects_n})`;
|
|
241
|
+
|
|
242
|
+
/** Text lines of depthReport. */
|
|
243
|
+
export function renderDepth(rep, { repo = null, since = null } = {}) {
|
|
244
|
+
const out = [`lane depth${repo ? ` ${repo}` : ""}${since ? ` since ${since}` : ""}: ${rep.lanes} lane(s) with a light-eligibility verdict; defect signals: ${rep.defects_source}${rep.defects_unresolved ? `, ${rep.defects_unresolved} unresolved (n/a: same-hunks needs a local clone of the repo)` : ""}`];
|
|
245
|
+
out.push("by verdict:");
|
|
246
|
+
for (const [v, c] of Object.entries(rep.by_verdict)) out.push(cellLine(v, c));
|
|
247
|
+
out.push("by reason/signal:");
|
|
248
|
+
const codes = Object.entries(rep.by_code);
|
|
249
|
+
if (!codes.length) out.push(" n/a");
|
|
250
|
+
for (const [k, c] of codes) out.push(cellLine(k, c));
|
|
251
|
+
const p = rep.promotion, ck = p.checks;
|
|
252
|
+
const fmt = (name, x, unit) => ` ${name}: ${x.verdict}${x.value == null ? "" : ` (${x.value}${unit} vs ${x.limit}${unit})`}, n treatment=${x.n_treatment}${x.n_control != null ? `, n control=${x.n_control}` : ""}`;
|
|
253
|
+
out.push(`light-lane promotion (#5052, min n ${p.min_n} per cell): ${p.met === true ? "met" : p.met === false ? "not met" : INSUFFICIENT}`
|
|
254
|
+
+ ` (treatment light|upgraded n=${p.n_treatment}, control eligible full n=${p.n_control}, sizes ${p.sizes.length ? p.sizes.join(",") : "none"})`);
|
|
255
|
+
out.push(fmt("cost ratio", ck.cost, "x"), fmt("wall/model", ck.wall, "x"), fmt("defect rate", ck.defects, ""));
|
|
256
|
+
out.push(` ${p.note}`);
|
|
257
|
+
const rc = rep.recommendation;
|
|
258
|
+
if (rc) out.push(`recommendation: ${rc.decision}; eligible share ${pct(rc.eligible_share)} (n=${rc.eligible_n}), would-be saving ${rc.would_be_saving_usd == null ? "n/a" : `$${rc.would_be_saving_usd.toFixed(2)}`} over the window, defect rate on eligible lanes ${pct(rc.eligible_defect_rate)}`);
|
|
259
|
+
return out.join("\n");
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Every run log under `runsDir` -> rows -> defects (gh, unless null) -> report. */
|
|
263
|
+
export async function buildDepth({ runsDir, repo = null, sinceMs = null, gh = null, minN = DEFAULT_MIN_N, now = null, env = process.env, useCache = false, refresh = false, onProgress = null, git = null } = {}) {
|
|
264
|
+
const rows = [];
|
|
265
|
+
if (runsDir && existsSync(runsDir)) {
|
|
266
|
+
for (const f of readdirSync(runsDir).filter((x) => x.endsWith(".jsonl")).sort()) {
|
|
267
|
+
let text = "";
|
|
268
|
+
try { text = readFileSync(join(runsDir, f), "utf8"); } catch { continue; }
|
|
269
|
+
const n = /^(\d+)\.jsonl$/.exec(f);
|
|
270
|
+
rows.push(...depthRows(parseLog(text), { repo, sinceMs, issue: n ? Number(n[1]) : null }));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const defects = gh ? await gatherDefects({ repo, gh, rows, now, env, useCache, refresh, onProgress, git }) : new Map();
|
|
274
|
+
return depthReport({ rows, defects, minN, defectsSource: gh ? "github" : "offline" });
|
|
275
|
+
}
|