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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* #5819: the checkpoint's deletion guard. A checkpoint stages everything (`git add -A`), so anything that removed files from
|
|
5
|
+
* the worktree behind the builder's back (a failed dependency-cache publish, a stray recursive delete) would be committed and
|
|
6
|
+
* pushed to the PR branch. Before the commit, the staged deletions of files the base tracks are compared with the contract's
|
|
7
|
+
* deliverables: deletions outside them (more than `max`, default 0) are unstaged and restored in the worktree, and the caller
|
|
8
|
+
* refuses to push. Deliverable deletions, and deletions of files the lane itself added, commit as before. Git is injected:
|
|
9
|
+
* `git(args) -> stdout`, throws on failure.
|
|
10
|
+
*/
|
|
11
|
+
export const MAX_FOREIGN_DELETIONS_ENV = "FORGE_CHECKPOINT_MAX_DELETIONS";
|
|
12
|
+
|
|
13
|
+
/** The tolerated number of non-deliverable deletions: `FORGE_CHECKPOINT_MAX_DELETIONS` (a non-negative integer), else 0. */
|
|
14
|
+
export function maxForeignDeletions(env = process.env) {
|
|
15
|
+
const v = String(env?.[MAX_FOREIGN_DELETIONS_ENV] ?? "").trim();
|
|
16
|
+
return /^\d+$/.test(v) ? Number(v) : 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const CHUNK = 200;
|
|
20
|
+
const chunks = (l) => { const out = []; for (let i = 0; i < l.length; i += CHUNK) out.push(l.slice(i, i + CHUNK)); return out; };
|
|
21
|
+
const clean = (p) => String(p ?? "").trim().replace(/^\.\//, "").replace(/\/+$/, "");
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Staged deletions as {path, to}: `to` is the rename destination (null for a plain deletion). Plumbing (`diff-index`), so a
|
|
25
|
+
* porcelain diff config never changes the format. Entries with a newline are not git -z output and are ignored.
|
|
26
|
+
*/
|
|
27
|
+
export function parseStagedDeletions(out) {
|
|
28
|
+
const f = String(out ?? "").split("\0");
|
|
29
|
+
const res = [];
|
|
30
|
+
for (let i = 0; i < f.length;) {
|
|
31
|
+
const st = f[i++];
|
|
32
|
+
if (!st) continue;
|
|
33
|
+
if (/^R\d*$/.test(st)) { const path = f[i++], to = f[i++]; if (path && to && !/\n/.test(path + to)) res.push({ path, to }); }
|
|
34
|
+
else if (st === "D") { const path = f[i++]; if (path && !/\n/.test(path)) res.push({ path, to: null }); }
|
|
35
|
+
else return res; // not --name-status -z output (an injected fake): nothing parsed past it
|
|
36
|
+
}
|
|
37
|
+
return res;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Is `p` a deliverable (an exact path, or under a deliverable directory)? */
|
|
41
|
+
const covered = (p, keep) => keep.some((k) => k && (p === k || p.startsWith(`${k}/`)));
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* After `git add -A`, before the checkpoint commit. Returns {refused, deleted, foreign, restored}: `foreign` are the staged
|
|
45
|
+
* deletions of base-tracked files outside `keep` (contract deliverable paths). When there are more than `max` of them they are
|
|
46
|
+
* unstaged and checked out again (refused: true, restored: whether every one is back on disk per git). Never throws: a git
|
|
47
|
+
* failure while listing is a refusal-free pass (nothing parsed), a failure while restoring is reported in `error`.
|
|
48
|
+
*/
|
|
49
|
+
export async function guardStagedDeletions({ git, base = null, keep = [], max = 0 }) {
|
|
50
|
+
const want = (keep ?? []).map(clean).filter(Boolean);
|
|
51
|
+
let dels = [];
|
|
52
|
+
try { dels = parseStagedDeletions(await git(["diff-index", "--cached", "--name-status", "-z", "-M", "--diff-filter=DR", "HEAD"])); } catch { return { refused: false, deleted: [], foreign: [] }; }
|
|
53
|
+
if (!dels.length) return { refused: false, deleted: [], foreign: [] };
|
|
54
|
+
// A rename into or out of a deliverable is the lane's own move; any other rename still removes the original path.
|
|
55
|
+
const cands = dels.filter((d) => !covered(d.path, want) && !(d.to && covered(d.to, want))).map((d) => d.path);
|
|
56
|
+
let foreign = cands;
|
|
57
|
+
if (base && cands.length) { // files the lane added itself (absent on the base) are its own to delete
|
|
58
|
+
try {
|
|
59
|
+
const onBase = new Set();
|
|
60
|
+
for (const c of chunks(cands)) for (const p of String(await git(["ls-tree", "-r", "--name-only", "-z", base, "--", ...c])).split("\0")) if (p) onBase.add(p);
|
|
61
|
+
foreign = cands.filter((p) => onBase.has(p));
|
|
62
|
+
} catch { foreign = cands; } // unreadable base: every candidate counts
|
|
63
|
+
}
|
|
64
|
+
const deleted = dels.map((d) => d.path);
|
|
65
|
+
if (foreign.length <= max) return { refused: false, deleted, foreign };
|
|
66
|
+
// Unstage the whole rename (both sides), then bring the originals back from HEAD.
|
|
67
|
+
const renamedTo = dels.filter((d) => d.to && foreign.includes(d.path)).map((d) => d.to);
|
|
68
|
+
try {
|
|
69
|
+
for (const c of chunks([...foreign, ...renamedTo])) await git(["reset", "-q", "--", ...c]);
|
|
70
|
+
for (const c of chunks(foreign)) await git(["checkout", "-q", "HEAD", "--", ...c]);
|
|
71
|
+
let still = [];
|
|
72
|
+
try { still = String(await git(["ls-files", "--deleted", "-z"])).split("\0").filter((p) => p && foreign.includes(p)); } catch { /* unverified */ }
|
|
73
|
+
return { refused: true, deleted, foreign, restored: still.length === 0 };
|
|
74
|
+
} catch (e) {
|
|
75
|
+
return { refused: true, deleted, foreign, restored: false, error: String(e?.message ?? e).slice(0, 300) };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** One-line evidence for the run log, the trajectory and the engine-error detail. */
|
|
80
|
+
export function deletionEvidence(g, reason = "checkpoint") {
|
|
81
|
+
const sample = g.foreign.slice(0, 8).map((p) => `\`${p}\``).join(", ");
|
|
82
|
+
return `${reason}: the staged diff deleted ${g.foreign.length} tracked file(s) outside the contract deliverables (${sample}${g.foreign.length > 8 ? ", ..." : ""}); `
|
|
83
|
+
+ `${g.restored ? "they were restored in the worktree" : `restoring them failed${g.error ? ` (${g.error})` : ""}`} and nothing was pushed (#5819)`;
|
|
84
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/** #5819: the checkpoint deletion guard on a real git repo. */
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { mkdirSync, writeFileSync, existsSync, rmSync, renameSync } from "node:fs";
|
|
8
|
+
import { join, dirname } from "node:path";
|
|
9
|
+
import { tmpDir } from "../tests/_tmp.mjs";
|
|
10
|
+
import { guardStagedDeletions, parseStagedDeletions, maxForeignDeletions, deletionEvidence } from "./delguard.mjs";
|
|
11
|
+
|
|
12
|
+
const sh = (cwd, ...a) => execFileSync("git", a, { cwd, encoding: "utf8" });
|
|
13
|
+
const put = (cwd, f, t = "x\n") => { mkdirSync(dirname(join(cwd, f)), { recursive: true }); writeFileSync(join(cwd, f), t); };
|
|
14
|
+
const PKG = Array.from({ length: 12 }, (_, i) => `packages/adapters/src/f${i}.ts`);
|
|
15
|
+
const repo = () => {
|
|
16
|
+
const d = tmpDir("delguard-repo-");
|
|
17
|
+
sh(d, "init", "-q", "-b", "main"); sh(d, "config", "user.email", "t@t"); sh(d, "config", "user.name", "t");
|
|
18
|
+
for (const f of ["src/a.js", "src/b.js", "docs/old.md", ...PKG]) put(d, f, `${f}\n`);
|
|
19
|
+
sh(d, "add", "-A"); sh(d, "commit", "-q", "-m", "base");
|
|
20
|
+
sh(d, "checkout", "-q", "-b", "lane");
|
|
21
|
+
return d;
|
|
22
|
+
};
|
|
23
|
+
const gitIn = (d) => async (args) => execFileSync("git", args, { cwd: d, encoding: "utf8" });
|
|
24
|
+
const stagedNames = (d) => sh(d, "diff", "--cached", "--name-status").trim().split("\n").filter(Boolean);
|
|
25
|
+
const checkpoint = async (d, o) => { sh(d, "add", "-A"); const g = await guardStagedDeletions({ git: gitIn(d), base: "main", ...o }); return g; };
|
|
26
|
+
|
|
27
|
+
describe("guardStagedDeletions (#5819)", () => {
|
|
28
|
+
it("a staged diff deleting tracked files outside the deliverables is refused: the files are unstaged and back on disk, the rest still commits", async () => {
|
|
29
|
+
const d = repo();
|
|
30
|
+
put(d, "src/a.js", "fixed\n");
|
|
31
|
+
rmSync(join(d, "packages"), { recursive: true }); // what the failed publish did
|
|
32
|
+
const g = await checkpoint(d, { keep: ["src/a.js"] });
|
|
33
|
+
assert.equal(g.refused, true);
|
|
34
|
+
assert.equal(g.foreign.length, PKG.length);
|
|
35
|
+
assert.equal(g.restored, true);
|
|
36
|
+
for (const f of PKG) assert.ok(existsSync(join(d, f)), f);
|
|
37
|
+
assert.deepEqual(stagedNames(d), ["M\tsrc/a.js"], "only the real change stays staged");
|
|
38
|
+
sh(d, "commit", "-q", "-m", "wip(forge): checkpoint after exit (needs-human)");
|
|
39
|
+
assert.equal(sh(d, "diff", "--name-status", "main", "HEAD").trim(), "M\tsrc/a.js");
|
|
40
|
+
assert.match(deletionEvidence(g), /deleted 12 tracked file\(s\) outside the contract deliverables .*restored in the worktree and nothing was pushed/);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("deletions listed as deliverables (a file or a directory) commit unchanged", async () => {
|
|
44
|
+
const d = repo();
|
|
45
|
+
rmSync(join(d, "src/b.js")); rmSync(join(d, "packages"), { recursive: true });
|
|
46
|
+
const g = await checkpoint(d, { keep: ["src/b.js", "packages/adapters/"] });
|
|
47
|
+
assert.equal(g.refused, false);
|
|
48
|
+
assert.equal(g.deleted.length, PKG.length + 1);
|
|
49
|
+
assert.deepEqual(g.foreign, []);
|
|
50
|
+
assert.ok(!existsSync(join(d, "src/b.js")));
|
|
51
|
+
assert.equal(stagedNames(d).filter((l) => l.startsWith("D\t")).length, PKG.length + 1);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("a file the lane added itself (absent on the base) is the lane's to delete", async () => {
|
|
55
|
+
const d = repo();
|
|
56
|
+
put(d, "src/tmp-helper.js"); sh(d, "add", "-A"); sh(d, "commit", "-q", "-m", "lane add");
|
|
57
|
+
rmSync(join(d, "src/tmp-helper.js"));
|
|
58
|
+
const g = await checkpoint(d, { keep: [] });
|
|
59
|
+
assert.equal(g.refused, false);
|
|
60
|
+
assert.deepEqual(g.deleted, ["src/tmp-helper.js"]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("the threshold tolerates up to `max` foreign deletions", async () => {
|
|
64
|
+
const d = repo();
|
|
65
|
+
rmSync(join(d, "src/b.js")); rmSync(join(d, "docs/old.md"));
|
|
66
|
+
assert.equal((await checkpoint(d, { keep: [], max: 2 })).refused, false);
|
|
67
|
+
const g = await checkpoint(d, { keep: [], max: 1 });
|
|
68
|
+
assert.equal(g.refused, true);
|
|
69
|
+
assert.ok(existsSync(join(d, "src/b.js")) && existsSync(join(d, "docs/old.md")));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("a rename into a deliverable commits; a rename of a non-deliverable is undone on both sides", async () => {
|
|
73
|
+
const d = repo();
|
|
74
|
+
renameSync(join(d, "docs/old.md"), join(d, "docs/new.md"));
|
|
75
|
+
assert.equal((await checkpoint(d, { keep: ["docs/new.md"] })).refused, false);
|
|
76
|
+
sh(d, "reset", "-q"); renameSync(join(d, "docs/new.md"), join(d, "docs/old.md"));
|
|
77
|
+
renameSync(join(d, "src/b.js"), join(d, "src/c.js"));
|
|
78
|
+
const g = await checkpoint(d, { keep: ["src/a.js"] });
|
|
79
|
+
assert.equal(g.refused, true);
|
|
80
|
+
assert.deepEqual(g.foreign, ["src/b.js"]);
|
|
81
|
+
assert.ok(existsSync(join(d, "src/b.js")), "original restored");
|
|
82
|
+
assert.deepEqual(stagedNames(d), [], "neither side of the rename stays staged");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("nothing staged, or git unreadable: no refusal", async () => {
|
|
86
|
+
const d = repo();
|
|
87
|
+
assert.deepEqual(await checkpoint(d, { keep: [] }), { refused: false, deleted: [], foreign: [] });
|
|
88
|
+
assert.equal((await guardStagedDeletions({ git: async () => { throw new Error("boom"); } })).refused, false);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("delguard helpers (#5819)", () => {
|
|
93
|
+
it("parses diff-index -z output and ignores anything else", () => {
|
|
94
|
+
assert.deepEqual(parseStagedDeletions("D\0a/b.js\0R087\0old.js\0new.js\0"), [{ path: "a/b.js", to: null }, { path: "old.js", to: "new.js" }]);
|
|
95
|
+
assert.deepEqual(parseStagedDeletions("diff --git a/src/foo.js b/src/foo.js\n+fix"), []);
|
|
96
|
+
assert.deepEqual(parseStagedDeletions(""), []);
|
|
97
|
+
});
|
|
98
|
+
it("FORGE_CHECKPOINT_MAX_DELETIONS: a non-negative integer, else 0", () => {
|
|
99
|
+
assert.equal(maxForeignDeletions({}), 0);
|
|
100
|
+
assert.equal(maxForeignDeletions({ FORGE_CHECKPOINT_MAX_DELETIONS: "5" }), 5);
|
|
101
|
+
assert.equal(maxForeignDeletions({ FORGE_CHECKPOINT_MAX_DELETIONS: "-1" }), 0);
|
|
102
|
+
assert.equal(maxForeignDeletions({ FORGE_CHECKPOINT_MAX_DELETIONS: "lots" }), 0);
|
|
103
|
+
});
|
|
104
|
+
});
|
package/bin/lean/depcache.mjs
CHANGED
|
@@ -14,11 +14,15 @@
|
|
|
14
14
|
* a missing tool, another filesystem (EXDEV) or a failed install leaves the lane as it was before. A snapshot that fails
|
|
15
15
|
* to link or repair falls back to a fresh install in the lane (status materialize-fallback, #4522); failed only when that
|
|
16
16
|
* install fails too.
|
|
17
|
+
* #5819: nothing here ever walks, chmods or removes through a link. pnpm links workspace packages into node_modules (a junction
|
|
18
|
+
* on Windows): every walk recreates a link instead of entering it, a recursive removal unlinks it, and a directory that resolves
|
|
19
|
+
* inside the worktree but outside every node_modules/.venv is never removed. A failed publish or materialize then checks out
|
|
20
|
+
* any tracked file that went missing (result `restore`), so a checkpoint can never commit the loss.
|
|
17
21
|
*/
|
|
18
22
|
import * as nodeFs from "node:fs";
|
|
19
23
|
import { createHash } from "node:crypto";
|
|
20
24
|
import { homedir, hostname } from "node:os";
|
|
21
|
-
import { join, dirname } from "node:path";
|
|
25
|
+
import { join, dirname, basename, relative, resolve, isAbsolute } from "node:path";
|
|
22
26
|
import { safeSegment } from "./ledger.mjs";
|
|
23
27
|
|
|
24
28
|
export const depcacheRoot = (env = process.env) => String(env.FORGE_DEPCACHE_ROOT ?? "").trim() || join(homedir(), ".forge", "depcache");
|
|
@@ -170,7 +174,7 @@ function commands(d, py = null) {
|
|
|
170
174
|
*/
|
|
171
175
|
export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = () => Date.now(), alive = pidAlive, host = hostname(), pid = process.pid,
|
|
172
176
|
env: procEnv = process.env, installTimeoutMs = DEPCACHE_INSTALL_TIMEOUT_MS, lockWaitMs = DEPCACHE_INSTALL_TIMEOUT_MS, pollMs = 1000,
|
|
173
|
-
sleep = (ms) => new Promise((r) => setTimeout(r, ms)) } = {}) {
|
|
177
|
+
sleep = (ms) => new Promise((r) => setTimeout(r, ms)), platform = process.platform } = {}) {
|
|
174
178
|
const disabled = () => String(procEnv.FORGE_DEPCACHE ?? "").trim() === "0";
|
|
175
179
|
const api = {}; // filled at the end; the env-library hook in prepare() passes it on
|
|
176
180
|
const store = (n) => join(root, STORES, n);
|
|
@@ -266,6 +270,68 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
266
270
|
try { return { locked: true, value: await fn() }; } finally { try { fs.rmSync(path, { force: true }); } catch { /* best effort */ } }
|
|
267
271
|
}
|
|
268
272
|
|
|
273
|
+
// ---- containment (#5819): never through a link, never a worktree path outside a dependency tree ----
|
|
274
|
+
const win = platform === "win32";
|
|
275
|
+
const real = (p) => { try { return fs.realpathSync(p); } catch { return null; } };
|
|
276
|
+
const same = (a, b) => (win ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
277
|
+
const inside = (p, dir) => { const r = relative(dir, p); return r === "" || (r.split(/[\\/]/)[0] !== ".." && !isAbsolute(r)); };
|
|
278
|
+
/** A path inside a dependency tree (some segment is node_modules or .venv). */
|
|
279
|
+
const depRel = (rel) => String(rel).split(/[\\/]/).some((x) => x === "node_modules" || x === ".venv");
|
|
280
|
+
let realMemo = { dir: null, real: null }; // the last parent resolved: a walk asks for siblings in a row
|
|
281
|
+
/**
|
|
282
|
+
* A symlink or junction. The dirent/lstat type decides on POSIX; on Windows a directory also counts when its real path is
|
|
283
|
+
* not its parent's real path plus its name (a junction a filesystem or Node version reports as a plain directory).
|
|
284
|
+
*/
|
|
285
|
+
function linkish(p, ent = null) {
|
|
286
|
+
let dir;
|
|
287
|
+
if (ent) { if (ent.isSymbolicLink()) return true; dir = ent.isDirectory(); }
|
|
288
|
+
else { try { const st = fs.lstatSync(p); if (st.isSymbolicLink()) return true; dir = st.isDirectory(); } catch { return false; } }
|
|
289
|
+
if (!win || !dir) return false;
|
|
290
|
+
const parent = dirname(p);
|
|
291
|
+
if (parent !== realMemo.dir) realMemo = { dir: parent, real: real(parent) };
|
|
292
|
+
const rp = real(p), rd = realMemo.real;
|
|
293
|
+
return !rp || !rd || !same(rp, join(rd, basename(p)));
|
|
294
|
+
}
|
|
295
|
+
/** Refuse a directory whose real path is inside `protect` (the worktree) but outside every dependency tree. */
|
|
296
|
+
function guardDep(p, protect, rw = protect ? real(protect) : null) {
|
|
297
|
+
const rp = real(p);
|
|
298
|
+
if (rp && rw && inside(rp, rw) && !depRel(relative(rw, rp))) {
|
|
299
|
+
throw Object.assign(new Error(`refusing to remove ${p}: it resolves to ${rp}, a worktree path outside every node_modules/.venv`), { code: "EFORGE_PROTECTED" });
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/** Remove the link itself (a Windows junction may need rmdir), never its target. */
|
|
303
|
+
const dropLink = (p) => { try { fs.unlinkSync(p); } catch (e) { if (e?.code === "ENOENT") return; fs.rmdirSync(p); } };
|
|
304
|
+
const dropFile = (p) => {
|
|
305
|
+
try { fs.unlinkSync(p); } catch (e) {
|
|
306
|
+
if (e?.code === "ENOENT") return;
|
|
307
|
+
if (e?.code !== "EPERM" && e?.code !== "EACCES") throw e;
|
|
308
|
+
fs.chmodSync(p, 0o666); fs.unlinkSync(p); // a read-only snapshot file on Windows
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
/**
|
|
312
|
+
* Recursive removal that never follows a link (unlinks it) and never removes a directory resolving to a worktree path outside a
|
|
313
|
+
* dependency tree (`protect`: the worktree; checked at the root, and at every real directory on Windows).
|
|
314
|
+
*/
|
|
315
|
+
function safeRm(p, protect = null) {
|
|
316
|
+
let st;
|
|
317
|
+
realMemo = { dir: null, real: null };
|
|
318
|
+
try { st = fs.lstatSync(p); } catch { return; }
|
|
319
|
+
if (st.isSymbolicLink() || (st.isDirectory() && linkish(p))) { dropLink(p); return; }
|
|
320
|
+
if (!st.isDirectory()) { dropFile(p); return; }
|
|
321
|
+
const rw = protect ? real(protect) : null;
|
|
322
|
+
guardDep(p, protect, rw);
|
|
323
|
+
const walk = (d) => {
|
|
324
|
+
for (const ent of fs.readdirSync(d, { withFileTypes: true })) {
|
|
325
|
+
const q = join(d, ent.name);
|
|
326
|
+
if (linkish(q, ent)) dropLink(q);
|
|
327
|
+
else if (ent.isDirectory()) { if (win) guardDep(q, protect, rw); walk(q); }
|
|
328
|
+
else dropFile(q);
|
|
329
|
+
}
|
|
330
|
+
fs.rmdirSync(d);
|
|
331
|
+
};
|
|
332
|
+
walk(p);
|
|
333
|
+
}
|
|
334
|
+
|
|
269
335
|
// ---- trees ----
|
|
270
336
|
const boundary = (p) => new RegExp(p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "(?=$|[/\\\\'\"\\s:;])", "g");
|
|
271
337
|
/** Hardlink a file; across filesystems (EXDEV, #4909) copy it with its mode so the cache is reused instead of reinstalled. */
|
|
@@ -282,16 +348,33 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
282
348
|
* shared inode, or the open-for-write fails with EACCES and the lane falls back to a full install.
|
|
283
349
|
*/
|
|
284
350
|
const mutableState = (rel, name) => (rel === "" && /^\.(modules\.yaml|pnpm-workspace-state.*\.json|package-lock\.json|yarn-state\.yml)$/.test(name)) || (rel === ".pnpm" && name === "lock.yaml");
|
|
285
|
-
/**
|
|
286
|
-
|
|
351
|
+
/**
|
|
352
|
+
* Recreate the link `sp` -> `t` at `dp`. #5807/#5819: without the symlink privilege on Windows (EPERM) a directory target
|
|
353
|
+
* becomes a junction (absolute, resolved against `at`, where `dp` finally lives) and a file target a hardlink or copy of the
|
|
354
|
+
* file; the target itself is never entered, moved or copied as a tree.
|
|
355
|
+
*/
|
|
356
|
+
function relink(sp, dp, t, at) {
|
|
357
|
+
try { fs.symlinkSync(t, dp); return; } catch (e) { if (!(win && e?.code === "EPERM")) throw e; }
|
|
358
|
+
const fileAt = isAbsolute(t) ? t : resolve(dirname(sp), t);
|
|
359
|
+
let st = null;
|
|
360
|
+
try { st = fs.statSync(fileAt); } catch { /* dangling: a junction to where it will be */ }
|
|
361
|
+
if (st?.isFile()) { linkOrCopy(fileAt, dp); return; }
|
|
362
|
+
fs.symlinkSync(isAbsolute(t) ? t : resolve(dirname(at), t), dp, "junction");
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Hardlink `src` into `dst` (copy on EXDEV); links recreated (never entered, #5819); files in bin dirs that name `from` are copied
|
|
366
|
+
* with `to` instead. `at`: where `dst` finally lives (a publish builds in a tmp dir renamed into place), for junction targets.
|
|
367
|
+
*/
|
|
368
|
+
function linkTree(src, dst, { from = null, to = null, binDir = () => false, at = dst } = {}) {
|
|
287
369
|
const re = from && to && from !== to ? boundary(from) : null;
|
|
370
|
+
realMemo = { dir: null, real: null };
|
|
288
371
|
const walk = (s, d, rel) => {
|
|
289
372
|
fs.mkdirSync(d, { recursive: true });
|
|
290
373
|
for (const ent of fs.readdirSync(s, { withFileTypes: true })) {
|
|
291
374
|
const sp = join(s, ent.name), dp = join(d, ent.name), r = rel ? `${rel}/${ent.name}` : ent.name;
|
|
292
|
-
if (ent
|
|
375
|
+
if (linkish(sp, ent)) {
|
|
293
376
|
const t = String(fs.readlinkSync(sp));
|
|
294
|
-
|
|
377
|
+
relink(sp, dp, re ? t.replace(re, to) : t, join(at, r));
|
|
295
378
|
} else if (ent.isDirectory()) walk(sp, dp, r);
|
|
296
379
|
else if (ent.isFile()) {
|
|
297
380
|
if (re && binDir(rel)) {
|
|
@@ -313,6 +396,7 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
313
396
|
function readOnly(dir) {
|
|
314
397
|
for (const ent of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
315
398
|
const p = join(dir, ent.name);
|
|
399
|
+
if (linkish(p, ent)) continue; // #5819: never chmod through a link
|
|
316
400
|
if (ent.isDirectory()) readOnly(p);
|
|
317
401
|
else if (ent.isFile()) fs.chmodSync(p, fs.statSync(p).mode & 0o7555);
|
|
318
402
|
}
|
|
@@ -321,7 +405,8 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
321
405
|
const treesOf = (wt, d, pkgs) => (JS.has(d.eco) ? pkgs.map((p) => (dirname(p) === "." ? "node_modules" : `${dirname(p)}/node_modules`)) : [".venv"])
|
|
322
406
|
.filter((t, i, a) => a.indexOf(t) === i && fs.existsSync(join(wt, t)));
|
|
323
407
|
const binDirFor = (d) => (JS.has(d.eco) ? (rel) => rel.split("/").includes(".bin") : (rel) => rel === "bin");
|
|
324
|
-
|
|
408
|
+
/** #5819: only dependency trees, never through a link, never a worktree path outside a dependency tree. */
|
|
409
|
+
const rmTrees = (wt, trees) => { for (const t of trees) { if (!depRel(t)) continue; try { safeRm(join(wt, t), wt); } catch { /* best effort */ } } };
|
|
325
410
|
|
|
326
411
|
/** #5590: the existing trees an install did not finish (no marker, a declared dependency missing, a venv without a working python). */
|
|
327
412
|
function brokenTrees(wt, d, trees) {
|
|
@@ -340,22 +425,41 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
340
425
|
function publish(wt, d, key, trees, snap) {
|
|
341
426
|
const tmp = `${snap}.tmp-${pid}`;
|
|
342
427
|
try {
|
|
343
|
-
|
|
344
|
-
for (const t of trees) linkTree(join(wt, t), join(tmp, t));
|
|
428
|
+
safeRm(tmp, wt);
|
|
429
|
+
for (const t of trees) linkTree(join(wt, t), join(tmp, t), { at: join(snap, t) });
|
|
345
430
|
readOnly(tmp);
|
|
346
431
|
fs.writeFileSync(join(tmp, "manifest.json"), JSON.stringify({ v: 1, eco: d.eco, key, prefix: wt, trees, created: now() }) + "\n");
|
|
347
432
|
fs.writeFileSync(join(tmp, "last-used"), String(now()));
|
|
348
433
|
try { fs.renameSync(tmp, snap); } catch (e) {
|
|
349
434
|
if (!fs.existsSync(join(snap, "manifest.json"))) throw e;
|
|
350
|
-
|
|
435
|
+
safeRm(tmp, wt); // another lane published first: never write into its snapshot
|
|
351
436
|
}
|
|
352
437
|
return null;
|
|
353
438
|
} catch (e) {
|
|
354
|
-
try {
|
|
439
|
+
try { safeRm(tmp, wt); } catch { /* best effort */ }
|
|
355
440
|
return e?.code === "EXDEV" ? "cache is on another filesystem than the worktree (EXDEV)" : `publish failed: ${msg(e)}`;
|
|
356
441
|
}
|
|
357
442
|
}
|
|
358
443
|
|
|
444
|
+
/**
|
|
445
|
+
* #5819: after a failed publish/materialize/install, check out every tracked file (outside node_modules/.venv) that is missing
|
|
446
|
+
* from the checkout `wt` belongs to. null: not a git checkout or nothing missing; else {restored, missing, sample} or {error}.
|
|
447
|
+
*/
|
|
448
|
+
async function restoreTracked(wt) {
|
|
449
|
+
let top = "";
|
|
450
|
+
try { top = String(await exec("git", ["rev-parse", "--show-toplevel"], { cwd: wt, timeoutMs: 60000 })).trim().split("\n")[0]; } catch { return null; }
|
|
451
|
+
if (!top || !isAbsolute(top)) return null;
|
|
452
|
+
try {
|
|
453
|
+
const out = String(await exec("git", ["ls-files", "--deleted", "-z"], { cwd: top, timeoutMs: 60000 }));
|
|
454
|
+
const gone = [...new Set(out.split("\0").filter((p) => p && !/\n/.test(p) && !depRel(p)))].filter((p) => !present(join(top, p)));
|
|
455
|
+
if (!gone.length) return null;
|
|
456
|
+
for (let i = 0; i < gone.length; i += 200) await exec("git", ["checkout", "-q", "--", ...gone.slice(i, i + 200)], { cwd: top, timeoutMs: 120000 });
|
|
457
|
+
const left = gone.filter((p) => !present(join(top, p)));
|
|
458
|
+
return { restored: gone.length - left.length, missing: left.length, sample: gone.slice(0, 10) };
|
|
459
|
+
} catch (e) { return { error: msg(e) }; }
|
|
460
|
+
}
|
|
461
|
+
const failedRun = (r) => r.status === "failed" || r.status === "materialize-fallback" || (r.published === false && /^(publish failed|cache is on another filesystem)/.test(String(r.reason ?? "")));
|
|
462
|
+
|
|
359
463
|
async function prepareOne(wt, keyRoot, d, laneEnv, publishSnap = true) {
|
|
360
464
|
const t0 = now();
|
|
361
465
|
let repaired = null;
|
|
@@ -467,11 +571,15 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
467
571
|
const keyRoot = join(root, safeSegment(repoKey ?? "repo"));
|
|
468
572
|
const out = [];
|
|
469
573
|
for (const d of found) {
|
|
574
|
+
const at = d.dir ? join(wt, d.dir) : wt;
|
|
575
|
+
let r;
|
|
470
576
|
try {
|
|
471
|
-
|
|
577
|
+
r = await prepareOne(at, keyRoot, d, laneEnv && typeof laneEnv === "object" ? laneEnv : undefined, publishSnap);
|
|
472
578
|
const claimed = envHit && r.status === "skipped" && /already exists in the worktree$/.test(String(r.reason ?? ""));
|
|
473
|
-
|
|
474
|
-
} catch (e) {
|
|
579
|
+
r = 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 ?? "." };
|
|
580
|
+
} catch (e) { r = { status: "failed", eco: d.eco, key: null, ms: 0, reason: msg(e), dir: d.dir ?? "." }; }
|
|
581
|
+
if (failedRun(r)) { const restore = await restoreTracked(at); if (restore) r = { ...r, restore }; } // #5819
|
|
582
|
+
out.push(r);
|
|
475
583
|
}
|
|
476
584
|
return out;
|
|
477
585
|
}
|
|
@@ -532,8 +640,8 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
532
640
|
async function remove(entry) {
|
|
533
641
|
const p = String(entry?.path ?? "");
|
|
534
642
|
if (!p.startsWith(root + "/") || p.slice(root.length + 1).split("/").length !== 2) return false;
|
|
535
|
-
if (entry.kind === "snapshot") return (await withLock(`${p}.lock`, async () => {
|
|
536
|
-
|
|
643
|
+
if (entry.kind === "snapshot") return (await withLock(`${p}.lock`, async () => { safeRm(p); return true; }, { wait: false })).locked; // #5819: never through a link
|
|
644
|
+
safeRm(p);
|
|
537
645
|
return true;
|
|
538
646
|
}
|
|
539
647
|
|
|
@@ -544,6 +652,6 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
544
652
|
return removed;
|
|
545
653
|
}
|
|
546
654
|
|
|
547
|
-
return Object.assign(api, { env, prepare, describe, prune, scan, remove, root, linkTree, readOnly });
|
|
655
|
+
return Object.assign(api, { env, prepare, describe, prune, scan, remove, root, linkTree, readOnly, safeRm });
|
|
548
656
|
}
|
|
549
657
|
|
|
@@ -5,6 +5,7 @@ import { describe, it } from "node:test";
|
|
|
5
5
|
import assert from "node:assert/strict";
|
|
6
6
|
import * as fs from "node:fs";
|
|
7
7
|
import { mkdirSync, writeFileSync, readFileSync, existsSync, statSync, lstatSync, readlinkSync, readdirSync, symlinkSync, rmSync, renameSync } from "node:fs";
|
|
8
|
+
import { execFileSync } from "node:child_process";
|
|
8
9
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
9
10
|
import { join, dirname, relative } from "node:path";
|
|
10
11
|
import { makeDepCache } from "./depcache.mjs";
|
|
@@ -688,3 +689,113 @@ describe("depcache (#5651): no silent fallback to an out-of-range default python
|
|
|
688
689
|
assert.match(r.reason ?? "", /--no-root/);
|
|
689
690
|
});
|
|
690
691
|
});
|
|
692
|
+
|
|
693
|
+
describe("depcache (#5819): a failed publish or materialize never touches workspace package sources", () => {
|
|
694
|
+
const sh = (cwd, ...a) => execFileSync("git", a, { cwd, encoding: "utf8" });
|
|
695
|
+
const SRC = Array.from({ length: 6 }, (_, i) => `packages/adapters/src/f${i}.ts`);
|
|
696
|
+
/** A pnpm workspace in a real git repo; node_modules ignored. */
|
|
697
|
+
const wsRepo = (base, name) => {
|
|
698
|
+
const wt = join(base, "wt", name);
|
|
699
|
+
mkdirSync(wt, { recursive: true });
|
|
700
|
+
put(join(wt, "package.json"), '{"name":"web","private":true}');
|
|
701
|
+
put(join(wt, "pnpm-workspace.yaml"), "packages:\n - packages/*\n");
|
|
702
|
+
put(join(wt, "pnpm-lock.yaml"), "lockfileVersion: 9\nlodash: 4.17.21\n");
|
|
703
|
+
put(join(wt, "packages/a/package.json"), '{"name":"a"}');
|
|
704
|
+
put(join(wt, "packages/adapters/package.json"), '{"name":"@scope/adapters"}');
|
|
705
|
+
for (const f of SRC) put(join(wt, f), `export const v = "${f}";\n`);
|
|
706
|
+
put(join(wt, ".gitignore"), "node_modules/\n");
|
|
707
|
+
sh(wt, "init", "-q"); sh(wt, "config", "user.email", "t@t"); sh(wt, "config", "user.name", "t");
|
|
708
|
+
sh(wt, "add", "-A"); sh(wt, "commit", "-q", "-m", "base");
|
|
709
|
+
return wt;
|
|
710
|
+
};
|
|
711
|
+
/** Real git; the fake pnpm, plus pnpm's link of the workspace package (absolute, as a Windows junction reads back). */
|
|
712
|
+
const wsExec = (f) => async (cmd, args, o = {}) => {
|
|
713
|
+
if (cmd === "git") return execFileSync("git", args, { cwd: o.cwd, encoding: "utf8" });
|
|
714
|
+
const out = await f.exec(cmd, args, o);
|
|
715
|
+
if (cmd === "pnpm" && !args.includes("--offline")) {
|
|
716
|
+
mkdirSync(join(o.cwd, "node_modules/@scope"), { recursive: true });
|
|
717
|
+
symlinkSync(join(o.cwd, "packages/adapters"), join(o.cwd, "node_modules/@scope/adapters"));
|
|
718
|
+
}
|
|
719
|
+
return out;
|
|
720
|
+
};
|
|
721
|
+
const eperm = () => Object.assign(new Error("EPERM: operation not permitted, symlink"), { code: "EPERM" });
|
|
722
|
+
/** Windows without the symlink privilege, where a junction reads as a plain directory (the worst case for a tree walk). */
|
|
723
|
+
const winFs = ({ junctions = true, extra = {} } = {}) => ({
|
|
724
|
+
...fs,
|
|
725
|
+
readdirSync: (p, o) => {
|
|
726
|
+
const l = fs.readdirSync(p, o);
|
|
727
|
+
if (!o?.withFileTypes) return l;
|
|
728
|
+
return l.map((e) => {
|
|
729
|
+
if (!e.isSymbolicLink()) return e;
|
|
730
|
+
let dir = false;
|
|
731
|
+
try { dir = fs.statSync(join(p, e.name)).isDirectory(); } catch { /* dangling */ }
|
|
732
|
+
return dir ? { name: e.name, isSymbolicLink: () => false, isDirectory: () => true, isFile: () => false } : e;
|
|
733
|
+
});
|
|
734
|
+
},
|
|
735
|
+
symlinkSync: (t, p, type) => { if (type !== "junction" || !junctions) throw eperm(); return fs.symlinkSync(t, p); },
|
|
736
|
+
...extra,
|
|
737
|
+
});
|
|
738
|
+
const clean = (wt) => sh(wt, "status", "--porcelain").trim();
|
|
739
|
+
const filesUnder = (dir) => { const out = []; const walk = (d) => { for (const e of readdirSync(d, { withFileTypes: true })) { const p = join(d, e.name); if (e.isDirectory()) walk(p); else out.push(p); } }; walk(dir); return out; };
|
|
740
|
+
|
|
741
|
+
it("publish: a link to a workspace package is recreated (a junction on EPERM), never entered, copied or chmodded", async () => {
|
|
742
|
+
const base = scratch(), root = join(base, "cache"), wt = wsRepo(base, "a");
|
|
743
|
+
const before = statSync(join(wt, SRC[0]));
|
|
744
|
+
const [r] = await makeDepCache({ root, exec: wsExec(fakeExec()), env: {}, fs: winFs(), platform: "win32", pollMs: 5 }).prepare({ wt, repoKey: "r" });
|
|
745
|
+
assert.equal(r.status, "miss-installed", JSON.stringify(r));
|
|
746
|
+
assert.equal(r.published, true, r.reason);
|
|
747
|
+
assert.equal(clean(wt), "", "every tracked file untouched");
|
|
748
|
+
assert.equal(statSync(join(wt, SRC[0])).mode, before.mode, "the source was not made read-only through a hardlink");
|
|
749
|
+
const [snap] = snapDirs(root, "pnpm");
|
|
750
|
+
assert.ok(lstatSync(join(snap, "node_modules/@scope/adapters")).isSymbolicLink(), "the snapshot holds a link, not the package");
|
|
751
|
+
const inos = new Set(SRC.map((f) => statSync(join(wt, f)).ino));
|
|
752
|
+
assert.deepEqual(filesUnder(snap).filter((p) => !lstatSync(p).isSymbolicLink() && inos.has(statSync(p).ino)), [], "no workspace source is hardlinked into the cache");
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
it("a publish that fails mid-way (EPERM, no junction either) leaves every tracked file and no tmp dir", async () => {
|
|
756
|
+
const base = scratch(), root = join(base, "cache"), wt = wsRepo(base, "a");
|
|
757
|
+
const [r] = await makeDepCache({ root, exec: wsExec(fakeExec()), env: {}, fs: winFs({ junctions: false }), platform: "win32", pollMs: 5 }).prepare({ wt, repoKey: "r" });
|
|
758
|
+
assert.equal(r.status, "miss-installed");
|
|
759
|
+
assert.equal(r.published, false);
|
|
760
|
+
assert.match(r.reason, /^publish failed: EPERM/);
|
|
761
|
+
assert.equal(clean(wt), "");
|
|
762
|
+
for (const f of SRC) assert.ok(existsSync(join(wt, f)), f);
|
|
763
|
+
assert.equal(r.restore, undefined, "nothing was missing");
|
|
764
|
+
assert.deepEqual(readdirSync(join(root, "r")).filter((n) => /\.tmp-/.test(n)), []);
|
|
765
|
+
assert.equal(snapDirs(root, "pnpm").length, 0);
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
it("tracked files that go missing during a failed publish are checked out again, with the evidence on the result", async () => {
|
|
769
|
+
const base = scratch(), root = join(base, "cache"), wt = wsRepo(base, "a");
|
|
770
|
+
let hit = false;
|
|
771
|
+
const destructive = { ...fs, linkSync: (s, d) => { if (!hit) { hit = true; rmSync(join(wt, "packages/adapters/src"), { recursive: true }); throw eperm(); } return fs.linkSync(s, d); } };
|
|
772
|
+
const [r] = await makeDepCache({ root, exec: wsExec(fakeExec()), env: {}, fs: destructive, pollMs: 5 }).prepare({ wt, repoKey: "r" });
|
|
773
|
+
assert.equal(r.published, false);
|
|
774
|
+
assert.deepEqual({ restored: r.restore.restored, missing: r.restore.missing }, { restored: SRC.length, missing: 0 });
|
|
775
|
+
assert.deepEqual([...r.restore.sample].sort(), [...SRC].sort());
|
|
776
|
+
assert.equal(clean(wt), "", "the worktree is whole again before the lane goes on");
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
it("materialize: a failed repair removes the linked trees without following the workspace link", async () => {
|
|
780
|
+
const base = scratch(), root = join(base, "cache");
|
|
781
|
+
const a = wsRepo(base, "a");
|
|
782
|
+
const [ra] = await makeDepCache({ root, exec: wsExec(fakeExec()), env: {}, pollMs: 5 }).prepare({ wt: a, repoKey: "r" });
|
|
783
|
+
assert.equal(ra.published, true, ra.reason);
|
|
784
|
+
const b = wsRepo(base, "b");
|
|
785
|
+
const [rb] = await makeDepCache({ root, exec: wsExec(fakeExec({ failRepair: true })), env: {}, fs: winFs(), platform: "win32", pollMs: 5 }).prepare({ wt: b, repoKey: "r" });
|
|
786
|
+
assert.equal(rb.status, "materialize-fallback", JSON.stringify(rb));
|
|
787
|
+
for (const wt of [a, b]) { assert.equal(clean(wt), "", wt); for (const f of SRC) assert.ok(existsSync(join(wt, f)), `${wt} ${f}`); }
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
it("safeRm unlinks links, never their targets, and refuses a worktree path outside node_modules/.venv", async () => {
|
|
791
|
+
const base = scratch(), wt = wsRepo(base, "a");
|
|
792
|
+
const cache = makeDepCache({ root: join(base, "cache"), exec: wsExec(fakeExec()), env: {}, fs: winFs(), platform: "win32" });
|
|
793
|
+
mkdirSync(join(wt, "node_modules/@scope"), { recursive: true });
|
|
794
|
+
symlinkSync(join(wt, "packages/adapters"), join(wt, "node_modules/@scope/adapters"));
|
|
795
|
+
put(join(wt, "node_modules/x/index.js"), "x");
|
|
796
|
+
assert.throws(() => cache.safeRm(join(wt, "packages"), wt), (e) => e.code === "EFORGE_PROTECTED");
|
|
797
|
+
cache.safeRm(join(wt, "node_modules"), wt);
|
|
798
|
+
assert.ok(!existsSync(join(wt, "node_modules")));
|
|
799
|
+
assert.equal(clean(wt), "");
|
|
800
|
+
});
|
|
801
|
+
});
|
package/bin/lean/design-gate.mjs
CHANGED
|
@@ -111,11 +111,11 @@ export function visualGate({ cfg = null, files = [], specs = false, sources = {}
|
|
|
111
111
|
// #5648: `changes` {file: pageChange class}: generated files are exempt, a copy-only edit needs the visual check but no spec
|
|
112
112
|
const routeFiles = designFiles(files, cfg).filter((f) => changes[f] !== "generated");
|
|
113
113
|
const routes = routeFiles.map((file) => ({ file, route: routeOf(file), page: PAGE_ENTRY_RE.test(file) }));
|
|
114
|
-
const rows = [], add = (kind, route, detail) => rows.push({ kind, route, detail });
|
|
114
|
+
const rows = [], add = (kind, route, detail, file) => rows.push({ kind, route, detail, file });
|
|
115
115
|
for (const r of routes) {
|
|
116
116
|
const spec = typeof specs === "object" && specs !== null ? Boolean(specs[r.route] ?? specs[r.file]) : Boolean(specs);
|
|
117
117
|
const copy = changes[r.file] === "copy";
|
|
118
|
-
if (r.page && !spec && !copy) add("design_spec_missing", r.route, `${r.file} has no approved FORGE:DESIGN_SPEC (label ${cfg.specLabel}): run /design first
|
|
118
|
+
if (r.page && !spec && !copy) add("design_spec_missing", r.route, `${r.file} has no approved FORGE:DESIGN_SPEC (label ${cfg.specLabel}): run /design first`, r.file);
|
|
119
119
|
if (r.page && !copy && sources[r.file] != null) {
|
|
120
120
|
for (const f of critiqueMarkup(sources[r.file])) if (f.severity === "block") add("visual_critique_failed", r.route, `${r.file}: ${f.id}: ${f.detail}`);
|
|
121
121
|
}
|
|
@@ -133,12 +133,12 @@ export function visualGate({ cfg = null, files = [], specs = false, sources = {}
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
/** Lane precheck rows (conformance.unimplemented) for the diff's user-visible routes; [] unless design.routes is set and gate is blocking. */
|
|
136
|
-
export function designFailures({ cfg = null, files = [], specs = false, readFile = () => "", added = null, diff = "" } = {}) {
|
|
136
|
+
export function designFailures({ cfg = null, files = [], specs = false, readFile = () => "", added = null, diff = "", covered = [], bugFix = false } = {}) {
|
|
137
137
|
if (!designOn(cfg) || cfg.gate !== "blocking") return [];
|
|
138
138
|
const sources = {}, changes = {};
|
|
139
|
-
for (const f of designFiles(files, cfg)) changes[f] = pageChange(f, { added, diff, readFile }); // no added list: "new", fail closed
|
|
139
|
+
for (const f of designFiles(files, cfg)) changes[f] = pageChange(f, { added, diff, readFile, bugFix }); // no added list: "new", fail closed
|
|
140
140
|
for (const f of designPages(files, cfg)) sources[f] = String(readFile(f) ?? "");
|
|
141
|
-
return visualGate({ cfg, files, specs, sources, changes }).rows.map((r) => ({ code: OUTCOME_CODES.CONFORMANCE_UNIMPLEMENTED, kind: r.kind, detail: r.detail }));
|
|
141
|
+
return visualGate({ cfg, files, specs, sources, changes }).rows.filter((r) => !(r.kind === "design_spec_missing" && covered.includes(r.file))).map((r) => ({ code: OUTCOME_CODES.CONFORMANCE_UNIMPLEMENTED, kind: r.kind, detail: r.detail })); // #5729: `covered`: files the page gate already reports page_design_missing for
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
/** Markdown for the FORGE:VISUAL_GATE comment (review-pr-staging). Rendered screenshots are listed by path. */
|
|
@@ -188,3 +188,17 @@ describe("copy-only edits to existing pages (#5648)", () => {
|
|
|
188
188
|
assert.equal(designGate({ files: [P], cfg }).route, true);
|
|
189
189
|
});
|
|
190
190
|
});
|
|
191
|
+
|
|
192
|
+
describe("designFailures dedupe against the page gate (#5729)", () => {
|
|
193
|
+
const page = "web/src/app/(site)/pricing/page.tsx";
|
|
194
|
+
const diff = `+++ b/${page}\n-<a href="/x">x</a>\n+<a href="/y">x</a>\n`;
|
|
195
|
+
const base = { cfg, files: [page], added: [], diff, readFile: () => "line\n".repeat(60) };
|
|
196
|
+
it("href-only edit is exempt from design_spec_missing", () => {
|
|
197
|
+
assert.ok(!designFailures(base).some((r) => r.kind === "design_spec_missing"));
|
|
198
|
+
});
|
|
199
|
+
it("a rewrite keeps one design_spec_missing unless the page gate covers the file", () => {
|
|
200
|
+
const rw = { ...base, diff: `+++ b/${page}\n+<div className="x">hi</div>\n` };
|
|
201
|
+
assert.equal(designFailures(rw).filter((r) => r.kind === "design_spec_missing").length, 1);
|
|
202
|
+
assert.equal(designFailures({ ...rw, covered: [page] }).filter((r) => r.kind === "design_spec_missing").length, 0);
|
|
203
|
+
});
|
|
204
|
+
});
|