forgedock 1.66.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 +3 -0
- package/bin/engine/outcome-codes.mjs +2 -0
- package/bin/engine-cli.mjs +193 -27
- package/bin/engine.mjs +10 -0
- package/bin/forgedock.mjs +24 -1
- package/bin/help-text.mjs +4 -3
- package/bin/introspect-schedule.mjs +98 -0
- package/bin/introspect-schedule.test.mjs +67 -0
- package/bin/lean/admission.mjs +21 -0
- package/bin/lean/admission.test.mjs +30 -0
- package/bin/lean/advisory.test.mjs +64 -0
- package/bin/lean/amendment-schema.mjs +30 -0
- package/bin/lean/attempts.mjs +162 -0
- package/bin/lean/attempts.test.mjs +141 -0
- package/bin/lean/basered.mjs +81 -0
- package/bin/lean/basered.test.mjs +68 -1
- package/bin/lean/batch-health.mjs +20 -12
- package/bin/lean/batch-health.test.mjs +55 -11
- package/bin/lean/batch.mjs +45 -0
- package/bin/lean/batch.test.mjs +105 -5
- package/bin/lean/capwait.mjs +14 -3
- package/bin/lean/capwait.test.mjs +20 -0
- 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.mjs +14 -0
- package/bin/lean/clear-breaker.test.mjs +4 -3
- package/bin/lean/commentstate.mjs +46 -0
- package/bin/lean/commentstate.test.mjs +43 -0
- package/bin/lean/concurrency.mjs +89 -0
- package/bin/lean/concurrency.test.mjs +113 -0
- package/bin/lean/conformance.e2e.test.mjs +13 -8
- package/bin/lean/conformance.mjs +73 -181
- package/bin/lean/conformance.test.mjs +61 -345
- 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/efficiency.mjs +162 -0
- package/bin/lean/efficiency.test.mjs +79 -0
- 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 +41 -17
- package/bin/lean/execution.test.mjs +58 -0
- package/bin/lean/failure-census.mjs +170 -0
- package/bin/lean/failure-census.test.mjs +59 -0
- package/bin/lean/failure-stop.mjs +46 -0
- package/bin/lean/failure-stop.test.mjs +45 -0
- package/bin/lean/fixtures/capacity-storm.json +609 -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 +311 -154
- package/bin/lean/lean.test.mjs +530 -223
- 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/liveness.mjs +37 -0
- package/bin/lean/liveness.test.mjs +33 -0
- package/bin/lean/orchestrate-attempts.test.mjs +82 -0
- 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 +76 -1
- package/bin/lean/orchestrate-reconcile.test.mjs +164 -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 +344 -45
- package/bin/lean/phaseledger.mjs +6 -0
- package/bin/lean/phaseledger.test.mjs +13 -1
- 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 +13 -28
- package/bin/lean/reconcile.mjs +90 -0
- package/bin/lean/recurrence.mjs +6 -112
- package/bin/lean/recurrence.test.mjs +11 -92
- 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 +49 -11
- package/bin/lean/sched.mjs +19 -0
- package/bin/lean/sched.test.mjs +11 -1
- package/bin/lean/schedd-health.mjs +4 -4
- package/bin/lean/schedd-health.test.mjs +8 -4
- package/bin/lean/schedd.mjs +45 -8
- package/bin/lean/schedd.test.mjs +120 -7
- package/bin/lean/selfreview.mjs +1 -1
- package/bin/lean/slo.mjs +126 -0
- package/bin/lean/slo.test.mjs +112 -0
- package/bin/lean/statuscomment.mjs +40 -0
- package/bin/lean/statuscomment.test.mjs +48 -1
- package/bin/lean/validate-catalog.mjs +108 -0
- package/bin/lean/validate-catalog.test.mjs +46 -1
- package/bin/lean/verify.mjs +3 -2
- package/bin/pool/affinity.test.mjs +91 -0
- package/bin/pool/agent.mjs +144 -10
- package/bin/pool/cache-sweep.mjs +31 -10
- package/bin/pool/ci-autoscale.mjs +160 -0
- package/bin/pool/cli.mjs +53 -9
- 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 +26 -0
- 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/attempts.mjs +54 -0
- package/bin/stats/attempts.test.mjs +30 -0
- package/bin/stats/churn.mjs +49 -0
- package/bin/stats/churn.test.mjs +31 -0
- package/bin/stats/index.mjs +11 -3
- 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/commands/orchestrate.md +21 -18
- package/docs/CONFIG.md +41 -0
- package/docs/OUTCOME-CODES.md +2 -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/check-devdocs-freshness.sh +1 -1
- 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/batch.test.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { join } from "node:path";
|
|
|
8
8
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
9
9
|
import { resolveLane, makeLaneCache } from "./lane.mjs";
|
|
10
10
|
import { orchestrate, deferPolicy, DEFER_BACKOFF_S, formatOutcomeLists, CAPACITY_FALLBACK_AFTER, isTransientEngineError, transientRetryDelayMs, DEFAULT_TRANSIENT_RETRIES } from "./orchestrate.mjs";
|
|
11
|
-
import { openBatch, fsTypeOf, assertDiskPath, isLaneAlive, writeAtomic, launchLane, detachedLanes, stackedOnOf } from "./batch.mjs";
|
|
11
|
+
import { openBatch, fsTypeOf, assertDiskPath, isLaneAlive, writeAtomic, launchLane, detachedLanes, stackedOnOf, keptSandboxes } from "./batch.mjs";
|
|
12
12
|
import { makeLedger } from "./ledger.mjs";
|
|
13
13
|
import { placeLane } from "./execution.mjs";
|
|
14
14
|
import { liveRemote } from "./live-execution.mjs";
|
|
@@ -114,6 +114,39 @@ await orchestrateFromCli(["1", "2", "3", "--parallel", "2", "--repo", "o/r", "--
|
|
|
114
114
|
assert.equal(other.saves.map((s) => s.breaker).find(Boolean)?.transport, undefined);
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
+
it("breaker trip with pending issues keeps the batch open and dispatches after the cooldown (#6042)", async () => {
|
|
118
|
+
const run = async (detail, clearAt = null) => {
|
|
119
|
+
let t = 0; const launched = []; let req = null;
|
|
120
|
+
const rows = await orchestrate({ issues: [1, 2, 3, 4], parallel: 1, readBody: async () => "", now: () => t, maxDeferrals: 3, breaker: { errors: 3, window_min: 30 }, pollMs: 1000,
|
|
121
|
+
sleep: async (ms) => { t += ms; if (clearAt !== null && t >= clearAt) req = t; },
|
|
122
|
+
getClearBreaker: clearAt === null ? null : () => req, consumeClearBreaker: () => { req = null; },
|
|
123
|
+
store: { load: () => null, save: () => {} },
|
|
124
|
+
runOne: async (n) => { launched.push(n); t += 1000; return n <= 3 && launched.filter((x) => x === n).length === 1 && launched.length <= 3 ? { terminalReason: "engine-error", detail } : { terminalReason: "merged", pr: 5 }; } });
|
|
125
|
+
return { rows, launched };
|
|
126
|
+
};
|
|
127
|
+
const env = await run("VM restart: sandbox.lost");
|
|
128
|
+
assert.ok(env.launched.length > 3, "the environmental trip auto-clears after the cooldown and dispatch resumes");
|
|
129
|
+
const hosted = await run("boom", 60000);
|
|
130
|
+
assert.ok(hosted.launched.length > 3, "a hosted clear request resumes dispatch without a --resume");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("a sandbox-gone burst from one pool agent (VM restart) does not trip the breaker (#6042, #5859)", async () => {
|
|
134
|
+
const updates = []; const seen = new Set();
|
|
135
|
+
const rows = await orchestrate({ issues: [1, 2, 3, 4, 5], parallel: 5, readBody: async () => "", maxDeferrals: 3, breaker: { errors: 3, window_min: 10 }, onUpdate: (r) => updates.push(r),
|
|
136
|
+
store: { load: () => null, save: () => {} },
|
|
137
|
+
runOne: async (n) => { if (!seen.has(n)) { seen.add(n); return { terminalReason: "engine-error", detail: `sandbox fake-${n} exited without a result`, lostWithoutResult: true, agent: "legion" }; } return { terminalReason: "merged", pr: 5 }; } });
|
|
138
|
+
assert.ok(!updates.some((u) => u.outcome === "breaker"), "the breaker never trips");
|
|
139
|
+
assert.ok(rows.filter((r) => r.outcome === "merged").length === 5);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("a non-environmental breaker with no clear channel still ends the run with issues pending (#6042 P1)", async () => {
|
|
143
|
+
let t = 0; const launched = [];
|
|
144
|
+
await orchestrate({ issues: [1, 2, 3, 4], parallel: 1, readBody: async () => "", now: () => t, sleep: async (ms) => { t += ms; }, maxDeferrals: 3, breaker: { errors: 3, window_min: 30 },
|
|
145
|
+
store: { load: () => null, save: () => {} },
|
|
146
|
+
runOne: async (n) => { launched.push(n); t += 1000; return { terminalReason: "engine-error", detail: "boom" }; } });
|
|
147
|
+
assert.ok(!launched.includes(4));
|
|
148
|
+
});
|
|
149
|
+
|
|
117
150
|
it("gh.unavailable deferrals (forge#4157) are requeued, never relaunched as engine-error, and never trip the breaker", async () => {
|
|
118
151
|
const { now, sleep } = fakeClock();
|
|
119
152
|
const updates = [];
|
|
@@ -273,9 +306,9 @@ await orchestrateFromCli(["1", "2", "3", "--parallel", "2", "--repo", "o/r", "--
|
|
|
273
306
|
assert.equal(isLaneAlive(42, "lane", { kill: () => true, procDir: proc }), false);
|
|
274
307
|
assert.deepEqual(stackedOnOf({ stacked: { 7: { dependency: 6, branch: "b", sha: "abcdef1" } } }, 7), { dependency: 6, branch: "b", sha: "abcdef1" }, "#5832: stackedOn read from batch state");
|
|
275
308
|
assert.equal(stackedOnOf({}, 7), null);
|
|
276
|
-
assert.deepEqual(readOrchestration(root), { breaker: { errors: 3, window_min: 30 }, maxDeferrals: 3, transientRetries: 4, blockedLabel: "blocked", globalParallel: null, stacking: "off", recovery: { maxAttempts: 1, mechanicalMaxAttempts: 2 }, baseSync: { enabled: true, unionGlobs: [] }, mergeTrain: "off", mergeTrainBatch: 4 });
|
|
309
|
+
assert.deepEqual(readOrchestration(root), { breaker: { errors: 3, window_min: 30 }, maxDeferrals: 3, transientRetries: 4, blockedLabel: "blocked", globalParallel: null, stacking: "off", recovery: { maxAttempts: 1, mechanicalMaxAttempts: 2 }, baseSync: { enabled: true, unionGlobs: [] }, mergeTrain: "off", mergeTrainBatch: 4, maxAttemptsPerIssue: 4, maxIdenticalSignature: 2 });
|
|
277
310
|
writeFileSync(join(root, "forge.yaml"), "orchestration:\n breaker:\n errors: 5\n window_min: 10\n max_deferrals: 2\n global_parallel: 4\n transient_retries: 2\n");
|
|
278
|
-
assert.deepEqual(readOrchestration(root), { breaker: { errors: 5, window_min: 10 }, maxDeferrals: 2, transientRetries: 2, blockedLabel: "blocked", globalParallel: 4, stacking: "off", recovery: { maxAttempts: 1, mechanicalMaxAttempts: 2 }, baseSync: { enabled: true, unionGlobs: [] }, mergeTrain: "off", mergeTrainBatch: 4 });
|
|
311
|
+
assert.deepEqual(readOrchestration(root), { breaker: { errors: 5, window_min: 10 }, maxDeferrals: 2, transientRetries: 2, blockedLabel: "blocked", globalParallel: 4, stacking: "off", recovery: { maxAttempts: 1, mechanicalMaxAttempts: 2 }, baseSync: { enabled: true, unionGlobs: [] }, mergeTrain: "off", mergeTrainBatch: 4, maxAttemptsPerIssue: 4, maxIdenticalSignature: 2 });
|
|
279
312
|
});
|
|
280
313
|
|
|
281
314
|
it("run-issue --result-file writes the lane result, also when the run throws", async () => {
|
|
@@ -1464,6 +1497,22 @@ describe("#4592: forgedock orchestrate --hold / --release", () => {
|
|
|
1464
1497
|
assert.ok(!lines.some((x) => /held \(none\)/.test(x)));
|
|
1465
1498
|
});
|
|
1466
1499
|
|
|
1500
|
+
it("#5988: --hold on more than 10 issues needs an explicit --ttl and prints the resume plan; --ttl is parsed like --for", async () => {
|
|
1501
|
+
const root = tmpDir("batch-hold-ttl-");
|
|
1502
|
+
const b = openBatch(root, "b1");
|
|
1503
|
+
const many = Array.from({ length: 12 }, (_, i) => i + 1);
|
|
1504
|
+
b.writePlan({ argv: [], repo: "o/r" });
|
|
1505
|
+
b.store.save({ order: many });
|
|
1506
|
+
const io = { gh: async () => JSON.stringify({ state: "OPEN" }) };
|
|
1507
|
+
await assert.rejects(orchestrateFromCli(["--hold", "b1", ...many.map(String)], { batchRoot: root, io }), /requires an explicit --ttl/);
|
|
1508
|
+
assert.deepEqual(b.readHeld(), []);
|
|
1509
|
+
const lines = []; const l = console.log; console.log = (x) => lines.push(String(x));
|
|
1510
|
+
let res; try { res = await orchestrateFromCli(["--hold", "b1", ...many.map(String), "--ttl", "4h"], { batchRoot: root, io }); } finally { console.log = l; }
|
|
1511
|
+
assert.equal(res.changed.length, 12);
|
|
1512
|
+
assert.ok(lines.some((x) => /resume plan: 12 issues held for 4h; an alert posts 30 min before expiry/.test(x)), lines.join("\n"));
|
|
1513
|
+
assert.ok(Object.values(b.readHoldInfo()).every((h) => Number.isFinite(Date.parse(h.expiresAt))), "the ttl set an expiry");
|
|
1514
|
+
});
|
|
1515
|
+
|
|
1467
1516
|
it("through the CLI: --hold / --release write the hold file (usage and unknown batch reject); --resume <id> N releases N", async () => {
|
|
1468
1517
|
const root = tmpDir("batch-hold-cli-");
|
|
1469
1518
|
const b = openBatch(root, "b1");
|
|
@@ -1741,7 +1790,7 @@ describe("#5161 transient engine-error retries", () => {
|
|
|
1741
1790
|
const rows = await orchestrate({ issues: [1, 2], parallel: 1, readBody: async () => "", now, sleep, breaker: { errors: 2, window_min: 30 },
|
|
1742
1791
|
store: { load: () => null, save: (st) => saves.push(st) }, runOne: async () => { throw new Error(CURL_502); } });
|
|
1743
1792
|
assert.equal(saves.map((st) => st.breaker).find(Boolean)?.transport, true);
|
|
1744
|
-
assert.ok(rows.some((r) => r.outcome === "held"));
|
|
1793
|
+
assert.ok(!rows.some((r) => r.outcome === "held"), "#6042: a transport trip pauses admission and the batch stays open instead of ending held");
|
|
1745
1794
|
});
|
|
1746
1795
|
});
|
|
1747
1796
|
|
|
@@ -1918,7 +1967,7 @@ describe("#5168: --requeue accepts engine-error; a claude login failure is held,
|
|
|
1918
1967
|
} });
|
|
1919
1968
|
assert.deepEqual(rows.map((r) => r.outcome), ["merged", "merged"]);
|
|
1920
1969
|
assert.equal(starts[1].length, 4, "deferred past maxDeferrals: the hold is uncapped");
|
|
1921
|
-
assert.ok(starts[2][0] >= t0 +
|
|
1970
|
+
assert.ok(starts[2][0] >= t0 + 300_000, "the held account admits nothing until the next probe (#5988: held at most 5 min, not the 15 min retry hint)");
|
|
1922
1971
|
assert.ok(!updates.some((u) => u.outcome === "breaker" || u.outcome === "engine-error"));
|
|
1923
1972
|
assert.ok(updates.some((u) => u.outcome === "paused" && /paused \(backend\.auth\)/.test(u.detail ?? "")));
|
|
1924
1973
|
});
|
|
@@ -2145,3 +2194,54 @@ describe("#5975: batch pause", () => {
|
|
|
2145
2194
|
assert.equal(evaluateDispatchStall(state, { ...opts, paused: { reason: "x" } }), null);
|
|
2146
2195
|
});
|
|
2147
2196
|
});
|
|
2197
|
+
|
|
2198
|
+
describe("#5992: base.red is a batch hold, not a per-issue capped deferral", () => {
|
|
2199
|
+
it("base.red is uncapped; other codes still cap", () => {
|
|
2200
|
+
assert.deepEqual(deferPolicy({ code: "base.red", retryInSeconds: 900 }, { now: 0, deferrals: 99, maxDeferrals: 3 }), { delayMs: 900000, host: true });
|
|
2201
|
+
assert.deepEqual(deferPolicy({ code: "merge.transient", retryInSeconds: 60 }, { now: 0, deferrals: 3, maxDeferrals: 3 }), { capped: true });
|
|
2202
|
+
});
|
|
2203
|
+
|
|
2204
|
+
it("10 lanes + red base: 1 probe run, only the fixer launches, no 'gave up'; a sha move resumes admission in one pass", async () => {
|
|
2205
|
+
const { c, now, sleep } = fakeClock();
|
|
2206
|
+
const issues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
2207
|
+
const launches = [], updates = [];
|
|
2208
|
+
let sha = "a".repeat(40), probes = 0;
|
|
2209
|
+
const baseProbe = async () => { probes++; return sha === "a".repeat(40) ? { red: true, sha, commands: ["guard"], att: { sha: "f".repeat(40), issue: 10 } } : { red: false, sha }; };
|
|
2210
|
+
let passes = 0;
|
|
2211
|
+
const rows = await orchestrate({ issues, parallel: 10, maxDeferrals: 3, now, readBody: async () => "", baseProbe, pollMs: 10,
|
|
2212
|
+
onUpdate: (u) => updates.push(u),
|
|
2213
|
+
sleep: async (ms) => { await sleep(ms); if (++passes === 3) sha = "b".repeat(40); },
|
|
2214
|
+
runOne: async (n) => { launches.push([n, sha === "a".repeat(40) ? "red" : "green"]); return { terminalReason: "merged", pr: 100 + n }; } });
|
|
2215
|
+
const redLaunches = launches.filter((l) => l[1] === "red").map((l) => l[0]);
|
|
2216
|
+
assert.deepEqual(redLaunches, [10], "only the attributed fixer is admitted while the base is red");
|
|
2217
|
+
assert.equal(launches.length, 10, "every lane runs once after the base moves");
|
|
2218
|
+
assert.ok(rows.every((r) => r.outcome === "merged"));
|
|
2219
|
+
assert.ok(!rows.some((r) => /gave up/.test(r.detail ?? "")));
|
|
2220
|
+
assert.equal(updates.filter((u) => u.code === "base.red").length, 1, "one batch-level hold row");
|
|
2221
|
+
assert.ok(updates.some((u) => /base\.red cleared/.test(u.detail ?? "")));
|
|
2222
|
+
assert.ok(c.t >= 1_000_000);
|
|
2223
|
+
});
|
|
2224
|
+
});
|
|
2225
|
+
|
|
2226
|
+
// #5978: the selector is kept in the batch plan argv/state; coverage classifies every matching open issue.
|
|
2227
|
+
import { coverage as coverage5978 } from "./batch.mjs";
|
|
2228
|
+
describe("coverage (#5978)", () => {
|
|
2229
|
+
it("every open match lands in exactly one class; human-blocked is the only unscheduled-allowed class", () => {
|
|
2230
|
+
const state = { pending: [2], running: { 1: {} }, results: { 3: { outcome: "needs-human", detail: "needs a product decision" } } };
|
|
2231
|
+
const c = coverage5978({ state, open: [1, 2, 3].map((number) => ({ number })) });
|
|
2232
|
+
assert.deepEqual([c.running, c.queued, c.humanBlocked, c.unscheduled], [[1], [2], [3], []]);
|
|
2233
|
+
});
|
|
2234
|
+
it("a human label blocks an issue with no row; an unknown one is unscheduled", () => {
|
|
2235
|
+
const c = coverage5978({ state: { pending: [] }, open: [{ number: 4, labels: ["human:credentials"] }, { number: 5, labels: ["bug"] }] });
|
|
2236
|
+
assert.deepEqual([c.humanBlocked, c.unscheduled], [[4], [5]]);
|
|
2237
|
+
});
|
|
2238
|
+
});
|
|
2239
|
+
|
|
2240
|
+
describe("#6008 kept-sandbox listing", () => {
|
|
2241
|
+
it("lists issue, age and phase from state.kept and, with no live dispatcher, from remote run records", () => {
|
|
2242
|
+
const state = { kept: { 5: { issue: 5, since: 1_000, phase: "review", id: "sbx-5" } }, running: { 6: { startedAt: 4_000, remote: true, handle: { id: "sbx-6" } }, 7: { startedAt: 4_000, pid: 99 } } };
|
|
2243
|
+
const rows = keptSandboxes(state, { now: 61_000 });
|
|
2244
|
+
assert.deepEqual(rows.map((r) => [r.issue, r.ageMs, r.phase]), [[5, 60_000, "review"], [6, 57_000, null]]);
|
|
2245
|
+
assert.deepEqual(keptSandboxes(state, { now: 61_000, live: true }).map((r) => r.issue), [5], "a live dispatcher's running lanes are not kept");
|
|
2246
|
+
});
|
|
2247
|
+
});
|
package/bin/lean/capwait.mjs
CHANGED
|
@@ -4,22 +4,33 @@
|
|
|
4
4
|
* Capacity wait (#4909): a lane whose sandbox launch was refused for capacity (`sandbox.capacity`) is admitted again only
|
|
5
5
|
* once the pool reports a free slot (`capacity() -> {free}`), not on a blind timer retry; the wait is recorded as queue
|
|
6
6
|
* time (`waits.queue`, ms). A pool that does not report `free` is unknown: the provider's retry-in applies as before.
|
|
7
|
+
* #5985: a refusal that names its reason (`pool.host_load`, `pool.host_mem`) waits on that condition clearing (load below
|
|
8
|
+
* 1.0, free memory above the floor) instead; with no figures for it the slot count above is the fallback.
|
|
7
9
|
*/
|
|
10
|
+
import { conditionCleared } from "./concurrency.mjs";
|
|
11
|
+
|
|
8
12
|
export function makeCapWait({ now = Date.now } = {}) {
|
|
9
13
|
const since = new Map(); // issue -> when its launch was refused for capacity
|
|
14
|
+
const reasons = new Map(); // issue -> the pool reason of its refusal (#5985)
|
|
10
15
|
const waited = new Map(); // issue -> queue ms accumulated, not yet recorded on a row
|
|
11
16
|
const isFree = (cap) => Boolean(cap) && Number.isInteger(cap.free) && cap.free > 0;
|
|
12
17
|
const isFull = (cap) => Boolean(cap) && Number.isInteger(cap.free) && cap.free <= 0;
|
|
13
18
|
return {
|
|
14
19
|
/** A launch of `issue` was refused for capacity. */
|
|
15
|
-
refused(issue) { if (!since.has(issue)) since.set(issue, now()); },
|
|
20
|
+
refused(issue, reason = null) { if (!since.has(issue)) since.set(issue, now()); if (reason) reasons.set(issue, reason); else reasons.delete(issue); },
|
|
16
21
|
/** True while a refused `issue` must keep waiting: the sampled pool reports no free slot. */
|
|
17
|
-
blocked(issue, cap) {
|
|
22
|
+
blocked(issue, cap) {
|
|
23
|
+
if (!since.has(issue)) return false;
|
|
24
|
+
const c = conditionCleared(reasons.get(issue), cap);
|
|
25
|
+
return c === null ? isFull(cap) : !c;
|
|
26
|
+
},
|
|
27
|
+
/** True when `cap` has the figures the refusal's named condition needs (the timer is not the wake). */
|
|
28
|
+
conditional(issue, cap) { return since.has(issue) && conditionCleared(reasons.get(issue), cap) !== null; },
|
|
18
29
|
/** `issue` was admitted: bank its wait as queue time. Returns the ms waited (0 when it was not refused). */
|
|
19
30
|
admitted(issue) {
|
|
20
31
|
if (!since.has(issue)) return 0;
|
|
21
32
|
const ms = Math.max(0, now() - since.get(issue));
|
|
22
|
-
since.delete(issue);
|
|
33
|
+
since.delete(issue); reasons.delete(issue);
|
|
23
34
|
waited.set(issue, (waited.get(issue) ?? 0) + ms);
|
|
24
35
|
return ms;
|
|
25
36
|
},
|
|
@@ -46,3 +46,23 @@ describe("at pool capacity a lane waits for a free slot (#4909)", () => {
|
|
|
46
46
|
assert.ok(Number.isFinite(rows[0].waits?.queue) && rows[0].waits.queue >= 0, "wait recorded as queue time");
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
|
+
|
|
50
|
+
describe("capwait wakes on the named condition (#5985)", () => {
|
|
51
|
+
it("a host_load refusal holds until load < 1.0 whatever the slots say; host_mem until free mem > floor; no figures: slot fallback", () => {
|
|
52
|
+
let t = 0;
|
|
53
|
+
const w = makeCapWait({ now: () => t });
|
|
54
|
+
w.refused(1, "host_load");
|
|
55
|
+
assert.equal(w.blocked(1, { free: 5, load_per_core: 1.2 }), true, "free slots do not wake a load refusal");
|
|
56
|
+
t += 1000;
|
|
57
|
+
assert.equal(w.blocked(1, { free: 0, load_per_core: 0.8 }), false, "wakes the moment load clears, not on a timer");
|
|
58
|
+
w.refused(2, "pool.host_mem");
|
|
59
|
+
assert.equal(w.blocked(2, { mem_available_gb: 2 }), true);
|
|
60
|
+
assert.equal(w.blocked(2, { mem_available_gb: 9 }), false);
|
|
61
|
+
w.refused(3, "host_load");
|
|
62
|
+
assert.equal(w.blocked(3, { free: 0 }), true, "no load figure: the slot count is the fallback");
|
|
63
|
+
assert.equal(w.conditional(3, { free: 0 }), false);
|
|
64
|
+
assert.equal(w.conditional(1, { load_per_core: 0.5 }), true);
|
|
65
|
+
w.refused(4);
|
|
66
|
+
assert.equal(w.blocked(4, { free: 1, load_per_core: 3 }), false, "no reason: slot gate only");
|
|
67
|
+
});
|
|
68
|
+
});
|
package/bin/lean/ci-gate.mjs
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
/**
|
|
4
|
-
* #5760: CI budget
|
|
5
|
-
*
|
|
6
|
-
* comment in the workflow YAML; a new workflow or job needs concurrency, timeout-minutes, path scoping and (issue/comment
|
|
7
|
-
* events) a job-level `if:`; `max_workflows`/`max_ci_jobs` cap the counts unless the same diff removes as many. Deterministic,
|
|
8
|
-
* 0 LLM calls, no YAML dependency (an indentation scan like bin/forge-utils.mjs). The one-level forge.yaml parser flattens
|
|
4
|
+
* #5760: CI budget reporting (the lane gate that parked on a missing `# FORGE:CI_BUDGET` annotation was cut in #6083; only the
|
|
5
|
+
* `CI_NET` report of the net workflow/job/minutes change remains). Deterministic, 0 LLM calls, no YAML dependency (an indentation scan like bin/forge-utils.mjs). The one-level forge.yaml parser flattens
|
|
9
6
|
* `ci.budget.*` into `ci`, so `ci.budget.monthly_minutes` is the same key as #5278's `ci.monthly_minutes`.
|
|
10
7
|
*/
|
|
11
8
|
import { execFileSync } from "node:child_process";
|
|
12
9
|
import { readFileSync } from "node:fs";
|
|
13
10
|
import { join } from "node:path";
|
|
14
11
|
import { fileURLToPath } from "node:url";
|
|
15
|
-
import { OUTCOME_CODES } from "../engine/outcome-codes.mjs";
|
|
16
12
|
import { parseForgeYaml } from "../forge-utils.mjs";
|
|
17
13
|
|
|
18
|
-
const C = OUTCOME_CODES.CONFORMANCE_UNIMPLEMENTED;
|
|
19
14
|
export const WORKFLOW_RE = /^\.github\/workflows\/[^/]+\.ya?ml$/;
|
|
20
|
-
const COMMENT_EVENTS = ["issues", "issue_comment", "pull_request_review_comment", "discussion_comment"];
|
|
21
|
-
const PATH_EVENTS = ["push", "pull_request", "pull_request_target"];
|
|
22
15
|
// A runner at command position: segment start, after env assignments and a launcher, never inside a path or extension (#5787).
|
|
23
16
|
const RUNNER_RE = /^(?:\w+=\S*\s+)*(?:(?:npx|bunx|pnpm(?:\s+exec)?|yarn|uv\s+run|poetry\s+run|python3?\s+-m)\s+)?(?:[^\s;&|]*\/)?(?:node\s+(?:[^\s]+\s+)*--test|vitest|jest|pytest|go\s+test|playwright\s+test|mocha|bash|sh)(?=\s|$)/;
|
|
24
17
|
const YAML_KEY_RE = /^["']?[A-Za-z_][\w-]*["']?\s*:(?:\s|$)/;
|
|
@@ -107,15 +100,6 @@ export function scanWorkflow(text) {
|
|
|
107
100
|
return { lines, triggers, pathsExempt, concurrency: top.some((t) => t.key === "concurrency"), jobs, annotations };
|
|
108
101
|
}
|
|
109
102
|
|
|
110
|
-
/** Lines of `head` not matched by a line of `base` (multiset on trimmed text), as indexes into head. */
|
|
111
|
-
function addedLineIdx(base, head) {
|
|
112
|
-
const left = new Map();
|
|
113
|
-
for (const l of String(base ?? "").split(/\r?\n/)) left.set(l.trim(), (left.get(l.trim()) ?? 0) + 1);
|
|
114
|
-
const out = [];
|
|
115
|
-
String(head ?? "").split(/\r?\n/).forEach((l, i) => { const k = l.trim(); if (left.get(k) > 0) left.set(k, left.get(k) - 1); else out.push(i); });
|
|
116
|
-
return out;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
103
|
/** The single test file a run line invokes, or null (a test runner with exactly one test-file argument). */
|
|
120
104
|
export function singleTestFile(line) {
|
|
121
105
|
const cmd = String(line ?? "").replace(/^\s*-?\s*(?:run\s*:\s*[|>]?)?/, "").trim();
|
|
@@ -130,70 +114,6 @@ export function singleTestFileSteps(addedLines) {
|
|
|
130
114
|
return (addedLines ?? []).map((l, i) => ({ line: i, file: singleTestFile(l) })).filter((x) => x.file);
|
|
131
115
|
}
|
|
132
116
|
|
|
133
|
-
const fail = (kind, detail) => ({ code: C, kind, detail });
|
|
134
|
-
const FIX = (shared) => `${shared ? `fold it into the shared job \`${shared}\` (forge.yaml ci.budget.shared_regression_job) or ` : ""}add \`# FORGE:CI_BUDGET trigger=<scope> minutes=<N>/month why=<why a shared job cannot hold it>\` in the workflow YAML`;
|
|
135
|
-
|
|
136
|
-
/** Annotation verdict over the scan's annotations inside [from, to]: "ok" | {invalid: missing[]} | null (none). */
|
|
137
|
-
function annotated(scan, from, to) {
|
|
138
|
-
const inScope = scan.annotations.filter((a) => a.line >= from && a.line <= to);
|
|
139
|
-
if (inScope.some((a) => !a.missing.length)) return "ok";
|
|
140
|
-
return inScope.length ? { invalid: inScope[0].missing } : null;
|
|
141
|
-
}
|
|
142
|
-
function annotationFailure(where, verdict, shared) {
|
|
143
|
-
if (verdict === "ok") return [];
|
|
144
|
-
if (verdict?.invalid) return [fail("ci_budget_annotation_invalid", `${where}: the FORGE:CI_BUDGET annotation is missing ${verdict.invalid.join(", ")} (needs trigger=, minutes= and why=)`)];
|
|
145
|
-
return [fail("ci_budget_unannotated", `${where} adds CI with no cost statement: ${FIX(shared)}`)];
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function hygiene(file, scan, job, { wholeFile }) {
|
|
149
|
-
const gaps = [];
|
|
150
|
-
if (!scan.concurrency && !job.concurrency) gaps.push("concurrency");
|
|
151
|
-
if (!job.timeout) gaps.push("timeout-minutes");
|
|
152
|
-
const pathTriggers = PATH_EVENTS.filter((e) => scan.triggers[e] && !scan.triggers[e].paths && !(e === "push" && scan.triggers[e].tagOnly) && !scan.pathsExempt);
|
|
153
|
-
if (pathTriggers.length && (wholeFile || !job.if)) gaps.push(`path scoping (paths/paths-ignore on ${pathTriggers.join(", ")}; tag-only push is exempt, or add \`# FORGE:CI_PATHS_EXEMPT why=<text>\`)`);
|
|
154
|
-
if (COMMENT_EVENTS.some((e) => scan.triggers[e]) && !job.if) gaps.push("a job-level if: filter for issue/comment events");
|
|
155
|
-
return gaps.length ? [fail("ci_hygiene", `${file} job \`${job.id}\` is new but has no ${gaps.join(", no ")}`)] : [];
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const countJobs = (scans) => Object.values(scans).reduce((n, s) => n + s.jobs.length, 0);
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* The gate over base and head workflow maps ({path: text}, only `.github/workflows/*.yml|yaml` are read).
|
|
162
|
-
* @returns {{code, kind, detail}[]} kinds: ci_budget_unannotated, ci_budget_annotation_invalid, ci_budget_exceeded, ci_hygiene
|
|
163
|
-
*/
|
|
164
|
-
export function ciGateFindings({ cfg = parseCiBudget(null), base = {}, head = {} } = {}) {
|
|
165
|
-
const wf = (m) => Object.fromEntries(Object.entries(m ?? {}).filter(([p]) => WORKFLOW_RE.test(p)).map(([p, t]) => [p, scanWorkflow(t)]));
|
|
166
|
-
const b = wf(base), h = wf(head), out = [];
|
|
167
|
-
const shared = cfg?.sharedJob ?? null;
|
|
168
|
-
const sharedDir = shared && shared.includes("/") ? shared.replace(/\/+$/, "") + "/" : null;
|
|
169
|
-
for (const [file, scan] of Object.entries(h)) {
|
|
170
|
-
if (!b[file]) {
|
|
171
|
-
out.push(...annotationFailure(`new workflow ${file}`, annotated(scan, 0, scan.lines.length), shared));
|
|
172
|
-
for (const j of scan.jobs) out.push(...hygiene(file, scan, j, { wholeFile: true }));
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
const baseIds = new Set(b[file].jobs.map((j) => j.id));
|
|
176
|
-
const added = new Set(addedLineIdx(base[file], head[file]));
|
|
177
|
-
for (const j of scan.jobs) {
|
|
178
|
-
if (baseIds.has(j.id)) continue;
|
|
179
|
-
out.push(...annotationFailure(`${file} new job \`${j.id}\``, annotated(scan, j.start, j.end), shared));
|
|
180
|
-
out.push(...hygiene(file, scan, j, { wholeFile: false }));
|
|
181
|
-
}
|
|
182
|
-
for (const i of added) {
|
|
183
|
-
const test = singleTestFile(scan.lines[i]);
|
|
184
|
-
if (!test) continue;
|
|
185
|
-
const j = scan.jobs.find((x) => i >= x.start && i <= x.end);
|
|
186
|
-
if (!j || !baseIds.has(j.id)) continue; // outside a job, or inside a new job (judged above)
|
|
187
|
-
if (shared && (j.id === shared || (sharedDir && test.replace(/^\.\//, "").startsWith(sharedDir)))) continue;
|
|
188
|
-
out.push(...annotationFailure(`${file} job \`${j.id}\` step running only ${test}`, annotated(scan, j.start, j.end), shared));
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
const [wb, wh, jbn, jhn] = [Object.keys(b).length, Object.keys(h).length, countJobs(b), countJobs(h)];
|
|
192
|
-
if (cfg?.maxWorkflows != null && wh > cfg.maxWorkflows && wh > wb) out.push(fail("ci_budget_exceeded", `${wh} workflow files exceed ci.budget.max_workflows ${cfg.maxWorkflows} (+${wh - wb} in this diff): remove or fold as many workflows as you add`));
|
|
193
|
-
if (cfg?.maxCiJobs != null && jhn > cfg.maxCiJobs && jhn > jbn) out.push(fail("ci_budget_exceeded", `${jhn} CI jobs exceed ci.budget.max_ci_jobs ${cfg.maxCiJobs} (+${jhn - jbn} in this diff): fold the new job(s) into an existing job or remove as many`));
|
|
194
|
-
return out;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
117
|
/** Net CI change between two workflow maps: {workflows, jobs, minutes, line}. */
|
|
198
118
|
export function netCiChange({ base = {}, head = {}, cfg = null } = {}) {
|
|
199
119
|
const wf = (m) => Object.entries(m ?? {}).filter(([p]) => WORKFLOW_RE.test(p)).map(([, t]) => scanWorkflow(t));
|
|
@@ -213,14 +133,6 @@ async function workflowsAt(git, ref) {
|
|
|
213
133
|
return out;
|
|
214
134
|
}
|
|
215
135
|
|
|
216
|
-
/** Lane wiring: [] after one `git diff` when the diff touches no workflow file; else the gate over merge-base vs HEAD. */
|
|
217
|
-
export async function ciBudgetFailures({ cfg = null, base, git }) {
|
|
218
|
-
const changed = String(await git(["diff", "--name-only", `${base}...HEAD`, "--", ".github/workflows"])).split("\n").map((x) => x.trim()).filter((p) => WORKFLOW_RE.test(p));
|
|
219
|
-
if (!changed.length) return [];
|
|
220
|
-
const mb = String(await git(["merge-base", base, "HEAD"])).trim() || base;
|
|
221
|
-
return ciGateFindings({ cfg: cfg ?? parseCiBudget(null), base: await workflowsAt(git, mb), head: await workflowsAt(git, "HEAD") });
|
|
222
|
-
}
|
|
223
|
-
|
|
224
136
|
/** `node bin/lean/ci-gate.mjs net --base REF --head REF [--cwd DIR]`: prints the CI_NET line; exit 0, `CI_NET: unknown (<why>)` on failure. */
|
|
225
137
|
export async function ciGateCli(argv, { print = (s) => process.stdout.write(s + "\n"), cwd: cwdIn = process.cwd() } = {}) {
|
|
226
138
|
const arg = (k) => { const i = argv.indexOf(k); return i >= 0 ? argv[i + 1] : null; };
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { describe, it } from "node:test";
|
|
5
5
|
import assert from "node:assert/strict";
|
|
6
6
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
7
|
-
import { parseCiBudget, parseAnnotation, scanWorkflow, singleTestFile, singleTestFileSteps,
|
|
7
|
+
import { parseCiBudget, parseAnnotation, scanWorkflow, singleTestFile, singleTestFileSteps, netCiChange, ciGateCli } from "./ci-gate.mjs";
|
|
8
8
|
import { parseForgeYaml } from "../forge-utils.mjs";
|
|
9
9
|
|
|
10
10
|
const kinds = (f) => f.map((x) => x.kind).sort();
|
|
@@ -50,44 +50,12 @@ const GOOD = [
|
|
|
50
50
|
"",
|
|
51
51
|
].join("\n");
|
|
52
52
|
|
|
53
|
-
describe("lane check (#5760 R10)", () => {
|
|
54
|
-
it("a lane adding a bare workflow fails (unannotated + hygiene)", () => {
|
|
55
|
-
const f = ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: BASE_CI, ".github/workflows/one.yml": BARE } });
|
|
56
|
-
assert.deepEqual(kinds(f), ["ci_budget_unannotated", "ci_hygiene"]);
|
|
57
|
-
assert.match(f.find((x) => x.kind === "ci_hygiene").detail, /concurrency.*timeout-minutes.*path scoping/);
|
|
58
|
-
assert.equal(f[0].code, "conformance.unimplemented");
|
|
59
|
-
assert.match(f.find((x) => x.kind === "ci_budget_unannotated").detail, /shared job `regression`/);
|
|
60
|
-
});
|
|
61
|
-
it("a lane folding a one-file check into the shared job passes", () => {
|
|
62
|
-
const head = BASE_CI.replace(" - run: node --test tests/a.test.mjs tests/b.test.mjs", " - run: node --test tests/a.test.mjs tests/b.test.mjs\n - run: node --test tests/new.test.mjs");
|
|
63
|
-
assert.deepEqual(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: head } }), []);
|
|
64
|
-
});
|
|
65
|
-
it("an annotated, scoped workflow passes", () => {
|
|
66
|
-
assert.deepEqual(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: BASE_CI, ".github/workflows/gpu.yaml": GOOD } }), []);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
53
|
describe("annotation and single-file steps", () => {
|
|
71
|
-
it("an annotation missing minutes is invalid", () => {
|
|
72
|
-
const f = ciGateFindings({ cfg, base: {}, head: { ".github/workflows/gpu.yml": GOOD.replace("minutes=120/month ", "") } });
|
|
73
|
-
assert.deepEqual(kinds(f), ["ci_budget_annotation_invalid"]);
|
|
74
|
-
assert.match(f[0].detail, /missing minutes/);
|
|
75
|
-
});
|
|
76
54
|
it("parseAnnotation reads the three fields", () => {
|
|
77
55
|
assert.deepEqual(parseAnnotation(" # FORGE:CI_BUDGET trigger=push:main minutes=30 why=deploy smoke, not a test"), { trigger: "push:main", minutes: 30, why: "deploy smoke, not a test", missing: [] });
|
|
78
56
|
assert.deepEqual(parseAnnotation("# FORGE:CI_BUDGET why=x").missing, ["trigger", "minutes"]);
|
|
79
57
|
assert.equal(parseAnnotation("# a comment"), null);
|
|
80
58
|
});
|
|
81
|
-
it("a single-file step added to another job fails unless annotated", () => {
|
|
82
|
-
const head = BASE_CI.replace(" - run: npm run lint", " - run: npm run lint\n - run: npx vitest run src/a.spec.ts");
|
|
83
|
-
assert.deepEqual(kinds(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: head } })), ["ci_budget_unannotated"]);
|
|
84
|
-
const ann = head.replace(" lint:\n", " # FORGE:CI_BUDGET trigger=pull_request minutes=5 why=lint-coupled spec\n lint:\n");
|
|
85
|
-
assert.deepEqual(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: ann } }), []);
|
|
86
|
-
});
|
|
87
|
-
it("a shared dir folds a step whose file lives under it", () => {
|
|
88
|
-
const head = BASE_CI.replace(" - run: npm run lint", " - run: npm run lint\n - run: pytest tests/regression/test_x.py");
|
|
89
|
-
assert.deepEqual(ciGateFindings({ cfg: parseCiBudget({ shared_regression_job: "tests/regression" }), base: { [CI]: BASE_CI }, head: { [CI]: head } }), []);
|
|
90
|
-
});
|
|
91
59
|
it("singleTestFile needs a runner and exactly one test file", () => {
|
|
92
60
|
assert.equal(singleTestFile(" - run: node --test bin/x.test.mjs"), "bin/x.test.mjs");
|
|
93
61
|
assert.equal(singleTestFile("run: bash scripts/foo.test.sh"), "scripts/foo.test.sh");
|
|
@@ -101,87 +69,10 @@ describe("annotation and single-file steps", () => {
|
|
|
101
69
|
for (const l of [" - run: echo scripts/foo.test.sh", " - name: check scripts/foo.test.sh", " - scripts/foo.test.sh", "run: cat x.test.sh", " - name: Run vitest on a.test.ts", "run: cat lib/bash/x.test.mjs"]) assert.equal(singleTestFile(l), null, l);
|
|
102
70
|
assert.equal(singleTestFile("run: npm ci && bash scripts/foo.test.sh"), "scripts/foo.test.sh");
|
|
103
71
|
assert.equal(singleTestFile(" npx vitest run src/a.test.ts"), "src/a.test.ts");
|
|
104
|
-
const head = BASE_CI.replace(" - run: npm run lint", " - run: npm run lint\n - name: check scripts/foo.test.sh\n - run: echo scripts/foo.test.sh");
|
|
105
|
-
assert.deepEqual(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: head } }), []);
|
|
106
72
|
});
|
|
107
73
|
it("singleTestFile still flags real runner steps (#5787 over-narrowing guard)", () => {
|
|
108
74
|
assert.equal(singleTestFile("run: cd x && pytest tests/test_a.py"), "tests/test_a.py");
|
|
109
75
|
assert.equal(singleTestFile("run: sh scripts/foo.test.sh"), "scripts/foo.test.sh");
|
|
110
|
-
const head = BASE_CI.replace(" - run: npm run lint", " - run: npm run lint\n - run: bash scripts/foo.test.sh");
|
|
111
|
-
assert.deepEqual(kinds(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: head } })), ["ci_budget_unannotated"]);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe("push path scoping exemptions (#5792)", () => {
|
|
116
|
-
const rel = (on, pre = "") => `${pre}# FORGE:CI_BUDGET trigger=push minutes=5 why=release\nname: rel\non:\n${on}\nconcurrency: rel\njobs:\n rel:\n runs-on: ubuntu-latest\n timeout-minutes: 10\n steps:\n - run: make release\n`;
|
|
117
|
-
const run = (text) => ciGateFindings({ cfg, base: {}, head: { ".github/workflows/rel.yml": text } });
|
|
118
|
-
it("a tag-only push trigger needs no paths", () => {
|
|
119
|
-
assert.deepEqual(run(rel(" push:\n tags: ['v*']")), []);
|
|
120
|
-
});
|
|
121
|
-
it("a push with branches (or tags and branches) still needs paths", () => {
|
|
122
|
-
assert.match(run(rel(" push:\n branches: [main]"))[0].detail, /path scoping/);
|
|
123
|
-
assert.match(run(rel(" push:\n tags: ['v*']\n branches: [main]"))[0].detail, /path scoping/);
|
|
124
|
-
});
|
|
125
|
-
it("a FORGE:CI_PATHS_EXEMPT annotation with why exempts a deploy-on-main push; without why it does not", () => {
|
|
126
|
-
const on = " push:\n branches: [main]";
|
|
127
|
-
assert.deepEqual(run(rel(on, "# FORGE:CI_PATHS_EXEMPT why=deploys on every merge\n")), []);
|
|
128
|
-
assert.match(run(rel(on, "# FORGE:CI_PATHS_EXEMPT\n"))[0].detail, /path scoping/);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe("new jobs and hygiene", () => {
|
|
133
|
-
const withJob = (job) => BASE_CI + job;
|
|
134
|
-
it("a job added to an existing workflow needs an annotation above or inside it", () => {
|
|
135
|
-
const job = " e2e:\n runs-on: ubuntu-latest\n timeout-minutes: 15\n steps:\n - run: npm run e2e\n";
|
|
136
|
-
assert.deepEqual(kinds(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: withJob(job) } })), ["ci_budget_unannotated"]);
|
|
137
|
-
const ann = " # FORGE:CI_BUDGET trigger=pull_request:src/** minutes=200 why=browser stack\n" + job;
|
|
138
|
-
assert.deepEqual(ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: withJob(ann) } }), []);
|
|
139
|
-
});
|
|
140
|
-
it("a new job without timeout-minutes is a hygiene failure", () => {
|
|
141
|
-
const job = " # FORGE:CI_BUDGET trigger=pr minutes=5 why=x\n e2e:\n runs-on: ubuntu-latest\n steps:\n - run: npm run e2e\n";
|
|
142
|
-
const f = ciGateFindings({ cfg, base: { [CI]: BASE_CI }, head: { [CI]: withJob(job) } });
|
|
143
|
-
assert.deepEqual(kinds(f), ["ci_hygiene"]);
|
|
144
|
-
assert.match(f[0].detail, /`e2e`.*timeout-minutes/);
|
|
145
|
-
});
|
|
146
|
-
it("an issue_comment job without a job-level if: fails ci_hygiene", () => {
|
|
147
|
-
const wf = "# FORGE:CI_BUDGET trigger=issue_comment minutes=10 why=bot command\non:\n issue_comment:\n types: [created]\nconcurrency: bot\njobs:\n bot:\n timeout-minutes: 5\n runs-on: ubuntu-latest\n steps:\n - run: echo hi\n";
|
|
148
|
-
const f = ciGateFindings({ cfg, base: {}, head: { ".github/workflows/bot.yml": wf } });
|
|
149
|
-
assert.deepEqual(kinds(f), ["ci_hygiene"]);
|
|
150
|
-
assert.match(f[0].detail, /job-level if:/);
|
|
151
|
-
const ok = wf.replace(" bot:\n", " bot:\n if: startsWith(github.event.comment.body, '/bot')\n");
|
|
152
|
-
assert.deepEqual(ciGateFindings({ cfg, base: {}, head: { ".github/workflows/bot.yml": ok } }), []);
|
|
153
|
-
});
|
|
154
|
-
it("a schedule-only workflow needs no path scoping", () => {
|
|
155
|
-
const wf = "# FORGE:CI_BUDGET trigger=nightly minutes=300 why=full suite\non:\n schedule:\n - cron: '0 3 * * *'\n workflow_dispatch:\nconcurrency: nightly\njobs:\n full:\n timeout-minutes: 60\n runs-on: ubuntu-latest\n steps:\n - run: npm test\n";
|
|
156
|
-
assert.deepEqual(ciGateFindings({ cfg, base: {}, head: { ".github/workflows/nightly.yml": wf } }), []);
|
|
157
|
-
});
|
|
158
|
-
it("scanWorkflow reads triggers, concurrency and job children", () => {
|
|
159
|
-
const s = scanWorkflow(BASE_CI);
|
|
160
|
-
assert.deepEqual(s.triggers, { pull_request: { paths: true, tagOnly: false } });
|
|
161
|
-
assert.equal(s.concurrency, true);
|
|
162
|
-
assert.deepEqual(s.jobs.map((j) => [j.id, j.timeout, j.if]), [["lint", true, false], ["regression", true, false]]);
|
|
163
|
-
assert.deepEqual(Object.keys(scanWorkflow("on: [push, pull_request]\njobs: {}\n").triggers), ["push", "pull_request"]);
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe("max_workflows / max_ci_jobs (#5760 R8)", () => {
|
|
168
|
-
const two = { [CI]: BASE_CI, ".github/workflows/old.yml": GOOD };
|
|
169
|
-
it("exceeding max_workflows fails, and passes when the same diff removes one", () => {
|
|
170
|
-
const c = parseCiBudget({ max_workflows: "2" });
|
|
171
|
-
const head = { ...two, ".github/workflows/gpu.yml": GOOD };
|
|
172
|
-
assert.deepEqual(kinds(ciGateFindings({ cfg: c, base: two, head })), ["ci_budget_exceeded"]);
|
|
173
|
-
const swapped = { [CI]: BASE_CI, ".github/workflows/gpu.yml": GOOD };
|
|
174
|
-
assert.deepEqual(ciGateFindings({ cfg: c, base: two, head: swapped }), []);
|
|
175
|
-
});
|
|
176
|
-
it("exceeding max_ci_jobs fails unless a job is folded away", () => {
|
|
177
|
-
const c = parseCiBudget({ max_ci_jobs: "2" });
|
|
178
|
-
const job = " # FORGE:CI_BUDGET trigger=pr minutes=5 why=x\n e2e:\n runs-on: ubuntu-latest\n timeout-minutes: 5\n steps:\n - run: npm run e2e\n";
|
|
179
|
-
assert.deepEqual(kinds(ciGateFindings({ cfg: c, base: { [CI]: BASE_CI }, head: { [CI]: BASE_CI + job } })), ["ci_budget_exceeded"]);
|
|
180
|
-
const folded = BASE_CI.replace(/ lint:\n(?: .*\n)*?(?= regression:)/, "") + job;
|
|
181
|
-
// the fold removes exactly the lint job (regression guard for the unambiguous, non-backtracking pattern)
|
|
182
|
-
assert.ok(!folded.includes("lint:") && !folded.includes("npm run lint"));
|
|
183
|
-
assert.ok(folded.includes(" regression:\n") && folded.endsWith(job));
|
|
184
|
-
assert.deepEqual(ciGateFindings({ cfg: c, base: { [CI]: BASE_CI }, head: { [CI]: folded } }), []);
|
|
185
76
|
});
|
|
186
77
|
});
|
|
187
78
|
|
|
@@ -200,23 +91,6 @@ describe("config, net change and wiring", () => {
|
|
|
200
91
|
assert.equal(r.line, "CI_NET: workflows +2, jobs +2, est. minutes/month +120 of 3000 budget");
|
|
201
92
|
assert.match(netCiChange({ base: head, head: { [CI]: BASE_CI } }).line, /workflows -2, jobs -2, est\. minutes\/month -120$/);
|
|
202
93
|
});
|
|
203
|
-
it("ciBudgetFailures makes one git call when no workflow changed", async () => {
|
|
204
|
-
const calls = [];
|
|
205
|
-
const git = async (a) => { calls.push(a); return "src/a.js\n"; };
|
|
206
|
-
assert.deepEqual(await ciBudgetFailures({ cfg, base: "origin/staging", git }), []);
|
|
207
|
-
assert.equal(calls.length, 1);
|
|
208
|
-
});
|
|
209
|
-
it("ciBudgetFailures reads merge-base and HEAD workflows when a workflow changed", async () => {
|
|
210
|
-
const files = { mb: { [CI]: BASE_CI }, HEAD: { [CI]: BASE_CI, ".github/workflows/one.yml": BARE } };
|
|
211
|
-
const git = async (a) => {
|
|
212
|
-
if (a[0] === "diff") return ".github/workflows/one.yml\n";
|
|
213
|
-
if (a[0] === "merge-base") return "mb\n";
|
|
214
|
-
if (a[0] === "ls-tree") return Object.keys(files[a[3]]).join("\n");
|
|
215
|
-
const [ref, p] = a[1].split(/:(.*)/s);
|
|
216
|
-
return files[ref][p];
|
|
217
|
-
};
|
|
218
|
-
assert.deepEqual(kinds(await ciBudgetFailures({ cfg, base: "origin/staging", git })), ["ci_budget_unannotated", "ci_hygiene"]);
|
|
219
|
-
});
|
|
220
94
|
it("the CLI prints CI_NET unknown on a bad ref and usage on bad args", async () => {
|
|
221
95
|
const out = [];
|
|
222
96
|
const cwd = tmpDir("ci-gate-");
|
package/bin/lean/ci-precheck.mjs
CHANGED
|
@@ -34,7 +34,8 @@ const HEAVY = [
|
|
|
34
34
|
];
|
|
35
35
|
const CHEAP = [
|
|
36
36
|
["typecheck", /type-?check|\btsc\b|\bmypy\b|pyright|\btypes\b/i],
|
|
37
|
-
["lint", /lint|eslint|ruff|prettier|\bformat|clippy|shellcheck|golangci|\bvet\b|stylelint|biome/i],
|
|
37
|
+
["lint", /lint|eslint|ruff|prettier|\bformat|\bfmt\b|\bblack\b|gofmt|rustfmt|clippy|shellcheck|golangci|\bvet\b|stylelint|biome/i],
|
|
38
|
+
["wiring", /wiring|registered|\bmanifest\b|\bcoverage[-_ ]map\b/i],
|
|
38
39
|
["test", /test|vitest|jest|pytest|\bspec\b|mocha|\bbats\b/i],
|
|
39
40
|
];
|
|
40
41
|
export const HEAVY_KINDS = HEAVY.map(([k]) => k);
|
|
@@ -93,13 +94,21 @@ export function requiredFor(job, required) {
|
|
|
93
94
|
* @returns {{source:"required"|"fallback", run:object[], skipped:{job,name,reason}[], unrunnable:{job,name,reason}[], note:string}}
|
|
94
95
|
* run: [{job, name, workflow, kind, why, steps: string[], plan: object}] (plan: a one-job ci-local plan)
|
|
95
96
|
*/
|
|
96
|
-
export function selectCiPrecheck({ plan, required = null, cfg = parseCiPrecheckConfig(null) }) {
|
|
97
|
+
export function selectCiPrecheck({ plan, required = null, releaseRequired = null, cfg = parseCiPrecheckConfig(null) }) {
|
|
97
98
|
const jobs = (Array.isArray(plan?.jobs) ? plan.jobs : []).filter((j) => j && CI_SOURCES.has(j.source) && !/:variants$/.test(str(j.id)));
|
|
98
99
|
const byId = new Map(jobs.map((j) => [j.id, j]));
|
|
99
100
|
const req = (Array.isArray(required) ? required : []).map(str).filter(Boolean);
|
|
100
101
|
// required jobs, then (transitively) the jobs an aggregator required job needs
|
|
101
102
|
const why = new Map();
|
|
102
103
|
for (const j of jobs) { const hit = requiredFor(j, req); if (hit.length) why.set(j.id, `required check ${hit.map((h) => `"${h}"`).join(", ")}`); }
|
|
104
|
+
// #6049: required checks of the release branch, run in the lane too (a release-only formatter or wiring job)
|
|
105
|
+
const relReq = (Array.isArray(releaseRequired) ? releaseRequired : []).map(str).filter(Boolean);
|
|
106
|
+
const relHit = new Set();
|
|
107
|
+
for (const j of jobs) {
|
|
108
|
+
const hit = requiredFor(j, relReq);
|
|
109
|
+
for (const h of hit) relHit.add(h);
|
|
110
|
+
if (hit.length && !why.has(j.id)) why.set(j.id, `required check ${hit.map((h) => `"${h}"`).join(", ")} on release branch`);
|
|
111
|
+
}
|
|
103
112
|
const queue = [...why.keys()];
|
|
104
113
|
while (queue.length) {
|
|
105
114
|
const id = queue.shift();
|
|
@@ -126,7 +135,15 @@ export function selectCiPrecheck({ plan, required = null, cfg = parseCiPrecheckC
|
|
|
126
135
|
}
|
|
127
136
|
const cap = Number.isInteger(cfg.maxJobs) ? cfg.maxJobs : DEFAULT_MAX_JOBS;
|
|
128
137
|
for (const r of run.splice(cap)) skipped.push({ job: r.job, name: r.name, reason: `over lean.ci_precheck_max_jobs (${cap}): left to CI` });
|
|
129
|
-
|
|
138
|
+
// #6049: release-required contexts with no job the lane runs (no job maps, or the job is skipped / unrunnable here)
|
|
139
|
+
const covered = new Set(run.flatMap((r) => requiredFor(jobs.find((j) => j.id === r.job), relReq)));
|
|
140
|
+
const parity = relReq.filter((c) => !covered.has(c)).map((context) => {
|
|
141
|
+
const j = jobs.find((x) => requiredFor(x, [context]).length);
|
|
142
|
+
if (!j) return { context, reason: "no CI job maps to this required release check" };
|
|
143
|
+
const s = [...skipped, ...unrunnable].find((x) => x.job === j.id);
|
|
144
|
+
return { context, job: j.id, reason: s?.reason ?? "job not run in the lane" };
|
|
145
|
+
});
|
|
146
|
+
return { source, run, skipped, unrunnable, note, parity };
|
|
130
147
|
}
|
|
131
148
|
|
|
132
149
|
const slug = (id) => str(id).replace(/[^A-Za-z0-9_.-]+/g, "_").slice(0, 120) || "job";
|
|
@@ -144,19 +161,19 @@ export function ciPrecheckCommand(sel, { perCommandMs = 300000, script = CI_LOCA
|
|
|
144
161
|
* skipJobs: job ids an earlier round found unrunnable (not rerun)
|
|
145
162
|
* @returns {Promise<{source, note, commands:{job,name,workflow,kind,why,steps,command}[], skipped, unrunnable}>}
|
|
146
163
|
*/
|
|
147
|
-
export async function deriveCiPrecheck({ buildPlan, required = null, cfg, wt, base, lane, files = [], perCommandMs, writeFile, skipJobs = new Set() }) {
|
|
164
|
+
export async function deriveCiPrecheck({ buildPlan, required = null, releaseRequired = null, releaseBranch = "", cfg, wt, base, lane, files = [], perCommandMs, writeFile, skipJobs = new Set() }) {
|
|
148
165
|
let plan;
|
|
149
|
-
try { plan = await buildPlan({ repo: wt, base, baseBranch: lane, files }); } catch (e) {
|
|
150
|
-
return { source: "none", note: "", commands: [], skipped: [], unrunnable: [{ job: "*", name: "ci-local plan", reason: `CI check plan unavailable: ${str(e?.message ?? e).split("\n")[0].slice(0, 200)}` }] };
|
|
166
|
+
try { plan = await buildPlan({ repo: wt, base, baseBranch: lane, ...(releaseBranch ? { releaseBranch } : {}), files }); } catch (e) {
|
|
167
|
+
return { source: "none", note: "", commands: [], skipped: [], unrunnable: [{ job: "*", name: "ci-local plan", reason: `CI check plan unavailable: ${str(e?.message ?? e).split("\n")[0].slice(0, 200)}` }], parity: [] };
|
|
151
168
|
}
|
|
152
|
-
const sel = selectCiPrecheck({ plan, required, cfg });
|
|
169
|
+
const sel = selectCiPrecheck({ plan, required, releaseRequired, cfg });
|
|
153
170
|
const commands = [], unrunnable = [...sel.unrunnable], skipped = [...sel.skipped];
|
|
154
171
|
for (const r of sel.run) {
|
|
155
172
|
if (skipJobs.has(r.job)) { skipped.push({ job: r.job, name: r.name, reason: "unrunnable in an earlier round: left to CI" }); continue; }
|
|
156
173
|
try { await writeFile(`${CI_PRECHECK_DIR}/${slug(r.job)}.json`, `${JSON.stringify(r.plan)}\n`); } catch (e) { unrunnable.push({ job: r.job, name: r.name, reason: `plan file not written: ${str(e?.message ?? e).slice(0, 120)}` }); continue; }
|
|
157
174
|
commands.push({ job: r.job, name: r.name, workflow: r.workflow, kind: r.kind, why: r.why, steps: r.steps, command: ciPrecheckCommand(r, { perCommandMs }) });
|
|
158
175
|
}
|
|
159
|
-
return { source: sel.source, note: sel.note, commands, skipped, unrunnable };
|
|
176
|
+
return { source: sel.source, note: sel.note, commands, skipped, unrunnable, parity: sel.parity };
|
|
160
177
|
}
|
|
161
178
|
|
|
162
179
|
/** The first line of `output` starting with `prefix`, without it; "" when none. */
|
|
@@ -94,6 +94,30 @@ describe("#5820 selection", () => {
|
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
+
describe("#6049 release-branch required checks", () => {
|
|
98
|
+
const plan = { ...PLAN, jobs: [...PLAN.jobs, job("fmt", "Format check", ["black --check ."]), job("wiring", "Suite wiring", ["bash scripts/check-test-wiring.sh"])] };
|
|
99
|
+
it("a release-only required formatter and a wiring job are selected with a release-branch why", () => {
|
|
100
|
+
const s = selectCiPrecheck({ plan, required: ["Lint"], releaseRequired: ["Format check", "Suite wiring"] });
|
|
101
|
+
assert.deepEqual(s.run.map((r) => [r.job, r.why]), [["gha:ci:lint", 'required check "Lint"'], ["gha:ci:fmt", 'required check "Format check" on release branch'], ["gha:ci:wiring", 'required check "Suite wiring" on release branch']]);
|
|
102
|
+
assert.deepEqual(s.parity, []);
|
|
103
|
+
});
|
|
104
|
+
it("a required release context with no job (or a heavy one) is a parity gap", () => {
|
|
105
|
+
const s = selectCiPrecheck({ plan, required: ["Lint"], releaseRequired: ["Format check", "Release signing", "E2E"] });
|
|
106
|
+
assert.deepEqual(s.parity.map((g) => g.context), ["Release signing", "E2E"]);
|
|
107
|
+
assert.match(s.parity[0].reason, /no CI job/);
|
|
108
|
+
assert.match(s.parity[1].reason, /heavy \(e2e\)/);
|
|
109
|
+
});
|
|
110
|
+
it("no gaps and an unchanged selection when releaseRequired is empty; ci_precheck exclude still applies", () => {
|
|
111
|
+
const a = selectCiPrecheck({ plan, required: ["Lint"] }), b = selectCiPrecheck({ plan, required: ["Lint"], releaseRequired: [] });
|
|
112
|
+
assert.deepEqual(b.run.map((r) => r.job), a.run.map((r) => r.job)); assert.deepEqual(b.parity, []);
|
|
113
|
+
const x = selectCiPrecheck({ plan, required: ["Lint"], releaseRequired: ["Format check"], cfg: parseCiPrecheckConfig({ ci_precheck_exclude: "gha:ci:fmt" }) });
|
|
114
|
+
assert.deepEqual(x.parity.map((g) => g.context), ["Format check"]);
|
|
115
|
+
});
|
|
116
|
+
it("classifier negatives: a deploy or docs job is not treated as wiring or formatting", () => {
|
|
117
|
+
assert.equal(classifyJob(job("deploy", "Deploy docs", ["bash deploy.sh"])).kind, "other");
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
97
121
|
describe("#5820 derive + outcome", () => {
|
|
98
122
|
it("writes one plan file per job and returns bounded ci-local commands", async () => {
|
|
99
123
|
const written = new Map();
|