forgedock 1.67.0 → 1.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/config-schema.mjs +1 -0
- package/bin/engine/outcome-codes.mjs +1 -0
- package/bin/engine-cli.mjs +99 -12
- package/bin/engine.mjs +10 -0
- package/bin/forgedock.mjs +17 -1
- package/bin/help-text.mjs +1 -0
- package/bin/lean/admission.mjs +21 -0
- package/bin/lean/admission.test.mjs +30 -0
- package/bin/lean/advisory.test.mjs +25 -10
- package/bin/lean/amendment-schema.mjs +3 -4
- package/bin/lean/attempts.mjs +34 -31
- package/bin/lean/attempts.test.mjs +33 -19
- package/bin/lean/basered.mjs +26 -0
- package/bin/lean/batch-health.mjs +17 -12
- package/bin/lean/batch-health.test.mjs +39 -11
- package/bin/lean/batch.test.mjs +51 -2
- package/bin/lean/ci-gate.mjs +2 -90
- package/bin/lean/ci-gate.test.mjs +1 -127
- package/bin/lean/ci-precheck.mjs +25 -8
- package/bin/lean/ci-precheck.test.mjs +24 -0
- package/bin/lean/clear-breaker.test.mjs +4 -3
- package/bin/lean/commentstate.mjs +10 -5
- package/bin/lean/commentstate.test.mjs +12 -1
- package/bin/lean/conformance.e2e.test.mjs +9 -6
- package/bin/lean/conformance.mjs +56 -196
- package/bin/lean/conformance.test.mjs +40 -376
- package/bin/lean/depcache.mjs +100 -10
- package/bin/lean/depcache.test.mjs +105 -0
- package/bin/lean/docsgate.mjs +0 -32
- package/bin/lean/docsgate.test.mjs +2 -23
- package/bin/lean/effects-cap.test.mjs +9 -1
- package/bin/lean/effects-killtree.test.mjs +35 -0
- package/bin/lean/effects.mjs +42 -24
- package/bin/lean/engine-readmit.test.mjs +35 -0
- package/bin/lean/envgap.mjs +93 -0
- package/bin/lean/envgap.test.mjs +53 -0
- package/bin/lean/execution.mjs +10 -4
- package/bin/lean/execution.test.mjs +12 -0
- package/bin/lean/failure-census.mjs +170 -0
- package/bin/lean/failure-census.test.mjs +59 -0
- package/bin/lean/guardgate.test.mjs +2 -3
- package/bin/lean/heavy.mjs +33 -4
- package/bin/lean/heavy.test.mjs +38 -6
- package/bin/lean/hotarea.mjs +0 -36
- package/bin/lean/hotarea.test.mjs +1 -22
- package/bin/lean/issuewatch-verify.mjs +19 -4
- package/bin/lean/issuewatch.mjs +21 -4
- package/bin/lean/issuewatch.test.mjs +48 -1
- package/bin/lean/lane-audit-gap.mjs +66 -0
- package/bin/lean/lane-audit-gap.test.mjs +59 -0
- package/bin/lean/lane-audit-llm.mjs +5 -0
- package/bin/lean/lane-audit-query.mjs +47 -0
- package/bin/lean/lane-audit-query.test.mjs +44 -0
- package/bin/lean/lane-audit-signatures.mjs +33 -0
- package/bin/lean/lane-audit.mjs +110 -0
- package/bin/lean/lane-audit.test.mjs +97 -0
- package/bin/lean/lane-recovery.test.mjs +33 -0
- package/bin/lean/lanecheck.mjs +5 -3
- package/bin/lean/lanecheck.test.mjs +6 -0
- package/bin/lean/lean.mjs +206 -148
- package/bin/lean/lean.test.mjs +406 -190
- package/bin/lean/limits.mjs +17 -0
- package/bin/lean/limits.test.mjs +15 -1
- package/bin/lean/live-execution.mjs +21 -2
- package/bin/lean/live-execution.test.mjs +39 -0
- package/bin/lean/orchestrate-attempts.test.mjs +17 -9
- package/bin/lean/orchestrate-envhold.test.mjs +47 -0
- package/bin/lean/orchestrate-heldroot.test.mjs +72 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +59 -1
- package/bin/lean/orchestrate-overload-recovery.test.mjs +37 -0
- package/bin/lean/orchestrate-pause.test.mjs +53 -1
- package/bin/lean/orchestrate-reconcile.test.mjs +17 -0
- package/bin/lean/orchestrate-relaunch-gates.test.mjs +57 -0
- package/bin/lean/orchestrate-stacking.test.mjs +10 -0
- package/bin/lean/orchestrate.mjs +188 -33
- package/bin/lean/postdeploy-check.test.mjs +1 -3
- package/bin/lean/precheck.mjs +20 -0
- package/bin/lean/preflight.mjs +100 -11
- package/bin/lean/preflight.test.mjs +44 -4
- package/bin/lean/prompts.mjs +10 -21
- package/bin/lean/recurrence.mjs +6 -148
- package/bin/lean/recurrence.test.mjs +11 -147
- package/bin/lean/release-flakes.mjs +14 -2
- package/bin/lean/release-flakes.test.mjs +17 -1
- package/bin/lean/release-ledger.mjs +19 -1
- package/bin/lean/release-ledger.test.mjs +23 -0
- package/bin/lean/release-preflight.mjs +28 -0
- package/bin/lean/release-preflight.test.mjs +42 -1
- package/bin/lean/release-review.mjs +40 -5
- package/bin/lean/release-review.test.mjs +43 -2
- package/bin/lean/release.mjs +43 -14
- package/bin/lean/release.test.mjs +32 -0
- package/bin/lean/retry.mjs +1 -1
- package/bin/lean/retry.test.mjs +6 -1
- package/bin/lean/rotator.mjs +9 -0
- package/bin/lean/rotator.test.mjs +11 -1
- package/bin/lean/sandbox-remote.mjs +16 -9
- package/bin/lean/schedd.mjs +11 -6
- package/bin/lean/schedd.test.mjs +65 -5
- package/bin/lean/selfreview.mjs +1 -1
- package/bin/lean/statuscomment.mjs +4 -1
- package/bin/lean/validate-catalog.mjs +108 -0
- package/bin/lean/validate-catalog.test.mjs +46 -1
- package/bin/lean/verify.mjs +1 -1
- package/bin/pool/affinity.test.mjs +91 -0
- package/bin/pool/agent.mjs +143 -9
- package/bin/pool/cache-sweep.mjs +31 -10
- package/bin/pool/ci-autoscale.mjs +160 -0
- package/bin/pool/cli.mjs +37 -8
- package/bin/pool/docker.mjs +3 -0
- package/bin/pool/engine-placement.test.mjs +94 -0
- package/bin/pool/lane-target.mjs +41 -0
- package/bin/pool/lane-tools.mjs +7 -2
- package/bin/pool/lane-tools.test.mjs +9 -0
- package/bin/pool/mirror-seed.mjs +15 -11
- package/bin/pool/router.mjs +88 -32
- package/bin/pool/version.mjs +29 -2
- package/bin/review-staging.mjs +11 -3
- package/bin/runner.mjs +59 -11
- package/bin/stats/release.mjs +7 -0
- package/bin/stats/release.test.mjs +20 -0
- package/bin/stats/scorecard.mjs +187 -0
- package/bin/stats/scorecard.test.mjs +89 -0
- package/docs/CONFIG.md +41 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/STATS.md +17 -0
- package/package.json +1 -1
- package/pool/image/Dockerfile +14 -2
- package/pool/image/manifest.json +25 -0
- package/pool/image/mirror.sh +11 -2
- package/pool/install/install-agent.ps1 +11 -4
- package/scripts/ci-local/adapters/github-actions.mjs +8 -0
- package/scripts/ci-local/cli.mjs +1 -1
- package/scripts/ci-local/plan.mjs +3 -2
- package/scripts/ci-local.test.sh +11 -0
- package/scripts/failure-census.mjs +67 -0
- package/scripts/review-finalize.sh +5 -5
- package/scripts/review-finalize.test.sh +8 -1
- package/scripts/verify-phase-trail.sh +11 -0
- package/scripts/verify-phase-trail.test.sh +9 -0
package/bin/lean/attempts.mjs
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* Nothing here clears the ledger: releaseHeld, --requeue and --set-env leave it alone. A missing ledger always admits.
|
|
8
8
|
*/
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
10
|
-
import { amendmentKindProblems } from "./conformance.mjs";
|
|
11
10
|
import { parseContractComment } from "./render.mjs";
|
|
12
11
|
import { postUpsert, findLeading, engineCommentCount } from "./statuscomment.mjs";
|
|
13
12
|
|
|
@@ -31,18 +30,28 @@ export const emptyLedger = () => ({ attempts: 0, signatures: [], lastInputHash:
|
|
|
31
30
|
export function normalizeLedger(x) {
|
|
32
31
|
if (!x || typeof x !== "object") return emptyLedger();
|
|
33
32
|
return { attempts: Number.isInteger(x.attempts) && x.attempts > 0 ? x.attempts : 0, signatures: Array.isArray(x.signatures) ? x.signatures.map((s) => ({ ...s, sig: String(s?.sig ?? "") })) : [],
|
|
34
|
-
lastInputHash: typeof x.lastInputHash === "string" ? x.lastInputHash : null, spend: Number(x.spend) > 0 ? Number(x.spend) : 0, ...(Number.isInteger(x.comments) && x.comments >= 0 ? { comments: x.comments } : {}), ...(x.escalated ? { escalated: x.escalated } : {}) };
|
|
33
|
+
lastInputHash: typeof x.lastInputHash === "string" ? x.lastInputHash : null, spend: Number(x.spend) > 0 ? Number(x.spend) : 0, ...(Number.isInteger(x.comments) && x.comments >= 0 ? { comments: x.comments } : {}), ...(x.escalated ? { escalated: x.escalated } : {}), ...(x.hostPin ? { hostPin: true } : {}) };
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
/** `{maxAttempts, maxIdentical}` from the orchestration config (posint, else the defaults 4 and 2). */
|
|
38
37
|
export const budgets = (cfg) => ({ maxAttempts: Number(cfg?.maxAttempts) >= 1 ? Math.floor(cfg.maxAttempts) : DEFAULT_ISSUE_ATTEMPTS, maxIdentical: Number(cfg?.maxIdentical) >= 1 ? Math.floor(cfg.maxIdentical) : DEFAULT_MAX_IDENTICAL });
|
|
39
38
|
|
|
40
39
|
/** The ledger after one failed lane (a new object): attempts+1, the signature with its run link, the hash it ran under, spend added. */
|
|
41
|
-
|
|
40
|
+
const normDetail = (d) => String(d ?? "").replace(/https?:\/\/\S+/g, "").replace(/\b[0-9a-f]{7,40}\b/g, "").replace(/\d+/g, "#").replace(/\s+/g, " ").trim().slice(0, 200);
|
|
41
|
+
/** #5931: what blocked a lane: code, normalized detail, contract hash, the engine version the lane ran, placement, and the env keys the detail names. */
|
|
42
|
+
export function blockerSignature({ code = null, detail = "", contractHash = null, engineVersion = null, placement = null, env = null } = {}) {
|
|
43
|
+
const envKeys = [...new Set(String(detail ?? "").match(/\b[A-Z][A-Z0-9]*_[A-Z0-9_]+\b/g) ?? [])].sort();
|
|
44
|
+
return { code: code ?? null, detail: normDetail(detail), contractHash: contractHash ?? null, engineVersion: engineVersion ? majorMinor(engineVersion) || String(engineVersion) : null, placement: placement ?? null, ...(envKeys.length ? { envKeys, env: Object.fromEntries(envKeys.map((k) => [k, env?.[k] == null ? null : sha(env[k])])) } : {}) };
|
|
45
|
+
}
|
|
46
|
+
/** A credentials block naming ops_credentials is pinned to the host on readmit. */
|
|
47
|
+
export const isCredentialsBlock = (detail) => /ops_credentials/i.test(String(detail ?? "")) && /credential/i.test(String(detail ?? ""));
|
|
48
|
+
|
|
49
|
+
export function recordFailure(ledger, { signature, hash = null, spend = 0, run = null, blocker = null }) {
|
|
42
50
|
const l = normalizeLedger(ledger);
|
|
43
51
|
const changed = hash && l.lastInputHash && hash !== l.lastInputHash; // a new input starts a new escalation window, the lifetime counters stay
|
|
44
|
-
const { escalated, ...rest } = l;
|
|
45
|
-
|
|
52
|
+
const { escalated, ...rest } = l;
|
|
53
|
+
const pin = l.hostPin || (blocker && isCredentialsBlock(blocker.detail)); // `comments` (the engine comment count seen at the last mirror) rides along
|
|
54
|
+
return { ...rest, ...(pin ? { hostPin: true } : {}), ...(escalated && !changed ? { escalated } : {}), attempts: l.attempts + 1, signatures: [...l.signatures, { sig: String(signature ?? ""), ...(hash ? { hash } : {}), ...(run ? { run } : {}), ...(blocker ? { blocker } : {}) }], lastInputHash: hash ?? l.lastInputHash, spend: Math.round((l.spend + (Number(spend) || 0)) * 1e6) / 1e6 };
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
/** The breach of the lifetime budget, or null: attempts reached the cap, or one signature exceeded `maxIdentical` failures. */
|
|
@@ -51,7 +60,7 @@ export function breach(ledger, cfg) {
|
|
|
51
60
|
const counts = new Map();
|
|
52
61
|
for (const s of l.signatures) counts.set(s.sig, (counts.get(s.sig) ?? 0) + 1);
|
|
53
62
|
const worst = [...counts].sort((a, b) => b[1] - a[1])[0];
|
|
54
|
-
if (worst && worst[1]
|
|
63
|
+
if (worst && worst[1] >= maxIdentical) return { kind: "identical", detail: `failure signature \`${worst[0]}\` repeated ${worst[1]} times (max_identical_signature ${maxIdentical})` };
|
|
55
64
|
if (l.attempts >= maxAttempts) return { kind: "attempts", detail: `${l.attempts} lanes ran (max_attempts_per_issue ${maxAttempts})` };
|
|
56
65
|
return null;
|
|
57
66
|
}
|
|
@@ -60,15 +69,28 @@ export function breach(ledger, cfg) {
|
|
|
60
69
|
* Admission of a re-run. `hash` null (unreadable input) fails open. Returns {ok:true} or {ok:false, code, reason}: `escalate` (a budget
|
|
61
70
|
* breach not yet escalated), or `loop.no_new_input` (the same input after a failure).
|
|
62
71
|
*/
|
|
63
|
-
export function admitInput(ledger, hash, cfg) {
|
|
72
|
+
export function admitInput(ledger, hash, cfg, cur = null) {
|
|
64
73
|
const l = normalizeLedger(ledger);
|
|
65
74
|
if (!hash || !l.attempts || !l.lastInputHash || hash !== l.lastInputHash) return { ok: true };
|
|
75
|
+
const why = changedSince(l.signatures[l.signatures.length - 1]?.blocker, cur); // #5931: the hash omits placement and env values
|
|
76
|
+
if (why) return { ok: true, reason: why };
|
|
66
77
|
const b = breach(l, cfg);
|
|
67
78
|
if (b && !l.escalated) return { ok: false, code: "escalate", reason: b.detail };
|
|
68
79
|
const last = l.signatures[l.signatures.length - 1]?.sig;
|
|
69
80
|
return { ok: false, code: NO_NEW_INPUT, reason: `input unchanged since the last failure${last ? ` (\`${last}\`)` : ""}${b ? `; ${b.detail}` : ""}` };
|
|
70
81
|
}
|
|
71
82
|
|
|
83
|
+
/** What relevant thing changed since the blocker (engine version, placement, contract hash, a referenced env key), or null. */
|
|
84
|
+
export function changedSince(b, cur) {
|
|
85
|
+
if (!b || !cur) return null;
|
|
86
|
+
const diff = (a, c) => a != null && c != null && String(a) !== String(c);
|
|
87
|
+
if (diff(b.engineVersion, cur.engineVersion ? majorMinor(cur.engineVersion) || cur.engineVersion : null)) return `engine version changed ${b.engineVersion} -> ${cur.engineVersion}`;
|
|
88
|
+
if (diff(b.placement, cur.placement)) return `placement changed ${b.placement} -> ${cur.placement}`;
|
|
89
|
+
if (diff(b.contractHash, cur.contractHash)) return "contract hash changed";
|
|
90
|
+
const keys = (b.envKeys ?? []).filter((k) => cur.env && cur.env[k] !== undefined && (b.env?.[k] ?? null) !== (cur.env[k] == null ? null : sha(cur.env[k])));
|
|
91
|
+
return keys.length ? `env key changed: ${keys.join(", ")}` : null;
|
|
92
|
+
}
|
|
93
|
+
|
|
72
94
|
export const markEscalated = (ledger, at) => ({ ...normalizeLedger(ledger), escalated: at ?? true });
|
|
73
95
|
|
|
74
96
|
/** The one consolidated FORGE:ESCALATION body: signatures with run links, spend, what unblocks it. */
|
|
@@ -87,28 +109,6 @@ export function parseAttempts(body) {
|
|
|
87
109
|
try { return normalizeLedger(JSON.parse(m[1])); } catch { return null; }
|
|
88
110
|
}
|
|
89
111
|
|
|
90
|
-
const ID_RE = /^#?\d+$/;
|
|
91
|
-
/**
|
|
92
|
-
* The shared amendment schema (#5986, extends #5979 past guard ids): kind/path/requirement presence plus field types. Returns the
|
|
93
|
-
* rejection strings, [] when valid; the lane returns them to the builder once and never posts a rejected shape.
|
|
94
|
-
*/
|
|
95
|
-
export function validateAmendments(amendments) {
|
|
96
|
-
if (amendments !== undefined && amendments !== null && !Array.isArray(amendments)) return ["amendments must be an array"];
|
|
97
|
-
const out = [...amendmentKindProblems(amendments)];
|
|
98
|
-
for (const a of amendments ?? []) {
|
|
99
|
-
if (!a || typeof a !== "object") { out.push(`amendment must be an object: ${JSON.stringify(a ?? null).slice(0, 120)}`); continue; }
|
|
100
|
-
const tag = JSON.stringify(a).slice(0, 200);
|
|
101
|
-
if (a.why !== undefined && typeof a.why !== "string") out.push(`amendment 'why' must be a string: ${tag}`);
|
|
102
|
-
if (a.path !== undefined && typeof a.path !== "string") out.push(`amendment 'path' must be a string: ${tag}`);
|
|
103
|
-
if (a.kind === "supersedes" && a.guard !== undefined && !ID_RE.test(String(a.guard))) out.push(`supersedes 'guard' must be an issue id like #123: ${tag}`);
|
|
104
|
-
if (a.kind === "decision") {
|
|
105
|
-
const d = a.decision;
|
|
106
|
-
if (!d || typeof d !== "object" || typeof d.choice !== "string" || !d.choice.trim() || (d.anchors !== undefined && !Array.isArray(d.anchors))) out.push(`decision needs {choice: string, anchors: [paths]}: ${tag}`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return [...new Set(out)];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
112
|
/** Hash of the last trusted, parseable FORGE:CONTRACT comment (the frozen contract), or null. */
|
|
113
113
|
export function frozenContractHash(comments, trusted) {
|
|
114
114
|
let h = null;
|
|
@@ -125,16 +125,19 @@ export function frozenContractHash(comments, trusted) {
|
|
|
125
125
|
* The orchestrate seam, bound to GitHub: `hash(n)` reads the issue and computes the input hash (null on any read failure: fail open),
|
|
126
126
|
* `load(n)` reads the FORGE:ATTEMPTS comment, `mirror(n, ledger)` upserts it, `notify(...)` posts the one escalation or the no-new-input note.
|
|
127
127
|
*/
|
|
128
|
-
export function makeAttemptsSeam({ gh, repo, engineVersion = null, sandboxVersion = null, cfg = {}, trusted = null, contractHash = null }) {
|
|
128
|
+
export function makeAttemptsSeam({ gh, repo, engineVersion = null, hostVersion = null, sandboxVersion = null, cfg = {}, trusted = null, contractHash = null }) {
|
|
129
129
|
const view = async (n) => JSON.parse(String(await gh(["issue", "view", String(n), "-R", repo, "--json", "title,body,labels,comments"])));
|
|
130
130
|
const isTrusted = async () => trusted ?? (await import("./prefilter.mjs")).isTrustedIssueComment;
|
|
131
|
+
let seenSandbox = sandboxVersion;
|
|
131
132
|
return {
|
|
133
|
+
noteSandboxVersion(v) { if (v) seenSandbox = v; },
|
|
132
134
|
cfg,
|
|
133
135
|
async hash(n) {
|
|
134
136
|
try {
|
|
135
137
|
const v = await view(n), t = await isTrusted();
|
|
136
138
|
const decisions = (v.comments ?? []).filter((c) => /^\s*<!--\s*FORGE:DECISION\b/.test(c?.body ?? "") && t(c)).map((c) => c.body);
|
|
137
|
-
return computeInputHash({ title: v.title, body: v.body, labels: v.labels, decisions, engineVersion, sandboxVersion,
|
|
139
|
+
return computeInputHash({ title: v.title, body: v.body, labels: v.labels, decisions, engineVersion, sandboxVersion: seenSandbox ?? hostVersion, // the version the lane ran; the host's only when none is known
|
|
140
|
+
contractHash: contractHash ? await contractHash(n) : frozenContractHash(v.comments, t) });
|
|
138
141
|
} catch { return null; }
|
|
139
142
|
},
|
|
140
143
|
async load(n) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { computeInputHash, emptyLedger, normalizeLedger, recordFailure, breach, admitInput, markEscalated, frozenContractHash, renderEscalation, renderAttempts, parseAttempts,
|
|
5
|
+
import { computeInputHash, emptyLedger, normalizeLedger, recordFailure, breach, admitInput, markEscalated, blockerSignature, frozenContractHash, renderEscalation, renderAttempts, parseAttempts, budgets, makeAttemptsSeam } from "./attempts.mjs";
|
|
6
6
|
import { renderContract } from "./render.mjs";
|
|
7
7
|
import { postKeyed } from "./statuscomment.mjs";
|
|
8
8
|
|
|
@@ -31,19 +31,19 @@ describe("#5986 admission, budgets, escalation", () => {
|
|
|
31
31
|
const a = admitInput(fail(null, "ci.red:x", "H1"), "H1", cfg);
|
|
32
32
|
assert.equal(a.ok, false); assert.equal(a.code, "loop.no_new_input"); assert.match(a.reason, /ci\.red:x/);
|
|
33
33
|
});
|
|
34
|
-
it("the
|
|
35
|
-
let l = fail(null, "s", "H1");
|
|
34
|
+
it("the 2nd identical signature breaches; 4 lanes breach; different signatures stay under max_identical", () => {
|
|
35
|
+
let l = fail(null, "s", "H1");
|
|
36
36
|
assert.equal(breach(l, cfg), null);
|
|
37
|
-
assert.equal(breach(fail(l, "s", "
|
|
37
|
+
assert.equal(breach(fail(l, "s", "H2"), cfg).kind, "identical");
|
|
38
38
|
let m = null; for (const [i, s] of ["a", "b", "c", "d"].entries()) m = fail(m, s, `H${i}`);
|
|
39
39
|
assert.equal(breach(m, cfg).kind, "attempts");
|
|
40
40
|
assert.equal(breach(m, { maxAttempts: 5 }), null);
|
|
41
41
|
});
|
|
42
42
|
it("a breach escalates once at the same hash, then loop.no_new_input; a new hash admits and clears the escalated flag after the next failure", () => {
|
|
43
|
-
let l = null; for (let i = 1; i <=
|
|
44
|
-
assert.equal(admitInput(l, "
|
|
43
|
+
let l = null; for (let i = 1; i <= 2; i++) l = fail(l, "s", `H${i}`);
|
|
44
|
+
assert.equal(admitInput(l, "H2", cfg).code, "escalate");
|
|
45
45
|
l = markEscalated(l);
|
|
46
|
-
assert.equal(admitInput(l, "
|
|
46
|
+
assert.equal(admitInput(l, "H2", cfg).code, "loop.no_new_input");
|
|
47
47
|
assert.deepEqual(admitInput(l, "H4", cfg), { ok: true });
|
|
48
48
|
assert.equal(fail(l, "s", "H4").escalated, undefined, "the next window escalates again");
|
|
49
49
|
});
|
|
@@ -73,18 +73,6 @@ describe("#5986 contract hash in the input hash", () => {
|
|
|
73
73
|
});
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
describe("#5986 shared amendment schema", () => {
|
|
77
|
-
it("accepts valid shapes and rejects wrong types with a message", () => {
|
|
78
|
-
assert.deepEqual(validateAmendments([{ kind: "add-deliverable", path: "a.mjs", why: "x" }, { kind: "decision", decision: { choice: "c", anchors: ["a.mjs"] }, why: "y" }]), []);
|
|
79
|
-
assert.deepEqual(validateAmendments(undefined), []);
|
|
80
|
-
assert.ok(validateAmendments([{ kind: "nope" }]).length);
|
|
81
|
-
assert.match(validateAmendments([{ kind: "add-deliverable", path: 5 }])[0], /path/);
|
|
82
|
-
assert.match(validateAmendments([{ kind: "supersedes", guard: "abc", why: "x" }]).join(), /guard/);
|
|
83
|
-
assert.match(validateAmendments([{ kind: "decision", decision: { anchors: "a" }, why: "x" }]).join(), /choice/);
|
|
84
|
-
assert.match(validateAmendments({ kind: "x" })[0], /array/);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
76
|
describe("#5986 synthetic replay of looping issue timelines", () => {
|
|
89
77
|
// shapes of the AlterLab timelines (#40762 repeated builder.blocked, #41419 repeated amendments, #41262 mixed signatures); the real logs are not in the repo
|
|
90
78
|
const timelines = [
|
|
@@ -125,3 +113,29 @@ describe("#5986 synthetic replay of looping issue timelines", () => {
|
|
|
125
113
|
assert.ok(lanes <= 4, `lanes ${lanes}`);
|
|
126
114
|
});
|
|
127
115
|
});
|
|
116
|
+
|
|
117
|
+
describe("#5931 blocker signature", () => {
|
|
118
|
+
const cfg = {};
|
|
119
|
+
const blk = (o = {}) => blockerSignature({ code: "ci.red", detail: "boom 12 abcdef1", contractHash: "c1", engineVersion: "1.63.0", placement: "remote", ...o });
|
|
120
|
+
const failB = (b) => recordFailure(null, { signature: "s", hash: "H1", blocker: b });
|
|
121
|
+
it("an unchanged signature is refused; a changed engine version, placement or contract hash is admitted with a reason", () => {
|
|
122
|
+
const l = failB(blk()), cur = { engineVersion: "1.63.1", placement: "remote", contractHash: "c1" };
|
|
123
|
+
assert.equal(admitInput(l, "H1", cfg, cur).code, "loop.no_new_input");
|
|
124
|
+
assert.match(admitInput(l, "H1", cfg, { ...cur, engineVersion: "1.64.0" }).reason, /engine version/);
|
|
125
|
+
assert.match(admitInput(l, "H1", cfg, { ...cur, placement: "local" }).reason, /placement/);
|
|
126
|
+
assert.match(admitInput(l, "H1", cfg, { ...cur, contractHash: "c2" }).reason, /contract hash/);
|
|
127
|
+
});
|
|
128
|
+
it("a referenced env key that changed admits", () => {
|
|
129
|
+
const l = failB(blk({ detail: "missing SOPS_KEY", env: { SOPS_KEY: "a" } }));
|
|
130
|
+
assert.equal(admitInput(l, "H1", cfg, { env: { SOPS_KEY: "a" } }).ok, false);
|
|
131
|
+
assert.match(admitInput(l, "H1", cfg, { env: { SOPS_KEY: "b" } }).reason, /SOPS_KEY/);
|
|
132
|
+
});
|
|
133
|
+
it("two identical signatures breach and a credentials block persists hostPin", () => {
|
|
134
|
+
let l = recordFailure(null, { signature: "x", hash: "H1", blocker: blk({ detail: "Builder is blocked (credentials): ops_credentials" }) });
|
|
135
|
+
assert.equal(l.hostPin, true);
|
|
136
|
+
assert.equal(normalizeLedger(JSON.parse(renderAttempts(l).replace(/^<!-- FORGE:ATTEMPTS /, "").replace(/ -->$/, ""))).hostPin, true);
|
|
137
|
+
l = recordFailure(l, { signature: "x", hash: "H2" });
|
|
138
|
+
assert.equal(breach(l, cfg).kind, "identical");
|
|
139
|
+
assert.equal(l.hostPin, true);
|
|
140
|
+
});
|
|
141
|
+
});
|
package/bin/lean/basered.mjs
CHANGED
|
@@ -43,6 +43,13 @@ export function baseRedPaths(rows = []) {
|
|
|
43
43
|
return { src: src.slice(0, 20), tests: tests.slice(0, 20) };
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/** #5913: true when the lane's changed files include a file the failing guard names (guarded code first, else its tests): the lane is then the base fix, not a bystander. */
|
|
47
|
+
export function diffTouchesGuard({ changed = [], failed = [] } = {}) {
|
|
48
|
+
const { src, tests } = baseRedPaths(failed);
|
|
49
|
+
const have = new Set((changed ?? []).map((f) => String(f).trim().replace(/^\.\//, "")).filter(Boolean));
|
|
50
|
+
return [...src, ...tests].some((p) => have.has(p));
|
|
51
|
+
}
|
|
52
|
+
|
|
46
53
|
/** Issue number a commit stands for: a closing keyword, else an `issue-N` branch name (merge commit), else the last `(#N)` of the subject. */
|
|
47
54
|
export function issueOf(subject = "", body = "") {
|
|
48
55
|
const text = `${subject}\n${body}`;
|
|
@@ -213,3 +220,22 @@ export function bypassesGuard({ laneFiles = [], att = null } = {}) {
|
|
|
213
220
|
if (!surface.length || !lane.length) return false;
|
|
214
221
|
return !lane.some((f) => surface.some((s) => f === s || f.startsWith(`${s}/`)));
|
|
215
222
|
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* #6049: one issue per required release check the lane cannot run (lane-check parity gap), deduped by a hidden marker
|
|
226
|
+
* keyed on the context name: an open or recent issue gets no second copy. Never throws; returns the issue numbers filed.
|
|
227
|
+
*/
|
|
228
|
+
export async function reportParityGaps({ ghc, repo, release, gaps = [] }) {
|
|
229
|
+
const filed = [];
|
|
230
|
+
for (const g of gaps) {
|
|
231
|
+
const key = `<!-- FORGE:PARITY_GAP ${String(g.context).replace(/[^\w .:/()-]/g, "_")} -->`;
|
|
232
|
+
try {
|
|
233
|
+
if ((await findKeyed({ ghc, repo, key })).length) continue;
|
|
234
|
+
const body = `${key}\n## Lane-check parity gap\nThe required check \`${g.context}\` on \`${release}\` has no lane equivalent, so a lane cannot catch its failures before the release PR: ${g.reason}.`;
|
|
235
|
+
const url = String(await ghc(["issue", "create", "-R", repo, "--title", `ci: required release check ${g.context} has no lane pre-PR check`.slice(0, 120), "--body", body])).trim();
|
|
236
|
+
const n = url.match(/\/issues\/(\d+)/);
|
|
237
|
+
if (n) filed.push(Number(n[1]));
|
|
238
|
+
} catch { /* best effort */ }
|
|
239
|
+
}
|
|
240
|
+
return filed;
|
|
241
|
+
}
|
|
@@ -313,7 +313,7 @@ export const appendBatchLog = (dir, text) => { try { appendFileSync(join(dir, BA
|
|
|
313
313
|
/** #5806: minutes without progress (setup reads or dispatch) before a stall is acted on; `FORGEDOCK_SCHEDD_STALL_MIN` overrides (was 10). */
|
|
314
314
|
export const DEFAULT_STALL_MIN = 3;
|
|
315
315
|
/** #5806: auto-recoveries one batch gets in total (one per distinct ready set); past it every stall alerts. */
|
|
316
|
-
export const MAX_STALL_RECOVERIES =
|
|
316
|
+
export const MAX_STALL_RECOVERIES = 6;
|
|
317
317
|
/** #5745: `; admission held by <code>: <detail>` for each failing preflight gate, "" when none. Pure. */
|
|
318
318
|
export const holdGateDetail = (gates) => (Array.isArray(gates) ? gates : []).filter((g) => g?.code).map((g) => `; admission held by ${g.code}: ${g.detail ?? "failing"}`).join("");
|
|
319
319
|
/** #5938: `{running, k, local, remote, text}`: the live lanes of a saved state against K; a run record with `remote` is a pool lane. Pure. */
|
|
@@ -331,7 +331,7 @@ export function runningSplit(state, parallel = null) {
|
|
|
331
331
|
export function evaluateDispatchStall(state, { held = [], parallel = null, hosted = false, lastProgressMs = null, now = Date.now(), windowMin = DEFAULT_STALL_MIN, cancelled = false, reported = false, gates = [], lanesAliveMs = null, paused = null } = {}) {
|
|
332
332
|
if (!state || cancelled || reported || lastProgressMs === null) return null;
|
|
333
333
|
if (paused) return null; // #5975: an operator pause is an intended wait, not a dispatch stall
|
|
334
|
-
if (state.breaker && !state.breaker.transport) return null; // an operator --resume clears it; a re-host would stop again at once
|
|
334
|
+
if (state.breaker && !state.breaker.transport && !state.breaker.environmental) return null; // an operator --resume clears it; a re-host would stop again at once
|
|
335
335
|
const order = new Set((state.order ?? []).map(Number)), results = state.results ?? {}, heldSet = new Set(held.map(Number));
|
|
336
336
|
const running = Object.keys(state.running ?? {}).length;
|
|
337
337
|
const k = Number.isInteger(parallel) && parallel > 0 ? parallel : Number.isInteger(state.parallel) && state.parallel > 0 ? state.parallel : 1;
|
|
@@ -353,17 +353,22 @@ export function evaluateDispatchStall(state, { held = [], parallel = null, hoste
|
|
|
353
353
|
* daemon restarts so a restart never re-arms it; `probe` is the batch env probe (lanecheck `probeBatchEnv`), null when the
|
|
354
354
|
* batch pins no env. A broken env alerts at once (a resume would stall or fail the same way); the first stall of a ready set
|
|
355
355
|
* is recovered once (`resume` an unhosted batch, `restart-daemon` when its runner is alive but wedged); the same ready set
|
|
356
|
-
* stalling again
|
|
357
|
-
*
|
|
356
|
+
* stalling again is recovered again after a doubling backoff (#6082), a batch past `maxRecoveries` alerts with the probed cause,
|
|
357
|
+
* and a `pool-capacity` stall only waits. Pure.
|
|
358
|
+
* @returns {{action: "resume"|"restart-daemon"|"alert"|"wait", sig: string, cause: string|null}}
|
|
358
359
|
*/
|
|
359
|
-
|
|
360
|
+
/** #5988: the diagnosis a stall recovery acts on: the `dispatch-stalled` cause plus the gates in force. */
|
|
361
|
+
export const stallCause = (stall) => `${stall.code ?? "dispatch-stalled"}${stall.gates?.length ? `[${[...stall.gates].sort().join(",")}]` : ""}`;
|
|
362
|
+
|
|
363
|
+
export function decideStallAction(stall, { recovery = null, probe = null, hosted = false, maxRecoveries = MAX_STALL_RECOVERIES, now = Date.now(), windowMin = DEFAULT_STALL_MIN } = {}) {
|
|
360
364
|
const sig = stall.ready.join(",");
|
|
365
|
+
if (stall.code === "pool-capacity") return { action: "wait", sig, cause: `pool capacity: ${stall.reason}` }; // #6082: an intended wait, never recovered or alerted
|
|
361
366
|
if (probe && !probe.ok) return { action: "alert", sig, cause: `batch env: ${probe.detail}; fix it with --set-env <id> PATH=<dirs holding the tools>, then --resume` };
|
|
362
367
|
const count = Number(recovery?.count) || 0;
|
|
363
|
-
if (
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
368
|
+
if (count >= maxRecoveries) return { action: "alert", sig, cause: `${count} auto-recoveries already spent${probe ? `; ${probe.detail}` : ""}` };
|
|
369
|
+
// #6082: a repeat stall is recovered again once the backoff (one window, doubling per recovery, capped at an hour) has passed
|
|
370
|
+
const at = Date.parse(recovery?.at ?? ""), cooldownMs = Math.min(60, windowMin * 2 ** Math.max(0, count - 1)) * 60000;
|
|
371
|
+
if (recovery && Number.isFinite(at) && now - at < cooldownMs) return { action: "wait", sig, cause: `recovered ${recovery.action} at ${recovery.at}; next attempt after the backoff` };
|
|
367
372
|
return { action: hosted ? "restart-daemon" : "resume", sig, cause: null };
|
|
368
373
|
}
|
|
369
374
|
|
|
@@ -371,8 +376,8 @@ export function decideStallAction(stall, { recovery = null, probe = null, hosted
|
|
|
371
376
|
export function recordStallRecovery(batch, stall, { action, sig = stall.ready.join(","), now = Date.now() } = {}) {
|
|
372
377
|
const prev = readHealth(batch.dir) ?? {}, at = new Date(now).toISOString();
|
|
373
378
|
const what = action === "restart-daemon" ? "restart the hosting schedd (its runner is alive but not progressing)" : "resume the batch (no runner hosts it)";
|
|
374
|
-
const text = `FORGE:DECISION batch ${batch.id} stall-recovery: ${what}; why: ${stall.detail}; alternative: alert only (a repeat of this stall
|
|
375
|
-
try { writeHealth(batch.dir, { ...prev, stallRecovery: { sig, at, action, count: (Number(prev.stallRecovery?.count) || 0) + 1, detail: stall.detail } }); } catch { /* advisory */ }
|
|
379
|
+
const text = `FORGE:DECISION batch ${batch.id} stall-recovery: ${what}; why: ${stall.detail}; alternative: alert only (a repeat of this stall is recovered again after a backoff, #6082)`;
|
|
380
|
+
try { writeHealth(batch.dir, { ...prev, stallRecovery: { sig, at, action, cause: stallCause(stall), gates: stall.gates ?? [], count: (Number(prev.stallRecovery?.count) || 0) + 1, detail: stall.detail } }); } catch { /* advisory */ }
|
|
376
381
|
appendBatchLog(batch.dir, `${at} ${text}`);
|
|
377
382
|
return text;
|
|
378
383
|
}
|
|
@@ -409,7 +414,7 @@ export function recordStallAlert(batch, stall, { now = Date.now(), cause = null
|
|
|
409
414
|
const sig = stall.ready.join(","), prev = readHealth(batch.dir) ?? {};
|
|
410
415
|
if (prev.stall?.sig === sig) return false;
|
|
411
416
|
const at = new Date(now).toISOString();
|
|
412
|
-
const text = `BATCH UNHEALTHY ${batch.id} (dispatch-stalled)\n cause: dispatch-stalled: ${stall.detail}${cause ? `\n probed: ${cause}` : ""}\n recovery:\n forgedock orchestrate --resume ${batch.id}\n forgedock orchestrate --cancel ${batch.id}`;
|
|
417
|
+
const text = `BATCH UNHEALTHY ${batch.id} (${stall.code ?? "dispatch-stalled"})\n cause: ${stall.code ?? "dispatch-stalled"}: ${stall.detail}${cause ? `\n probed: ${cause}` : ""}\n recovery:\n forgedock orchestrate --resume ${batch.id}\n forgedock orchestrate --cancel ${batch.id}`;
|
|
413
418
|
try { writeHealth(batch.dir, { ...prev, stall: { at, sig, detail: stall.detail, ...(cause ? { cause } : {}) }, ...(prev.alertedAt ? {} : { alertedAt: at, alert: text }) }); } catch { return false; }
|
|
414
419
|
appendBatchLog(batch.dir, `${at} ${text.split("\n").slice(0, cause ? 3 : 2).join(" | ")}`);
|
|
415
420
|
return true;
|
|
@@ -288,25 +288,34 @@ describe("#5806 setup/dispatch stall: 3-min threshold, one auto-recovery, then a
|
|
|
288
288
|
assert.match(d.cause, /batch env: gh, git not resolvable on the batch env PATH \(1 entry: \/bogus\)/);
|
|
289
289
|
});
|
|
290
290
|
|
|
291
|
-
it("a recovery is recorded
|
|
291
|
+
it("a recovery is recorded (health.json + FORGE:DECISION in batch.log); a repeat waits out the backoff, then is recovered again (#6082)", () => {
|
|
292
292
|
const root = tmpDir("stall-recover-"), b = openBatch(root, "b1");
|
|
293
293
|
b.writePlan({ daemon: true, repo: "o/r" });
|
|
294
|
-
const s = at(4);
|
|
294
|
+
const s = at(4), ok = { ok: true, detail: "batch env PATH resolves gh, git, node" };
|
|
295
295
|
const text = recordStallRecovery(b, s, { action: "resume", now: NOW });
|
|
296
296
|
assert.match(text, /^FORGE:DECISION batch b1 stall-recovery: resume the batch/);
|
|
297
297
|
assert.match(readFileSync(join(b.dir, "batch.log"), "utf8"), /FORGE:DECISION batch b1 stall-recovery/);
|
|
298
298
|
const rec = readHealth(b.dir).stallRecovery;
|
|
299
299
|
assert.deepEqual([rec.sig, rec.action, rec.count], ["1,2,3,4", "resume", 1]);
|
|
300
300
|
// the daemon restarted meanwhile: the decision reads health.json, not memory
|
|
301
|
-
const
|
|
302
|
-
assert.equal(
|
|
303
|
-
|
|
304
|
-
assert.equal(
|
|
305
|
-
assert.equal(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
301
|
+
const early = decideStallAction(s, { recovery: rec, hosted: true, probe: ok, now: NOW + 60_000 });
|
|
302
|
+
assert.equal(early.action, "wait", "inside the backoff nothing acts and nothing alerts");
|
|
303
|
+
const later = decideStallAction(s, { recovery: rec, hosted: true, probe: ok, now: NOW + 4 * 60_000 });
|
|
304
|
+
assert.equal(later.action, "restart-daemon", "the same stall persisting past the backoff is healed again, no operator");
|
|
305
|
+
assert.equal(decideStallAction(s, { recovery: { ...rec, count: 3 }, hosted: false, now: NOW + 3 * 3600_000 }).action, "resume");
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("a pool-capacity stall only waits: no recovery, no alert (#6082)", () => {
|
|
309
|
+
const s = { code: "pool-capacity", reason: "pool full", ready: [1], detail: "waiting on pool capacity" };
|
|
310
|
+
assert.equal(decideStallAction(s, { hosted: true }).action, "wait");
|
|
311
|
+
assert.equal(decideStallAction(s, { hosted: false, recovery: { sig: "1", at: "x", action: "resume", count: MAX_STALL_RECOVERIES } }).action, "wait");
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("an alert names the stall code, not always dispatch-stalled (#6082)", () => {
|
|
315
|
+
const root = tmpDir("stall-code-"), b = openBatch(root, "b1");
|
|
316
|
+
b.writePlan({ daemon: true, repo: "o/r" });
|
|
317
|
+
recordStallAlert(b, { ...at(4), code: "pool-capacity" }, { now: NOW });
|
|
318
|
+
assert.match(readHealth(b.dir).alert, /BATCH UNHEALTHY b1 \(pool-capacity\)/);
|
|
310
319
|
});
|
|
311
320
|
|
|
312
321
|
it("a batch that spent MAX_STALL_RECOVERIES alerts even on a new ready set", () => {
|
|
@@ -407,6 +416,25 @@ describe("#5938 stall verdict is re-evaluated: full K, recovery lanes, pool capa
|
|
|
407
416
|
});
|
|
408
417
|
});
|
|
409
418
|
|
|
419
|
+
describe("#5988: a second restart for the same stall cause is refused", () => {
|
|
420
|
+
const stall = (ready, gates) => ({ code: "dispatch-stalled", ready, gates, detail: "stalled" });
|
|
421
|
+
it("a different ready set with the same cause waits out the backoff and the diagnosis is recorded", () => {
|
|
422
|
+
const root = tmpDir("stallcause");
|
|
423
|
+
mkdirSync(join(root, "b1"), { recursive: true });
|
|
424
|
+
const batch = { id: "b1", dir: join(root, "b1") };
|
|
425
|
+
const first = decideStallAction(stall([1, 2], ["base.red"]), { recovery: null, hosted: true });
|
|
426
|
+
assert.equal(first.action, "restart-daemon");
|
|
427
|
+
recordStallRecovery(batch, stall([1, 2], ["base.red"]), { action: first.action, sig: first.sig });
|
|
428
|
+
const rec = readHealth(batch.dir).stallRecovery;
|
|
429
|
+
assert.equal(rec.cause, "dispatch-stalled[base.red]");
|
|
430
|
+
assert.deepEqual(rec.gates, ["base.red"]);
|
|
431
|
+
const again = decideStallAction(stall([3], ["base.red"]), { recovery: rec, hosted: true });
|
|
432
|
+
assert.equal(again.action, "wait", "#6082: inside the backoff");
|
|
433
|
+
assert.equal(decideStallAction(stall([3], ["base.red"]), { recovery: rec, hosted: true, now: Date.now() + 3600_000 }).action, "restart-daemon", "#6082: after it, healed again");
|
|
434
|
+
assert.equal(decideStallAction(stall([3], []), { recovery: rec, hosted: true }).action, "wait", "backoff is per batch");
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
|
|
410
438
|
describe("#5987 efficiency status line", () => {
|
|
411
439
|
it("batch status shows the efficiency line with and without breaches; none without a ledger", async () => {
|
|
412
440
|
const { writeEfficiency } = await import("./efficiency.mjs");
|
package/bin/lean/batch.test.mjs
CHANGED
|
@@ -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 = [];
|
|
@@ -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
|
});
|
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; };
|