forgedock 1.61.2 → 1.62.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 +10 -1
- package/bin/engine/outcome-codes.mjs +4 -0
- package/bin/engine-cli.mjs +159 -17
- package/bin/env/env.mjs +6 -4
- package/bin/forge-home-check.mjs +91 -0
- package/bin/forgedock.mjs +50 -7
- package/bin/gc.mjs +2 -0
- package/bin/hooks/pre-tool-use.mjs +4 -0
- package/bin/journey.mjs +55 -5
- package/bin/lean/admission.mjs +16 -5
- package/bin/lean/batch-health.mjs +55 -16
- package/bin/lean/batch-health.test.mjs +67 -1
- package/bin/lean/batch.mjs +8 -0
- package/bin/lean/batch.test.mjs +5 -0
- package/bin/lean/ceiling.mjs +20 -0
- package/bin/lean/ceiling.test.mjs +33 -2
- package/bin/lean/ci-gate.mjs +240 -0
- package/bin/lean/ci-gate.test.mjs +227 -0
- package/bin/lean/ci-precheck.mjs +178 -0
- package/bin/lean/ci-precheck.test.mjs +149 -0
- package/bin/lean/conformance.mjs +85 -9
- package/bin/lean/conformance.test.mjs +155 -3
- package/bin/lean/context.test.mjs +7 -6
- package/bin/lean/dag.mjs +128 -0
- package/bin/lean/dag.test.mjs +131 -0
- package/bin/lean/decisions.mjs +5 -4
- package/bin/lean/decisions.test.mjs +11 -0
- package/bin/lean/delguard.mjs +84 -0
- package/bin/lean/delguard.test.mjs +104 -0
- package/bin/lean/depcache.mjs +125 -17
- package/bin/lean/depcache.test.mjs +111 -0
- package/bin/lean/design-gate.mjs +5 -5
- package/bin/lean/design-gate.test.mjs +14 -0
- package/bin/lean/effects.mjs +72 -4
- package/bin/lean/execution.mjs +41 -7
- package/bin/lean/execution.test.mjs +99 -3
- package/bin/lean/forgedock-lane-workflow.test.mjs +35 -0
- package/bin/lean/guardgate.mjs +30 -7
- package/bin/lean/guardgate.test.mjs +44 -1
- package/bin/lean/guards.test.mjs +1 -1
- package/bin/lean/heavy.test.mjs +87 -0
- package/bin/lean/hotarea.mjs +73 -0
- package/bin/lean/hotarea.test.mjs +73 -0
- package/bin/lean/issuewatch-reconcile.mjs +20 -1
- package/bin/lean/issuewatch-reconcile.test.mjs +30 -0
- package/bin/lean/lanecheck.mjs +27 -3
- package/bin/lean/lanecheck.test.mjs +47 -5
- package/bin/lean/laneconfine.mjs +83 -0
- package/bin/lean/laneconfine.test.mjs +113 -0
- package/bin/lean/lean.mjs +376 -79
- package/bin/lean/lean.test.mjs +710 -22
- package/bin/lean/live-reconcile.mjs +169 -0
- package/bin/lean/live-reconcile.test.mjs +176 -0
- package/bin/lean/orchestrate-envhold.test.mjs +245 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +39 -0
- package/bin/lean/orchestrate.mjs +207 -17
- package/bin/lean/outcomeevidence.mjs +104 -0
- package/bin/lean/outcomeevidence.test.mjs +78 -0
- package/bin/lean/page-capture.mjs +68 -0
- package/bin/lean/page-capture.test.mjs +44 -0
- package/bin/lean/pagegate.mjs +46 -7
- package/bin/lean/pagegate.test.mjs +66 -1
- package/bin/lean/postdeploy-check.mjs +18 -4
- package/bin/lean/postdeploy-check.test.mjs +32 -1
- package/bin/lean/prefilter.mjs +36 -4
- package/bin/lean/prefilter.test.mjs +31 -1
- package/bin/lean/preflight.mjs +22 -0
- package/bin/lean/preflight.test.mjs +19 -1
- package/bin/lean/probe.mjs +18 -0
- package/bin/lean/probe.test.mjs +40 -0
- package/bin/lean/prompts.mjs +40 -3
- package/bin/lean/recovery.test.mjs +20 -0
- package/bin/lean/recurrence.mjs +133 -0
- package/bin/lean/recurrence.test.mjs +99 -0
- package/bin/lean/release-config.mjs +2 -1
- package/bin/lean/release-config.test.mjs +18 -0
- package/bin/lean/release-control.mjs +4 -2
- package/bin/lean/release-control.test.mjs +15 -0
- package/bin/lean/release-merge-hold.mjs +65 -0
- package/bin/lean/release-merge-hold.test.mjs +69 -0
- package/bin/lean/release-review.mjs +26 -9
- package/bin/lean/release-review.test.mjs +53 -0
- package/bin/lean/release-status.mjs +3 -1
- package/bin/lean/release-status.test.mjs +11 -0
- package/bin/lean/release.test.mjs +26 -1
- package/bin/lean/render.mjs +8 -7
- package/bin/lean/routing.mjs +49 -0
- package/bin/lean/routing.test.mjs +54 -1
- package/bin/lean/run-issue-placement.test.mjs +30 -1
- package/bin/lean/sandbox-actions.mjs +121 -0
- package/bin/lean/sandbox-actions.test.mjs +94 -0
- package/bin/lean/sandbox-provider.contract.test.mjs +22 -1
- package/bin/lean/sandbox-remote.mjs +3 -1
- package/bin/lean/schedd-health.mjs +14 -2
- package/bin/lean/schedd-health.test.mjs +13 -0
- package/bin/lean/schedd.mjs +43 -17
- package/bin/lean/schedd.test.mjs +61 -1
- package/bin/lean/toolchain.mjs +16 -6
- package/bin/lean/toolplace.mjs +12 -0
- package/bin/lean/weakguard.mjs +105 -0
- package/bin/lean/weakguard.test.mjs +59 -0
- package/bin/lean/winspawn.mjs +61 -0
- package/bin/lean/winspawn.test.mjs +45 -0
- package/bin/lean/worktree.mjs +3 -1
- package/bin/lean/worktree.test.mjs +11 -0
- package/bin/pool/agent.mjs +210 -14
- package/bin/pool/cache-sweep.mjs +74 -0
- package/bin/pool/cli.mjs +11 -3
- package/bin/pool/docker.mjs +33 -2
- package/bin/pool/health.mjs +38 -0
- package/bin/pool/lane-tools.mjs +23 -4
- package/bin/pool/lane-tools.test.mjs +12 -1
- package/bin/pool/router.mjs +21 -3
- package/bin/runner.mjs +37 -0
- package/bin/splash-scene.mjs +356 -0
- package/bin/win-hide-children.mjs +114 -0
- package/commands/orchestrate.md +18 -27
- package/commands/review-pr-agents/infra.md +1 -0
- package/commands/review-pr-staging.md +2 -2
- package/docs/CONFIG.md +60 -3
- package/docs/OUTCOME-CODES.md +3 -0
- package/package.json +1 -1
- package/plugins/forgedock-splash/.claude-plugin/plugin.json +1 -1
- package/plugins/forgedock-splash/README.md +1 -1
- package/plugins/forgedock-splash/hooks/scene.ts +142 -8
- package/pool/README.md +6 -0
- package/pool/image/entrypoint.sh +1 -0
- package/scripts/check-spec-size.sh +3 -1
- package/scripts/gen-splash-scene.mjs +24 -0
- package/scripts/review-staging-pre.sh +8 -3
- package/scripts/review-staging-pre.test.sh +2 -0
package/bin/lean/effects.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { readFileSync, appendFileSync, mkdirSync, mkdtempSync, statSync, existsS
|
|
|
6
6
|
import { homedir, hostname, freemem, loadavg, cpus, tmpdir } from "node:os";
|
|
7
7
|
import { promises as fsp } from "node:fs";
|
|
8
8
|
import { dirname, join, resolve, sep } from "node:path";
|
|
9
|
+
import { resolveSpawn } from "./winspawn.mjs";
|
|
9
10
|
import { fileURLToPath } from "node:url";
|
|
10
11
|
import { randomBytes } from "node:crypto";
|
|
11
12
|
import { runCliBackendAsync, resolveClaudeCliBinary, getClaudeCliCapabilities, buildLeanSessionFlags, buildReadOnlyToolFlags, sanitizeCliModel } from "../runner.mjs";
|
|
@@ -14,7 +15,9 @@ import { makeProjector } from "../engine/projector.mjs";
|
|
|
14
15
|
import { makeLedger, countLiveLanes, ledgerRoot } from "./ledger.mjs";
|
|
15
16
|
import { makeDepCache } from "./depcache.mjs";
|
|
16
17
|
import { makeHeavyIo } from "./heavy.mjs";
|
|
17
|
-
import { diskLow } from "./admission.mjs";
|
|
18
|
+
import { diskLow, ADMISSION_DEFAULTS } from "./admission.mjs";
|
|
19
|
+
import { writeAtomic } from "./batch.mjs";
|
|
20
|
+
import { schedDir } from "./sched.mjs";
|
|
18
21
|
import { gatherContextFacts } from "./context.mjs";
|
|
19
22
|
import { makePitfallStore } from "./pitfalls.mjs";
|
|
20
23
|
import { enumeratingTests, missingEntries } from "./enumerating.mjs";
|
|
@@ -29,6 +32,7 @@ import { parseVersioned } from "./seqversioned.mjs";
|
|
|
29
32
|
import { followupMap } from "./conformance.mjs";
|
|
30
33
|
import { toolStats } from "./toolstats.mjs";
|
|
31
34
|
import { detectApiShape } from "./apishape.mjs";
|
|
35
|
+
import { verifyLaneWorktree, quarantineDir } from "./laneconfine.mjs";
|
|
32
36
|
|
|
33
37
|
/** #5531: children started by this process's gh/script helpers still running; the schedd kills them on close so none outlives the daemon. */
|
|
34
38
|
const liveChildren = new Set();
|
|
@@ -39,7 +43,8 @@ export function killTrackedChildren(signal = "SIGKILL") {
|
|
|
39
43
|
return n;
|
|
40
44
|
}
|
|
41
45
|
export const trackedChildCount = () => liveChildren.size;
|
|
42
|
-
const pexec = (
|
|
46
|
+
const pexec = (bin0, args0, opts) => new Promise((res, rej) => {
|
|
47
|
+
const { bin, args } = resolveSpawn(bin0, args0, { env: opts?.env ?? process.env }); // #5799: npm .cmd shims on Windows
|
|
43
48
|
const child = execFile(bin, args, opts, (err, stdout, stderr) => {
|
|
44
49
|
liveChildren.delete(child);
|
|
45
50
|
if (err) { err.stdout = stdout; err.stderr = stderr; rej(err); } else res({ stdout, stderr });
|
|
@@ -132,7 +137,7 @@ export const leanSettingsFlags = ({ subagentModel = null, reread = false, guard
|
|
|
132
137
|
export function makeLeanRunner({ runCli = runCliBackendAsync, probe = systemdRunAvailable, subagentModel = null, sandboxed = inSandbox() } = {}) {
|
|
133
138
|
return async ({ role, issue, cwd, model, resume, system, prompt, readOnly = false, noTools = false, rereadNudge = false, maxTurns = null, agents = null, env = null, idleMs = 0, maxMs = 0, laneLimits = null, control = null, onSpawn = null, session = null, contextMax = 0, turnMax = 0, busy = null, busyMs = 0, onIdleExtend = null, bin: pinnedBin = null, fullSession = false }) => {
|
|
134
139
|
// #5205: a rotation relaunch pins the real claude past the tokenbaton shim; absent, the usual resolution
|
|
135
|
-
const bin = pinnedBin || resolveClaudeCliBinary(cwd) || "claude";
|
|
140
|
+
const bin = pinnedBin || resolveClaudeCliBinary(cwd) || resolveSpawn("claude", []).bin; // win32: a probe miss must not fall back to a bare name (spawn ENOENT)
|
|
136
141
|
const caps = getClaudeCliCapabilities(cwd);
|
|
137
142
|
// #4391: custom subagents (the explorer) for the builder session; null leaves argv unchanged
|
|
138
143
|
// #5516: fullSession keeps slash commands/Skill/Task (the release test gate invokes /test-gate); otherwise the lean minimal group
|
|
@@ -146,7 +151,8 @@ export function makeLeanRunner({ runCli = runCliBackendAsync, probe = systemdRun
|
|
|
146
151
|
idleMs, maxMs, stream: idleMs > 0, control, onSpawn, session, busy, busyMs, onIdleExtend, ...(contextMax > 0 ? { contextMax } : {}), ...(turnMax > 0 ? { turnMax } : {}), wrap: probe() ? (b, a) => wrapLaneLimits(b, a, laneLimits) : null });
|
|
147
152
|
// #4395: a resumed session's first turn carries the prior history, so only a fresh session reports a baseline.
|
|
148
153
|
return { text: r.text, sessionId: r.sessionId, usage: r.usage, costUsd: r.costUsd, durationMs: r.durationMs, turns: r.turns, model: r.cliModel ?? "default",
|
|
149
|
-
baselineTokens: resume ? null : (r.baselineTokens ?? null), tools: toolStats(r.toolUses)
|
|
154
|
+
baselineTokens: resume ? null : (r.baselineTokens ?? null), tools: toolStats(r.toolUses), // #4410: tool calls per turn, re-reads
|
|
155
|
+
endTokens: r.endTokens ?? null, toolUses: Array.isArray(r.toolUses) ? r.toolUses : null }; // #5812: the route hand-off sizes the plan session and lists what it read
|
|
150
156
|
};
|
|
151
157
|
}
|
|
152
158
|
|
|
@@ -261,9 +267,54 @@ export function guardHeavyDisk(heavy, { host, minFreeGb = () => null, gc = async
|
|
|
261
267
|
};
|
|
262
268
|
}
|
|
263
269
|
|
|
270
|
+
/**
|
|
271
|
+
* Lane ramp stamps (#5845): lanes are separate processes, so the lanes admitted within the ramp window are files in
|
|
272
|
+
* `schedDir()/lane-ramp/` (one `<pid>.json` per lane, `{pid, at, mb}`, so concurrent lanes never overwrite each other),
|
|
273
|
+
* plus `peaks.json` (recent peak RSS in MB, newest last). Every read fails open to null/0 and drops dead or expired stamps.
|
|
274
|
+
*/
|
|
275
|
+
const PEAKS_KEPT = 20;
|
|
276
|
+
export function makeRampStore({ dir = join(schedDir(), "lane-ramp"), now = () => Date.now(), pid = process.pid, defaultMb = ADMISSION_DEFAULTS.lane_mem_mb } = {}) {
|
|
277
|
+
const live = (rampS) => {
|
|
278
|
+
const out = [];
|
|
279
|
+
for (const f of readdirSync(dir)) {
|
|
280
|
+
if (!/^\d+\.json$/.test(f)) continue;
|
|
281
|
+
const file = join(dir, f);
|
|
282
|
+
try {
|
|
283
|
+
const st = JSON.parse(readFileSync(file, "utf8"));
|
|
284
|
+
const stale = now() - st.at >= Math.max(rampS, 1) * 1000 * 2; // kept for one extra window so a slightly longer ramp still sees it
|
|
285
|
+
if (stale || !pidAlive(st.pid)) { rmSync(file, { force: true }); continue; }
|
|
286
|
+
if (now() - st.at < rampS * 1000) out.push(st);
|
|
287
|
+
} catch { /* unreadable stamp: ignore */ }
|
|
288
|
+
}
|
|
289
|
+
return out;
|
|
290
|
+
};
|
|
291
|
+
const peaks = () => { try { return (JSON.parse(readFileSync(join(dir, "peaks.json"), "utf8")).peaks ?? []).filter(Number.isFinite); } catch { return []; } };
|
|
292
|
+
const footprint = () => {
|
|
293
|
+
const p = peaks();
|
|
294
|
+
if (!p.length) return defaultMb;
|
|
295
|
+
const sorted = [...p].sort((a, b) => a - b);
|
|
296
|
+
return Math.max(defaultMb, Math.ceil(sorted[Math.floor(sorted.length / 2)]), Math.ceil(sorted[sorted.length - 1] * 0.9)); // conservative: near the max, never under the default
|
|
297
|
+
};
|
|
298
|
+
const guard = (fn, fallback) => (...a) => { try { return fn(...a); } catch { return fallback; } };
|
|
299
|
+
return {
|
|
300
|
+
rampingMb: guard((rampS) => live(rampS).reduce((t, st) => t + (Number(st.mb) > 0 ? Number(st.mb) : defaultMb), 0), null),
|
|
301
|
+
rampingLanes: guard((rampS) => live(rampS).length, null),
|
|
302
|
+
laneFootprintMb: guard(footprint, null),
|
|
303
|
+
/** Called once this lane passed admission: it will grow for the next ramp window. */
|
|
304
|
+
recordAdmission: guard((mb = footprint()) => { writeAtomic(join(dir, `${pid}.json`), JSON.stringify({ pid, at: now(), mb })); return true; }, false),
|
|
305
|
+
/** Called at lane end with the lane's peak RSS in MB. */
|
|
306
|
+
recordPeakRss: guard((mb) => {
|
|
307
|
+
if (!(Number(mb) > 0)) return false;
|
|
308
|
+
writeAtomic(join(dir, "peaks.json"), JSON.stringify({ peaks: [...peaks(), Math.ceil(Number(mb))].slice(-PEAKS_KEPT) }));
|
|
309
|
+
return true;
|
|
310
|
+
}, false),
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
264
314
|
/** Real host probes for admission (#4105). MemAvailable from /proc/meminfo (fallback os.freemem), statfs for tmp. */
|
|
265
315
|
export function makeHostProbe() {
|
|
266
316
|
return {
|
|
317
|
+
...makeRampStore(),
|
|
267
318
|
memAvailableMb() {
|
|
268
319
|
try {
|
|
269
320
|
const m = /^MemAvailable:\s+(\d+)\s+kB/m.exec(readFileSync("/proc/meminfo", "utf8"));
|
|
@@ -446,6 +497,21 @@ export function makeLeanIo({ repo, subagentModel = readSubagentModel() }) {
|
|
|
446
497
|
deps: makeDepCache({ exec: async (cmd, args, { cwd, env, timeoutMs } = {}) => String((await pexec(cmd, args, { cwd, env: { ...process.env, ...(env ?? {}) }, timeout: timeoutMs ?? 0, maxBuffer: 100 * 1024 * 1024 })).stdout) }),
|
|
447
498
|
/** Names of the checks the base branch requires: classic protection plus rulesets (#4158). [] when neither has any. */
|
|
448
499
|
async requiredChecks(lane) { return requiredChecksFor({ gh: run("gh"), repo, lane }); },
|
|
500
|
+
/**
|
|
501
|
+
* #5820: the scripts/ci-local plan of the lane's change (CI definitions from the base ref plus the lane's edits, change
|
|
502
|
+
* scoped), in a child process so the yq calls never block the lane. Rejects with ci-local's DEGRADED reason (no yq).
|
|
503
|
+
*/
|
|
504
|
+
async ciLocalPlan({ repo: wt, base, baseBranch, files = [] }) {
|
|
505
|
+
const list = join(wt, ".forge-lean", "ci-precheck", "files.txt");
|
|
506
|
+
mkdirSync(dirname(list), { recursive: true }); writeFileSync(list, `${files.join("\n")}\n`);
|
|
507
|
+
try {
|
|
508
|
+
const { stdout } = await pexec(process.execPath, [script("ci-local/cli.mjs"), "plan", "--repo", wt, "--base", base, "--base-branch", baseBranch, "--files-from", list, "--json"], { cwd: wt, timeout: 120000, maxBuffer: 64 * 1024 * 1024 });
|
|
509
|
+
return JSON.parse(String(stdout));
|
|
510
|
+
} catch (e) {
|
|
511
|
+
const why = /CI_LOCAL_RESULT: DEGRADED reason=(.*)/.exec(String(e?.stdout ?? ""))?.[1] ?? String(e?.stderr || e?.message || e).split("\n")[0];
|
|
512
|
+
throw new Error(why);
|
|
513
|
+
}
|
|
514
|
+
},
|
|
449
515
|
/** [{name, state: success|failure|pending, url, head}] for the PR's checks; `head` is the PR head the rollup belongs to (#4240). */
|
|
450
516
|
async checkStates(pr) {
|
|
451
517
|
const j = JSON.parse(await run("gh")(["pr", "view", String(pr), "-R", repo, "--json", "statusCheckRollup,headRefOid"]));
|
|
@@ -646,6 +712,8 @@ export function makeLeanIo({ repo, subagentModel = readSubagentModel() }) {
|
|
|
646
712
|
return { ok: false, output: `${e.stdout ?? ""}${e.stderr ?? ""}`.slice(0, 6000) };
|
|
647
713
|
}
|
|
648
714
|
},
|
|
715
|
+
/** #5825: is the lane folder a worktree of this repo (toplevel + common dir), and moving aside a folder that is not. */
|
|
716
|
+
confine: { verify: ({ wt, cwd }) => verifyLaneWorktree({ git: run("git"), exists: async (p) => existsSync(p), wt, cwd }), quarantine: async ({ wt }) => quarantineDir(wt) },
|
|
649
717
|
/** #4162: processes left running inside a lane worktree (Linux /proc). */
|
|
650
718
|
proc: { inDir: async (dir) => procsInDir(dir), alive: pidAlive, kill: (pid, sig) => { try { process.kill(pid, sig); } catch { /* already gone */ } } },
|
|
651
719
|
fs: {
|
package/bin/lean/execution.mjs
CHANGED
|
@@ -64,6 +64,7 @@ import { OUTCOME_CODES } from "../engine/outcome-codes.mjs";
|
|
|
64
64
|
import { validateLaneTools } from "../pool/lane-tools.mjs";
|
|
65
65
|
import { resolveCredential, memoKeychain, defaultKeychain } from "./credentials.mjs";
|
|
66
66
|
import { httpTransport, isActionsEndpoint, remoteProvider } from "./sandbox-remote.mjs";
|
|
67
|
+
import { actionsProvider, laneCap } from "./sandbox-actions.mjs";
|
|
67
68
|
import { ADMISSION_DEFAULTS } from "./admission.mjs";
|
|
68
69
|
import { classifyStep, heavyConfig, memAvailableMb } from "./heavy.mjs";
|
|
69
70
|
import { detectPins } from "./toolchain.mjs";
|
|
@@ -72,7 +73,7 @@ import { parseRelayCommands } from "./relay.mjs";
|
|
|
72
73
|
import { detectUsageLimit, parseSessionLimitResetEpochMs } from "../runner.mjs";
|
|
73
74
|
|
|
74
75
|
export const EXECUTION_MODES = Object.freeze(["local", "remote", "hybrid"]);
|
|
75
|
-
export const SANDBOX_PROVIDERS = Object.freeze(["local", "container", "remote", "pool"]);
|
|
76
|
+
export const SANDBOX_PROVIDERS = Object.freeze(["local", "container", "remote", "pool", "actions"]);
|
|
76
77
|
const NAME_RE = /^[a-z][a-z0-9-]*$/;
|
|
77
78
|
const CAPABILITY_RE = /^[a-z][a-z0-9_-]*$/;
|
|
78
79
|
const safeRegExp = (src) => { try { return new RegExp(src, "i"); } catch { return null; } };
|
|
@@ -146,7 +147,13 @@ export function parseExecution(sec = {}) {
|
|
|
146
147
|
// #5094: rotator.mjs reads its per-account quota state; #5205: off/none/false disables auto-detection, anything else is unset (auto)
|
|
147
148
|
const rot = str(s.account_rotator).toLowerCase(), accountRotator = rot === "tokenbaton" ? "tokenbaton" : ["off", "none", "false"].includes(rot) ? "off" : null;
|
|
148
149
|
const unreachableWindowMin = str(s.unreachable_window_min) !== "" && Number.isFinite(uw) && uw >= 0 ? uw : null; // unset: providerLanes defaults to 5
|
|
149
|
-
|
|
150
|
+
// #5748: the `actions` provider's plan (concurrent-job limit), explicit job_limit, CI reserve and dispatcher identity
|
|
151
|
+
const jl = Number(str(s.job_limit)), cr = Number(str(s.ci_reserve));
|
|
152
|
+
const jobLimit = str(s.job_limit) !== "" && Number.isInteger(jl) && jl > 0 ? jl : null;
|
|
153
|
+
const ciReserve = str(s.ci_reserve) !== "" && Number.isInteger(cr) && cr >= 0 ? cr : null;
|
|
154
|
+
const plan = ["free", "pro", "team", "enterprise"].includes(str(s.plan).toLowerCase()) ? str(s.plan).toLowerCase() : null;
|
|
155
|
+
const dispatcher = /^[A-Za-z0-9][A-Za-z0-9-]*(\[bot\])?$/.test(str(s.dispatcher)) ? str(s.dispatcher) : null;
|
|
156
|
+
return { mode, maxRemote, provider, image, secrets, budget, ...(jobLimit ? { jobLimit } : {}), ...(ciReserve !== null ? { ciReserve } : {}), ...(plan ? { plan } : {}), ...(dispatcher ? { dispatcher } : {}), ...(hostFallback !== null ? { hostFallback } : {}), ...(hostCapabilities.length ? { hostCapabilities } : {}), ...(hostCapabilityPatterns.length ? { hostCapabilityPatterns } : {}), ...(endpoint ? { endpoint } : {}), ...(tokenEnv ? { tokenEnv } : {}), ...(tokenFile ? { tokenFile } : {}), ...(cacheStore ? { cacheStore } : {}), ...(allowActions ? { allowActions } : {}), ...(fallbackLocal ? { fallbackLocal } : {}), ...(capacityFallbackAfter !== null ? { capacityFallbackAfter } : {}), ...(heavy !== null ? { heavy } : {}), ...(unreachableWindowMin !== null ? { unreachableWindowMin } : {}), ...(Object.keys(relay).length ? { relay } : {}), ...(warmSandboxes ? { warmSandboxes } : {}), ...(accountRotator ? { accountRotator } : {}), ...(lt.tools.length ? { laneTools: lt.tools } : {}), ...(lt.errors.length ? { laneToolsErrors: lt.errors } : {}) };
|
|
150
157
|
}
|
|
151
158
|
|
|
152
159
|
const round1 = (x) => Math.round(x * 10) / 10;
|
|
@@ -215,6 +222,25 @@ export function openExecutionBudget({ budget = {}, file = executionBudgetFile(),
|
|
|
215
222
|
};
|
|
216
223
|
}
|
|
217
224
|
|
|
225
|
+
/**
|
|
226
|
+
* #5748: the product default. An `execution.mode` that forge.yaml does not set (`exec.modeExplicit` unset) on a public repo
|
|
227
|
+
* places lanes on GitHub-hosted runners (`provider: actions`, free minutes), capped at the plan's job limit minus a CI reserve.
|
|
228
|
+
* A private repo, an unknown visibility (`isPublic` not true: fails closed) and any explicit mode, `local` included, keep
|
|
229
|
+
* `exec` as is.
|
|
230
|
+
*/
|
|
231
|
+
export function resolveDefaultExecution(exec, { isPublic = false } = {}) {
|
|
232
|
+
if (exec?.modeExplicit || isPublic !== true) return exec;
|
|
233
|
+
const base = exec ?? parseExecution({});
|
|
234
|
+
const cap = laneCap({ jobLimit: base.jobLimit ?? null, plan: base.plan ?? null, ciReserve: base.ciReserve });
|
|
235
|
+
return { ...base, mode: "remote", provider: "actions", maxRemote: cap, defaultedActions: true };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** #5748: whether `repo` is public, from `gh api repos/<repo>`; any failure is false (private: today's default). */
|
|
239
|
+
export async function repoIsPublic({ repo, gh }) {
|
|
240
|
+
if (!repo || typeof gh !== "function") return false;
|
|
241
|
+
try { return JSON.parse(await gh(["api", `repos/${repo}`]))?.private === false; } catch { return false; }
|
|
242
|
+
}
|
|
243
|
+
|
|
218
244
|
/** Where a `mode: remote` lane runs: remote only with `max_remote >= 1`. Hybrid is placed per lane by `placeLane` (#4256). */
|
|
219
245
|
export function placement(exec) {
|
|
220
246
|
return exec?.mode === "remote" && Number.isInteger(exec.maxRemote) && exec.maxRemote >= 1 ? "remote" : "local";
|
|
@@ -439,7 +465,8 @@ export function hostHeadroom({ cfg = {}, heavyCfg = {}, host = { memAvailableMb,
|
|
|
439
465
|
if (c.enabled === false) return { ok: true, detail: "" };
|
|
440
466
|
const reasons = [];
|
|
441
467
|
const need = c.min_free_mem_mb + h.step_mem_mb, mem = probe(host?.memAvailableMb);
|
|
442
|
-
|
|
468
|
+
const ramping = mem === null ? 0 : Math.max(0, probe(() => host?.rampingMb?.(c.ramp_s)) ?? 0); // #5845: lanes admitted within the ramp window have not grown yet
|
|
469
|
+
if (mem !== null && mem - ramping < need) reasons.push(ramping > 0 ? `mem ${mem} MB − ramping ${ramping} MB < ${need} MB` : `mem ${mem} MB < ${need} MB`);
|
|
443
470
|
const maxLoad = typeof c.max_load_per_core === "number" && Number.isFinite(c.max_load_per_core) ? c.max_load_per_core : null;
|
|
444
471
|
if (maxLoad !== null) {
|
|
445
472
|
const load = probe(host?.loadAvg1), cores = probe(host?.cores);
|
|
@@ -602,6 +629,7 @@ export function poolRouterConfig({ env = process.env, path = env.COMPUTESHARE_CO
|
|
|
602
629
|
export function providerByName(name, opts) {
|
|
603
630
|
if (name === "local") return localProvider(opts);
|
|
604
631
|
if (name === "container") return containerProvider(opts);
|
|
632
|
+
if (name === "actions") return actionsProvider({ batch: opts.batch, repo: opts.repo, settings: opts.exec ?? {}, env: opts?.env ?? process.env, ...(opts?.transport ? { transport: opts.transport } : {}), ...(opts?.actionsApi ? { api: opts.actionsApi } : {}), ...(opts?.now ? { now: opts.now } : {}) });
|
|
605
633
|
if (name === "remote" || name === "pool") {
|
|
606
634
|
const env = opts?.env ?? process.env;
|
|
607
635
|
const exec = opts?.exec ?? {};
|
|
@@ -682,6 +710,13 @@ export function providerLanes({ provider, laneArgs, ledgerFor, env = process.env
|
|
|
682
710
|
if (ok) { try { led?.release("sandbox", h.id); led?.remove(); } catch { /* the reaper retries */ } }
|
|
683
711
|
return ok;
|
|
684
712
|
};
|
|
713
|
+
// #5808: the result is handed back at once; the teardown starts now and the dispatcher's postRun hook waits for it (the batch
|
|
714
|
+
// never ends before it, the ledger still holds the sandbox until it is released), so it is off the slot's path.
|
|
715
|
+
const tearAfter = (led, h, r) => {
|
|
716
|
+
const torn = tear(led, h), prev = r && typeof r === "object" && typeof r.postRun === "function" ? r.postRun : null;
|
|
717
|
+
const postRun = async () => { await torn; if (prev) await prev(); };
|
|
718
|
+
return (r && typeof r === "object") ? { ...r, postRun } : r;
|
|
719
|
+
};
|
|
685
720
|
// #4672: a transport failure (router restart, refused/reset connection, 502/503/504) is retried with backoff until the lane has
|
|
686
721
|
// waited `unreachableWindowMs` in a row without one successful poll; then it ends sandbox.unreachable with the sandbox kept.
|
|
687
722
|
const guard = (st) => async (fn) => {
|
|
@@ -774,8 +809,8 @@ export function providerLanes({ provider, laneArgs, ledgerFor, env = process.env
|
|
|
774
809
|
if (started && e?.unreachable) return withUsage(unreachable(h, e), h); // #4672: no tear, the ledger keeps it
|
|
775
810
|
r = started ? settleClone({ terminalReason: "engine-error", detail: `sandbox ${base.id}: ${errText(e)}` }, base.id) : startFailed(base.id, e);
|
|
776
811
|
}
|
|
777
|
-
|
|
778
|
-
return started ? withUsage(
|
|
812
|
+
const torn = tearAfter(led, h, r); // every path, after the result is in (tear never throws); #5808: not awaited here
|
|
813
|
+
return started ? withUsage(torn, h) : torn; // a sandbox that never started used nothing
|
|
779
814
|
},
|
|
780
815
|
adopt: (n, rec, ctx = {}) => adoptSaved(n, rec, ctx),
|
|
781
816
|
};
|
|
@@ -803,8 +838,7 @@ export function providerLanes({ provider, laneArgs, ledgerFor, env = process.env
|
|
|
803
838
|
if (e?.unreachable) return withUsage(unreachable(h, e), h); // #4672: same tolerance; no tear, left for the next adopt
|
|
804
839
|
r = { terminalReason: "engine-error", detail: `sandbox ${h.id}: ${errText(e)}` };
|
|
805
840
|
}
|
|
806
|
-
|
|
807
|
-
return withUsage(r, h);
|
|
841
|
+
return withUsage(tearAfter(led, h, r), h); // #5808: teardown runs after the result is handed back
|
|
808
842
|
}
|
|
809
843
|
// A leftover ledger entry of this lane's sandbox: its result if it can still be had, else null (torn down by the caller).
|
|
810
844
|
async function adoptLeft(n, left, ctx) {
|
|
@@ -7,7 +7,7 @@ import { mkdirSync, writeFileSync, existsSync, readFileSync } from "node:fs";
|
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
9
9
|
import { renderContract } from "./render.mjs";
|
|
10
|
-
import { parseExecution, hostFallbackAllowed, SANDBOX_PROVIDERS, detectNeeds, hostCapabilityBlock, placementText, contractHostNeeds, placement, placeLane, validationWeight, hostHeadroom, scopedEnv, providerLanes, remoteHoldId, usageLimitInTail, isTransportError, isCloneFailure, containerProvider, providerByName, openExecutionBudget, poolCredential, remoteTransportFor } from "./execution.mjs";
|
|
10
|
+
import { parseExecution, hostFallbackAllowed, SANDBOX_PROVIDERS, detectNeeds, hostCapabilityBlock, placementText, contractHostNeeds, placement, placeLane, validationWeight, hostHeadroom, scopedEnv, providerLanes, remoteHoldId, usageLimitInTail, isTransportError, isCloneFailure, containerProvider, providerByName, openExecutionBudget, poolCredential, remoteTransportFor, resolveDefaultExecution, repoIsPublic } from "./execution.mjs";
|
|
11
11
|
import * as executionModule from "./execution.mjs";
|
|
12
12
|
import { remoteProvider } from "./sandbox-remote.mjs";
|
|
13
13
|
import { makeLedger, countLiveLanes } from "./ledger.mjs";
|
|
@@ -161,6 +161,49 @@ describe("providerLanes: an unreachable provider is retried, then deferred witho
|
|
|
161
161
|
});
|
|
162
162
|
});
|
|
163
163
|
|
|
164
|
+
describe("providerLanes: runOne returns the result before sandbox teardown (#5808)", () => {
|
|
165
|
+
const setup = (usage) => {
|
|
166
|
+
const root = tmpDir("exec-5808-");
|
|
167
|
+
const ledgerFor = ledgerIn(root);
|
|
168
|
+
const prov = fakeProvider({ finish: () => ({ terminalReason: "merged", pr: 9 }), ...(usage ? { usage } : {}) });
|
|
169
|
+
let release;
|
|
170
|
+
const gate = new Promise((res) => { release = res; });
|
|
171
|
+
const origTeardown = prov.teardown;
|
|
172
|
+
prov.teardown = async (h) => { await gate; return origTeardown(h); };
|
|
173
|
+
const lanes = providerLanes({ provider: prov, laneArgs: () => [], ledgerFor, pollMs: 1, now: () => 1000 });
|
|
174
|
+
return { prov, lanes, release, led: ledgerFor(7) };
|
|
175
|
+
};
|
|
176
|
+
it("runOne resolves while teardown is pending; postRun finishes it and releases the ledger", async () => {
|
|
177
|
+
const { prov, lanes, release, led } = setup();
|
|
178
|
+
const r = await lanes.runOne(7, "staging"); // resolves although provider.teardown is still gated
|
|
179
|
+
assert.equal(r.terminalReason, "merged");
|
|
180
|
+
assert.equal(typeof r.postRun, "function");
|
|
181
|
+
assert.deepEqual(led.entries("sandbox").map((e) => e.value), ["fake-7"]); // still listed until torn down
|
|
182
|
+
release();
|
|
183
|
+
await r.postRun();
|
|
184
|
+
assert.ok(prov.calls.some((c) => c[0] === "teardown" && c[1] === "fake-7"));
|
|
185
|
+
assert.equal(led.read(), null);
|
|
186
|
+
});
|
|
187
|
+
it("a failed teardown keeps the entry for the reaper after postRun", async () => {
|
|
188
|
+
const root = tmpDir("exec-5808b-");
|
|
189
|
+
const ledgerFor = ledgerIn(root);
|
|
190
|
+
const prov = fakeProvider({ finish: () => ({ terminalReason: "merged" }), teardownOk: false });
|
|
191
|
+
const r = await providerLanes({ provider: prov, laneArgs: () => [], ledgerFor, pollMs: 1 }).runOne(7, null);
|
|
192
|
+
await r.postRun();
|
|
193
|
+
assert.deepEqual(ledgerFor(7).entries("sandbox").map((e) => e.value), ["fake-7"]);
|
|
194
|
+
});
|
|
195
|
+
it("an unreachable provider still ends without a teardown", async () => {
|
|
196
|
+
const root = tmpDir("exec-5808c-");
|
|
197
|
+
const ledgerFor = ledgerIn(root);
|
|
198
|
+
const prov = fakeProvider();
|
|
199
|
+
prov.fetchResult = async () => { throw Object.assign(new Error("ECONNRESET"), { code: "ECONNRESET" }); };
|
|
200
|
+
prov.status = async () => { throw Object.assign(new Error("ECONNRESET"), { code: "ECONNRESET" }); };
|
|
201
|
+
const r = await providerLanes({ provider: prov, laneArgs: () => [], ledgerFor, pollMs: 1, unreachableWindowMs: 0, sleep: async () => {} }).runOne(7, null);
|
|
202
|
+
assert.equal(prov.calls.some((c) => c[0] === "teardown"), false);
|
|
203
|
+
assert.equal(r.postRun, undefined);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
164
207
|
describe("providerLanes: sandbox ledger and teardown on every exit path (#4253)", () => {
|
|
165
208
|
const run = async ({ finish, startThrows, teardownOk, pollMs = 1 } = {}) => {
|
|
166
209
|
const root = tmpDir("exec-ledger-");
|
|
@@ -171,7 +214,8 @@ describe("providerLanes: sandbox ledger and teardown on every exit path (#4253)"
|
|
|
171
214
|
sleep: async () => { if (++ticks === 2 && !finish) { prov.results[7] = { terminalReason: "merged", pr: 9 }; prov.live.delete(7); } } });
|
|
172
215
|
const started = [];
|
|
173
216
|
const r = await lanes.runOne(7, "staging", { onStart: (i) => started.push(i) });
|
|
174
|
-
|
|
217
|
+
await r.postRun?.(); // #5808: the teardown runs after the result is handed back
|
|
218
|
+
return { r: Object.fromEntries(Object.entries(r).filter(([k]) => k !== "postRun")), prov, started, led: ledgerFor(7) };
|
|
175
219
|
};
|
|
176
220
|
|
|
177
221
|
it("success: registered before start, result reaches the batch, torn down and released", async () => {
|
|
@@ -226,7 +270,8 @@ describe("providerLanes: sandbox ledger and teardown on every exit path (#4253)"
|
|
|
226
270
|
const prov = fakeProvider();
|
|
227
271
|
prov.live.add(7);
|
|
228
272
|
const lanes = providerLanes({ provider: prov, laneArgs: () => [], ledgerFor, pollMs: 1, sleep: async () => { prov.results[7] = { terminalReason: "merged", pr: 3 }; prov.live.delete(7); } });
|
|
229
|
-
const r = await lanes.adopt(7, { pid: undefined, remote: true, handle: { provider: "fake", id: "fake-7", issue: 7 } });
|
|
273
|
+
const { postRun, ...r } = await lanes.adopt(7, { pid: undefined, remote: true, handle: { provider: "fake", id: "fake-7", issue: 7 } });
|
|
274
|
+
await postRun(); // #5808
|
|
230
275
|
assert.deepEqual(r, { terminalReason: "merged", pr: 3, sandbox: { provider: "fake", id: "fake-7", minutes: 0, cost_usd: 0 } });
|
|
231
276
|
assert.ok(prov.calls.some((c) => c[0] === "teardown"));
|
|
232
277
|
assert.equal(ledgerFor(7).read(), null);
|
|
@@ -964,6 +1009,21 @@ describe("host capabilities in placement (#4542)", () => {
|
|
|
964
1009
|
assert.equal(rows.find((r) => r.issue === 5).outcome, "merged");
|
|
965
1010
|
});
|
|
966
1011
|
|
|
1012
|
+
it("#5727 placeOf does not retry a recipe-less tool miss remotely", async () => {
|
|
1013
|
+
for (const toolNoRecipe of [true, false]) {
|
|
1014
|
+
const calls = [];
|
|
1015
|
+
await orchestrate({ issues: [5], parallel: 2, recovery: { maxAttempts: 1 }, readBody: async () => "",
|
|
1016
|
+
remote: { max: 2, isRemote: () => true, place: () => ({ where: "remote", reason: "mode remote" }), admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 },
|
|
1017
|
+
runOne: async (n, _l, ctx = {}) => {
|
|
1018
|
+
calls.push({ placement: ctx.placement?.where, reason: ctx.placement?.reason });
|
|
1019
|
+
return ctx.recover ? { terminalReason: "merged", pr: 9 } : { terminalReason: "needs-human", code: "env.tool_missing", detail: "Remote sandbox lacks forgedock, and no lane_tools recipe exists for it.", placement: { where: "remote" }, ...(toolNoRecipe ? { toolNoRecipe } : {}) };
|
|
1020
|
+
} });
|
|
1021
|
+
assert.equal(calls.length, 2);
|
|
1022
|
+
if (toolNoRecipe) { assert.equal(calls[1].placement, "local"); assert.notEqual(calls[1].reason, "retry remotely after sandbox provisioning"); }
|
|
1023
|
+
else assert.equal(calls[1].reason, "retry remotely after sandbox provisioning");
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
|
|
967
1027
|
it("#5371 orchestrate: a remote env.validate_placement or mechanical failure is requeued on a different placement", async () => {
|
|
968
1028
|
for (const code of ["env.validate_placement", "env.repro_unrunnable"]) {
|
|
969
1029
|
const calls = [];
|
|
@@ -1261,3 +1321,39 @@ describe("providerLanes: a halted batch keeps its sandbox for adopt (#5669)", ()
|
|
|
1261
1321
|
assert.equal(r.terminalReason, "merged");
|
|
1262
1322
|
});
|
|
1263
1323
|
});
|
|
1324
|
+
|
|
1325
|
+
describe("public-repo default placement (#5748)", () => {
|
|
1326
|
+
it("actions is a known provider; plan, job_limit, ci_reserve and dispatcher parse", () => {
|
|
1327
|
+
assert.ok(SANDBOX_PROVIDERS.includes("actions"));
|
|
1328
|
+
assert.equal(providerByName("actions", { batch: { id: "b" }, repo: "o/r", exec: {}, actionsApi: async () => null }).name, "actions");
|
|
1329
|
+
const e = parseExecution({ plan: "Team", job_limit: "30", ci_reserve: "4", dispatcher: "forgedock[bot]" });
|
|
1330
|
+
assert.deepEqual([e.plan, e.jobLimit, e.ciReserve, e.dispatcher], ["team", 30, 4, "forgedock[bot]"]);
|
|
1331
|
+
for (const k of ["jobLimit", "ciReserve", "plan", "dispatcher"]) assert.ok(!(k in parseExecution({ plan: "x", job_limit: "0", ci_reserve: "-1", dispatcher: "a b" })));
|
|
1332
|
+
});
|
|
1333
|
+
it("public + mode unset -> actions, capped at job limit minus reserve; private or unknown visibility unchanged", () => {
|
|
1334
|
+
const d = resolveDefaultExecution(undefined, { isPublic: true });
|
|
1335
|
+
assert.equal(d.provider, "actions"); assert.equal(placement(d), "remote"); assert.equal(d.maxRemote, 15);
|
|
1336
|
+
assert.equal(placeLane({ exec: d }).where, "remote");
|
|
1337
|
+
assert.equal(resolveDefaultExecution(parseExecution({ plan: "team", ci_reserve: "10" }), { isPublic: true }).maxRemote, 50);
|
|
1338
|
+
const base = parseExecution({ image: "i:1" });
|
|
1339
|
+
assert.equal(resolveDefaultExecution(base, { isPublic: false }), base);
|
|
1340
|
+
assert.equal(resolveDefaultExecution(base, {}), base);
|
|
1341
|
+
assert.equal(resolveDefaultExecution(undefined, { isPublic: false }), undefined);
|
|
1342
|
+
});
|
|
1343
|
+
it("an explicit mode always wins, local included", () => {
|
|
1344
|
+
for (const mode of ["local", "remote", "hybrid"]) {
|
|
1345
|
+
const e = { ...parseExecution({ mode, max_remote: "2", provider: "pool" }), modeExplicit: true };
|
|
1346
|
+
assert.equal(resolveDefaultExecution(e, { isPublic: true }), e);
|
|
1347
|
+
}
|
|
1348
|
+
});
|
|
1349
|
+
it("a defaulted lane that needs a host capability still places local", () => {
|
|
1350
|
+
assert.equal(placeLane({ exec: resolveDefaultExecution(undefined, { isPublic: true }), needs: ["sops"] }).where, "local");
|
|
1351
|
+
});
|
|
1352
|
+
it("repoIsPublic reads private:false and fails closed", async () => {
|
|
1353
|
+
assert.equal(await repoIsPublic({ repo: "o/r", gh: async () => JSON.stringify({ private: false }) }), true);
|
|
1354
|
+
assert.equal(await repoIsPublic({ repo: "o/r", gh: async () => JSON.stringify({ private: true }) }), false);
|
|
1355
|
+
assert.equal(await repoIsPublic({ repo: "o/r", gh: async () => { throw new Error("timeout"); } }), false);
|
|
1356
|
+
assert.equal(await repoIsPublic({ repo: "o/r", gh: async () => "not json" }), false);
|
|
1357
|
+
assert.equal(await repoIsPublic({ repo: null, gh: async () => "{}" }), false);
|
|
1358
|
+
});
|
|
1359
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
// #5748: the lane workflow's security shape, checked as text (zero LLM).
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const text = readFileSync(fileURLToPath(new URL("../../.github/workflows/forgedock-lane.yml", import.meta.url)), "utf8");
|
|
10
|
+
const code = text.split("\n").filter((l) => !l.trim().startsWith("#")).join("\n");
|
|
11
|
+
|
|
12
|
+
describe("forgedock-lane.yml (#5748)", () => {
|
|
13
|
+
it("triggers on workflow_dispatch only, never pull_request or pull_request_target", () => {
|
|
14
|
+
const on = /^on:\n((?:[ ]+.*\n|\n)+)/m.exec(code)[1];
|
|
15
|
+
assert.deepEqual([...on.matchAll(/^ ([a-z_]+):/gm)].map((m) => m[1]), ["workflow_dispatch"]);
|
|
16
|
+
assert.doesNotMatch(code, /pull_request/);
|
|
17
|
+
});
|
|
18
|
+
it("has least-privilege permissions, an environment holding the credential, and a job limit under 6 h", () => {
|
|
19
|
+
assert.match(code, /^permissions:\n contents: write\n issues: write\n pull-requests: write\n/m);
|
|
20
|
+
assert.doesNotMatch(code, /permissions:[\s\S]*(actions|packages|id-token|security-events): write/);
|
|
21
|
+
assert.match(code, /environment: forgedock-lane/);
|
|
22
|
+
assert.match(code, /secrets\.CLAUDE_CODE_OAUTH_TOKEN/);
|
|
23
|
+
const m = /timeout-minutes: (\d+)/.exec(code); assert.ok(m && Number(m[1]) < 360);
|
|
24
|
+
assert.match(code, /timeout 345m forgedock run-issue/);
|
|
25
|
+
assert.doesNotMatch(code, /run-issue[^\n]*\|\| true/); // the cap must not be swallowed: rc 124 posts the retryable deferral
|
|
26
|
+
assert.match(code, /\[ "\$rc" = 124 \][\s\S]*sandbox\.actions_timeout/);
|
|
27
|
+
});
|
|
28
|
+
it("keeps inputs out of shell text, pushes to feat/* only and never echoes env or secrets", () => {
|
|
29
|
+
assert.doesNotMatch(code, /run:[^\n]*\$\{\{ *inputs\./);
|
|
30
|
+
assert.match(code, /refs\/heads\/feat\/\*/);
|
|
31
|
+
assert.doesNotMatch(code, /\b(printenv|set -x)\b|\benv\s*(\||$)|echo[^\n]*(secrets\.|TOKEN)/m);
|
|
32
|
+
assert.match(code, /run-issue[^\n]*> \/dev\/null 2>&1/);
|
|
33
|
+
assert.match(code, /run-name: forgedock-lane \$\{\{ inputs\.lane_id \}\}/);
|
|
34
|
+
});
|
|
35
|
+
});
|
package/bin/lean/guardgate.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { dirname, extname, join } from "node:path";
|
|
|
13
13
|
import { OUTCOME_CODES } from "../engine/outcome-codes.mjs";
|
|
14
14
|
import { collectGuards, guardsIndexPath, readIndex, writeIndex } from "./guards.mjs";
|
|
15
15
|
import { isTestPath } from "./enumerating.mjs";
|
|
16
|
+
import { isWeakGuardTest } from "./weakguard.mjs";
|
|
16
17
|
|
|
17
18
|
export const GUARD_CAP_MS = 120000;
|
|
18
19
|
export const INDEX_MAX_AGE_MS = 6 * 3600000;
|
|
@@ -178,6 +179,7 @@ export async function runGuards({ selected, mergeBase, contract, guardCommand, g
|
|
|
178
179
|
const materialize = async (j) => {
|
|
179
180
|
let body;
|
|
180
181
|
try { body = await git(["show", `${mergeBase}:${j.path}`]); } catch { skipped.push(`#${j.guard.issue} ${j.path}: not on base`); return false; }
|
|
182
|
+
j.weak = isWeakGuardTest(body, j.path); // #5752: only asserts literals exist in file text: a review note, never a park
|
|
181
183
|
const abs = join(cwd, j.copy);
|
|
182
184
|
try { fs.mkdirSync(dirname(abs), { recursive: true }); fs.writeFileSync(abs, body); made.push(abs); return true; } catch (e) { skipped.push(`#${j.guard.issue} ${j.path}: ${String(e?.message ?? e).slice(0, 80)}`); return false; }
|
|
183
185
|
};
|
|
@@ -203,7 +205,7 @@ export async function runGuards({ selected, mergeBase, contract, guardCommand, g
|
|
|
203
205
|
try { r = await runCommand({ command, cwd, timeoutMs: capMs - (now() - t0), env }); } catch (e) { r = { rc: 127, output: String(e?.message ?? e) }; }
|
|
204
206
|
if (r?.rc !== 0) return;
|
|
205
207
|
batches++;
|
|
206
|
-
for (const j of ready) { settled.add(j); runs.push({ issue: j.guard.issue, why: j.guard.why, test: j.path, command, rc: 0, output: String(r?.output ?? ""), failed: null }); }
|
|
208
|
+
for (const j of ready) { settled.add(j); runs.push({ issue: j.guard.issue, why: j.guard.why, test: j.path, command, rc: 0, output: String(r?.output ?? ""), failed: null, weak: Boolean(j.weak) }); }
|
|
207
209
|
}));
|
|
208
210
|
return settled;
|
|
209
211
|
};
|
|
@@ -226,7 +228,7 @@ export async function runGuards({ selected, mergeBase, contract, guardCommand, g
|
|
|
226
228
|
if (v.skip) { skipped.push(`guard #${j.guard.issue} ${j.path}: ${v.skip}`); continue; }
|
|
227
229
|
if (v.fresh) failed = v.fresh;
|
|
228
230
|
}
|
|
229
|
-
runs.push({ issue: j.guard.issue, why: j.guard.why, test: j.path, command: j.command, rc, output, failed });
|
|
231
|
+
runs.push({ issue: j.guard.issue, why: j.guard.why, test: j.path, command: j.command, rc, output, failed, weak: Boolean(j.weak) });
|
|
230
232
|
}
|
|
231
233
|
};
|
|
232
234
|
await Promise.all(Array.from({ length: Math.max(1, Math.min(parallelism, queue.length)) }, work));
|
|
@@ -245,19 +247,40 @@ export async function runGuards({ selected, mergeBase, contract, guardCommand, g
|
|
|
245
247
|
/** The only override of a guard_broken failure, named for the builder (#4883); leads the detail so the resume prompt's truncation keeps it. */
|
|
246
248
|
const supersedesHint = (guard) => `If this change intentionally changes the guarded behaviour (e.g. adding a code to an enum an exhaustiveness test enumerates), add {"kind":"supersedes","guard":"${guard}","why":"..."} to the amendments in the result file; the reviewer judges it.`;
|
|
247
249
|
|
|
248
|
-
/** conformance.guard_broken rows (one per failing guard test): the guard's issue, its one-line why, the failing test and its output tail. */
|
|
250
|
+
/** conformance.guard_broken rows (one per failing strong guard test): the guard's issue, its one-line why, the failing test and its output tail. #5752: weak runs are notes (weakGuardNotes). */
|
|
249
251
|
export function guardFailures(runs) {
|
|
250
|
-
return (runs ?? []).filter((r) => r.rc !== 0).map((r) => ({
|
|
252
|
+
return (runs ?? []).filter((r) => r.rc !== 0 && !r.weak).map((r) => ({
|
|
251
253
|
code: OUTCOME_CODES.CONFORMANCE_GUARD_BROKEN, kind: "guard_broken", guard: `#${r.issue}`, test: r.test,
|
|
252
254
|
detail: `${supersedesHint(`#${r.issue}`)} guard #${r.issue} broken (${String(r.why ?? "").slice(0, 200)}): base test ${r.test} fails against your tree (\`${r.command}\`, exit ${r.rc})${r.failed?.length ? `; failing tests: ${r.failed.slice(0, 20).join(" | ")}` : ""}:\n${tailOf(r.output)}`,
|
|
253
255
|
}));
|
|
254
256
|
}
|
|
255
257
|
|
|
258
|
+
/** #5752: review notes for failing weak guards (tests that only assert a literal exists in file text): recorded for the reviewer, never a precheck failure. */
|
|
259
|
+
export function weakGuardNotes(runs) {
|
|
260
|
+
return (runs ?? []).filter((r) => r.rc !== 0 && r.weak).map((r) => ({
|
|
261
|
+
guard: `#${r.issue}`, test: r.test,
|
|
262
|
+
note: `Weak guard #${r.issue} broken (review note, not a park): base test ${r.test} only asserts that literal text exists in a file (${String(r.why ?? "").slice(0, 160)}); confirm the removed text is intentional`,
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
|
|
256
266
|
/** The comment the engine posts on a guarded issue once its guard is superseded. */
|
|
257
267
|
export const supersessionComment = ({ guard, pr, why }) => `The fix guard from ${guard} was superseded by PR #${pr}: ${String(why ?? "").trim()}\n\nThe lane's contract carried a \`supersedes\` amendment the reviewer accepted; this guard's test no longer describes current behaviour.`;
|
|
258
268
|
|
|
259
|
-
/**
|
|
260
|
-
|
|
269
|
+
/**
|
|
270
|
+
* Guard ids the effective contract's accepted supersedes amendments retire, limited to guards the gate selected.
|
|
271
|
+
* #5752: with a mechanism amendment (contract.mechanisms), also each selected guard whose test files the lane deleted (`removedPaths`).
|
|
272
|
+
*/
|
|
273
|
+
export function supersededIds(contract, selected, removedPaths = []) {
|
|
261
274
|
const sel = new Set((selected ?? []).map((s) => `#${s.guard.issue}`));
|
|
262
|
-
|
|
275
|
+
const out = (contract?.supersedes ?? []).filter((s) => sel.has(s.guard));
|
|
276
|
+
const mech = contract?.mechanisms ?? [];
|
|
277
|
+
if (!mech.length || !removedPaths?.length) return out;
|
|
278
|
+
const gone = new Set(removedPaths.map(norm)), seen = new Set(out.map((s) => s.guard));
|
|
279
|
+
const why = mech.map((m) => `mechanism ${m.mechanism} removed: ${m.why}`).join("; ");
|
|
280
|
+
for (const { guard } of selected ?? []) {
|
|
281
|
+
const id = `#${guard.issue}`, tests = (guard.tests ?? []).map((t) => norm(t.path));
|
|
282
|
+
if (seen.has(id) || !tests.length || !tests.every((t) => gone.has(t))) continue;
|
|
283
|
+
seen.add(id); out.push({ guard: id, why, mechanism: mech.map((m) => m.mechanism).join(", ") });
|
|
284
|
+
}
|
|
285
|
+
return out;
|
|
263
286
|
}
|
|
@@ -6,7 +6,7 @@ import * as nodeFs from "node:fs";
|
|
|
6
6
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
7
7
|
import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { join } from "node:path";
|
|
9
|
-
import { oldRanges, selectGuards, runGuards, commandFor, basePathOf, failingNames, guardFailures, supersessionComment, supersededIds, loadGuards } from "./guardgate.mjs";
|
|
9
|
+
import { oldRanges, selectGuards, runGuards, commandFor, basePathOf, failingNames, guardFailures, supersessionComment, supersededIds, loadGuards, weakGuardNotes } from "./guardgate.mjs";
|
|
10
10
|
import { applyAmendments, precheck } from "./conformance.mjs";
|
|
11
11
|
import { builderImplementPrompt, conformanceResumePrompt } from "./prompts.mjs";
|
|
12
12
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
@@ -334,3 +334,46 @@ test("a template that repeats the path is never batched", async () => {
|
|
|
334
334
|
await runGuards({ selected: [{ guard: guard(1, "a.test.mjs"), reason: "r" }, { guard: guard(2, "b.test.mjs"), reason: "r" }], mergeBase: "b", contract: {}, guardCommand: { ".mjs": "run {path} {path}" }, git: async () => "x", fs, cwd: "/w", env: {}, runCommand: async (a) => { calls.push(a.command); return { rc: 0, output: "" }; } });
|
|
335
335
|
assert.ok(calls.every((c) => !c.includes("a.test__guardbase.mjs") || !c.includes("b.test__guardbase.mjs")), "no single invocation spans both files");
|
|
336
336
|
});
|
|
337
|
+
|
|
338
|
+
const WEAK_SRC = `import test from "node:test";\nimport assert from "node:assert/strict";\nimport { readFileSync } from "node:fs";\nconst src = readFileSync("src/a.mjs", "utf8");\ntest("price literal", () => assert.match(src, /return 2;/));\n`;
|
|
339
|
+
|
|
340
|
+
test("#5752: a broken weak guard (literal-presence test) is a review note, never guard_broken", async () => {
|
|
341
|
+
const { d, guard } = fixture(WEAK_SRC);
|
|
342
|
+
put(d, "src/a.mjs", "export function price() {\n return 3;\n}\n");
|
|
343
|
+
commit(d, "change");
|
|
344
|
+
const { r } = await gate(d, guard);
|
|
345
|
+
assert.equal(r.runs.length, 1, JSON.stringify(r.skipped));
|
|
346
|
+
assert.equal(r.runs[0].weak, true);
|
|
347
|
+
assert.notEqual(r.runs[0].rc, 0);
|
|
348
|
+
assert.deepEqual(r.failures, [], "weak guards never park");
|
|
349
|
+
const notes = weakGuardNotes(r.runs);
|
|
350
|
+
assert.deepEqual(notes.map((n) => [n.guard, n.test]), [["#7", "src/a.test.mjs"]]);
|
|
351
|
+
assert.match(notes[0].note, /review note, not a park/);
|
|
352
|
+
const pc = precheck({ contract: { requirements: [], deliverables: [{ id: "D1", path: "src/a.mjs" }], validate: [] }, result: {}, changedFiles: ["src/a.mjs"], guardFailures: r.failures });
|
|
353
|
+
assert.equal(pc.ok, true, JSON.stringify(pc.failures));
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
test("#5752: a broken behavioural guard stays strong: guard_broken and no weak note", async () => {
|
|
357
|
+
const { d, guard } = fixture();
|
|
358
|
+
put(d, "src/a.mjs", "export function price() {\n return 3;\n}\n");
|
|
359
|
+
commit(d, "change");
|
|
360
|
+
const { r } = await gate(d, guard);
|
|
361
|
+
assert.equal(r.runs[0].weak, false);
|
|
362
|
+
assert.deepEqual(r.failures.map((f) => f.kind), ["guard_broken"]);
|
|
363
|
+
assert.deepEqual(weakGuardNotes(r.runs), []);
|
|
364
|
+
assert.deepEqual(guardFailures([{ issue: 1, test: "t", rc: 1, weak: true, output: "" }]), [], "guardFailures excludes weak runs");
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test("#5752: a mechanism amendment reaches supersededIds only for guards whose test files the lane deleted", () => {
|
|
368
|
+
const sel = [
|
|
369
|
+
{ guard: { issue: 7, tests: [{ path: "src/a.test.mjs" }] } },
|
|
370
|
+
{ guard: { issue: 8, tests: [{ path: "src/b.test.mjs" }, { path: "src/c.test.mjs" }] } },
|
|
371
|
+
{ guard: { issue: 9, tests: [{ path: "src/d.test.mjs" }] } },
|
|
372
|
+
];
|
|
373
|
+
const contract = { mechanisms: [{ mechanism: "keyword triage", why: "replaced by the scorer" }], supersedes: [{ guard: "#9", why: "own" }] };
|
|
374
|
+
const ids = supersededIds(contract, sel, ["src/a.test.mjs", "src/b.test.mjs", "src/d.test.mjs"]);
|
|
375
|
+
assert.deepEqual(ids.map((s) => s.guard), ["#9", "#7"], "#8 keeps a surviving test; #9 is listed once");
|
|
376
|
+
assert.match(ids[1].why, /mechanism keyword triage removed: replaced by the scorer/);
|
|
377
|
+
assert.deepEqual(supersededIds({ supersedes: [] }, sel, ["src/a.test.mjs"]), [], "no mechanism: deleted tests retire nothing");
|
|
378
|
+
assert.deepEqual(supersededIds(contract, sel).map((s) => s.guard), ["#9"], "no removed paths: per-guard rows only");
|
|
379
|
+
});
|
package/bin/lean/guards.test.mjs
CHANGED
|
@@ -153,7 +153,7 @@ test("guardAfterMerge fetches the bare branch (not origin/<lane>) and the merge
|
|
|
153
153
|
gh: async (a) => a[0] === "issue" ? JSON.stringify({ number: 9, title: "t", comments: [{ body }] }) : a[0] === "pr" ? JSON.stringify({ number: 3, mergeCommit: { oid: "abc123" } }) : "",
|
|
154
154
|
git: async (a) => { calls.push(a.join(" ")); if (a[0] === "diff") { if (!have) throw new Error("bad object"); return DIFF; } if (a.join(" ") === "fetch origin abc123") have = true; return ""; },
|
|
155
155
|
};
|
|
156
|
-
const r = await guardAfterMerge({ io, repo: "o/r", issue: 9, pr: 3, cwd: "/x", base: "origin/staging" });
|
|
156
|
+
const r = await guardAfterMerge({ io, repo: "o/r", issue: 9, pr: 3, cwd: "/x", base: "origin/staging", root: tmpDir("guards-fetch-") });
|
|
157
157
|
assert.ok(calls.includes("fetch origin staging"));
|
|
158
158
|
assert.ok(!calls.some((c) => c.includes("origin/staging")));
|
|
159
159
|
assert.ok(r.posted, JSON.stringify(r));
|