forgedock 1.59.1 → 1.60.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 -3
- package/bin/engine-cli.mjs +50 -10
- package/bin/labels.json +5 -0
- package/bin/lean/batch.mjs +21 -2
- package/bin/lean/batch.test.mjs +116 -1
- package/bin/lean/conformance.mjs +12 -5
- package/bin/lean/conformance.test.mjs +30 -2
- package/bin/lean/depcache.mjs +34 -15
- package/bin/lean/depcache.test.mjs +100 -1
- package/bin/lean/design-gate.mjs +15 -10
- package/bin/lean/design-gate.test.mjs +21 -0
- package/bin/lean/effects.mjs +18 -2
- package/bin/lean/execution.mjs +23 -5
- package/bin/lean/execution.test.mjs +81 -1
- package/bin/lean/gatewatch.test.mjs +5 -5
- package/bin/lean/issuewatch-triage.mjs +68 -0
- package/bin/lean/issuewatch-triage.test.mjs +98 -0
- package/bin/lean/issuewatch.mjs +34 -6
- package/bin/lean/issuewatch.test.mjs +11 -0
- package/bin/lean/lanelock.mjs +5 -4
- package/bin/lean/lean.mjs +123 -17
- package/bin/lean/lean.test.mjs +154 -6
- package/bin/lean/orchestrate-cancel.test.mjs +33 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +41 -0
- package/bin/lean/orchestrate-recovering.test.mjs +42 -0
- package/bin/lean/orchestrate.mjs +23 -10
- package/bin/lean/pagegate.mjs +50 -12
- package/bin/lean/pagegate.test.mjs +38 -1
- package/bin/lean/phaseledger.mjs +65 -2
- package/bin/lean/phaseledger.test.mjs +70 -2
- package/bin/lean/preflight.mjs +5 -2
- package/bin/lean/preflight.test.mjs +7 -0
- package/bin/lean/prompts.mjs +2 -1
- package/bin/lean/recovery.test.mjs +11 -6
- package/bin/lean/release-classify.mjs +143 -0
- package/bin/lean/release-classify.test.mjs +130 -0
- package/bin/lean/release-conductor.mjs +163 -0
- package/bin/lean/release-conductor.test.mjs +194 -0
- package/bin/lean/release-config.mjs +60 -8
- package/bin/lean/release-config.test.mjs +43 -1
- package/bin/lean/release-control.mjs +22 -5
- package/bin/lean/release-control.test.mjs +22 -0
- package/bin/lean/release-credentials.mjs +40 -0
- package/bin/lean/release-credentials.test.mjs +42 -0
- package/bin/lean/release-deploy.mjs +3 -3
- package/bin/lean/release-deploy.test.mjs +8 -0
- package/bin/lean/release-docs.test.mjs +93 -0
- package/bin/lean/release-fence.mjs +2 -0
- package/bin/lean/release-gate.mjs +88 -0
- package/bin/lean/release-gate.test.mjs +116 -0
- package/bin/lean/release-gates.mjs +5 -1
- package/bin/lean/release-ledger.mjs +47 -1
- package/bin/lean/release-ledger.test.mjs +33 -1
- package/bin/lean/release-mergeback.mjs +148 -0
- package/bin/lean/release-mergeback.test.mjs +129 -0
- package/bin/lean/release-p0.mjs +193 -0
- package/bin/lean/release-p0.test.mjs +127 -0
- package/bin/lean/release-plan.mjs +267 -0
- package/bin/lean/release-plan.test.mjs +202 -0
- package/bin/lean/release-preflight.mjs +16 -0
- package/bin/lean/release-regate.mjs +141 -0
- package/bin/lean/release-regate.test.mjs +149 -0
- package/bin/lean/release-review.mjs +5 -3
- package/bin/lean/release-rollback.mjs +277 -0
- package/bin/lean/release-rollback.test.mjs +245 -0
- package/bin/lean/release-snapshot.mjs +48 -9
- package/bin/lean/release-snapshot.test.mjs +43 -1
- package/bin/lean/release-start.mjs +164 -0
- package/bin/lean/release-start.test.mjs +171 -0
- package/bin/lean/release-status.mjs +6 -2
- package/bin/lean/release-train.mjs +159 -0
- package/bin/lean/release-train.test.mjs +139 -0
- package/bin/lean/release.mjs +127 -5
- package/bin/lean/release.test.mjs +80 -0
- package/bin/lean/sandbox-remote.mjs +2 -0
- package/bin/lean/schedd-load.test.mjs +82 -0
- package/bin/lean/schedd.mjs +67 -31
- package/bin/lean/schedd.test.mjs +80 -1
- package/bin/lean/validate-catalog.mjs +94 -0
- package/bin/lean/validate-catalog.test.mjs +42 -0
- package/bin/pool/agent.mjs +4 -1
- package/bin/pool/lane-tools.mjs +115 -0
- package/bin/pool/lane-tools.test.mjs +26 -0
- package/bin/pool/warm.mjs +1 -1
- package/docs/CONFIG.md +225 -1
- package/docs/ISSUE-WATCH.md +1 -0
- package/docs/design/visual-gate.md +10 -0
- package/docs/eval/adversarial-bench.md +1 -0
- package/package.json +5 -2
- package/pool/README.md +2 -0
- package/scripts/bench-adversarial.mjs +4 -0
- package/scripts/bench-lightlane.mjs +2 -1
- package/templates/github-actions/forge-conductor.scopes.json +7 -0
- package/templates/github-actions/forge-conductor.yml +57 -0
package/bin/lean/release.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync } from "node:fs";
|
|
|
12
12
|
import { execFileSync } from "node:child_process";
|
|
13
13
|
import { homedir } from "node:os";
|
|
14
14
|
import { join } from "node:path";
|
|
15
|
+
import { createInterface } from "node:readline";
|
|
15
16
|
import { writeAtomic, assertDiskPath, batchRoot, listBatches, openBatch, isLaneAlive } from "./batch.mjs";
|
|
16
17
|
import { readBranches, DEFAULT_STAGING_BRANCH } from "./lane.mjs";
|
|
17
18
|
import { ghRunner } from "./issuewatch.mjs";
|
|
@@ -24,7 +25,7 @@ import { rehearsalStep, parseRehearsalConfig } from "./release-rehearsal.mjs";
|
|
|
24
25
|
import { budgetReportLine, releaseRuns, detectBudget, readCiPolicy } from "./ci-budget.mjs";
|
|
25
26
|
import { parseNightlyConfig, readNightly, blocksRelease, fileNightlyRed } from "./release-nightly.mjs";
|
|
26
27
|
import { parseBudgetConfig, applyOnExceed, waveReport, trailingMedian, historyFromRoot, gateHistoryFromRoot, releaseMinutes } from "./release-minutes.mjs";
|
|
27
|
-
import { cutSnapshot, writeRecord, checkChain, verifyRelease, DEFAULT_PATTERN } from "./release-snapshot.mjs";
|
|
28
|
+
import { cutSnapshot, writeRecord, checkChain, verifyRelease, defaultBehind, DEFAULT_PATTERN } from "./release-snapshot.mjs";
|
|
28
29
|
import { createReleaseLedger, writeRelease, readLedger, acquireLease, heartbeat } from "./release-ledger.mjs";
|
|
29
30
|
import { fenced, epochTrailer } from "./release-fence.mjs";
|
|
30
31
|
import { holdCheck, exemptionsSection, runControl, VERBS as CONTROL_VERBS } from "./release-control.mjs";
|
|
@@ -33,6 +34,8 @@ import { readActive } from "./release-ledger.mjs";
|
|
|
33
34
|
import { statusFromCli, policyFromYaml } from "./release-status.mjs";
|
|
34
35
|
import { parseFixConfig } from "./release-fixloop.mjs";
|
|
35
36
|
import { hostPreflightStep, markReadyStep, parsePreflightConfig } from "./release-preflight.mjs";
|
|
37
|
+
import { roleRefusal } from "./release-credentials.mjs";
|
|
38
|
+
import { mergeGuard } from "./release-gate.mjs";
|
|
36
39
|
|
|
37
40
|
export const RELEASE_STEPS = ["preflight", "host-preflight", "release-pr", "review", "fixes", "mark-ready", "rehearsal", "promotion", "post-merge", "deploy"];
|
|
38
41
|
const ID_RE = /^r\d{8}-\d{6}-\d+$/;
|
|
@@ -79,6 +82,14 @@ const off2 = (v) => ["false", "off", "no", "0", ""].includes(String(v ?? "").tri
|
|
|
79
82
|
* (p0 never). Every read is best effort: unreadable facts proceed. @returns {{blocked?, reason?, ciMode?}}
|
|
80
83
|
*/
|
|
81
84
|
export async function managedGate({ io, repo, config, lane, root }) {
|
|
85
|
+
if (lane === "release" && config.managed && io.api) { // #5566: a conflicted or unvalidated merge-back holds the release (never trains or p0)
|
|
86
|
+
try {
|
|
87
|
+
const { syncBlocksRelease } = await import("./release-mergeback.mjs");
|
|
88
|
+
const { readActive } = await import("./release-ledger.mjs");
|
|
89
|
+
const active = await readActive({ io, repo, credential: "driver" });
|
|
90
|
+
if (syncBlocksRelease(active, lane)) return { blocked: true, reason: `merge-back sync PR #${active.sync?.pr ?? "?"} is ${active.sync?.conflicted ? "conflicted" : "unvalidated or unmerged"}; merge it green before a release starts` };
|
|
91
|
+
} catch { /* best effort: an unreadable ledger proceeds */ }
|
|
92
|
+
}
|
|
82
93
|
if (config.nightly) {
|
|
83
94
|
try {
|
|
84
95
|
const n = await readNightly({ gh: (a) => io.gh(a), repo, cfg: config.nightly, now: io.now() });
|
|
@@ -286,6 +297,11 @@ async function promotionStep(ctx) {
|
|
|
286
297
|
const chain = checkChain({ git: io.git, record: state.release, sha: head, staging: ctx.staging, exact: true });
|
|
287
298
|
if (!chain.ok) return { stopped: true, why: `release head ${head} is not snapshot + recorded cherry-picks: ${chain.why}`, head };
|
|
288
299
|
}
|
|
300
|
+
if (state.release && ctx.config.managed && io.git) { // #5565: a p0 may have landed on the default branch after the cut; the merge refuses until it is in the head (recut brings it in)
|
|
301
|
+
let behind = false; try { behind = defaultBehind({ git: io.git, def: ctx.def, head }); } catch { /* unreadable: the chain check above already read the repo */ }
|
|
302
|
+
if (behind) return { stopped: true, why: `${ctx.def} is not an ancestor of release head ${String(head).slice(0, 8)}: a p0 landed after the cut; recut the release (release.fix_mode: recut) to merge ${ctx.def} in`, head };
|
|
303
|
+
}
|
|
304
|
+
if (ctx.fence) return managedPromotion(ctx, { pr, head });
|
|
289
305
|
let gate = await gateState({ io, repo, pr, head });
|
|
290
306
|
if (gate.marker !== "pass") return { stopped: true, why: `no FORGE:GATE_PASS on #${pr} (last marker: ${gate.marker ?? "none"})`, head };
|
|
291
307
|
if (gate.deployGate !== "success" && gate.deployGate !== "failure") gate = await awaitGate({ io, repo, pr, head, gate, fence: ctx.fence });
|
|
@@ -303,6 +319,28 @@ async function promotionStep(ctx) {
|
|
|
303
319
|
return { merged: true, head, gate };
|
|
304
320
|
}
|
|
305
321
|
|
|
322
|
+
const MERGE_FLAG = { "merge-commit": "--merge", squash: "--squash", rebase: "--rebase" };
|
|
323
|
+
|
|
324
|
+
/** #5561 (I1, I12): the managed merge. The gate is the `forge/release-gate` check run from the configured app, never the GATE_PASS marker. */
|
|
325
|
+
export async function managedPromotion(ctx, { pr, head }) {
|
|
326
|
+
const { io, repo, state, opts } = ctx;
|
|
327
|
+
const refusedRole = roleRefusal(ctx.fence.lctx.credential, "merge", { branch: ctx.def });
|
|
328
|
+
if (refusedRole) return { refused: refusedRole, head };
|
|
329
|
+
const { readPolicy } = await import("./release-config.mjs"); // lazy: release-config imports this module
|
|
330
|
+
const policy = readPolicy({ io, defaultBranch: ctx.def }).policy;
|
|
331
|
+
const g = await (io.mergeGuard ?? mergeGuard)({ io, repo, head, state, policy, staging: ctx.staging });
|
|
332
|
+
if (!g.ok) {
|
|
333
|
+
if (policy && /failure|not green/.test(g.why)) await rerunInfraFlakes({ io, repo, head, fence: ctx.fence, policy }); // #5568: transient infra only; the next resume re-checks the guard
|
|
334
|
+
return { stopped: true, why: `merge guard: ${g.why}`, head };
|
|
335
|
+
}
|
|
336
|
+
const flag = MERGE_FLAG[policy.merge?.method ?? "merge-commit"];
|
|
337
|
+
const cmd = `gh pr merge ${pr} --repo ${repo} ${flag} --match-head-commit ${head}`;
|
|
338
|
+
if (!opts.merge && !ctx.config.autoMerge) { io.print(`Release gate passed on #${pr}. Merge when ready:\n ${cmd}`); return { stopped: true, why: "release gate passed; promotion is opt-in (--merge or release.auto_merge)", cmd, head }; }
|
|
339
|
+
const f = await fenced(ctx.fence, { action: "merge", key: `merge:${pr}:${head}` }, (epoch) => io.gh(["pr", "merge", String(pr), "--repo", repo, flag, "--match-head-commit", head, "--body", [`Forge-Release: ${state.id}`, ...(epoch != null ? [epochTrailer(epoch)] : [])].join("\n")]));
|
|
340
|
+
if (f.refused) return { refused: f.refused, head };
|
|
341
|
+
return { merged: true, head };
|
|
342
|
+
}
|
|
343
|
+
|
|
306
344
|
const OPTIONAL_STEPS = ["host-preflight", "mark-ready", "deploy"];
|
|
307
345
|
|
|
308
346
|
const STEP_FNS = {
|
|
@@ -355,12 +393,14 @@ export async function runRelease({ io, repo, opts = {}, config = {}, branches =
|
|
|
355
393
|
ctx.fence = { lctx, lease: l.lease, record, now: () => new Date(io.now()).toISOString() };
|
|
356
394
|
return null;
|
|
357
395
|
};
|
|
358
|
-
const ctx = { io, repo, opts: state.opts, config, state, staging: branches.staging || DEFAULT_STAGING_BRANCH, def: branches.default || "main", git: io.git, save: () => rel.save(state) };
|
|
396
|
+
const ctx = { laneStrip: [], io, repo, opts: state.opts, config, state, staging: branches.staging || DEFAULT_STAGING_BRANCH, def: branches.default || "main", git: io.git, save: () => rel.save(state) };
|
|
397
|
+
ctx.rollbackTrigger = (t) => { state.rollbackPending = { reason: t.reason, sha: t.sha }; rel.save(state); io.print?.(`release ${id}: rollback trigger recorded; run \`forgedock release rollback ${id} --reason "${String(t.reason).replace(/"/g, "'")}"\``); }; // #5563
|
|
359
398
|
if (lctx) { // #5567: the fix loop's HELD goes through the control path; an infra-flake rerun through the fenced rerun
|
|
360
399
|
ctx.hold = (ask) => runControl("hold", [id, "--reason", ask], { io, repo, policy: null, actor: holder, host: holder });
|
|
361
400
|
ctx.rerunInfra = ({ head }) => rerunInfraFlakes({ io, repo, head, fence: ctx.fence, policy: config.policy });
|
|
362
401
|
}
|
|
363
402
|
ctx.save();
|
|
403
|
+
if (lctx && io.git) { const { readPolicy } = await import("./release-config.mjs"); ctx.laneStrip = readPolicy({ io, defaultBranch: ctx.def }).policy?.credentials?.lane_env_strip ?? []; }
|
|
364
404
|
let out;
|
|
365
405
|
try {
|
|
366
406
|
for (const step of RELEASE_STEPS) {
|
|
@@ -397,7 +437,8 @@ export async function runRelease({ io, repo, opts = {}, config = {}, branches =
|
|
|
397
437
|
try {
|
|
398
438
|
if (tf && existsSync(tf) && existsSync(join(process.cwd(), ".forge/gates.yaml"))) {
|
|
399
439
|
const recs = (await import("./release-gates.mjs")).parseTelemetry(readFileSync(tf, "utf8"));
|
|
400
|
-
|
|
440
|
+
const gs = state.regates?.at(-1)?.gate_sha; // #5584: which gate-script sha evaluated these gates
|
|
441
|
+
if (recs.length) state.gates = [...(state.gates ?? []), ...recs.map((r) => (gs && !r.gate_sha ? { ...r, gate_sha: gs } : r))];
|
|
401
442
|
}
|
|
402
443
|
} catch { /* best effort */ }
|
|
403
444
|
}
|
|
@@ -437,7 +478,7 @@ export function realReleaseIo({ env = process.env, exec = execFileSync, print =
|
|
|
437
478
|
}
|
|
438
479
|
|
|
439
480
|
const flag = (argv, f) => { const i = argv.indexOf(f); return i >= 0 ? argv[i + 1] : null; };
|
|
440
|
-
export const RELEASE_USAGE = "usage: forgedock release [--repo owner/repo] [--merge] [--watch] [--resume <id>] | forgedock release verify <sha | release id> [--repo owner/repo] | forgedock release status [<id>] [--watch] [--interval s] [--json] | forgedock release explain <id | #issue | PR> [--json] | forgedock release check-config [--ref <git ref>] | forgedock release init | forgedock release control <hold|resume|cancel|lane|exempt|freeze|unfreeze> ... --reason <text> [--repo owner/repo] [--json] (the verbs also work as `forgedock release <verb>`) | forgedock release gates [check [--base <ref>] | demote] [--since 30d] [--json] | forgedock release gates record <release-id> --file <jsonl> | forgedock release report";
|
|
481
|
+
export const RELEASE_USAGE = "usage: forgedock release [--repo owner/repo] [--merge] [--watch] [--resume <id>] | forgedock release p0 <#issue | --branch B> [--units a,b] [--preempt] [--yes] | forgedock release verify <sha | release id> [--repo owner/repo] | forgedock release recover <release id> [--repo owner/repo] | forgedock release rollback <release id> --reason <text> [--to flag|unit|full] [--later id,id] [--repo owner/repo] [--json] | forgedock release plan [--lane auto|train|release|p0] [--milestone <slug>] [--issues N,N] [--repo owner/repo] [--json] | forgedock release start [--plan <id|hash>] [--approve] [--wave train|release|all] [--milestone <slug>] [--repo owner/repo] | forgedock release go <id> [--plan|--merge|--activate <key>] [--repo owner/repo] | forgedock release status [<id>] [--watch] [--interval s] [--json] | forgedock release explain <id | #issue | PR> [--json] | forgedock release check-config [--ref <git ref>] [--coverage] | forgedock release init [--conductor] | forgedock release control <hold|resume|cancel|lane|exempt|freeze|unfreeze> ... --reason <text> [--repo owner/repo] [--json] (the verbs also work as `forgedock release <verb>`) | forgedock release gates [check [--base <ref>] | demote] [--since 30d] [--json] | forgedock release gates record <release-id> --file <jsonl> | forgedock release report";
|
|
441
482
|
|
|
442
483
|
/** `forgedock release ...`; @returns the process exit code (0 done or stopped at GATE_PASS, 1 refused, 3 blocked on a manual step). */
|
|
443
484
|
export async function releaseFromCli(argv, deps = {}) {
|
|
@@ -456,6 +497,82 @@ export async function releaseFromCli(argv, deps = {}) {
|
|
|
456
497
|
const r = await verifyReleaseById({ io, state, save: () => rel.save(state), def, policy: readPolicy({ io, defaultBranch: def, cwd }).policy, lane: flag(argv, "--lane") ?? state.lane });
|
|
457
498
|
return r.verified ? 0 : BLOCKED_EXIT;
|
|
458
499
|
}
|
|
500
|
+
if (argv[0] === "plan") { // #5559: the read-only release planner; loaded lazily like the other managed-release modules
|
|
501
|
+
const { planFromCli } = await import("./release-plan.mjs");
|
|
502
|
+
const { readPolicy } = await import("./release-config.mjs");
|
|
503
|
+
const def = readBranches(cwd).default || "main", rp = readPolicy({ io, defaultBranch: def, cwd });
|
|
504
|
+
let raw = ""; try { raw = readFileSync(join(cwd, "forge.yaml"), "utf8"); } catch { /* no forge.yaml: defaults */ }
|
|
505
|
+
const rc = readReleaseConfig(raw), repo = flag(argv, "--repo") ?? JSON.parse(String(await io.gh(["repo", "view", "--json", "nameWithOwner"]))).nameWithOwner;
|
|
506
|
+
const ctx = { io, repo, credential: "driver" };
|
|
507
|
+
return planFromCli([...argv.slice(1).filter((a, i, all) => a !== "--repo" && all[i - 1] !== "--repo"), "--repo", repo], {
|
|
508
|
+
io, policy: rp.policy, policySha: rp.sha, managed: !!rc.managed, newId: newReleaseId(io.now()), history: historyFromRoot(releaseRoot(env)), budget: { cfg: parseBudgetConfig(parseForgeYaml(raw)?.budget) },
|
|
509
|
+
readLanes: rc.managed && io.api ? async () => (await readActive(ctx).catch(() => ({}))).lanes : undefined,
|
|
510
|
+
ledger: async ({ id, plan }) => { await createReleaseLedger(ctx, id, { v: 1, id, repo, kind: "plan", status: "planned", plan }); },
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
if (argv[0] === "start" || argv[0] === "go") { // #5571: the managed runner and the typed approval; loaded lazily like the other managed-release modules
|
|
514
|
+
const { startFromCli, goFromCli } = await import("./release-start.mjs");
|
|
515
|
+
const { readPolicy } = await import("./release-config.mjs");
|
|
516
|
+
const { runReleaseTrain } = await import("./release-train.mjs");
|
|
517
|
+
const { verifyReleaseById } = await import("./release-verify.mjs");
|
|
518
|
+
const { syncValidated } = await import("./release-mergeback.mjs");
|
|
519
|
+
const { PLAN_LABEL } = await import("./release-plan.mjs");
|
|
520
|
+
const def = readBranches(cwd).default || "main", rp = readPolicy({ io, defaultBranch: def, cwd });
|
|
521
|
+
let raw = ""; try { raw = readFileSync(join(cwd, "forge.yaml"), "utf8"); } catch { /* no forge.yaml: defaults */ }
|
|
522
|
+
const rc = readReleaseConfig(raw), rest = argv.slice(1), repo = flag(rest, "--repo") ?? JSON.parse(String(await io.gh(["repo", "view", "--json", "nameWithOwner"]))).nameWithOwner;
|
|
523
|
+
const ctx = { io, repo, credential: "driver" }, root = releaseRoot(env), managed = !!rc.managed && !!io.api;
|
|
524
|
+
const ledger = { read: (id) => readLedger(ctx, id), create: (id, st) => createReleaseLedger(ctx, id, st), write: (id, st, head) => writeRelease(ctx, id, st, head), list: async () => (await (await import("./release-ledger.mjs")).listLedgers({ io, repo })).map((l) => l.id ?? l) };
|
|
525
|
+
const tracker = async () => JSON.parse(String(await io.gh(["issue", "list", "--repo", repo, "--label", PLAN_LABEL, "--state", "open", "--json", "number,comments"])) || "[]");
|
|
526
|
+
const post = async (body) => { const t = (await tracker())[0]; if (!t) throw new Error(`no open issue labelled ${PLAN_LABEL} to carry the decision`); await io.gh(["issue", "comment", String(t.number), "--repo", repo, "--body", body]); };
|
|
527
|
+
if (argv[0] === "go") return goFromCli(rest, { io, ledger, post, managed, actor: deps.actor });
|
|
528
|
+
const id = newReleaseId(io.now()), state = { id };
|
|
529
|
+
const prOf = async (n) => Number(JSON.parse(String(await io.gh(["pr", "list", "--repo", repo, "--state", "open", "--search", `#${n} in:body`, "--json", "number"])) || "[]")[0]?.number) || null;
|
|
530
|
+
const { takeFence } = await import("./release-rollback.mjs"), { readRollouts, detectNewOffKeys } = await import("./activation.mjs");
|
|
531
|
+
const rollouts = readRollouts(cwd);
|
|
532
|
+
const takeWaveFence = async (st) => { // the wave lease; intents land in the plan state; the lease comment goes on the plan tracker
|
|
533
|
+
const t = (await tracker())[0];
|
|
534
|
+
return takeFence({ io, repo, state: { id: st.id, steps: { "release-pr": { result: { pr: t?.number } } }, intents: (st.intents ??= []) }, save: () => {} }, io.holder ?? `host-${process.pid}`);
|
|
535
|
+
};
|
|
536
|
+
const runners = {
|
|
537
|
+
rollouts: async (w, plan) => { // feature wave: new default-off rollout keys come from the wave PRs' diffs of the forge.yaml rollouts.files registry
|
|
538
|
+
const feature = w.issues.some((n) => String(plan.issues?.[n]?.reason ?? "").startsWith("feature"));
|
|
539
|
+
if (!feature || !rollouts) return { feature, added: [], offKeys: [] };
|
|
540
|
+
const diffs = await Promise.all(w.issues.map(async (n) => { const pr = await prOf(n); return pr ? String(await io.gh(["pr", "diff", String(pr), "--repo", repo])) : ""; }));
|
|
541
|
+
const offKeys = detectNewOffKeys(rollouts, diffs.join("\n"));
|
|
542
|
+
return { feature, added: offKeys, offKeys };
|
|
543
|
+
},
|
|
544
|
+
train: async (w) => runReleaseTrain({ io, repo, def, state, save: () => {}, config: { deploy: rp.policy?.deploy }, policy: rp.policy, actor: deps.actor, host: deps.host, date: new Date(io.now()).toISOString().slice(0, 10), n: 1 }, await Promise.all(w.issues.map(async (n) => ({ issue: n, pr: await prOf(n), record: {} })))),
|
|
545
|
+
release: async (w, o) => { const r = await runRelease({ io, repo, opts: { merge: true, lane: "release" }, config: { ...rc, policy: rp.policy, deploy: rp.policy?.deploy, verify: rp.policy?.verify, verifyRisk: o.soak }, branches: readBranches(cwd), root, id }); return { status: r.status === "done" ? "done" : r.status, reason: r.reason }; },
|
|
546
|
+
verify: async (w, r) => ({ verified: r.status === "done" || (await verifyReleaseById({ io, state, save: () => {}, def, policy: rp.policy, lane: "train" })).verified }),
|
|
547
|
+
mergeback: async () => ({ validated: syncValidated(state.sync) || state.sync == null }),
|
|
548
|
+
};
|
|
549
|
+
return startFromCli(rest, { io, policy: rp.policy, policySha: rp.sha, managed, newId: id, history: historyFromRoot(root), budget: { cfg: parseBudgetConfig(parseForgeYaml(raw)?.budget) }, ledger, runners, takeFence: takeWaveFence,
|
|
550
|
+
decisions: async () => (await tracker()).flatMap((i) => (i.comments ?? []).map((c) => ({ author: c.author?.login, body: c.body }))), post, actor: deps.actor });
|
|
551
|
+
}
|
|
552
|
+
if (argv[0] === "rollback") { // #5563: the rollback ladder; loaded lazily like the other managed-release modules
|
|
553
|
+
const { rollbackFromCli } = await import("./release-rollback.mjs");
|
|
554
|
+
const { readPolicy } = await import("./release-config.mjs");
|
|
555
|
+
if (!ID_RE.test(String(argv[1] ?? ""))) throw new Error(`rollback needs a release id; ${RELEASE_USAGE}`);
|
|
556
|
+
const def = readBranches(cwd).default || "main";
|
|
557
|
+
return rollbackFromCli(argv.slice(1), { io, rel: openRelease(releaseRoot(env), argv[1]), policy: readPolicy({ io, defaultBranch: def, cwd }).policy, def, actor: deps.actor, host: deps.host });
|
|
558
|
+
}
|
|
559
|
+
if (argv[0] === "p0") { // #5565: the managed P0 lane; loaded lazily like the other managed-release modules
|
|
560
|
+
const { p0FromCli } = await import("./release-p0.mjs");
|
|
561
|
+
const { readPolicy } = await import("./release-config.mjs");
|
|
562
|
+
const def = readBranches(cwd).default || "main", policy = readPolicy({ io, defaultBranch: def, cwd }).policy;
|
|
563
|
+
let raw = ""; try { raw = readFileSync(join(cwd, "forge.yaml"), "utf8"); } catch { /* no forge.yaml: defaults */ }
|
|
564
|
+
const rc = readReleaseConfig(raw), id = newReleaseId(io.now());
|
|
565
|
+
const config = { ...rc, deploy: policy?.deploy, verify: policy?.verify, verifySoak: policy?.lanes?.p0?.soak_min };
|
|
566
|
+
const ask = deps.ask ?? ((q) => new Promise((res) => { const rl = createInterface({ input: process.stdin, output: process.stdout }); rl.question(q, (a) => { rl.close(); res(a); }); }));
|
|
567
|
+
return p0FromCli(argv.slice(1), { io, rel: openRelease(releaseRoot(env), id), id, config, policy, def, actor: deps.actor, host: deps.host, ask });
|
|
568
|
+
}
|
|
569
|
+
if (argv[0] === "recover") { // #5564: the conductor's host-less recovery; loaded lazily like the other managed-release modules
|
|
570
|
+
const { recoverFromCli } = await import("./release-conductor.mjs");
|
|
571
|
+
const { readPolicy } = await import("./release-config.mjs");
|
|
572
|
+
if (!ID_RE.test(String(argv[1] ?? ""))) throw new Error(`recover needs a release id; ${RELEASE_USAGE}`);
|
|
573
|
+
const def = readBranches(cwd).default || "main";
|
|
574
|
+
return recoverFromCli(argv.slice(1), { io, policy: readPolicy({ io, defaultBranch: def, cwd }).policy ?? {}, def, actor: deps.actor ?? env.GITHUB_ACTOR, host: deps.host });
|
|
575
|
+
}
|
|
459
576
|
if (argv[0] === "gates") { // #5583: catalogue, telemetry report, admission check; release-gates is loaded lazily
|
|
460
577
|
const g = await import("./release-gates.mjs");
|
|
461
578
|
const { readPolicy } = await import("./release-config.mjs");
|
|
@@ -485,7 +602,9 @@ export async function releaseFromCli(argv, deps = {}) {
|
|
|
485
602
|
const { controlFromCli } = await import("./release-control.mjs");
|
|
486
603
|
const { readPolicy } = await import("./release-config.mjs");
|
|
487
604
|
const policy = readPolicy({ io, defaultBranch: readBranches(cwd).default || "main", cwd }).policy;
|
|
488
|
-
|
|
605
|
+
const cargs = argv.slice(argv[0] === "control" ? 2 : 1);
|
|
606
|
+
const rel = cv === "regate" && cargs[0] && ID_RE.test(cargs[0]) ? openRelease(releaseRoot(env), cargs[0]) : undefined; // #5584: regate reads the release's recorded deploy target
|
|
607
|
+
return controlFromCli(cv, cargs, { io, policy, actor: deps.actor, host: deps.host, rel });
|
|
489
608
|
}
|
|
490
609
|
if (argv[0] === "control") throw new Error(`unknown control verb ${argv[1] ?? ""}; ${RELEASE_USAGE}`);
|
|
491
610
|
const unknown = argv.filter((a, i) => a.startsWith("--") && !["--repo", "--merge", "--watch", "--resume", "--lane", "--interval"].includes(a) && !(argv[i - 1] === "--resume" || argv[i - 1] === "--repo" || argv[i - 1] === "--lane" || argv[i - 1] === "--interval"));
|
|
@@ -505,6 +624,9 @@ export async function releaseFromCli(argv, deps = {}) {
|
|
|
505
624
|
const { readPolicy } = await import("./release-config.mjs");
|
|
506
625
|
const pol = readPolicy({ io, defaultBranch: readBranches(cwd).default || "main", cwd }).policy;
|
|
507
626
|
if (pol?.deploy) config.deploy = pol.deploy;
|
|
627
|
+
const { conductorGuard } = await import("./release-conductor.mjs"); // #5564: a configured conductor must exist on the default branch
|
|
628
|
+
const noConductor = conductorGuard({ io, policy: pol, def: readBranches(cwd).default || "main" });
|
|
629
|
+
if (noConductor) { io.print(`release: refused: ${noConductor}`); return 1; }
|
|
508
630
|
config.policy = pol; config.fix = parseFixConfig(pol?.ci?.fix); // #5567: ci.fix.max_rounds / co_start / full_run_workflow
|
|
509
631
|
config.deployPipeline = pol?.lanes?.[flag(argv, "--lane")]?.pipeline ?? "full"; // service/hotfix lanes dispatch with unit inputs
|
|
510
632
|
if (pol?.verify) { // #5562: verification layers; risk class picks the soak minutes
|
|
@@ -58,6 +58,17 @@ describe("unmanaged release carries no epoch (#5553)", () => {
|
|
|
58
58
|
});
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
+
describe("legacy managed promotion without a fence (#5561 regression)", () => {
|
|
62
|
+
it("a failing deploy-gate still reads the policy to rerun infra flakes (as before the managed split)", async () => {
|
|
63
|
+
const mod = await import("./release.mjs");
|
|
64
|
+
const io = fakeIo({ gate: "failure" });
|
|
65
|
+
const shown = [];
|
|
66
|
+
io.git = (a) => { if (a[0] === "show") shown.push(a[1]); throw new Error("no git"); };
|
|
67
|
+
await mod.runRelease({ io, repo: REPO, root: tmp(), mounts: DISK, id: newReleaseId(), opts: { merge: true }, config: { managed: true }, branches: { staging: "staging", default: "main" }, steps: mod.withStubs({ review: ok, fixes: ok, "post-merge": ok }) });
|
|
68
|
+
assert.ok(shown.some((x) => x.startsWith("origin/main:")), "policy read for the flake rerun");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
61
72
|
describe("release job (#5211)", () => {
|
|
62
73
|
const promote = async (world, { opts = {}, config = {} } = {}) => {
|
|
63
74
|
const io = fakeIo(world), root = tmp(), id = newReleaseId();
|
|
@@ -489,3 +500,72 @@ describe("release control routing (#5556)", () => {
|
|
|
489
500
|
await assert.rejects(releaseFromCli(["control", "nope"], { io: { print() {}, gh: async () => "" }, cwd: tmp() }), /unknown control verb/);
|
|
490
501
|
});
|
|
491
502
|
});
|
|
503
|
+
|
|
504
|
+
describe("managed merge (#5561)", () => {
|
|
505
|
+
const LEASE = { holder: "A", epoch: 3 };
|
|
506
|
+
const fence = (lctxCred = "driver") => ({ lctx: { repo: REPO, credential: lctxCred, io: { api: async (_m, path) => {
|
|
507
|
+
if (/active\.json/.test(path)) return { content: Buffer.from(JSON.stringify({ epoch: 3, lease: LEASE })).toString("base64") };
|
|
508
|
+
throw Object.assign(new Error("404 Not Found"), { status: 404 });
|
|
509
|
+
} } }, lease: { ...LEASE, release: "r1" }, now: () => "t", record: async () => {} });
|
|
510
|
+
const mk = (over = {}, method) => {
|
|
511
|
+
const merges = [];
|
|
512
|
+
const io = { print() {}, git: () => `schema: 1\nmerge: {method: ${method ?? "merge-commit"}}\n`, gh: async (a) => { merges.push(a); return ""; }, mergeGuard: async () => ({ ok: true }), ...over };
|
|
513
|
+
return { merges, ctx: { io, repo: REPO, state: { id: "r20240101-000000-1" }, opts: { merge: true }, config: { managed: true }, def: "main", staging: "staging", fence: fence() } };
|
|
514
|
+
};
|
|
515
|
+
it("merge carries --match-head-commit, Forge-Release and Forge-Epoch trailers", async () => {
|
|
516
|
+
const { ctx, merges } = mk();
|
|
517
|
+
const { managedPromotion } = await import("./release.mjs");
|
|
518
|
+
assert.deepEqual(await managedPromotion(ctx, { pr: 7, head: HEAD }), { merged: true, head: HEAD });
|
|
519
|
+
assert.deepEqual(merges[0], ["pr", "merge", "7", "--repo", REPO, "--merge", "--match-head-commit", HEAD, "--body", "Forge-Release: r20240101-000000-1\nForge-Epoch: 3"]);
|
|
520
|
+
});
|
|
521
|
+
it("merge.method picks the gh flag", async () => {
|
|
522
|
+
const { managedPromotion } = await import("./release.mjs");
|
|
523
|
+
for (const [m, flag] of [["squash", "--squash"], ["rebase", "--rebase"]]) {
|
|
524
|
+
const { ctx, merges } = mk({}, m);
|
|
525
|
+
await managedPromotion(ctx, { pr: 7, head: HEAD });
|
|
526
|
+
assert.ok(merges[0].includes(flag), m);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
it("a refused guard (moved head, stale approval, no gate status, unreadable gate) merges nothing", async () => {
|
|
530
|
+
const { managedPromotion } = await import("./release.mjs");
|
|
531
|
+
const { ctx, merges } = mk({ mergeGuard: async () => ({ ok: false, why: "no forge/release-gate on x" }) });
|
|
532
|
+
const r = await managedPromotion(ctx, { pr: 7, head: HEAD });
|
|
533
|
+
assert.match(r.why, /merge guard: no forge\/release-gate/);
|
|
534
|
+
assert.equal(merges.length, 0);
|
|
535
|
+
});
|
|
536
|
+
it("I12: a lane-role context cannot merge", async () => {
|
|
537
|
+
const { managedPromotion } = await import("./release.mjs");
|
|
538
|
+
const { ctx, merges } = mk();
|
|
539
|
+
ctx.fence = fence("lane");
|
|
540
|
+
assert.match((await managedPromotion(ctx, { pr: 7, head: HEAD })).refused, /role lane may not merge/);
|
|
541
|
+
assert.equal(merges.length, 0);
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
describe("release plan routing (#5559)", () => {
|
|
546
|
+
const POLICY_TEXT = "schema: 1\nbranches: {default: main}\nplan: {approval: wait}\nlanes: {release: {pipeline: existing}}\nmerge: {approval: confirm}\nunits:\n api: {paths: [\"api/**\"]}\ntrust: {actors: [owner]}\ndeploy: {live_release_command: \"echo live\"}\n";
|
|
547
|
+
const issue = { number: 5, title: "t", body: "", labels: [], createdAt: "2026-01-01T00:00:00Z", updatedAt: "2026-01-02T00:00:00Z", comments: [{ author: { login: "b" }, body: "<!-- FORGE:CLASSIFY -->\n```json\n{\"type\":\"bug\",\"severity\":\"P2\",\"exists_in\":\"live\",\"confidence\":0.9,\"files\":[\"api/a.py\"]}\n```" }] };
|
|
548
|
+
const mkIo = (out, gh) => ({ print: (l) => out.push(l), gh: async (a) => { gh.push(a); return a[0] === "issue" ? JSON.stringify([issue]) : JSON.stringify({ nameWithOwner: "o/r" }); }, git: (a) => { if (a[0] === "show") return POLICY_TEXT; throw new Error("none"); }, rehearse: async () => ({ ok: true, output: "abc1234" }), now: () => 1 });
|
|
549
|
+
it("`release plan --json` is read-only and lists the plan; the bare release options still reject unknown flags", async () => {
|
|
550
|
+
const out = [], gh = [];
|
|
551
|
+
assert.equal(await releaseFromCli(["plan", "--json"], { io: mkIo(out, gh), cwd: tmp(), env: { ...process.env, FORGEDOCK_RELEASE_DIR: tmp() } }), 0);
|
|
552
|
+
const p = JSON.parse(out[0]);
|
|
553
|
+
assert.equal(p.schema, "forgedock.release.plan/v1"); assert.equal(p.issues[5].lane, "train"); assert.equal(p.live_sha, "abc1234");
|
|
554
|
+
assert.ok(gh.every((a) => a[0] === "issue" || a[0] === "repo"));
|
|
555
|
+
await assert.rejects(releaseFromCli(["--bogus"], { io: mkIo([], []), cwd: tmp() }), /unknown option/);
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
describe("release start|go routing (#5571)", () => {
|
|
560
|
+
const POLICY_TEXT = "schema: 1\nbranches: {default: main}\nlanes: {release: {pipeline: existing}}\nunits:\n api: {paths: [\"api/**\"]}\ntrust: {actors: [owner]}\n";
|
|
561
|
+
const mkIo = (out, gh) => ({ print: (l) => out.push(l), gh: async (a) => { gh.push(a); return a[0] === "repo" ? JSON.stringify({ nameWithOwner: "o/r" }) : "[]"; }, git: (a) => (a[0] === "show" ? POLICY_TEXT : "abc1234\n"), now: () => 1_700_000_000_000 });
|
|
562
|
+
const opts = (out, gh) => ({ io: mkIo(out, gh), cwd: tmp(), env: { ...process.env, FORGEDOCK_RELEASE_DIR: tmp() } });
|
|
563
|
+
it("an unmanaged `start` and `go <id>` make no GitHub writes; `go` needs an id; a bad --wave is rejected", async () => {
|
|
564
|
+
const out = [], gh = [];
|
|
565
|
+
assert.equal(await releaseFromCli(["start"], opts(out, gh)), 0);
|
|
566
|
+
assert.equal(await releaseFromCli(["go", "r1"], opts(out, gh)), 0);
|
|
567
|
+
assert.ok(out.every((l) => /unmanaged/.test(l)) && gh.every((a) => a[0] === "repo"));
|
|
568
|
+
await assert.rejects(releaseFromCli(["go"], opts([], [])), /release id/);
|
|
569
|
+
await assert.rejects(releaseFromCli(["start", "--wave", "x"], opts([], [])), /--wave/);
|
|
570
|
+
});
|
|
571
|
+
});
|
|
@@ -212,6 +212,7 @@ export function remoteProvider({ batch, repo, settings = {}, name = "remote", tr
|
|
|
212
212
|
relays,
|
|
213
213
|
serviceRelay,
|
|
214
214
|
async start({ issue, args = [], env: laneEnv = env, secrets = settings.secrets ?? [] }) {
|
|
215
|
+
if (settings.laneToolsErrors?.length) throw Object.assign(new Error(settings.laneToolsErrors.join("; ")), { code: "lane_tools.invalid" }); // #5650
|
|
215
216
|
const id = idFor(issue);
|
|
216
217
|
// Each allowlisted secret from the env, else the keychain (#4254); nothing else from the host.
|
|
217
218
|
const resolved = {};
|
|
@@ -224,6 +225,7 @@ export function remoteProvider({ batch, repo, settings = {}, name = "remote", tr
|
|
|
224
225
|
const spec = {
|
|
225
226
|
id, issue, batch: batch.id, image: settings.image ?? null,
|
|
226
227
|
repo: { slug: repo, url: repo ? `https://github.com/${repo}.git` : null, ref: li >= 0 ? args[li + 1] ?? null : null },
|
|
228
|
+
...(settings.laneTools?.length ? { lane_tools: settings.laneTools } : {}), // #5650: per-repo lane image
|
|
227
229
|
...(warm ? { warm } : {}), // #4912: the pool agent keeps this many warm sandboxes for the repo
|
|
228
230
|
cache: settings.cacheStore ? { store: settings.cacheStore, key: safeSegment(String(repo ?? "repo")) } : null,
|
|
229
231
|
// The host's git identity: without it the lane image falls back to a placeholder author that fails DCO.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
// #5531: a real schedd process under synthetic CPU load still answers `status` in under a second and keeps dispatching.
|
|
4
|
+
// End to end: the daemon runs in its own node process (real socket, real batch dir, a runBatch that dispatches by writing
|
|
5
|
+
// log rows), the CPU hogs are real processes, and the client is this process plus the real `forgedock schedd status` CLI.
|
|
6
|
+
// FORGEDOCK_SCHEDD_LOAD_HOGS: hog count (default 2); `auto` = 4 x nproc (the issue's load; run on a dedicated host only).
|
|
7
|
+
import { describe, it } from "node:test";
|
|
8
|
+
import assert from "node:assert/strict";
|
|
9
|
+
import { execFile, spawn } from "node:child_process";
|
|
10
|
+
import { readFileSync } from "node:fs";
|
|
11
|
+
import { cpus, setPriority } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
14
|
+
import { tmpDir } from "../tests/_tmp.mjs";
|
|
15
|
+
import { openBatch } from "./batch.mjs";
|
|
16
|
+
import { connectDaemon, request } from "./schedd.mjs";
|
|
17
|
+
|
|
18
|
+
const hogs = process.env.FORGEDOCK_SCHEDD_LOAD_HOGS === "auto" ? cpus().length * 4 : Number(process.env.FORGEDOCK_SCHEDD_LOAD_HOGS) || 2;
|
|
19
|
+
const CLI = fileURLToPath(new URL("../forgedock.mjs", import.meta.url));
|
|
20
|
+
const SCHEDD = pathToFileURL(fileURLToPath(new URL("./schedd.mjs", import.meta.url))).href;
|
|
21
|
+
const BATCH = pathToFileURL(fileURLToPath(new URL("./batch.mjs", import.meta.url))).href;
|
|
22
|
+
|
|
23
|
+
/** The daemon process: hosts the given batch and dispatches one log row every 50 ms until it is told to stop. */
|
|
24
|
+
const daemonSrc = (dir, root, id) => `
|
|
25
|
+
import { startDaemon } from ${JSON.stringify(SCHEDD)};
|
|
26
|
+
import { openBatch } from ${JSON.stringify(BATCH)};
|
|
27
|
+
const b = openBatch(${JSON.stringify(root)}, ${JSON.stringify(id)});
|
|
28
|
+
let n = 0;
|
|
29
|
+
const runBatch = async ({ sink, signal }) => {
|
|
30
|
+
sink.batch({ id: b.id, dir: b.dir });
|
|
31
|
+
const t = setInterval(() => b.store.log({ type: "dispatch", n: ++n }), 50);
|
|
32
|
+
await new Promise((r) => signal?.addEventListener?.("abort", r));
|
|
33
|
+
clearInterval(t);
|
|
34
|
+
};
|
|
35
|
+
const d = await startDaemon({ dir: ${JSON.stringify(dir)}, root: ${JSON.stringify(root)}, runBatch, log: (m) => console.log(m), resumeOnStart: true });
|
|
36
|
+
process.on("SIGTERM", async () => { await d.close(); process.exit(0); });
|
|
37
|
+
console.log("ready");
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
const dispatches = (b) => { try { return readFileSync(join(b.dir, "log.jsonl"), "utf8").split("\n").filter((l) => l.includes('"dispatch"')).length; } catch { return 0; } };
|
|
41
|
+
const until = async (fn, ms) => { const end = Date.now() + ms; while (!fn()) { if (Date.now() > end) throw new Error("timed out"); await new Promise((r) => setTimeout(r, 25)); } };
|
|
42
|
+
|
|
43
|
+
describe("schedd under CPU load (#5531)", () => {
|
|
44
|
+
it("#5531: status answers in under 1 s and a hosted batch keeps dispatching while CPU hogs run", async () => {
|
|
45
|
+
const dir = tmpDir("schedd-load-"), root = join(dir, "batches");
|
|
46
|
+
const b = openBatch(root, "b20261031-000000-8001");
|
|
47
|
+
b.writePlan({ daemon: true, repo: "o/r", created: new Date().toISOString() });
|
|
48
|
+
b.store.save({ v: 1, order: [1], results: {}, running: {}, pending: [1], parallel: 1 });
|
|
49
|
+
// a long history the status scan has to walk (finished batches)
|
|
50
|
+
for (let i = 0; i < 100; i++) { const o = openBatch(root, `b20261001-000000-${7000 + i}`); o.writePlan({ daemon: true, created: "2026-10-01T00:00:00Z" }); o.store.save({ v: 1, order: [1], pending: [] }); o.requestCancel({ reason: "done" }); }
|
|
51
|
+
const daemon = spawn(process.execPath, ["--input-type=module", "-e", daemonSrc(dir, root, b.id)], { stdio: ["ignore", "pipe", "pipe"] });
|
|
52
|
+
let out = ""; daemon.stdout.on("data", (c) => { out += c; }); daemon.stderr.on("data", (c) => { out += c; });
|
|
53
|
+
const procs = [];
|
|
54
|
+
try {
|
|
55
|
+
await until(() => out.includes("ready") && dispatches(b) > 0, 45000);
|
|
56
|
+
// the hogs stand in for lanes: lower class than the daemon, as in production (the unit runs CPUWeight=500, pool/install/unit-hardening.sh)
|
|
57
|
+
for (let i = 0; i < hogs; i++) { const h = spawn(process.execPath, ["-e", "for(;;){}"], { stdio: "ignore" }); try { setPriority(h.pid, 10); } catch { /* best effort */ } procs.push(h); }
|
|
58
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
59
|
+
const n0 = dispatches(b);
|
|
60
|
+
// a client outside the daemon process, over the real socket
|
|
61
|
+
const sock = await connectDaemon({ dir, spawnDaemon: null });
|
|
62
|
+
const times = []; let st;
|
|
63
|
+
for (let i = 0; i < 5; i++) { const t0 = Date.now(); st = await request(i ? await connectDaemon({ dir, spawnDaemon: null }) : sock, { op: "status" }, undefined, { timeoutMs: 5000 }); times.push(Date.now() - t0); }
|
|
64
|
+
const took = Math.min(...times); // best of 5: the full suite runs other test files at normal priority beside this one
|
|
65
|
+
assert.equal(st.type, "status");
|
|
66
|
+
assert.equal(st.pid, daemon.pid, "answered by the spawned daemon");
|
|
67
|
+
assert.ok(st.batches.some((x) => x.id === b.id && x.running), "the batch is hosted");
|
|
68
|
+
assert.ok(took < 1000, `status took ${took} ms under ${hogs} hogs`);
|
|
69
|
+
// the real CLI: `forgedock schedd status` against the same daemon (node startup excluded from the 1 s bound)
|
|
70
|
+
const cli = await new Promise((res) => execFile(process.execPath, [CLI, "schedd", "status"], { env: { ...process.env, FORGEDOCK_SCHED_DIR: dir }, timeout: 60000 }, (err, stdout) => res({ err, stdout })));
|
|
71
|
+
assert.equal(cli.err, null, String(cli.err));
|
|
72
|
+
assert.match(cli.stdout, new RegExp(`schedd: pid ${daemon.pid}, `));
|
|
73
|
+
assert.match(cli.stdout, new RegExp(b.id));
|
|
74
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
75
|
+
assert.ok(dispatches(b) > n0, `the hosted batch kept dispatching (${n0} → ${dispatches(b)})`);
|
|
76
|
+
} finally {
|
|
77
|
+
for (const p of procs) p.kill("SIGKILL");
|
|
78
|
+
daemon.kill("SIGTERM");
|
|
79
|
+
await new Promise((r) => { const t = setTimeout(() => { daemon.kill("SIGKILL"); r(); }, 5000); daemon.on("exit", () => { clearTimeout(t); r(); }); });
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|