forgedock 1.60.0 → 1.61.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 +44 -1
- package/bin/engine/runlog.mjs +52 -0
- package/bin/engine-cli.mjs +9 -4
- package/bin/env/bench.mjs +38 -0
- package/bin/env/cli.mjs +134 -0
- package/bin/env/env.mjs +339 -0
- package/bin/forgedock.mjs +32 -3
- package/bin/help-text.mjs +2 -0
- package/bin/lean/ci-budget.mjs +3 -1
- package/bin/lean/ci-classify.mjs +74 -0
- package/bin/lean/ci-classify.test.mjs +147 -0
- package/bin/lean/ci-emit.mjs +175 -0
- package/bin/lean/ci-emit.test.mjs +177 -0
- package/bin/lean/ci-preflight.mjs +183 -0
- package/bin/lean/ci-preflight.test.mjs +122 -0
- package/bin/lean/ci-runner-health.mjs +213 -0
- package/bin/lean/ci-runner-health.test.mjs +113 -0
- package/bin/lean/ci-watch.mjs +79 -0
- package/bin/lean/ci-watch.test.mjs +80 -0
- package/bin/lean/conformance.mjs +7 -1
- package/bin/lean/conformance.test.mjs +7 -1
- package/bin/lean/depcache.mjs +38 -8
- package/bin/lean/deploy-stages.mjs +514 -0
- package/bin/lean/deploy-stages.test.mjs +580 -0
- package/bin/lean/effects.mjs +50 -0
- package/bin/lean/execution.mjs +8 -1
- package/bin/lean/lean.mjs +61 -12
- package/bin/lean/lean.test.mjs +87 -0
- package/bin/lean/preflight.mjs +62 -1
- package/bin/lean/preflight.test.mjs +30 -1
- package/bin/lean/release-deploy.mjs +12 -6
- package/bin/lean/release-flakes.mjs +16 -0
- package/bin/lean/release-flakes.test.mjs +15 -0
- package/bin/lean/release-gates.mjs +24 -1
- package/bin/lean/release-ledger.mjs +21 -0
- package/bin/lean/release-minutes-timing.test.mjs +57 -0
- package/bin/lean/release-minutes.mjs +98 -0
- package/bin/lean/release-promote.mjs +444 -0
- package/bin/lean/release-promote.test.mjs +470 -0
- package/bin/lean/release-rollback.mjs +14 -6
- package/bin/lean/release.mjs +31 -2
- package/bin/lean/sandbox-remote.mjs +11 -3
- package/bin/lean/testengine-recall.mjs +82 -0
- package/bin/lean/testengine-recall.test.mjs +103 -0
- package/bin/lean/testengine-shard.mjs +150 -0
- package/bin/lean/testengine-shard.test.mjs +111 -0
- package/bin/lean/testengine.mjs +486 -0
- package/bin/lean/testengine.test.mjs +303 -0
- package/bin/lean/validate-catalog.mjs +16 -0
- package/bin/lean/validate-catalog.test.mjs +14 -1
- package/bin/lean/verify-settle.test.mjs +156 -0
- package/bin/lean/verify.mjs +98 -3
- package/bin/pool/agent.mjs +65 -6
- package/bin/pool/ci-events.mjs +183 -0
- package/bin/pool/ci-events.test.mjs +143 -0
- package/bin/pool/docker.mjs +7 -0
- package/bin/pool/lane-tools.mjs +32 -0
- package/bin/pool/router.mjs +21 -1
- package/bin/pool/warm.mjs +14 -3
- package/bin/stats/ci-awareness.mjs +66 -0
- package/bin/stats/index.mjs +44 -3
- package/bin/stats/release-ledger.test.mjs +226 -0
- package/bin/stats/release.mjs +365 -1
- package/bin/stats/stats.test.mjs +36 -0
- package/docs/CI.md +31 -0
- package/docs/CONFIG.md +235 -2
- package/docs/ENV-LIBRARY.md +172 -0
- package/docs/STATS.md +43 -0
- package/docs/ci-events.md +88 -0
- package/docs/test-engine.md +98 -0
- package/package.json +1 -1
- package/pool/README.md +1 -0
- package/pool/image/entrypoint.sh +15 -3
- package/pool/services/docker-compose.yml +53 -0
- package/pool/services/git-mirror.sh +22 -0
- package/scripts/acceptance-red-green.sh +5 -2
- package/scripts/acceptance-red-green.test.sh +11 -0
- package/templates/github-actions/forge-env/action.yml +65 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* #5692: step-granular CI awareness for the lane's merge wait. `watchCi` yields `step_failed` / `test_failed` events for
|
|
5
|
+
* one head sha: from the router's long-poll GET /ci/events (#5688) when it is configured and has events for the sha,
|
|
6
|
+
* else by polling the Actions jobs API and synthesizing `step_failed` from the first failed step of an in_progress job.
|
|
7
|
+
* Events only start a fix round; the GitHub check status stays the merge gate (lean.mjs). Never throws.
|
|
8
|
+
*/
|
|
9
|
+
import { failFastDecision } from "./ci-classify.mjs";
|
|
10
|
+
|
|
11
|
+
export const POLL_MS = 15000, LONG_POLL_S = 25;
|
|
12
|
+
const FAIL_TYPES = new Set(["step_failed", "test_failed"]);
|
|
13
|
+
const FAILED = new Set(["failure", "timed_out"]);
|
|
14
|
+
|
|
15
|
+
/** First failed step of every in_progress job: [{job, step, completed_at, run_id}] (a finished job is the check poll's business). */
|
|
16
|
+
export function failedStepsOf(jobs, runId = null) {
|
|
17
|
+
const out = [];
|
|
18
|
+
for (const j of jobs ?? []) {
|
|
19
|
+
if (j?.status !== "in_progress") continue;
|
|
20
|
+
const s = (j.steps ?? []).find((x) => FAILED.has(String(x?.conclusion ?? "")));
|
|
21
|
+
if (s) out.push({ job: j.name ?? null, step: s.name ?? null, completed_at: s.completed_at ?? null, run_id: runId });
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Async iterator of failure events for `sha`. `io`: ciEventsWait({repo,sha,pr,since,waitS}) -> {events,next}|null (router),
|
|
28
|
+
* runsForSha(sha) -> [{id|databaseId}], jobsOf(runId) -> [job]. `sleep`/`now` are injectable (fake clock in tests).
|
|
29
|
+
*/
|
|
30
|
+
export async function* watchCi({ repo, sha, pr, io, sleep, now = Date.now, pollMs = POLL_MS, waitS = LONG_POLL_S, signal } = {}) {
|
|
31
|
+
const seen = new Set();
|
|
32
|
+
const fresh = (key) => (seen.has(key) ? false : (seen.add(key), true));
|
|
33
|
+
let since = 0, router = false;
|
|
34
|
+
const poll = async (w) => {
|
|
35
|
+
try { return (await io?.ciEventsWait?.({ repo, sha, pr, since, waitS: w })) ?? null; } catch { return null; }
|
|
36
|
+
};
|
|
37
|
+
if (io?.ciEventsWait) { // the router is used only when it has already emitted events for this sha
|
|
38
|
+
const first = await poll(0);
|
|
39
|
+
if (first?.events?.length) { router = true; since = first.next ?? since; for (const e of first.events) if (FAIL_TYPES.has(e.type) && fresh(`e${e.seq}`)) yield e; }
|
|
40
|
+
}
|
|
41
|
+
while (!signal?.aborted) {
|
|
42
|
+
if (router) {
|
|
43
|
+
const r = await poll(waitS);
|
|
44
|
+
if (!r) { await sleep(pollMs); continue; }
|
|
45
|
+
since = r.next ?? since;
|
|
46
|
+
for (const e of r.events ?? []) if (FAIL_TYPES.has(e.type) && fresh(`e${e.seq}`)) yield e;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
for (const run of (await io?.runsForSha?.(sha)) ?? []) {
|
|
51
|
+
const id = run.id ?? run.databaseId;
|
|
52
|
+
if (id == null || run.status === "completed") continue;
|
|
53
|
+
for (const f of failedStepsOf(await io.jobsOf(id), id)) {
|
|
54
|
+
if (fresh(`j${id}\n${f.job}\n${f.step}`)) yield { type: "step_failed", repo, sha, run_id: String(id), job: f.job, step: f.step, lines: [], ts: f.completed_at ?? new Date(now()).toISOString(), source: "jobs-api" };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} catch { /* the check poll still runs */ }
|
|
58
|
+
await sleep(pollMs);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** One pending `next()` at a time, so the merge loop can race it against its own sleep: `next()` resolves an event or null once stopped. */
|
|
63
|
+
export function ciSignal(opts) {
|
|
64
|
+
const ac = new AbortController(), it = watchCi({ ...opts, signal: ac.signal });
|
|
65
|
+
let pending = null;
|
|
66
|
+
return {
|
|
67
|
+
next() {
|
|
68
|
+
pending ??= it.next().then((r) => { pending = null; return r.done ? null : r.value; }, () => { pending = null; return null; });
|
|
69
|
+
return pending;
|
|
70
|
+
},
|
|
71
|
+
stop() { ac.abort(); it.return?.().catch?.(() => {}); },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Cancel the run only when the classifier says downstream and the policy is `deterministic` (#5690). */
|
|
76
|
+
export const cancelDecision = (event, policy) => failFastDecision(event, policy);
|
|
77
|
+
|
|
78
|
+
/** Builder context for an event-triggered round: the failing step's lines and test id. */
|
|
79
|
+
export const eventLog = (e) => [e.test ? `test: ${e.test}` : null, e.step ? `step: ${e.step}` : null, ...(e.lines ?? [])].filter(Boolean).join("\n");
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { watchCi, ciSignal, failedStepsOf, cancelDecision, eventLog } from "./ci-watch.mjs";
|
|
6
|
+
import { tmpDir } from "../tests/_tmp.mjs";
|
|
7
|
+
|
|
8
|
+
/** Fake clock: sleep advances time, never waits. */
|
|
9
|
+
const clock = () => { const c = { t: 0 }; c.sleep = async (ms) => { c.t += ms; }; c.now = () => c.t; return c; };
|
|
10
|
+
const JOBS = [{ name: "build", status: "in_progress", conclusion: null, steps: [{ name: "setup", conclusion: "success" }, { name: "pnpm test", conclusion: "failure", completed_at: "2026-11-15T10:00:00Z" }, { name: "after", conclusion: null }] }];
|
|
11
|
+
|
|
12
|
+
describe("watchCi (#5692)", () => {
|
|
13
|
+
it("fallback: an in_progress job with one failed step yields step_failed on the next poll", async () => {
|
|
14
|
+
const c = clock(); let polls = 0;
|
|
15
|
+
const io = { runsForSha: async () => [{ id: 9, status: "in_progress" }], jobsOf: async () => (++polls < 2 ? [{ ...JOBS[0], steps: [{ name: "pnpm test", conclusion: null }] }] : JOBS) };
|
|
16
|
+
const it_ = watchCi({ repo: "o/r", sha: "abc", io, sleep: c.sleep, now: c.now });
|
|
17
|
+
const e = (await it_.next()).value;
|
|
18
|
+
assert.equal(e.type, "step_failed"); assert.equal(e.step, "pnpm test"); assert.equal(e.job, "build"); assert.equal(e.ts, "2026-11-15T10:00:00Z"); assert.equal(e.source, "jobs-api");
|
|
19
|
+
assert.equal(polls, 2); assert.equal(c.t, 15000, "one 15 s poll interval");
|
|
20
|
+
await it_.return();
|
|
21
|
+
});
|
|
22
|
+
it("fallback: the same failed step is yielded once; finished jobs and runs are not synthesized", async () => {
|
|
23
|
+
assert.deepEqual(failedStepsOf([{ ...JOBS[0], status: "completed" }]), []);
|
|
24
|
+
assert.equal(failedStepsOf(JOBS).length, 1);
|
|
25
|
+
const c = clock(); let n = 0;
|
|
26
|
+
const io = { runsForSha: async () => [{ id: 9, status: "in_progress" }, { id: 8, status: "completed" }], jobsOf: async (id) => { assert.equal(id, 9); return JOBS; } };
|
|
27
|
+
const sig = ciSignal({ repo: "o/r", sha: "abc", io, sleep: async (ms) => { c.t += ms; if (++n > 3) await new Promise(() => {}); }, now: c.now });
|
|
28
|
+
assert.equal((await sig.next()).type, "step_failed");
|
|
29
|
+
const second = await Promise.race([sig.next(), new Promise((r) => setTimeout(() => r("none"), 20))]);
|
|
30
|
+
assert.equal(second, "none"); sig.stop();
|
|
31
|
+
});
|
|
32
|
+
it("router: yields step_failed/test_failed from the long-poll when it has events for the sha, and resumes from the cursor", async () => {
|
|
33
|
+
const c = clock(), calls = [];
|
|
34
|
+
const batches = [{ events: [{ seq: 1, type: "step_started" }, { seq: 2, type: "step_failed", step: "lint", lines: ["x"] }], next: 2 }, { events: [{ seq: 3, type: "test_failed", test: "t" }], next: 3 }];
|
|
35
|
+
const io = { ciEventsWait: async (q) => { calls.push(q.since); return batches.shift() ?? { events: [], next: 3 }; }, runsForSha: async () => { throw new Error("must not poll the jobs API"); } };
|
|
36
|
+
const it_ = watchCi({ repo: "o/r", sha: "abc", io, sleep: c.sleep, now: c.now });
|
|
37
|
+
assert.equal((await it_.next()).value.step, "lint");
|
|
38
|
+
assert.equal((await it_.next()).value.test, "t");
|
|
39
|
+
assert.deepEqual(calls.slice(0, 2), [0, 2]); await it_.return();
|
|
40
|
+
});
|
|
41
|
+
it("router configured but silent for the sha: falls back to the jobs API", async () => {
|
|
42
|
+
const c = clock();
|
|
43
|
+
const io = { ciEventsWait: async () => ({ events: [], next: 0 }), runsForSha: async () => [{ id: 1, status: "queued" }], jobsOf: async () => JOBS };
|
|
44
|
+
const it_ = watchCi({ repo: "o/r", sha: "abc", io, sleep: c.sleep, now: c.now });
|
|
45
|
+
assert.equal((await it_.next()).value.source, "jobs-api"); await it_.return();
|
|
46
|
+
});
|
|
47
|
+
it("an unreachable io never throws", async () => {
|
|
48
|
+
const c = clock(); let n = 0;
|
|
49
|
+
const io = { runsForSha: async () => { throw new Error("HTTP 502"); } };
|
|
50
|
+
const sig = ciSignal({ repo: "o/r", sha: "a", io, sleep: async (ms) => { c.t += ms; if (++n > 2) await new Promise(() => {}); }, now: c.now });
|
|
51
|
+
assert.equal(await Promise.race([sig.next(), new Promise((r) => setTimeout(() => r("quiet"), 20))]), "quiet"); sig.stop();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("cancelDecision (#5692)", () => {
|
|
56
|
+
const setup = { type: "step_failed", step: "pnpm install", lines: ["ERR_PNPM_OUTDATED_LOCKFILE Cannot install with frozen-lockfile"] };
|
|
57
|
+
const code = { type: "test_failed", test: "a.test.ts > adds", lines: ["AssertionError: expected 1 to be 2"] };
|
|
58
|
+
it("cancels only for a downstream class under policy deterministic", () => {
|
|
59
|
+
assert.equal(cancelDecision({ ...setup, class: "deterministic-setup" }, { fail_fast: "deterministic" }).action, "cancel");
|
|
60
|
+
assert.equal(cancelDecision({ ...setup, class: "generated-artifact-stale" }, "deterministic").action, "cancel");
|
|
61
|
+
assert.equal(cancelDecision(code, "deterministic").action, "continue");
|
|
62
|
+
for (const class_ of ["code", "infra", "flaky-suspect"]) assert.equal(cancelDecision({ ...code, class: class_ }, "deterministic").action, "continue");
|
|
63
|
+
for (const policy of [undefined, "off", { fail_fast: "off" }, {}]) assert.equal(cancelDecision({ ...setup, class: "deterministic-setup" }, policy).action, "continue");
|
|
64
|
+
});
|
|
65
|
+
it("eventLog carries the test id, step and lines to the builder", () => {
|
|
66
|
+
assert.equal(eventLog({ test: "t1", step: "s", lines: ["l1", "l2"] }), "test: t1\nstep: s\nl1\nl2");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("forge.yaml ci.fail_fast plumbing (#5692)", () => {
|
|
71
|
+
it("readCiFailFast returns deterministic only for that value", async () => {
|
|
72
|
+
const { writeFileSync } = await import("node:fs"), { tmpdir } = await import("node:os"), { join } = await import("node:path");
|
|
73
|
+
const { readCiFailFast } = await import("../engine-cli.mjs");
|
|
74
|
+
const at = (yaml) => { const d = tmpDir("ci-ff-"); writeFileSync(join(d, "forge.yaml"), yaml); return readCiFailFast(d); };
|
|
75
|
+
assert.equal(at("ci:\n fail_fast: deterministic\n"), "deterministic");
|
|
76
|
+
assert.equal(at("ci:\n fail_fast: off\n"), undefined);
|
|
77
|
+
assert.equal(at("name: x\n"), undefined);
|
|
78
|
+
assert.equal(readCiFailFast(join(tmpdir(), "no-such-dir-5692")), undefined);
|
|
79
|
+
});
|
|
80
|
+
});
|
package/bin/lean/conformance.mjs
CHANGED
|
@@ -1206,7 +1206,7 @@ function frozenAmendedFiles(frozen, contract, outside, creep) {
|
|
|
1206
1206
|
* #4271: the frozen repro_test's red-green proof ({base, head} words from scripts/acceptance-red-green.sh). Anything but
|
|
1207
1207
|
* HEAD=RAN BASE=FAILED fails; code conformance.unimplemented, so it blocks in shadow too and goes back to the builder.
|
|
1208
1208
|
* #4334: HEAD=UNRUNNABLE or no words (the harness could not run the test) is env.repro_unrunnable, kind repro_env: an
|
|
1209
|
-
* environment error, never a builder resume.
|
|
1209
|
+
* environment error, never a builder resume. So is BASE=UNRUNNABLE with HEAD=RAN (the base checkout could not run it).
|
|
1210
1210
|
*/
|
|
1211
1211
|
export function reproFailures(contract, { base, head, pristine } = {}) {
|
|
1212
1212
|
if (head === "RAN" && base === "FAILED") return [];
|
|
@@ -1218,6 +1218,12 @@ export function reproFailures(contract, { base, head, pristine } = {}) {
|
|
|
1218
1218
|
return [{ code: C.ENV_REPRO_UNRUNNABLE, kind: "repro_env",
|
|
1219
1219
|
detail: `repro test ${name} (\`${t.command ?? ""}\`): the harness could not run the test on head (environment, not the change); got BASE=${base ?? "UNRUNNABLE"} HEAD=${head ?? "UNRUNNABLE"}` }];
|
|
1220
1220
|
}
|
|
1221
|
+
// A head that ran but a base the harness could not run (e.g. a missing dependency tree in the base checkout) is the
|
|
1222
|
+
// environment too: the change cannot fix it, so it is never a builder resume (AlterLab 40652/40665, BASE=UNRUNNABLE HEAD=RAN).
|
|
1223
|
+
if (head === "RAN" && base === "UNRUNNABLE") {
|
|
1224
|
+
return [{ code: C.ENV_REPRO_UNRUNNABLE, kind: "repro_env",
|
|
1225
|
+
detail: `repro test ${name} (\`${t.command ?? ""}\`): the harness could not run the test on the base (environment, not the change); got BASE=UNRUNNABLE HEAD=RAN` }];
|
|
1226
|
+
}
|
|
1221
1227
|
const skipped = base === "SKIPPED" ? " (base not run: head did not pass)" : "";
|
|
1222
1228
|
// #5080: the test already passes on the base: the fix is there (a hotfix or another PR), not missing from this change
|
|
1223
1229
|
if (base === "RAN") return [{ code: C.CONFORMANCE_UNIMPLEMENTED, kind: "repro_base_green",
|
|
@@ -862,7 +862,7 @@ describe("repro_test on bug lanes (#4271)", () => {
|
|
|
862
862
|
it("red on base and green on head passes; anything else fails the precheck as conformance.unimplemented", () => {
|
|
863
863
|
const k = { ...C, repro_test: RT };
|
|
864
864
|
assert.deepEqual(precheck({ contract: k, result: res, changedFiles: files, repro: { base: "FAILED", head: "RAN" } }), { ok: true, failures: [], superseded: [], ciCovered: [], equivalent: [] });
|
|
865
|
-
for (const repro of [{ base: "SKIPPED", head: "FAILED" }, { base: "
|
|
865
|
+
for (const repro of [{ base: "SKIPPED", head: "FAILED" }, { base: "SKIPPED", head: "RAN_NOTHING" }]) {
|
|
866
866
|
const pc = precheck({ contract: k, result: res, changedFiles: files, repro });
|
|
867
867
|
assert.deepEqual(pc.failures.map((f) => [f.code, f.kind]), [["conformance.unimplemented", "repro_red_green"]], JSON.stringify(repro));
|
|
868
868
|
assert.match(pc.failures[0].detail, new RegExp(`BASE=${repro.base} HEAD=${repro.head}`));
|
|
@@ -907,6 +907,12 @@ describe("repro_test on bug lanes (#4271)", () => {
|
|
|
907
907
|
assert.match(pc.failures[0].detail, new RegExp(`BASE=${repro.base ?? "UNRUNNABLE"} HEAD=UNRUNNABLE$`));
|
|
908
908
|
}
|
|
909
909
|
});
|
|
910
|
+
it("BASE=UNRUNNABLE with HEAD=RAN (the base checkout could not run the test) is env.repro_unrunnable, never a builder resume", () => {
|
|
911
|
+
const k = { ...C, repro_test: RT };
|
|
912
|
+
const pc = precheck({ contract: k, result: res, changedFiles: files, repro: { base: "UNRUNNABLE", head: "RAN" } });
|
|
913
|
+
assert.deepEqual(pc.failures.map((f) => [f.code, f.kind]), [["env.repro_unrunnable", "repro_env"]]);
|
|
914
|
+
assert.match(pc.failures[0].detail, /could not run the test on the base \(environment, not the change\); got BASE=UNRUNNABLE HEAD=RAN$/);
|
|
915
|
+
});
|
|
910
916
|
it("off (no repro option) is today's contract check and precheck exactly", () => {
|
|
911
917
|
assert.deepEqual(validateContract(C, ISSUE), validateContract(C, ISSUE, { repro: false }));
|
|
912
918
|
assert.deepEqual(validateContract(C, ISSUE), { ok: true, problems: [] });
|
package/bin/lean/depcache.mjs
CHANGED
|
@@ -143,6 +143,10 @@ export function pySatisfies(spec, v) {
|
|
|
143
143
|
return String(spec).split("||").some((grp) => grp.replace(/(\^|~=|~|==|!=|>=|<=|>|<)\s+/g, "$1").split(/[,\s]+/).filter(Boolean).every((c) => clauseOk(c, v)));
|
|
144
144
|
}
|
|
145
145
|
/** Full frozen install on a miss, and the warm no-op repair pass on a hit (null: nothing path-dependent to repair). */
|
|
146
|
+
export { commands as depCommands };
|
|
147
|
+
/** The files a component's key hashes, relative to its own dir (lockfile, manifests, package-manager config). */
|
|
148
|
+
const keyFiles = (d, pkgs) => (JS.has(d.eco) ? [d.lock, ...pkgs, "pnpm-workspace.yaml", ".npmrc", ".yarnrc.yml"] : [d.lock, "pyproject.toml", ".python-version"]);
|
|
149
|
+
const expectedTrees = (d, pkgs) => (JS.has(d.eco) ? [...new Set(pkgs.map((p) => (dirname(p) === "." ? "node_modules" : `${dirname(p)}/node_modules`)))] : [".venv"]);
|
|
146
150
|
function commands(d, py = null) {
|
|
147
151
|
// #5651: with an in-range interpreter poetry itself runs under it (`<py> -m poetry`), so its resolver never sees the host default python.
|
|
148
152
|
const poetry = (args) => (py ? [py.cmd, ["-m", "poetry", ...args]] : ["poetry", args]);
|
|
@@ -168,6 +172,7 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
168
172
|
env: procEnv = process.env, installTimeoutMs = DEPCACHE_INSTALL_TIMEOUT_MS, lockWaitMs = DEPCACHE_INSTALL_TIMEOUT_MS, pollMs = 1000,
|
|
169
173
|
sleep = (ms) => new Promise((r) => setTimeout(r, ms)) } = {}) {
|
|
170
174
|
const disabled = () => String(procEnv.FORGE_DEPCACHE ?? "").trim() === "0";
|
|
175
|
+
const api = {}; // filled at the end; the env-library hook in prepare() passes it on
|
|
171
176
|
const store = (n) => join(root, STORES, n);
|
|
172
177
|
|
|
173
178
|
/** Shared package-manager stores for every runner call, so the builder's own installs reuse them too. */
|
|
@@ -227,8 +232,7 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
227
232
|
const h = createHash("sha256").update(`v1\0${d.eco}\0${process.platform}-${process.arch}\0`);
|
|
228
233
|
if (d.dir) h.update(`${d.dir}\0`);
|
|
229
234
|
h.update(py ? py.version : await runtime(JS.has(d.eco) ? "node" : "python3")).update("\0");
|
|
230
|
-
const
|
|
231
|
-
for (const f of files) {
|
|
235
|
+
for (const f of keyFiles(d, pkgs)) {
|
|
232
236
|
h.update(`${f}\0`);
|
|
233
237
|
try { h.update(fs.readFileSync(join(wt, f))); } catch { h.update("<absent>"); }
|
|
234
238
|
h.update("\0");
|
|
@@ -352,7 +356,7 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
352
356
|
}
|
|
353
357
|
}
|
|
354
358
|
|
|
355
|
-
async function prepareOne(wt, keyRoot, d, laneEnv) {
|
|
359
|
+
async function prepareOne(wt, keyRoot, d, laneEnv, publishSnap = true) {
|
|
356
360
|
const t0 = now();
|
|
357
361
|
let repaired = null;
|
|
358
362
|
const done = (status, extra = {}) => ({ status, eco: d.eco, key: extra.key ?? null, ms: now() - t0, reason: extra.reason ?? repaired, ...(extra.published === undefined ? {} : { published: extra.published }) });
|
|
@@ -373,7 +377,7 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
373
377
|
const key = await keyOf(wt, d, pkgs, py);
|
|
374
378
|
const snap = join(keyRoot, `${d.eco}-${key}`);
|
|
375
379
|
const cmds = commands(d, py);
|
|
376
|
-
const expected =
|
|
380
|
+
const expected = expectedTrees(d, pkgs);
|
|
377
381
|
const existing = expected.filter((t) => present(join(wt, t)));
|
|
378
382
|
if (existing.length) {
|
|
379
383
|
const broken = brokenTrees(wt, d, existing);
|
|
@@ -419,6 +423,10 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
419
423
|
return { trees: treesOf(wt, d, pkgs) };
|
|
420
424
|
};
|
|
421
425
|
|
|
426
|
+
if (!publishSnap) { // env snapshot build: the caller publishes the trees itself
|
|
427
|
+
const ins = await install();
|
|
428
|
+
return ins.failed ?? done("miss-installed", { key, published: false, reason: "publish off" });
|
|
429
|
+
}
|
|
422
430
|
const lockPath = `${snap}.lock`;
|
|
423
431
|
const r = await withLock(lockPath, async () => {
|
|
424
432
|
if (fs.existsSync(join(snap, "manifest.json"))) return materialize(); // hit, or another lane published while we waited
|
|
@@ -445,22 +453,44 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
445
453
|
* Materialize or build node_modules/.venv for `wt`; one result per detected ecosystem. Never throws.
|
|
446
454
|
* `env` (#4347): the lane's toolchain env (PATH with the pinned pm shims) for install/repair; absent means the host PATH.
|
|
447
455
|
*/
|
|
448
|
-
async function prepare({ wt, repoKey, env: laneEnv } = {}) {
|
|
456
|
+
async function prepare({ wt, repoKey, env: laneEnv, publish: publishSnap = true } = {}) {
|
|
449
457
|
if (disabled()) return [{ status: "skipped", eco: null, key: null, ms: 0, reason: "FORGE_DEPCACHE=0" }];
|
|
450
458
|
let found;
|
|
451
459
|
try { found = detect(fs, wt); } catch (e) { return [{ status: "failed", eco: null, key: null, ms: 0, reason: msg(e) }]; }
|
|
452
460
|
if (!found.length) return [{ status: "skipped", eco: null, key: null, ms: 0, reason: "no lockfile" }];
|
|
461
|
+
let envHit = null;
|
|
462
|
+
if (String(procEnv.FORGE_ENV_SNAPSHOTS ?? "").trim() === "1" && publishSnap) {
|
|
463
|
+
// Environment library (bin/env): a whole-environment snapshot for this exact lock set is claimed by rename. The loop
|
|
464
|
+
// below then finds complete trees (same completeness check as any existing tree); a miss or error is today's path.
|
|
465
|
+
try { envHit = await (await import("../env/env.mjs")).claimForLane({ wt, deps: api, fs, env: procEnv, now }); } catch { envHit = null; }
|
|
466
|
+
}
|
|
453
467
|
const keyRoot = join(root, safeSegment(repoKey ?? "repo"));
|
|
454
468
|
const out = [];
|
|
455
469
|
for (const d of found) {
|
|
456
470
|
try {
|
|
457
|
-
const r = await prepareOne(d.dir ? join(wt, d.dir) : wt, keyRoot, d, laneEnv && typeof laneEnv === "object" ? laneEnv : undefined);
|
|
458
|
-
|
|
471
|
+
const r = await prepareOne(d.dir ? join(wt, d.dir) : wt, keyRoot, d, laneEnv && typeof laneEnv === "object" ? laneEnv : undefined, publishSnap);
|
|
472
|
+
const claimed = envHit && r.status === "skipped" && /already exists in the worktree$/.test(String(r.reason ?? ""));
|
|
473
|
+
out.push(claimed ? { ...r, status: "hit", key: envHit.key, ms: r.ms + (out.some((x) => x.env) ? 0 : envHit.ms), reason: `env snapshot (${envHit.mode})`, env: true, dir: d.dir ?? "." } : { ...r, dir: d.dir ?? "." });
|
|
459
474
|
} catch (e) { out.push({ status: "failed", eco: d.eco, key: null, ms: 0, reason: msg(e), dir: d.dir ?? "." }); }
|
|
460
475
|
}
|
|
461
476
|
return out;
|
|
462
477
|
}
|
|
463
478
|
|
|
479
|
+
/**
|
|
480
|
+
* What `prepare` would install for `wt`, without installing: one entry per detected ecosystem with the files its key
|
|
481
|
+
* hashes (`inputs`) and the trees an install leaves (`trees`), both relative to `wt`. Used by the environment library.
|
|
482
|
+
*/
|
|
483
|
+
async function describe({ wt } = {}) {
|
|
484
|
+
const out = [];
|
|
485
|
+
for (const d of detect(fs, wt)) {
|
|
486
|
+
const base = d.dir ? join(wt, d.dir) : wt, at = (f) => (d.dir ? `${d.dir}/${f}` : f);
|
|
487
|
+
const pkgs = !d.skip && JS.has(d.eco) ? await manifests(base) : [];
|
|
488
|
+
out.push({ eco: d.eco, lock: d.lock, dir: d.dir ?? ".", ...(d.berry ? { berry: true } : {}), ...(d.skip ? { skip: d.skip } : {}),
|
|
489
|
+
inputs: d.skip ? [] : keyFiles(d, pkgs).map(at), trees: d.skip ? [] : expectedTrees(d, pkgs).map(at) });
|
|
490
|
+
}
|
|
491
|
+
return out;
|
|
492
|
+
}
|
|
493
|
+
|
|
464
494
|
/**
|
|
465
495
|
* Read-only scan for the reaper: snapshots unused for maxAgeMs, tmp dirs of dead publishers, locks of dead holders on
|
|
466
496
|
* this host. Only names this module creates are listed. Each entry: {name, path, kind: snapshot|tmp|lock, ageMs, locked?, reason};
|
|
@@ -514,6 +544,6 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
514
544
|
return removed;
|
|
515
545
|
}
|
|
516
546
|
|
|
517
|
-
return { env, prepare, prune, scan, remove, root };
|
|
547
|
+
return Object.assign(api, { env, prepare, describe, prune, scan, remove, root, linkTree, readOnly });
|
|
518
548
|
}
|
|
519
549
|
|