forgedock 1.51.0 → 1.53.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/engine/outcome-codes.mjs +3 -0
- package/bin/engine/telemetry-seam.mjs +4 -2
- package/bin/engine-cli.mjs +61 -17
- package/bin/experiment.mjs +58 -6
- package/bin/forge-utils.mjs +6 -2
- package/bin/forgedock.mjs +25 -1
- package/bin/lean/account-watch.mjs +28 -0
- package/bin/lean/account-watch.test.mjs +30 -0
- package/bin/lean/activation.mjs +20 -0
- package/bin/lean/activation.test.mjs +14 -1
- package/bin/lean/basered.mjs +115 -0
- package/bin/lean/basered.test.mjs +66 -0
- package/bin/lean/batch-health.mjs +40 -6
- package/bin/lean/batch-health.test.mjs +34 -1
- package/bin/lean/batch.mjs +41 -2
- package/bin/lean/batch.test.mjs +104 -2
- package/bin/lean/checkpoint-reconcile.mjs +43 -0
- package/bin/lean/checkpoint-reconcile.test.mjs +95 -0
- package/bin/lean/conformance.e2e.test.mjs +1 -1
- package/bin/lean/conformance.mjs +205 -23
- package/bin/lean/conformance.test.mjs +164 -3
- package/bin/lean/context.mjs +27 -17
- package/bin/lean/context.test.mjs +15 -0
- package/bin/lean/effects.mjs +11 -7
- package/bin/lean/execution.mjs +19 -3
- package/bin/lean/execution.test.mjs +39 -0
- package/bin/lean/findinglabel.mjs +16 -0
- package/bin/lean/findinglabel.test.mjs +39 -0
- package/bin/lean/heavy.mjs +6 -3
- package/bin/lean/hostload.mjs +78 -0
- package/bin/lean/hostload.test.mjs +117 -0
- package/bin/lean/hotspots-remote.e2e.test.mjs +71 -0
- package/bin/lean/issuewatch-release.mjs +6 -2
- package/bin/lean/issuewatch-release.test.mjs +16 -0
- package/bin/lean/issuewatch.mjs +11 -1
- package/bin/lean/lanelock.mjs +14 -0
- package/bin/lean/lean.mjs +171 -36
- package/bin/lean/lean.test.mjs +302 -10
- package/bin/lean/light.mjs +48 -7
- package/bin/lean/light.test.mjs +37 -3
- package/bin/lean/limits.test.mjs +142 -9
- package/bin/lean/orchestrate-cancel.test.mjs +143 -0
- package/bin/lean/orchestrate.mjs +110 -26
- package/bin/lean/postdeploy-check.test.mjs +39 -0
- package/bin/lean/prompts.mjs +8 -7
- package/bin/lean/quota.mjs +39 -0
- package/bin/lean/recovery.test.mjs +10 -0
- package/bin/lean/relaxation.mjs +73 -0
- package/bin/lean/relaxation.test.mjs +54 -0
- package/bin/lean/release-postmerge.mjs +119 -0
- package/bin/lean/release-rehearsal.mjs +63 -0
- package/bin/lean/release-rehearsal.test.mjs +93 -0
- package/bin/lean/release-review.e2e.test.mjs +77 -0
- package/bin/lean/release-review.mjs +198 -0
- package/bin/lean/release-review.test.mjs +180 -0
- package/bin/lean/release.mjs +228 -0
- package/bin/lean/release.test.mjs +292 -0
- package/bin/lean/rotator.mjs +150 -31
- package/bin/lean/rotator.test.mjs +105 -2
- package/bin/lean/sandbox-remote.mjs +9 -2
- package/bin/lean/schedd.mjs +56 -6
- package/bin/lean/schedd.test.mjs +108 -6
- package/bin/lean/verifier.mjs +3 -2
- package/bin/lean/verify.mjs +2 -1
- package/bin/lean/verify.test.mjs +6 -0
- package/bin/pool/agent.mjs +18 -4
- package/bin/pool/router.mjs +68 -25
- package/bin/review-staging.mjs +23 -0
- package/bin/stats/conformance-outcomes.mjs +208 -0
- package/bin/stats/conformance-outcomes.test.mjs +188 -0
- package/bin/stats/depth.mjs +218 -0
- package/bin/stats/depth.test.mjs +133 -0
- package/bin/stats/experiment.mjs +7 -5
- package/bin/stats/github-source.mjs +2 -2
- package/bin/stats/index.mjs +64 -2
- package/bin/stats/local-source.mjs +11 -0
- package/bin/stats/query.mjs +69 -0
- package/bin/stats/selffiled.mjs +52 -0
- package/bin/stats/selffiled.test.mjs +71 -0
- package/commands/orchestrate.md +1 -1
- package/commands/review-pr-agents/security.md +4 -0
- package/commands/review-pr-staging.md +2 -0
- package/commands/work-on/build.md +4 -6
- package/docs/CONFIG.md +66 -8
- package/docs/ISSUE-WATCH.md +2 -0
- package/docs/OUTCOME-CODES.md +3 -0
- package/docs/STATS.md +44 -0
- package/docs/TELEMETRY.md +1 -1
- package/package.json +1 -1
- package/pool/README.md +1 -1
- package/pool/image/cs-cred +14 -1
- package/pool/install/install-agent.ps1 +6 -2
- package/scripts/backfill-finding-labels.mjs +50 -0
- package/scripts/backfill-finding-labels.test.mjs +36 -0
- package/scripts/doctor-pipeline-state.sh +21 -6
- package/scripts/file-deferred-followups.sh +60 -238
- package/scripts/file-deferred-followups.test.sh +99 -187
- package/scripts/followup-route.mjs +12 -0
- package/scripts/hotspots.sh +12 -8
- package/scripts/hotspots.test.sh +22 -0
- package/scripts/owner-route-parity.test.sh +17 -1
- package/scripts/prior-attempts.test.mjs +1 -1
- package/scripts/review-pr-side-effects.test.sh +40 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { tmpDir } from "../tests/_tmp.mjs";
|
|
8
|
+
import { releaseFromCli, readReleaseConfig, openRelease, newReleaseId } from "./release.mjs";
|
|
9
|
+
import { reviewStep, fixStep } from "./release-review.mjs";
|
|
10
|
+
import { postMergeStep } from "./release-postmerge.mjs";
|
|
11
|
+
|
|
12
|
+
const DISK = [{ mount: "/", type: "ext4" }]; // CI /tmp can be tmpfs, which assertDiskPath refuses
|
|
13
|
+
const tmp = () => tmpDir("release-");
|
|
14
|
+
const REPO = "o/r", HEAD = "a".repeat(40);
|
|
15
|
+
|
|
16
|
+
/** io fake; `world` tunes the gh answers. */
|
|
17
|
+
function fakeIo(world = {}) {
|
|
18
|
+
const calls = [], par = [], printed = [];
|
|
19
|
+
const w = { lanes: [], openStaging: [], batches: [], releasePr: [{ number: 7, headRefOid: HEAD, url: "u" }], comments: [{ body: "FORGE:GATE_PASS" }], gate: "success", ...world };
|
|
20
|
+
const io = {
|
|
21
|
+
calls, par, printed, now: () => 1_700_000_000_000, print: (l) => printed.push(l),
|
|
22
|
+
sleeps: [], ran: [], sleep: async (ms) => { io.sleeps.push(ms); },
|
|
23
|
+
run: async (cmd) => { io.ran.push(cmd); return { ok: io.ran.length >= (w.artifactOkAt ?? 1) }; },
|
|
24
|
+
runningLanes: async () => w.lanes,
|
|
25
|
+
batches: async () => w.batches,
|
|
26
|
+
setParallel: async (id, k) => { par.push([id, k]); },
|
|
27
|
+
gh: async (a) => {
|
|
28
|
+
calls.push(a);
|
|
29
|
+
const j = a.join(" ");
|
|
30
|
+
const pm = w.pm?.(a); if (pm !== undefined) return pm;
|
|
31
|
+
if (a[0] === "pr" && a[1] === "list" && a.includes("--state") && a[a.indexOf("--state") + 1] === "open") return JSON.stringify(a.includes("--head") ? w.releasePr : w.openStaging);
|
|
32
|
+
if (a[0] === "pr" && a[1] === "list") return JSON.stringify([]);
|
|
33
|
+
if (a[0] === "pr" && a[1] === "create") return "https://github.com/o/r/pull/9";
|
|
34
|
+
if (a[0] === "pr" && a[1] === "view" && j.includes("--json state,mergeCommit,headRefOid")) return JSON.stringify({ state: w.prState ?? "OPEN", mergeCommit: w.prState === "MERGED" ? { oid: "m".repeat(40) } : null, headRefOid: HEAD });
|
|
35
|
+
if (j.includes("--json headRefOid")) return JSON.stringify({ headRefOid: HEAD });
|
|
36
|
+
if (j.includes("--json comments")) return JSON.stringify({ comments: w.comments });
|
|
37
|
+
if (a[0] === "api") return JSON.stringify(w.gate ? [{ name: "forge/deploy-gate", conclusion: w.gate }] : []);
|
|
38
|
+
if (a[0] === "pr" && a[1] === "merge") return "";
|
|
39
|
+
throw new Error(`unexpected gh ${j}`);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return io;
|
|
43
|
+
}
|
|
44
|
+
const ok = async () => ({ ok: true });
|
|
45
|
+
|
|
46
|
+
describe("release job (#5211)", () => {
|
|
47
|
+
const promote = async (world, { opts = {}, config = {} } = {}) => {
|
|
48
|
+
const io = fakeIo(world), root = tmp(), id = newReleaseId();
|
|
49
|
+
// Real preflight/release-pr/promotion, with review/fixes/post-merge replaced by no-ops.
|
|
50
|
+
const mod = await import("./release.mjs");
|
|
51
|
+
const out = await mod.runRelease({ io, repo: REPO, root, mounts: DISK, id, opts, config, branches: { staging: "staging", default: "main" }, steps: mod.withStubs({ review: ok, fixes: ok, "post-merge": ok }) });
|
|
52
|
+
return { io, out, root, id };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
it("R3: stops at GATE_PASS without --merge / auto_merge and prints the command; never merges", async () => {
|
|
56
|
+
const { io, out } = await promote({});
|
|
57
|
+
assert.equal(out.status, "stopped");
|
|
58
|
+
assert.ok(io.printed.some((l) => l.includes(`gh pr merge 7 --repo ${REPO} --merge --match-head-commit ${HEAD}`)));
|
|
59
|
+
assert.ok(!io.calls.some((a) => a[0] === "pr" && a[1] === "merge"));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("R3: --merge merges with --match-head-commit when forge/deploy-gate is success", async () => {
|
|
63
|
+
const { io, out } = await promote({}, { opts: { merge: true } });
|
|
64
|
+
assert.equal(out.status, "done");
|
|
65
|
+
assert.ok(io.calls.some((a) => a[1] === "merge" && a.includes("--match-head-commit") && a.includes(HEAD)));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("R3: release.auto_merge merges too; a non-success deploy-gate does not", async () => {
|
|
69
|
+
const a = await promote({}, { config: { autoMerge: true } });
|
|
70
|
+
assert.equal(a.out.status, "done");
|
|
71
|
+
for (const gate of ["pending", "failure", null]) {
|
|
72
|
+
const b = await promote({ gate }, { opts: { merge: true } });
|
|
73
|
+
assert.equal(b.out.status, "stopped", String(gate));
|
|
74
|
+
assert.ok(!b.io.calls.some((c) => c[1] === "merge"));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("#5266: a release PR merged by hand moves to post-merge with the merge sha, without the opt-in stop", async () => {
|
|
79
|
+
const io = fakeIo({ prState: "MERGED" }), root = tmp(), id = newReleaseId();
|
|
80
|
+
const mod = await import("./release.mjs");
|
|
81
|
+
let seen = null;
|
|
82
|
+
const out = await mod.runRelease({ io, repo: REPO, root, mounts: DISK, id, opts: {}, config: {}, branches: { staging: "staging", default: "main" }, steps: mod.withStubs({ review: ok, fixes: ok, "post-merge": async (c) => { seen = c.state.steps.promotion.result; return {}; } }) });
|
|
83
|
+
assert.equal(out.status, "done");
|
|
84
|
+
assert.equal(seen.alreadyMerged, true);
|
|
85
|
+
assert.equal(seen.mergeCommit, "m".repeat(40));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("#5266: --merge resume on an already-merged PR does not call gh pr merge", async () => {
|
|
89
|
+
const { io, out } = await promote({ prState: "MERGED" }, { opts: { merge: true } });
|
|
90
|
+
assert.equal(out.status, "done");
|
|
91
|
+
assert.ok(!io.calls.some((a) => a[0] === "pr" && a[1] === "merge"));
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("#5266: a release PR closed without merging stops", async () => {
|
|
95
|
+
const { io, out } = await promote({ prState: "CLOSED" }, { opts: { merge: true } });
|
|
96
|
+
assert.equal(out.status, "stopped");
|
|
97
|
+
assert.ok(!io.calls.some((a) => a[0] === "pr" && a[1] === "merge"));
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("R3: no GATE_PASS marker never merges", async () => {
|
|
101
|
+
const { io, out } = await promote({ comments: [{ body: "FORGE:GATE_FAILURE" }] }, { opts: { merge: true } });
|
|
102
|
+
assert.equal(out.status, "stopped");
|
|
103
|
+
assert.ok(!io.calls.some((c) => c[1] === "merge"));
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("preflight refuses while a lane runs; nothing is held", async () => {
|
|
107
|
+
const { io, out } = await promote({ lanes: [{ batch: "b1", issue: 3 }], batches: [{ id: "b1", k: 4 }] });
|
|
108
|
+
assert.equal(out.status, "refused");
|
|
109
|
+
assert.match(out.reason, /b1#3/);
|
|
110
|
+
assert.deepEqual(io.par, []);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("preflight refuses while PRs to the staging branch are open", async () => {
|
|
114
|
+
const { io, out } = await promote({ openStaging: [{ number: 12 }], batches: [{ id: "b1", k: 4 }] });
|
|
115
|
+
assert.equal(out.status, "refused");
|
|
116
|
+
assert.match(out.reason, /#12/);
|
|
117
|
+
assert.deepEqual(io.par, []);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("preflight holds batches at K=1 and restores the previous K at the end", async () => {
|
|
121
|
+
const { io, out, root, id } = await promote({ batches: [{ id: "b1", k: 4 }, { id: "b2", k: 2 }] });
|
|
122
|
+
assert.equal(out.status, "stopped");
|
|
123
|
+
assert.deepEqual(io.par, [["b1", 1], ["b2", 1], ["b1", 4], ["b2", 2]]);
|
|
124
|
+
assert.ok(openRelease(root, id).load().held.every((h) => h.restored));
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("release PR: reuses an open one; otherwise creates it with the bundle list", async () => {
|
|
128
|
+
const a = await promote({});
|
|
129
|
+
assert.ok(!a.io.calls.some((c) => c[1] === "create"));
|
|
130
|
+
const b = await promote({ releasePr: [] });
|
|
131
|
+
const create = b.io.calls.find((c) => c[1] === "create");
|
|
132
|
+
assert.ok(create && create.includes("--head") && create.includes("staging") && create.includes("main"));
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("R5: a killed job resumes from the last completed step", async () => {
|
|
136
|
+
const io = fakeIo(), root = tmp(), id = newReleaseId();
|
|
137
|
+
const mod = await import("./release.mjs");
|
|
138
|
+
const ran = [];
|
|
139
|
+
const rec = (n, fn) => async (ctx) => { ran.push(n); return fn(ctx); };
|
|
140
|
+
const base = mod.withStubs({ review: ok, fixes: ok, "post-merge": ok });
|
|
141
|
+
const kill = async () => { throw new Error("killed"); };
|
|
142
|
+
const first = { ...base, preflight: rec("preflight", base.preflight), "release-pr": rec("release-pr", base["release-pr"]), review: kill };
|
|
143
|
+
await assert.rejects(() => mod.runRelease({ io, repo: REPO, root, mounts: DISK, id, opts: { merge: true }, config: {}, branches: {}, steps: first }), /killed/);
|
|
144
|
+
const st = openRelease(root, id).load();
|
|
145
|
+
assert.deepEqual(Object.keys(st.steps), ["preflight", "release-pr"]);
|
|
146
|
+
const second = { ...base, preflight: rec("preflight2", base.preflight), "release-pr": rec("release-pr2", base["release-pr"]) };
|
|
147
|
+
const out = await mod.runRelease({ io, repo: REPO, root, mounts: DISK, id, opts: { merge: true }, config: {}, branches: {}, steps: second });
|
|
148
|
+
assert.equal(out.status, "done");
|
|
149
|
+
assert.deepEqual(ran, ["preflight", "release-pr"]); // preflight/release-pr not run again
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("unfinished steps return a blocked result that names the manual path; the job exits blocked", async () => {
|
|
153
|
+
for (const r of [await reviewStep({}), await fixStep({})]) { assert.equal(r.blocked, true); assert.match(r.reason, /manual path/); }
|
|
154
|
+
const io = fakeIo(), root = tmp();
|
|
155
|
+
io.review = { pre: async () => ({ code: 1, data: null, lines: ["stopped"] }) }; // the review step runs against a seam, never a real repo
|
|
156
|
+
const out = await (await import("./release.mjs")).runRelease({ io, repo: REPO, root, mounts: DISK, id: newReleaseId(), opts: {}, config: {}, branches: {} });
|
|
157
|
+
assert.equal(out.status, "blocked");
|
|
158
|
+
assert.equal(out.step, "review");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("state is written atomically under FORGEDOCK_RELEASE_DIR and is private", async () => {
|
|
162
|
+
const root = tmp(), id = newReleaseId();
|
|
163
|
+
openRelease(root, id, DISK).save({ v: 1 });
|
|
164
|
+
assert.deepEqual(JSON.parse(readFileSync(join(root, id, "state.json"), "utf8")), { v: 1 });
|
|
165
|
+
assert.ok(!existsSync(join(root, id, `state.json.tmp-${process.pid}`)));
|
|
166
|
+
assert.throws(() => openRelease(root, "../x"), /invalid release id/);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("readReleaseConfig reads auto_merge / artifact_check / version_sync", () => {
|
|
170
|
+
assert.deepEqual(readReleaseConfig("release:\n auto_merge: true\n artifact_check: npm view x\n version_sync: true\n"), { autoMerge: true, artifactCheck: "npm view x", versionSync: true, publishWorkflow: null });
|
|
171
|
+
assert.deepEqual(readReleaseConfig(""), { autoMerge: false, artifactCheck: null, versionSync: false, publishWorkflow: null });
|
|
172
|
+
assert.equal(readReleaseConfig("release:\n publish_workflow: pub.yml\n").publishWorkflow, "pub.yml");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("CLI: rejects unknown options and exits 3 on a blocked step, naming the resume command", async () => {
|
|
176
|
+
const root = tmp(), io = fakeIo();
|
|
177
|
+
await assert.rejects(() => releaseFromCli(["--bogus"], { io, env: { FORGEDOCK_RELEASE_DIR: root }, cwd: root, mounts: DISK }), /unknown option/);
|
|
178
|
+
const code = await releaseFromCli(["--repo", REPO], { io, env: { FORGEDOCK_RELEASE_DIR: root }, cwd: root, mounts: DISK });
|
|
179
|
+
assert.equal(code, 3);
|
|
180
|
+
assert.ok(io.printed.some((l) => /forgedock release --resume r\d/.test(l)));
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("release post-merge step (#5213)", () => {
|
|
185
|
+
const SHA = "b".repeat(40);
|
|
186
|
+
const PKG = Buffer.from(JSON.stringify({ version: "1.2.3" })).toString("base64");
|
|
187
|
+
/** gh answers for the post-merge calls; `o` tunes them. */
|
|
188
|
+
const pmWorld = (o = {}) => {
|
|
189
|
+
const st = { runs: o.runs ?? [[{ databaseId: 5, status: "completed", conclusion: "success" }]], runCalls: 0, dispatched: 0, syncPrs: o.syncPrs ?? [], created: 0 };
|
|
190
|
+
return {
|
|
191
|
+
st,
|
|
192
|
+
pm: (a) => {
|
|
193
|
+
const j = a.join(" ");
|
|
194
|
+
if (a[0] === "pr" && a[1] === "view" && j.includes("mergeCommit")) return JSON.stringify({ state: o.prState ?? "MERGED", mergeCommit: { oid: SHA } });
|
|
195
|
+
if (a[0] === "run" && a[1] === "list") { assert.ok(j.includes(`--commit ${SHA}`) && j.includes(`--workflow ${o.wf ?? "publish.yml"}`)); const r = st.runs[Math.min(st.runCalls++, st.runs.length - 1)]; return JSON.stringify(r); }
|
|
196
|
+
if (a[0] === "workflow" && a[1] === "run") { st.dispatched++; assert.ok(a.includes("main")); return ""; }
|
|
197
|
+
if (a[0] === "api" && j.includes("contents/package.json")) return PKG;
|
|
198
|
+
if (a[0] === "api" && j.includes("branches/chore/sync-version-1.2.3")) { if (o.noBranch) throw new Error("404"); return "x"; }
|
|
199
|
+
if (a[0] === "pr" && a[1] === "list" && j.includes("chore/sync-version")) return JSON.stringify(st.syncPrs);
|
|
200
|
+
if (a[0] === "pr" && a[1] === "create") { st.created++; assert.ok(a.includes("staging") && a.includes("chore/sync-version-1.2.3")); return "https://github.com/o/r/pull/30"; }
|
|
201
|
+
if (a[0] === "pr" && a[1] === "view" && j.includes("statusCheckRollup")) return JSON.stringify({ state: "OPEN", headRefOid: "c".repeat(40), statusCheckRollup: o.checks ?? [{ conclusion: "SUCCESS" }] });
|
|
202
|
+
if (a[0] === "pr" && a[1] === "merge" && Number(a[2]) >= 30) return "";
|
|
203
|
+
return undefined;
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
const run = (o = {}, config = {}) => {
|
|
208
|
+
const w = pmWorld(o), io = fakeIo({ pm: w.pm, ...o });
|
|
209
|
+
const ctx = { io, repo: REPO, def: "main", staging: "staging", config: { postMerge: { publishPolls: 2, runPolls: 2, branchPolls: 2, checkPolls: 2, artifactTries: 3 }, ...config }, state: { steps: { "release-pr": { result: { pr: 7 } } } } };
|
|
210
|
+
return postMergeStep(ctx).then((out) => ({ out, io, st: w.st }));
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
it("R1: a publish run for the merge commit is confirmed; nothing is dispatched", async () => {
|
|
214
|
+
const { out, st } = await run();
|
|
215
|
+
assert.equal(out.published, true);
|
|
216
|
+
assert.equal(out.run, 5);
|
|
217
|
+
assert.equal(st.dispatched, 0);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("R2: no run appears -> one is dispatched on the default branch, then awaited", async () => {
|
|
221
|
+
const { out, st } = await run({ runs: [[], [], [{ databaseId: 8, status: "completed", conclusion: "success" }]] });
|
|
222
|
+
assert.equal(out.published, true);
|
|
223
|
+
assert.equal(out.dispatched, true);
|
|
224
|
+
assert.equal(st.dispatched, 1);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("R2: a custom release.publish_workflow is used", async () => {
|
|
228
|
+
const { out } = await run({ wf: "pub.yml" }, { publishWorkflow: "pub.yml" });
|
|
229
|
+
assert.equal(out.published, true);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("blocked when no run appears even after the dispatch, or the run fails or never finishes", async () => {
|
|
233
|
+
const a = await run({ runs: [[]] });
|
|
234
|
+
assert.equal(a.out.blocked, true); assert.equal(a.st.dispatched, 1);
|
|
235
|
+
const b = await run({ runs: [[{ databaseId: 1, status: "completed", conclusion: "failure" }]] });
|
|
236
|
+
assert.match(b.out.reason, /failure/);
|
|
237
|
+
const c = await run({ runs: [[{ databaseId: 1, status: "in_progress", conclusion: null }]] });
|
|
238
|
+
assert.match(c.out.reason, /did not finish/);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("stopped (not blocked) while the release PR is not merged", async () => {
|
|
242
|
+
const { out, st } = await run({ prState: "OPEN" });
|
|
243
|
+
assert.equal(out.stopped, true);
|
|
244
|
+
assert.equal(st.runCalls, 0);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("R3: artifact_check is polled with exponential backoff until it passes; exhausting it blocks", async () => {
|
|
248
|
+
const a = await run({ artifactOkAt: 3 }, { artifactCheck: "npm view x@1" });
|
|
249
|
+
assert.equal(a.out.artifact, true);
|
|
250
|
+
assert.deepEqual(a.io.ran, ["npm view x@1", "npm view x@1", "npm view x@1"]);
|
|
251
|
+
assert.deepEqual(a.io.sleeps.slice(-2), [5000, 10000]);
|
|
252
|
+
const b = await run({ artifactOkAt: 99 }, { artifactCheck: "npm view x@1" });
|
|
253
|
+
assert.equal(b.out.blocked, true);
|
|
254
|
+
assert.match(b.out.reason, /artifact_check/);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("R4: version_sync opens the sync PR to staging and merges it with --match-head-commit when green", async () => {
|
|
258
|
+
const { out, st, io } = await run({}, { versionSync: true });
|
|
259
|
+
assert.equal(st.created, 1);
|
|
260
|
+
assert.equal(out.sync.merged, true);
|
|
261
|
+
assert.ok(io.calls.some((a) => a[1] === "merge" && a.includes("30") && a.includes("--match-head-commit") && a.includes("c".repeat(40))));
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("version_sync reuses an open sync PR, skips a merged one, and never merges red or check-less PRs", async () => {
|
|
265
|
+
const open = await run({ syncPrs: [{ number: 31, state: "OPEN" }] }, { versionSync: true });
|
|
266
|
+
assert.equal(open.st.created, 0);
|
|
267
|
+
assert.ok(open.io.calls.some((a) => a[1] === "merge" && a.includes("31")));
|
|
268
|
+
const merged = await run({ syncPrs: [{ number: 32, state: "MERGED" }] }, { versionSync: true });
|
|
269
|
+
assert.equal(merged.out.sync.merged, true);
|
|
270
|
+
assert.ok(!merged.io.calls.some((a) => a[1] === "merge"));
|
|
271
|
+
for (const checks of [[], [{ conclusion: "FAILURE" }], [{ conclusion: "SUCCESS" }, { status: "IN_PROGRESS", state: "PENDING" }]]) {
|
|
272
|
+
const r = await run({ syncPrs: [{ number: 33, state: "OPEN" }], checks }, { versionSync: true });
|
|
273
|
+
assert.equal(r.out.blocked, true, JSON.stringify(checks));
|
|
274
|
+
assert.ok(!r.io.calls.some((a) => a[1] === "merge"));
|
|
275
|
+
}
|
|
276
|
+
const nb = await run({ noBranch: true }, { versionSync: true });
|
|
277
|
+
assert.equal(nb.out.blocked, true);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("R1: through the job, a blocked post-merge is retried on resume and finishes once the run exists", async () => {
|
|
281
|
+
const mod = await import("./release.mjs");
|
|
282
|
+
const root = tmp(), id = newReleaseId();
|
|
283
|
+
const world = (runs) => pmWorld({ runs });
|
|
284
|
+
const go = async (runs) => {
|
|
285
|
+
const io = fakeIo({ pm: world(runs).pm });
|
|
286
|
+
const config = { postMerge: { publishPolls: 1, runPolls: 1 } };
|
|
287
|
+
return mod.runRelease({ io, repo: REPO, root, mounts: DISK, id, opts: { merge: true }, config, branches: { staging: "staging", default: "main" }, steps: mod.withStubs({ review: ok, fixes: ok }) });
|
|
288
|
+
};
|
|
289
|
+
assert.equal((await go([[{ databaseId: 1, status: "completed", conclusion: "failure" }]])).status, "blocked");
|
|
290
|
+
assert.equal((await go([[{ databaseId: 2, status: "completed", conclusion: "success" }]])).status, "done");
|
|
291
|
+
});
|
|
292
|
+
});
|
package/bin/lean/rotator.mjs
CHANGED
|
@@ -6,13 +6,21 @@
|
|
|
6
6
|
* exhausted host. This adapter reads tokenbaton's per-account quota state: `~/.tokenbaton/current` (the account number)
|
|
7
7
|
* and `~/.tokenbaton/live.<n>` (`"<5h used %> <5h reset epoch s> <weekly used %> <weekly reset epoch s> <updated s>"`).
|
|
8
8
|
* Every method re-reads the files (no cache), never writes, and fails open: unreadable state behaves as no rotator.
|
|
9
|
+
* #5205: detected without config when TOKENBATON_HOME is set or the shim is the first `claude` on PATH; a sample whose
|
|
10
|
+
* reset has passed is stale (unknown, never 0%); callers pass the accounts that just hit a limit as `exclude`; a rotation
|
|
11
|
+
* relaunch pins an account picked here (tokenbaton#3 `--pick --json --exclude` when the CLI has it, else live.N).
|
|
9
12
|
*/
|
|
10
|
-
import {
|
|
13
|
+
import { spawnSync } from "node:child_process";
|
|
14
|
+
import { accessSync, constants, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
11
15
|
import { homedir } from "node:os";
|
|
12
|
-
import { join } from "node:path";
|
|
16
|
+
import { basename, delimiter, join } from "node:path";
|
|
13
17
|
import { backendIdentity } from "../engine.mjs";
|
|
14
18
|
|
|
15
19
|
export const ROTATOR_KINDS = ["tokenbaton"];
|
|
20
|
+
/** Env switch: `off` disables auto-detection (bin/tests/_tmp.mjs sets it for test processes, #5205). */
|
|
21
|
+
export const ROTATOR_ENV = "FORGEDOCK_ACCOUNT_ROTATOR";
|
|
22
|
+
/** Bound on every tokenbaton / tokenbaton-ctl call (ms). */
|
|
23
|
+
export const ROTATOR_CALL_TIMEOUT_MS = 5000;
|
|
16
24
|
/** An account has headroom below this 5-hour use (%), like the computeshare quota-aware picker. */
|
|
17
25
|
export const HEADROOM_PCT = 95;
|
|
18
26
|
|
|
@@ -20,16 +28,74 @@ export const HEADROOM_PCT = 95;
|
|
|
20
28
|
export function parseLive(text) {
|
|
21
29
|
const f = String(text ?? "").trim().split(/\s+/).map(Number);
|
|
22
30
|
if (f.length < 4 || !f.slice(0, 4).every(Number.isFinite)) return null;
|
|
23
|
-
return { fiveHourPct: f[0], fiveHourResetMs: f[1] * 1000, weeklyPct: f[2], weeklyResetMs: f[3] * 1000 };
|
|
31
|
+
return { fiveHourPct: f[0], fiveHourResetMs: f[1] * 1000, weeklyPct: f[2], weeklyResetMs: f[3] * 1000, updatedMs: Number.isFinite(f[4]) && f[4] > 0 ? f[4] * 1000 : 0 };
|
|
24
32
|
}
|
|
25
33
|
|
|
34
|
+
/** #5236: a sample older than this is unknown for the 5-hour window, whatever its reset says (0 or absent updated = age unknown). */
|
|
35
|
+
export const ROTATOR_SAMPLE_MAX_AGE_MS = 30 * 60000;
|
|
36
|
+
|
|
37
|
+
const isExec = (p) => { try { accessSync(p, constants.X_OK); return true; } catch { return false; } };
|
|
38
|
+
const real = (p) => { try { return realpathSync(p); } catch { return p; } };
|
|
39
|
+
/** True when `p` (resolved) is tokenbaton's shim: `tokenbaton-exec`, or a `.tokenbaton/shim/claude`. */
|
|
40
|
+
export const isShim = (p) => { const r = real(p); return basename(r) === "tokenbaton-exec" || /[\\/]\.tokenbaton[\\/]shim[\\/]claude$/.test(r); };
|
|
41
|
+
/** Every executable `claude` on env.PATH, in PATH order. */
|
|
42
|
+
const claudesOnPath = (env) => String(env?.PATH ?? "").split(delimiter).filter(Boolean).map((d) => join(d, "claude")).filter(isExec);
|
|
43
|
+
/** First `claude` on PATH, or null. */
|
|
44
|
+
export const firstClaude = (env = process.env) => claudesOnPath(env)[0] ?? null;
|
|
45
|
+
/** The real claude: the first `claude` on PATH that is not the shim (the shim's own rule), or null. */
|
|
46
|
+
export const realClaude = (env = process.env) => claudesOnPath(env).find((c) => !isShim(c)) ?? null;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The account rotator in use (#5205): explicit `execution.account_rotator: tokenbaton` wins; `off` (or env
|
|
50
|
+
* FORGEDOCK_ACCOUNT_ROTATOR=off) disables; unset auto-detects TOKENBATON_HOME or the shim first on PATH.
|
|
51
|
+
* @returns {"tokenbaton"|null}
|
|
52
|
+
*/
|
|
53
|
+
export function rotatorKind({ execution = null, env = process.env, which = firstClaude } = {}) {
|
|
54
|
+
const set = execution?.accountRotator;
|
|
55
|
+
if (ROTATOR_KINDS.includes(set)) return set;
|
|
56
|
+
if (set === "off" || String(env?.[ROTATOR_ENV] ?? "").toLowerCase() === "off") return null;
|
|
57
|
+
if (env?.TOKENBATON_HOME) return "tokenbaton";
|
|
58
|
+
try { const c = which(env); return c && isShim(c) ? "tokenbaton" : null; } catch { return null; }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The account a running claude uses, from /proc/<pid>/environ: TOKENBATON_ACCOUNT, else CLAUDE_CONFIG_DIR=<home>/.claude-<n>; null when unreadable. */
|
|
62
|
+
export function accountOfPid(pid, { procRoot = "/proc", readFile = (p) => readFileSync(p, "utf8") } = {}) {
|
|
63
|
+
if (!Number.isInteger(pid) || pid <= 0) return null;
|
|
64
|
+
let vars;
|
|
65
|
+
try { vars = String(readFile(join(procRoot, String(pid), "environ"))).split("\0"); } catch { return null; }
|
|
66
|
+
const get = (k) => { const v = vars.find((x) => x.startsWith(`${k}=`)); return v === undefined ? null : v.slice(k.length + 1); };
|
|
67
|
+
const t = Number(get("TOKENBATON_ACCOUNT"));
|
|
68
|
+
if (get("TOKENBATON_ACCOUNT") && Number.isInteger(t) && t > 0) return t;
|
|
69
|
+
const m = /[\\/]\.claude-(\d+)[\\/]?$/.exec(get("CLAUDE_CONFIG_DIR") ?? "");
|
|
70
|
+
return m ? Number(m[1]) : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** `exclude` as a Map account -> until ms (null when unknown): accepts a Set/array of numbers, a Map, or a plain object. */
|
|
74
|
+
export function excludeMap(exclude) {
|
|
75
|
+
const out = new Map();
|
|
76
|
+
if (!exclude) return out;
|
|
77
|
+
const add = (n, until) => { const k = Number(n); if (Number.isInteger(k) && k > 0) out.set(k, Number.isFinite(Number(until)) && until !== null ? Number(until) : null); };
|
|
78
|
+
if (exclude instanceof Map) for (const [n, u] of exclude) add(n, u);
|
|
79
|
+
else if (Array.isArray(exclude) || exclude instanceof Set) for (const n of exclude) add(n, null);
|
|
80
|
+
else if (typeof exclude === "object") for (const [n, u] of Object.entries(exclude)) add(n, u);
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const defaultExec = (cmd, args, { env, timeout = ROTATOR_CALL_TIMEOUT_MS } = {}) => {
|
|
85
|
+
const r = spawnSync(cmd, args, { encoding: "utf8", timeout, windowsHide: true, stdio: ["ignore", "pipe", "ignore"], env });
|
|
86
|
+
return { status: r.error ? null : r.status, stdout: String(r.stdout ?? "") };
|
|
87
|
+
};
|
|
88
|
+
|
|
26
89
|
/**
|
|
27
|
-
* Handle on an account rotator, or null (unknown kind, or no readable state).
|
|
28
|
-
*
|
|
90
|
+
* Handle on an account rotator, or null (unknown kind, or no readable state). The state dir is env.TOKENBATON_HOME
|
|
91
|
+
* (as-is) unless `home` is passed, else ~/.tokenbaton.
|
|
92
|
+
* @returns {null | {kind, accounts, current(), headroom(exclude), resumeAt(exclude), pick({exclude}), markLimited(n, untilMs),
|
|
93
|
+
* accountOfPid(pid), realClaude(env), accountIdentity(n), currentIdentity(), isAccount(id)}}
|
|
29
94
|
*/
|
|
30
|
-
export function openRotator({ kind, home =
|
|
95
|
+
export function openRotator({ kind, home = undefined, env = process.env, now = () => Date.now(), readFile = (p) => readFileSync(p, "utf8"), listDir = (d) => readdirSync(d), exec = defaultExec, stat = (p) => statSync(p).mtimeMs } = {}) {
|
|
31
96
|
if (!ROTATOR_KINDS.includes(kind)) return null;
|
|
32
|
-
const dir = join(home, ".tokenbaton");
|
|
97
|
+
const dir = home === undefined && env?.TOKENBATON_HOME ? String(env.TOKENBATON_HOME) : join(home ?? homedir(), ".tokenbaton");
|
|
98
|
+
const userHome = home ?? homedir();
|
|
33
99
|
const current = () => { try { const n = Number(String(readFile(join(dir, "current"))).trim()); return Number.isInteger(n) && n > 0 ? n : null; } catch { return null; } };
|
|
34
100
|
const accounts = () => {
|
|
35
101
|
let names = [];
|
|
@@ -40,32 +106,83 @@ export function openRotator({ kind, home = homedir(), env = process.env, now = (
|
|
|
40
106
|
if (!m) continue;
|
|
41
107
|
let live = null;
|
|
42
108
|
try { live = parseLive(readFile(join(dir, name))); } catch { live = null; }
|
|
43
|
-
if (live)
|
|
109
|
+
if (!live) continue;
|
|
110
|
+
const aged = live.updatedMs > 0 && now() - live.updatedMs > ROTATOR_SAMPLE_MAX_AGE_MS;
|
|
111
|
+
// #5236: the polled `used.N` percent, when newer than the sample and itself fresh, replaces the 5-hour figure.
|
|
112
|
+
let polled = null;
|
|
113
|
+
try {
|
|
114
|
+
const p = Number(String(readFile(join(dir, `used.${m[1]}`))).trim().split(/\s+/)[0]), at = stat(join(dir, `used.${m[1]}`));
|
|
115
|
+
if (Number.isFinite(p) && p >= 0 && Number.isFinite(at) && at > live.updatedMs && now() - at <= ROTATOR_SAMPLE_MAX_AGE_MS) polled = p;
|
|
116
|
+
} catch { polled = null; }
|
|
117
|
+
out.push({ n: Number(m[1]), ...live, polledPct: polled, aged: aged && polled === null, stale: live.fiveHourResetMs <= now() || live.weeklyResetMs <= now() || (aged && polled === null) });
|
|
44
118
|
}
|
|
45
119
|
return out.sort((a, b) => a.n - b.n);
|
|
46
120
|
};
|
|
47
121
|
if (current() === null || !accounts().length) return null;
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const
|
|
122
|
+
// #5205: a window whose reset has passed is unknown (null), never 0%.
|
|
123
|
+
const used = (pct, resetMs) => (resetMs <= now() ? null : pct);
|
|
124
|
+
const full = (a) => { const r = []; const f = a.polledPct !== null && a.polledPct !== undefined ? a.polledPct : a.aged ? null : used(a.fiveHourPct, a.fiveHourResetMs), w = used(a.weeklyPct, a.weeklyResetMs);
|
|
125
|
+
if (f !== null && f >= HEADROOM_PCT) r.push(a.fiveHourResetMs); if (w !== null && w >= 100) r.push(a.weeklyResetMs); return r; };
|
|
126
|
+
/** "room" (fresh, under the caps), "stale" (a window unknown, none known full: worth one try), or "full". */
|
|
127
|
+
const state = (a) => (full(a).length ? "full" : a.stale ? "stale" : "room");
|
|
128
|
+
const resumeAt = (exclude) => {
|
|
129
|
+
const ex = excludeMap(exclude), t = now();
|
|
130
|
+
const at = accounts().map((a) => {
|
|
131
|
+
if (ex.has(a.n)) { const r = [ex.get(a.n), ...full(a)].filter((x) => Number.isFinite(x) && x > t); return r.length ? Math.max(...r) : NaN; }
|
|
132
|
+
return state(a) === "full" ? Math.max(...full(a)) : t;
|
|
133
|
+
}).filter((x) => Number.isFinite(x) && x > 0);
|
|
134
|
+
return at.length ? Math.min(...at) : null;
|
|
135
|
+
};
|
|
136
|
+
const localPick = (exclude) => {
|
|
137
|
+
const ex = excludeMap(exclude), list = accounts().filter((a) => !ex.has(a.n));
|
|
138
|
+
const fresh = list.filter((a) => state(a) === "room").sort((a, b) => (a.polledPct ?? a.fiveHourPct) - (b.polledPct ?? b.fiveHourPct) || a.n - b.n);
|
|
139
|
+
if (fresh.length) return { account: fresh[0].n, stale: false };
|
|
140
|
+
const stale = list.filter((a) => state(a) === "stale");
|
|
141
|
+
if (stale.length) return { account: stale[0].n, stale: true };
|
|
142
|
+
return { account: null, earliestReset: resumeAt(ex) };
|
|
143
|
+
};
|
|
144
|
+
const childEnv = () => ({ ...process.env, ...env, TOKENBATON_HOME: dir });
|
|
145
|
+
const accountIdentity = (n) => backendIdentity({ backend: "cli", env: { ...env, CLAUDE_CONFIG_DIR: join(userHome, `.claude-${n}`) } });
|
|
51
146
|
return {
|
|
52
147
|
kind,
|
|
53
|
-
/** The accounts with readable `live.N` state, re-read on every access. */
|
|
148
|
+
/** The accounts with readable `live.N` state (`stale` when a window's reset has passed), re-read on every access. */
|
|
54
149
|
get accounts() { return accounts(); },
|
|
55
150
|
current,
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
151
|
+
/** The tokenbaton state dir read. */
|
|
152
|
+
dir,
|
|
153
|
+
/** True when any non-excluded account has headroom (a fresh sample under the caps, or a stale one: worth a try). */
|
|
154
|
+
headroom: (exclude) => { const ex = excludeMap(exclude); return accounts().some((a) => !ex.has(a.n) && state(a) !== "full"); },
|
|
155
|
+
/** Epoch ms at which the first account regains headroom (now when one has it), or null when unknown; excluded ones count from their until. */
|
|
156
|
+
resumeAt,
|
|
157
|
+
/**
|
|
158
|
+
* The account to run on next (#5205): tokenbaton#3 `--pick --json --exclude` when the CLI prints JSON (exit 2 = none),
|
|
159
|
+
* else from live.N (fresh lowest use first, then stale). {account, stale} | {account:null, earliestReset}.
|
|
160
|
+
*/
|
|
161
|
+
pick: ({ exclude } = {}) => {
|
|
162
|
+
const ex = excludeMap(exclude);
|
|
163
|
+
try {
|
|
164
|
+
const r = exec("tokenbaton", ["--pick", "--json", ...(ex.size ? ["--exclude", [...ex.keys()].join(",")] : [])], { env: childEnv() });
|
|
165
|
+
let j = null; try { j = JSON.parse(String(r?.stdout ?? "").trim()); } catch { j = null; }
|
|
166
|
+
if (j && typeof j === "object") {
|
|
167
|
+
const n = Number(j.account);
|
|
168
|
+
if (r.status === 0 && Number.isInteger(n) && n > 0 && !ex.has(n)) return { account: n, stale: Boolean(j.stale) };
|
|
169
|
+
if (r.status === 2) { const e = Number(j.earliest_reset); return { account: null, earliestReset: Number.isFinite(e) && e > 0 ? e * 1000 : resumeAt(ex) }; }
|
|
170
|
+
}
|
|
171
|
+
} catch { /* fall back to live.N */ }
|
|
172
|
+
try { return localPick(ex); } catch { return { account: null, earliestReset: null }; }
|
|
173
|
+
},
|
|
174
|
+
/** Best-effort `tokenbaton-ctl mark-limited <n> --until <epoch s>`; false when unsupported. Never writes files itself. */
|
|
175
|
+
markLimited: (n, untilMs) => {
|
|
176
|
+
try {
|
|
177
|
+
if (!Number.isInteger(n) || n <= 0) return false;
|
|
178
|
+
const args = ["mark-limited", String(n), ...(Number.isFinite(untilMs) ? ["--until", String(Math.round(untilMs / 1000))] : [])];
|
|
179
|
+
return exec("tokenbaton-ctl", args, { env: childEnv() })?.status === 0;
|
|
180
|
+
} catch { return false; }
|
|
68
181
|
},
|
|
182
|
+
accountOfPid: (pid, opts) => { try { return accountOfPid(pid, opts); } catch { return null; } },
|
|
183
|
+
realClaude: (e = env) => { try { return realClaude(e); } catch { return null; } },
|
|
184
|
+
/** CLAUDE_CONFIG_DIR of account n. */
|
|
185
|
+
configDir: (n) => join(userHome, `.claude-${n}`),
|
|
69
186
|
accountIdentity,
|
|
70
187
|
/** Identity of the current account; null when `current` is unreadable. */
|
|
71
188
|
currentIdentity: () => { const n = current(); return n === null ? null : accountIdentity(n); },
|
|
@@ -74,23 +191,25 @@ export function openRotator({ kind, home = homedir(), env = process.env, now = (
|
|
|
74
191
|
};
|
|
75
192
|
}
|
|
76
193
|
|
|
77
|
-
/** True while a usage-limited call should be retried at once on the next account: headroom, and fewer tries than accounts. */
|
|
78
|
-
export function rotatorRetry(rotator, tries) {
|
|
79
|
-
try { return Boolean(rotator) && tries < rotator.accounts.length && rotator.headroom(); } catch { return false; }
|
|
194
|
+
/** True while a usage-limited call should be retried at once on the next account: headroom (outside `exclude`), and fewer tries than accounts. */
|
|
195
|
+
export function rotatorRetry(rotator, tries, exclude = null) {
|
|
196
|
+
try { return Boolean(rotator) && tries < rotator.accounts.length && rotator.headroom(exclude); } catch { return false; }
|
|
80
197
|
}
|
|
81
198
|
|
|
82
199
|
/**
|
|
83
200
|
* How orchestrate requeues a `rate_limited` lane under a rotator (#5094), or null when the host hold applies (no rotator,
|
|
84
|
-
* no account with headroom
|
|
201
|
+
* no account with headroom outside `exclude`, unreadable state). A lane that ran on one of the rotator's accounts (or reported none) is rerun
|
|
85
202
|
* at once, at most once per account; any other credential (a remote sandbox's) waits for its own reset. Neither sets a host hold.
|
|
203
|
+
* #5203: `poolId` (orchestrate's `remote.identity()`, the pool hold key) rotates like a rotator account: since #5165 the pool
|
|
204
|
+
* router hands each sandbox the lowest-usage tokenbaton login, so a rerun lands on another account.
|
|
86
205
|
* @returns {null | {delayMs:number, rotated:boolean}}
|
|
87
206
|
*/
|
|
88
|
-
export function quotaRequeue({ rotator, r, prior = null, delayMs }) {
|
|
207
|
+
export function quotaRequeue({ rotator, r, prior = null, delayMs, exclude = null, poolId = null }) {
|
|
89
208
|
if (!rotator) return null;
|
|
90
209
|
try {
|
|
91
|
-
if (!rotator.headroom()) return null;
|
|
210
|
+
if (!rotator.headroom(exclude)) return null;
|
|
92
211
|
const id = r?.backendId ?? null, rotations = Number(prior?.rotations) || 0;
|
|
93
|
-
if ((!id || rotator.isAccount(id)) && rotations < rotator.accounts.length) return { delayMs: 0, rotated: true };
|
|
212
|
+
if ((!id || (poolId && id === poolId) || rotator.isAccount(id)) && rotations < rotator.accounts.length) return { delayMs: 0, rotated: true };
|
|
94
213
|
return { delayMs, rotated: false };
|
|
95
214
|
} catch { return null; }
|
|
96
215
|
}
|