forgedock 1.61.1 → 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.
Files changed (134) hide show
  1. package/bin/config-schema.mjs +10 -1
  2. package/bin/engine/outcome-codes.mjs +4 -0
  3. package/bin/engine-cli.mjs +160 -18
  4. package/bin/env/env.mjs +6 -4
  5. package/bin/forge-home-check.mjs +91 -0
  6. package/bin/forgedock.mjs +50 -7
  7. package/bin/gc.mjs +2 -0
  8. package/bin/hooks/pre-tool-use.mjs +4 -0
  9. package/bin/journey.mjs +55 -5
  10. package/bin/lean/admission.mjs +16 -5
  11. package/bin/lean/batch-health.mjs +55 -16
  12. package/bin/lean/batch-health.test.mjs +67 -1
  13. package/bin/lean/batch.mjs +8 -0
  14. package/bin/lean/batch.test.mjs +5 -0
  15. package/bin/lean/ceiling.mjs +20 -0
  16. package/bin/lean/ceiling.test.mjs +33 -2
  17. package/bin/lean/ci-gate.mjs +240 -0
  18. package/bin/lean/ci-gate.test.mjs +227 -0
  19. package/bin/lean/ci-precheck.mjs +178 -0
  20. package/bin/lean/ci-precheck.test.mjs +149 -0
  21. package/bin/lean/conformance.mjs +118 -20
  22. package/bin/lean/conformance.test.mjs +193 -3
  23. package/bin/lean/context.test.mjs +7 -6
  24. package/bin/lean/dag.mjs +128 -0
  25. package/bin/lean/dag.test.mjs +131 -0
  26. package/bin/lean/decisions.mjs +5 -4
  27. package/bin/lean/decisions.test.mjs +11 -0
  28. package/bin/lean/delguard.mjs +84 -0
  29. package/bin/lean/delguard.test.mjs +104 -0
  30. package/bin/lean/depcache.mjs +125 -17
  31. package/bin/lean/depcache.test.mjs +111 -0
  32. package/bin/lean/design-gate.mjs +5 -5
  33. package/bin/lean/design-gate.test.mjs +14 -0
  34. package/bin/lean/effects.mjs +81 -7
  35. package/bin/lean/execution.mjs +81 -15
  36. package/bin/lean/execution.test.mjs +156 -3
  37. package/bin/lean/forgedock-lane-workflow.test.mjs +35 -0
  38. package/bin/lean/guardgate.mjs +30 -7
  39. package/bin/lean/guardgate.test.mjs +44 -1
  40. package/bin/lean/guards.test.mjs +1 -1
  41. package/bin/lean/heavy.test.mjs +87 -0
  42. package/bin/lean/hotarea.mjs +73 -0
  43. package/bin/lean/hotarea.test.mjs +73 -0
  44. package/bin/lean/issuewatch-reconcile.mjs +20 -1
  45. package/bin/lean/issuewatch-reconcile.test.mjs +30 -0
  46. package/bin/lean/lanecheck.mjs +27 -3
  47. package/bin/lean/lanecheck.test.mjs +47 -5
  48. package/bin/lean/laneconfine.mjs +83 -0
  49. package/bin/lean/laneconfine.test.mjs +113 -0
  50. package/bin/lean/lean.mjs +398 -91
  51. package/bin/lean/lean.test.mjs +792 -26
  52. package/bin/lean/live-reconcile.mjs +169 -0
  53. package/bin/lean/live-reconcile.test.mjs +176 -0
  54. package/bin/lean/orchestrate-envhold.test.mjs +245 -0
  55. package/bin/lean/orchestrate-hostfallback.test.mjs +39 -0
  56. package/bin/lean/orchestrate.mjs +207 -17
  57. package/bin/lean/outcomeevidence.mjs +104 -0
  58. package/bin/lean/outcomeevidence.test.mjs +78 -0
  59. package/bin/lean/page-capture.mjs +68 -0
  60. package/bin/lean/page-capture.test.mjs +44 -0
  61. package/bin/lean/pagegate.mjs +46 -7
  62. package/bin/lean/pagegate.test.mjs +66 -1
  63. package/bin/lean/postdeploy-check.mjs +18 -4
  64. package/bin/lean/postdeploy-check.test.mjs +32 -1
  65. package/bin/lean/prefilter.mjs +36 -4
  66. package/bin/lean/prefilter.test.mjs +31 -1
  67. package/bin/lean/preflight.mjs +22 -0
  68. package/bin/lean/preflight.test.mjs +19 -1
  69. package/bin/lean/probe.mjs +18 -0
  70. package/bin/lean/probe.test.mjs +40 -0
  71. package/bin/lean/prompts.mjs +41 -4
  72. package/bin/lean/recovery.test.mjs +20 -0
  73. package/bin/lean/recurrence.mjs +133 -0
  74. package/bin/lean/recurrence.test.mjs +99 -0
  75. package/bin/lean/release-config.mjs +2 -1
  76. package/bin/lean/release-config.test.mjs +18 -0
  77. package/bin/lean/release-control.mjs +4 -2
  78. package/bin/lean/release-control.test.mjs +15 -0
  79. package/bin/lean/release-merge-hold.mjs +65 -0
  80. package/bin/lean/release-merge-hold.test.mjs +69 -0
  81. package/bin/lean/release-review.mjs +26 -9
  82. package/bin/lean/release-review.test.mjs +53 -0
  83. package/bin/lean/release-status.mjs +3 -1
  84. package/bin/lean/release-status.test.mjs +11 -0
  85. package/bin/lean/release.test.mjs +26 -1
  86. package/bin/lean/render.mjs +8 -7
  87. package/bin/lean/repro-output.test.mjs +45 -0
  88. package/bin/lean/routing.mjs +49 -0
  89. package/bin/lean/routing.test.mjs +54 -1
  90. package/bin/lean/run-issue-placement.test.mjs +30 -1
  91. package/bin/lean/sandbox-actions.mjs +121 -0
  92. package/bin/lean/sandbox-actions.test.mjs +94 -0
  93. package/bin/lean/sandbox-provider.contract.test.mjs +22 -1
  94. package/bin/lean/sandbox-remote.mjs +3 -1
  95. package/bin/lean/schedd-health.mjs +14 -2
  96. package/bin/lean/schedd-health.test.mjs +13 -0
  97. package/bin/lean/schedd.mjs +43 -17
  98. package/bin/lean/schedd.test.mjs +61 -1
  99. package/bin/lean/toolchain.mjs +16 -6
  100. package/bin/lean/toolplace.mjs +12 -0
  101. package/bin/lean/weakguard.mjs +105 -0
  102. package/bin/lean/weakguard.test.mjs +59 -0
  103. package/bin/lean/winspawn.mjs +61 -0
  104. package/bin/lean/winspawn.test.mjs +45 -0
  105. package/bin/lean/worktree.mjs +3 -1
  106. package/bin/lean/worktree.test.mjs +11 -0
  107. package/bin/pool/agent.mjs +215 -15
  108. package/bin/pool/cache-sweep.mjs +74 -0
  109. package/bin/pool/cli.mjs +11 -3
  110. package/bin/pool/docker.mjs +33 -2
  111. package/bin/pool/health.mjs +38 -0
  112. package/bin/pool/lane-tools.mjs +23 -4
  113. package/bin/pool/lane-tools.test.mjs +12 -1
  114. package/bin/pool/router.mjs +21 -3
  115. package/bin/runner.mjs +37 -0
  116. package/bin/splash-scene.mjs +356 -0
  117. package/bin/win-hide-children.mjs +114 -0
  118. package/commands/orchestrate.md +18 -27
  119. package/commands/review-pr-agents/infra.md +1 -0
  120. package/commands/review-pr-staging.md +2 -2
  121. package/docs/CONFIG.md +60 -3
  122. package/docs/OUTCOME-CODES.md +3 -0
  123. package/package.json +1 -1
  124. package/plugins/forgedock-splash/.claude-plugin/plugin.json +1 -1
  125. package/plugins/forgedock-splash/README.md +1 -1
  126. package/plugins/forgedock-splash/hooks/scene.ts +142 -8
  127. package/pool/README.md +6 -0
  128. package/pool/image/entrypoint.sh +1 -0
  129. package/scripts/acceptance-red-green.sh +8 -3
  130. package/scripts/acceptance-red-green.test.sh +8 -0
  131. package/scripts/check-spec-size.sh +3 -1
  132. package/scripts/gen-splash-scene.mjs +24 -0
  133. package/scripts/review-staging-pre.sh +8 -3
  134. package/scripts/review-staging-pre.test.sh +2 -0
@@ -9,7 +9,7 @@
9
9
  import { readFile, writeFile, mkdir, chmod } from "node:fs/promises";
10
10
  import { accessSync, constants, readFileSync, statSync } from "node:fs";
11
11
  import { execFileSync } from "node:child_process";
12
- import { join, delimiter, resolve, dirname, isAbsolute } from "node:path";
12
+ import { join, delimiter, resolve, dirname, isAbsolute, extname, posix, win32 } from "node:path";
13
13
 
14
14
  const PMS = ["pnpm", "yarn", "npm"];
15
15
  const VERSION_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
@@ -131,13 +131,23 @@ export function nodeWarning(pin, hostVersion = process.version) {
131
131
  return `host node ${hostVersion} does not satisfy the ${pin.source} pin "${pin.spec}"; installs, builds and tests may behave differently from the repo's CI`;
132
132
  }
133
133
 
134
- /** First executable `name` on `pathStr`, skipping `exclude` dirs (the shim dir itself, so a shim never calls itself). */
135
- export function which(name, pathStr = process.env.PATH ?? "", exclude = []) {
134
+ /**
135
+ * First executable `name` on `pathStr`, skipping `exclude` dirs (the shim dir itself, so a shim never calls itself). No shell.
136
+ * #5806: `platform` picks the PATH separator (`;` on win32); with `pathext` (a `PATHEXT` value) on win32, a name without an
137
+ * extension matches only `name` + one of its extensions (`.exe`, `.cmd`, ...), as Windows resolves a command. Without
138
+ * `pathext` the lookup is the exact name, as before.
139
+ */
140
+ export function which(name, pathStr = process.env.PATH ?? "", exclude = [], { platform = process.platform, pathext = null, access = (p) => accessSync(p, constants.X_OK) } = {}) {
141
+ const win = platform === "win32", native = platform === process.platform;
142
+ const sep = win ? ";" : native ? delimiter : ":", pj = win ? win32.join : native ? join : posix.join;
136
143
  const skip = new Set(exclude.map((d) => resolve(d)));
137
- for (const d of String(pathStr).split(delimiter)) {
144
+ const exts = win && pathext != null && !extname(name) ? String(pathext || ".COM;.EXE;.BAT;.CMD").split(";").map((e) => e.trim().toLowerCase()).filter(Boolean) : [""];
145
+ for (const d of String(pathStr).split(sep)) {
138
146
  if (!d || skip.has(resolve(d))) continue;
139
- const p = join(d, name);
140
- try { accessSync(p, constants.X_OK); return p; } catch { /* next */ }
147
+ for (const e of exts) {
148
+ const p = pj(d, name + e);
149
+ try { access(p); return p; } catch { /* next */ }
150
+ }
141
151
  }
142
152
  return null;
143
153
  }
@@ -5,10 +5,22 @@
5
5
  * validate step. Pure, never throws. `toolMisses` filters the validate preflight's misses (run where the lane runs) to the
6
6
  * tools a different placement could supply; `lackedTools` names the contract's tools a target is known to lack.
7
7
  */
8
+ import { accessSync, constants, statSync } from "node:fs";
9
+ import { join } from "node:path";
8
10
  import { preflightProbes, declaredEnv } from "./preflight.mjs";
9
11
 
10
12
  const TOOL_KINDS = new Set(["command", "python-module", "node-module"]);
11
13
 
14
+ /**
15
+ * #5805: the names in `tools` with no executable on `path` (PATHEXT suffixes on Windows): the re-probe that re-admits an issue
16
+ * held on env.tool_missing. A module the lane reported (not an executable) stays missing here: it waits for an engine or env change.
17
+ */
18
+ export function hostMissingTools(tools, { path = process.env.PATH ?? "", pathext = process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD", platform = process.platform, exists = (f) => { try { accessSync(f, platform === "win32" ? constants.F_OK : constants.X_OK); return statSync(f).isFile(); } catch { return false; } } } = {}) {
19
+ const dirs = String(path ?? "").split(platform === "win32" ? ";" : ":").filter(Boolean);
20
+ const exts = platform === "win32" ? ["", ...String(pathext).split(";").filter(Boolean).map((x) => x.toLowerCase())] : [""];
21
+ return (Array.isArray(tools) ? tools : []).map(String).filter((t) => t && !(/[\\/]/.test(t) ? exts.some((x) => exists(t + x)) : dirs.some((d) => exts.some((x) => exists(join(d, t + x))))));
22
+ }
23
+
12
24
  /** `{tools, ids}` from preflight misses: executables and modules, never an unset env var (no placement fixes that). */
13
25
  export function toolMisses(misses) {
14
26
  const tools = new Set(), ids = new Set();
@@ -0,0 +1,105 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ /**
4
+ * #5752: weak vs strong fix guards. A guard test that only asserts "this literal exists" in a file's text is weak: breaking it is
5
+ * a review note, not a park. A behavioural test (inputs -> outputs) stays strong. Deterministic source analysis of the base test
6
+ * body (0 LLM calls); anything the classifier cannot prove weak is strong, so a misread never weakens a behavioural guard.
7
+ * Weak only when the file reads file text, imports no local non-test module, runs no process, has at least one assertion and
8
+ * every assertion is a literal-presence form.
9
+ */
10
+
11
+ const PY_RE = /\.py$/i;
12
+ const TESTISH_RE = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$|(?:^|\/)(?:tests?|__tests__|fixtures?)\/|(?:^|\/)_[\w-]*\.[cm]?[jt]s$)/;
13
+ const JS_READ_RE = /\breadFileSync\s*\(|\breadFile\s*\(|\bBun\.file\s*\(/;
14
+ const JS_PROC_RE = /\b(?:spawnSync|spawn|execFileSync|execFile|execSync|exec|fork)\s*\(|\bfetch\s*\(/;
15
+ const PY_READ_RE = /\.read_text\s*\(|\bopen\s*\([^)]*\)[\s\S]{0,80}?\.read(?:lines)?\s*\(/;
16
+ const PY_PROC_RE = /\bsubprocess\b|\bos\.system\s*\(|\bos\.popen\s*\(|\brequests\.|\burllib\b/;
17
+ const PY_SAFE_MODS = new Set(["os", "re", "pathlib", "sys", "json", "pytest", "unittest", "io", "typing", "textwrap", "glob", "__future__"]);
18
+
19
+ /** Strip comments (keeping strings), so a commented-out assertion or import counts for nothing. */
20
+ function stripJsComments(src) {
21
+ let out = "", i = 0;
22
+ while (i < src.length) {
23
+ const c = src[i], n = src[i + 1];
24
+ if (c === "/" && n === "/") { while (i < src.length && src[i] !== "\n") i++; continue; }
25
+ if (c === "/" && n === "*") { const e = src.indexOf("*/", i + 2); i = e < 0 ? src.length : e + 2; continue; }
26
+ if (c === "\"" || c === "'" || c === "`") { const s = i; i++; while (i < src.length && src[i] !== c) i += src[i] === "\\" ? 2 : 1; out += src.slice(s, i + 1); i++; continue; }
27
+ out += c; i++;
28
+ }
29
+ return out;
30
+ }
31
+
32
+ /** Index just past the `)` matching the `(` at `open`, skipping strings; -1 when unbalanced. */
33
+ function closeParen(src, open) {
34
+ let depth = 0;
35
+ for (let i = open; i < src.length; i++) {
36
+ const c = src[i];
37
+ if (c === "\"" || c === "'" || c === "`") { i++; while (i < src.length && src[i] !== c) i += src[i] === "\\" ? 2 : 1; continue; }
38
+ if (c === "(") depth++;
39
+ else if (c === ")" && --depth === 0) return i + 1;
40
+ }
41
+ return -1;
42
+ }
43
+
44
+ // A regex literal body is escapes or non-`/`, non-`\` chars: `\` must not match both branches (CodeQL js/redos, exponential backtracking).
45
+ const PRESENCE_ARG_RE = /^\s*!?\s*(?:[\w$.[\]"'`]+(?:\([^()]*\))?)\.includes\s*\(|^\s*!?\s*\/(?:\\.|[^/\\\n])+\/[a-z]*\.test\s*\(/;
46
+
47
+ /** JS/TS: every assertion's literal-presence verdict, or null when the file has none. */
48
+ function jsAssertions(src) {
49
+ const verdicts = [];
50
+ for (const m of src.matchAll(/\bassert(?:\.(\w+))?\s*\(/g)) {
51
+ const open = m.index + m[0].length - 1, end = closeParen(src, open);
52
+ const method = m[1] ?? "ok";
53
+ if (method === "match" || method === "doesNotMatch") verdicts.push(true);
54
+ else if (method === "ok") verdicts.push(end > 0 && PRESENCE_ARG_RE.test(src.slice(open + 1, end - 1)));
55
+ else verdicts.push(false);
56
+ }
57
+ for (const m of src.matchAll(/\bexpect\s*\(/g)) {
58
+ const open = m.index + m[0].length - 1, end = closeParen(src, open);
59
+ const tail = end > 0 ? src.slice(end, end + 40) : "";
60
+ verdicts.push(/^\s*(?:\.not)?\s*\.(?:toContain|toMatch)\s*\(/.test(tail));
61
+ }
62
+ return verdicts.length ? verdicts : null;
63
+ }
64
+
65
+ /** JS/TS: true when some import/require names a local module that is not a test helper or fixture. */
66
+ function jsImportsLocal(src) {
67
+ const specs = [...src.matchAll(/\bimport\s+(?:[^"'`;]*?\s+from\s+)?["'`]([^"'`]+)["'`]|\bimport\s*\(\s*["'`]([^"'`]+)["'`]|\brequire\s*\(\s*["'`]([^"'`]+)["'`]/g)].map((m) => m[1] ?? m[2] ?? m[3]);
68
+ return specs.some((s) => (s.startsWith(".") || s.startsWith("/")) && !TESTISH_RE.test(s));
69
+ }
70
+
71
+ /** Python: every assertion's literal-presence verdict, or null when the file has none. */
72
+ function pyAssertions(src) {
73
+ const verdicts = [];
74
+ for (const m of src.matchAll(/^[ \t]*assert\s+(.+)$/gm)) {
75
+ const e = m[1].split(/,\s*["'f]/)[0];
76
+ verdicts.push(/^\s*(?:[rbuf]?["'][^"']*["'])\s+(?:not\s+)?in\s+[\w.()[\]"']+\s*$/.test(e) || /^\s*(?:not\s+)?re\.(?:search|match|fullmatch)\s*\(/.test(e));
77
+ }
78
+ for (const m of src.matchAll(/\bself\.assert(\w+)\s*\(/g)) verdicts.push(["In", "NotIn", "Regex", "NotRegex"].includes(m[1]));
79
+ return verdicts.length ? verdicts : null;
80
+ }
81
+
82
+ /** Python: true when some import is not a known stdlib/test module (a relative import or the project's package). */
83
+ function pyImportsLocal(src) {
84
+ for (const m of src.matchAll(/^[ \t]*(?:from\s+(\.*[\w.]*)\s+import|import\s+([\w., ]+))/gm)) {
85
+ if (m[1] !== undefined) { if (m[1].startsWith(".") || !PY_SAFE_MODS.has(m[1].split(".")[0])) return true; continue; }
86
+ if (m[2].split(",").some((x) => !PY_SAFE_MODS.has(x.trim().split(/[.\s]/)[0]))) return true;
87
+ }
88
+ return false;
89
+ }
90
+
91
+ /** True when the test source only asserts that literals exist in file text (a weak guard); false for anything else. */
92
+ export function isWeakGuardTest(source, path = "") {
93
+ const raw = String(source ?? "");
94
+ if (!raw.trim()) return false;
95
+ if (PY_RE.test(String(path))) {
96
+ const src = raw.replace(/^[ \t]*#.*$/gm, "");
97
+ if (!PY_READ_RE.test(src) || PY_PROC_RE.test(src) || pyImportsLocal(src)) return false;
98
+ const v = pyAssertions(src);
99
+ return Boolean(v) && v.every(Boolean);
100
+ }
101
+ const src = stripJsComments(raw);
102
+ if (!JS_READ_RE.test(src) || JS_PROC_RE.test(src) || jsImportsLocal(src)) return false;
103
+ const v = jsAssertions(src);
104
+ return Boolean(v) && v.every(Boolean);
105
+ }
@@ -0,0 +1,59 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ import test from "node:test";
4
+ import assert from "node:assert/strict";
5
+ import { isWeakGuardTest } from "./weakguard.mjs";
6
+
7
+ const HEAD = `import test from "node:test";\nimport assert from "node:assert/strict";\nimport { readFileSync } from "node:fs";\nconst src = readFileSync("bin/lean/prompts.mjs", "utf8");\n`;
8
+
9
+ test("weak: literal-presence assertions over file text (includes, regex match, toContain)", () => {
10
+ assert.equal(isWeakGuardTest(`${HEAD}test("rule", () => { assert.ok(src.includes("negative examples")); assert.ok(!src.includes("old rule")); });\n`, "a.test.mjs"), true);
11
+ assert.equal(isWeakGuardTest(`${HEAD}test("rule", () => { assert.match(src, /supersedes/); assert.doesNotMatch(src, /legacy/); });\n`, "a.test.mjs"), true);
12
+ assert.equal(isWeakGuardTest(`${HEAD}test("rule", () => assert(/guard_weak/.test(src)));\n`, "a.test.mjs"), true);
13
+ assert.equal(isWeakGuardTest(`import { readFileSync } from "node:fs";\nimport { tmpDir } from "../tests/_tmp.mjs";\nconst s = readFileSync("x.ts", "utf8");\nit("has it", () => { expect(s).toContain("LIT"); expect(s).not.toMatch(/OLD/); });\n`, "x.test.ts"), true);
14
+ });
15
+
16
+ test("strong: a test that calls an imported local function is behavioural", () => {
17
+ assert.equal(isWeakGuardTest(`${HEAD}import { price } from "./a.mjs";\ntest("p", () => { assert.match(String(price()), /2/); assert.ok(src.includes("price")); });\n`, "a.test.mjs"), false);
18
+ assert.equal(isWeakGuardTest(`const { price } = require("../src/a");\nconst fs = require("fs");\nconst s = fs.readFileSync("a.js", "utf8");\nassert.match(s, /x/);\n`, "a.test.js"), false);
19
+ });
20
+
21
+ test("strong: a mixed file (one literal check plus an equality on a computed value)", () => {
22
+ assert.equal(isWeakGuardTest(`${HEAD}test("m", () => { assert.match(src, /x/); assert.equal(src.split("\\n").length > 3, true); });\n`, "a.test.mjs"), false);
23
+ assert.equal(isWeakGuardTest(`${HEAD}test("m", () => { expect(src).toContain("x"); expect(src.length).toBe(12); });\n`, "a.test.mjs"), false);
24
+ });
25
+
26
+ test("negative examples: inputs the classifier must not call weak", () => {
27
+ // no file read: a pure computation
28
+ assert.equal(isWeakGuardTest(`import assert from "node:assert/strict";\nassert.match("abc", /b/);\n`, "a.test.mjs"), false);
29
+ // runs a program and matches its output: behavioural (inputs -> outputs), even with only match assertions
30
+ assert.equal(isWeakGuardTest(`${HEAD}import { spawnSync } from "node:child_process";\nconst r = spawnSync("node", ["cli.mjs"], { encoding: "utf8" });\nassert.match(r.stdout, /ok/);\nassert.ok(src.includes("x"));\n`, "a.test.mjs"), false);
31
+ // reads a file but asserts nothing
32
+ assert.equal(isWeakGuardTest(HEAD, "a.test.mjs"), false);
33
+ // a commented-out import or assertion does not change the verdict; a real deepEqual makes it strong
34
+ assert.equal(isWeakGuardTest(`${HEAD}// import { x } from "./a.mjs";\n// assert.equal(1, 1);\nassert.match(src, /y/);\n`, "a.test.mjs"), true);
35
+ assert.equal(isWeakGuardTest(`${HEAD}assert.deepEqual(JSON.parse(src), { a: 1 });\n`, "a.test.mjs"), false);
36
+ // includes() equality is an equality assertion, not the literal-presence form
37
+ assert.equal(isWeakGuardTest(`${HEAD}assert.equal(src.includes("x"), true);\n`, "a.test.mjs"), false);
38
+ // empty or missing source
39
+ assert.equal(isWeakGuardTest("", "a.test.mjs"), false);
40
+ assert.equal(isWeakGuardTest(undefined), false);
41
+ });
42
+
43
+ test("python: literal-in-text and re.search over read_text are weak; calling project code is strong", () => {
44
+ const PY = `import re\nfrom pathlib import Path\nsrc = Path("app/x.py").read_text()\n`;
45
+ assert.equal(isWeakGuardTest(`${PY}def test_lit():\n assert "FLAG" in src\n assert "OLD" not in src, "gone"\n assert re.search(r"def handler", src)\n`, "tests/test_x.py"), true);
46
+ assert.equal(isWeakGuardTest(`import unittest\nclass T(unittest.TestCase):\n def test(self):\n s = open("a.py").read()\n self.assertIn("X", s)\n`, "tests/test_y.py"), true);
47
+ assert.equal(isWeakGuardTest(`${PY}from app.x import handler\ndef test_h():\n assert handler(1) == 2\n`, "tests/test_x.py"), false);
48
+ assert.equal(isWeakGuardTest(`${PY}def test_len():\n assert len(src) > 10\n`, "tests/test_x.py"), false);
49
+ assert.equal(isWeakGuardTest(`${PY}import subprocess\ndef test_cli():\n out = subprocess.run(["x"], capture_output=True, text=True).stdout\n assert "ok" in out\n`, "tests/test_x.py"), false);
50
+ assert.equal(isWeakGuardTest(`def test_no_read():\n assert "a" in "abc"\n`, "tests/test_z.py"), false);
51
+ });
52
+
53
+ test("regex-literal presence check stays linear on many backslash escapes (CodeQL js/redos)", () => {
54
+ const evil = `assert.ok(/${"\\a".repeat(5000)}\n)`; // an unterminated regex literal full of escapes
55
+ const t0 = Date.now();
56
+ assert.equal(isWeakGuardTest(`${HEAD}test("r", () => { ${evil}; });\n`, "a.test.mjs"), false);
57
+ assert.ok(Date.now() - t0 < 1000, `took ${Date.now() - t0} ms`);
58
+ assert.equal(isWeakGuardTest(`${HEAD}test("r", () => assert.ok(/a\\/b\\.c/.test(src)));\n`, "a.test.mjs"), true); // escaped "/" and "." still parse
59
+ });
@@ -0,0 +1,61 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ /**
4
+ * #5799: Windows-safe path and spawn helpers for lean lanes.
5
+ *
6
+ * - `isAbsPath`: git on Windows prints `C:/...` (or `C:\...`, `\\server\...`), which a `startsWith("/")` check reads as
7
+ * relative, so the lane prefixed the worktree and wrote to `<wt>/C:/...` (ENOENT at scratch setup).
8
+ * - `resolveSpawn`: `execFile`/`spawn` with `shell:false` cannot launch a bare `pnpm` on Windows when it is installed as
9
+ * an npm `.cmd` shim, so every validate/install ended `env.tool_missing` (spawn ENOENT). The shim is resolved to what it
10
+ * runs (a native `.exe`, or `node <script>`) and launched directly; cmd.exe never parses the argv.
11
+ */
12
+ import * as nodeFs from "node:fs";
13
+ import { win32 } from "node:path";
14
+
15
+ /** True for a POSIX absolute path, a Windows drive path (`C:/`, `C:\`) or a UNC path. Platform-independent on purpose. */
16
+ export const isAbsPath = (p) => {
17
+ const s = String(p ?? "");
18
+ return s.startsWith("/") || /^[A-Za-z]:[\\/]/.test(s) || s.startsWith("\\\\");
19
+ };
20
+
21
+ const NODE_SCRIPT_RE = /"%(?:~)?dp0%?[\\/]([^"\r\n%]+\.(?:c|m)?js)"\s+%\*/i;
22
+ const EXE_DIRECT_RE = /(?:^|\r?\n)\s*"%(?:~)?dp0%?[\\/]([^"\r\n%]+\.(?:exe|com))"\s+%\*\s*(?:\r?\n|$)/i;
23
+
24
+ /**
25
+ * Resolve `bin` the way cmd.exe would (PATH x PATHEXT) and return a `{ bin, args }` pair `execFile` can run with
26
+ * `shell:false`. Non-Windows, paths with a directory part, and unresolvable names are returned unchanged.
27
+ */
28
+ export function resolveSpawn(bin, args = [], { platform = process.platform, env = process.env, fs = nodeFs, nodePath = process.execPath } = {}) {
29
+ const same = { bin, args };
30
+ if (platform !== "win32" || typeof bin !== "string" || !bin || /[\\/]/.test(bin)) return same;
31
+ const pathVar = env.PATH ?? env.Path ?? env.path ?? "";
32
+ const exts = (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map((e) => e.trim().toLowerCase()).filter(Boolean);
33
+ const hasExt = exts.includes(win32.extname(bin).toLowerCase());
34
+ for (const dir of String(pathVar).split(";").filter(Boolean)) {
35
+ for (const ext of hasExt ? [""] : exts) {
36
+ const file = win32.join(dir, bin + ext);
37
+ let ok = false;
38
+ try { ok = fs.statSync(file).isFile(); } catch { ok = false; }
39
+ if (!ok) continue;
40
+ const e = win32.extname(file).toLowerCase();
41
+ if (e === ".exe" || e === ".com") return { bin: file, args };
42
+ if (e !== ".cmd" && e !== ".bat") continue; // .js/.vbs etc.: not launchable without a host; keep looking
43
+ let shim = "";
44
+ try { shim = String(fs.readFileSync(file, "utf8")); } catch { continue; }
45
+ const exe = shim.match(EXE_DIRECT_RE);
46
+ if (exe) {
47
+ const target = win32.join(dir, ...exe[1].split(/[\\/]+/));
48
+ if (fs.existsSync(target)) return { bin: target, args };
49
+ }
50
+ const js = shim.match(NODE_SCRIPT_RE);
51
+ if (js) {
52
+ const script = win32.join(dir, ...js[1].split(/[\\/]+/));
53
+ if (!fs.existsSync(script)) continue;
54
+ const localNode = win32.join(dir, "node.exe");
55
+ return { bin: fs.existsSync(localNode) ? localNode : nodePath, args: [script, ...args] };
56
+ }
57
+ // An unknown batch script is never run through cmd.exe (argv injection); keep looking, then fall through.
58
+ }
59
+ }
60
+ return same;
61
+ }
@@ -0,0 +1,45 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ import { test } from "node:test";
4
+ import assert from "node:assert/strict";
5
+ import { isAbsPath, resolveSpawn } from "./winspawn.mjs";
6
+
7
+ test("#5799 isAbsPath: POSIX, Windows drive and UNC paths are absolute; relative ones are not", () => {
8
+ for (const p of ["/repo/.git/info/exclude", "C:/Users/u/repo/.git/info/exclude", "C:\\Users\\u\\repo\\.git", "d:/x", "\\\\srv\\share\\repo"]) assert.equal(isAbsPath(p), true, p);
9
+ for (const p of [".git/info/exclude", "info/exclude", "C:", "c:repo", "", null, undefined]) assert.equal(isAbsPath(p), false, String(p));
10
+ });
11
+
12
+ /** In-memory fs keyed by win32 path. */
13
+ const memFs = (files) => ({
14
+ statSync: (f) => { if (!(f in files)) throw Object.assign(new Error("ENOENT"), { code: "ENOENT" }); return { isFile: () => true }; },
15
+ existsSync: (f) => f in files,
16
+ readFileSync: (f) => { if (!(f in files)) throw new Error("ENOENT"); return files[f]; },
17
+ });
18
+ const NPM = "C:\\npm";
19
+ const PNPM_CMD = `@ECHO off\r\nGOTO start\r\n:find_dp0\r\nSET dp0=%~dp0\r\nEXIT /b\r\n:start\r\nSETLOCAL\r\nCALL :find_dp0\r\n\r\nIF EXIST "%dp0%\\node.exe" (\r\n SET "_prog=%dp0%\\node.exe"\r\n) ELSE (\r\n SET "_prog=node"\r\n)\r\n\r\nendLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\\node_modules\\pnpm\\bin\\pnpm.cjs" %*\r\n`;
20
+ const env = { PATH: `C:\\Windows;${NPM}`, PATHEXT: ".COM;.EXE;.BAT;.CMD" };
21
+
22
+ test("#5799 resolveSpawn: an npm node-script .cmd shim runs as node <script> with the argv untouched", () => {
23
+ const fs = memFs({ [`${NPM}\\pnpm.cmd`]: PNPM_CMD, [`${NPM}\\node_modules\\pnpm\\bin\\pnpm.cjs`]: "" });
24
+ const r = resolveSpawn("pnpm", ["install", "--frozen-lockfile", "a&b"], { platform: "win32", env, fs, nodePath: "C:\\node\\node.exe" });
25
+ assert.deepEqual(r, { bin: "C:\\node\\node.exe", args: [`${NPM}\\node_modules\\pnpm\\bin\\pnpm.cjs`, "install", "--frozen-lockfile", "a&b"] });
26
+ });
27
+
28
+ test("#5799 resolveSpawn: prefers the node.exe beside the shim, and a native .exe on PATH wins as found", () => {
29
+ const fs = memFs({ [`${NPM}\\pnpm.cmd`]: PNPM_CMD, [`${NPM}\\node_modules\\pnpm\\bin\\pnpm.cjs`]: "", [`${NPM}\\node.exe`]: "" });
30
+ assert.equal(resolveSpawn("pnpm", [], { platform: "win32", env, fs }).bin, `${NPM}\\node.exe`);
31
+ const fs2 = memFs({ "C:\\Windows\\pnpm.exe": "", [`${NPM}\\pnpm.cmd`]: PNPM_CMD });
32
+ assert.deepEqual(resolveSpawn("pnpm", ["-v"], { platform: "win32", env, fs: fs2 }), { bin: "C:\\Windows\\pnpm.exe", args: ["-v"] });
33
+ });
34
+
35
+ test("#5799 resolveSpawn: a .cmd shim delegating to a native .exe runs that .exe", () => {
36
+ const fs = memFs({ [`${NPM}\\tool.cmd`]: `@ECHO off\r\n"%~dp0\\node_modules\\tool\\bin\\tool.exe" %*\r\n`, [`${NPM}\\node_modules\\tool\\bin\\tool.exe`]: "" });
37
+ assert.deepEqual(resolveSpawn("tool", ["x"], { platform: "win32", env, fs }), { bin: `${NPM}\\node_modules\\tool\\bin\\tool.exe`, args: ["x"] });
38
+ });
39
+
40
+ test("#5799 resolveSpawn: unchanged off Windows, for paths, unknown batch scripts and missing tools", () => {
41
+ const fs = memFs({ [`${NPM}\\odd.cmd`]: "@echo off\r\nset X=%1\r\ncall something %X%\r\n" });
42
+ for (const [bin, opt] of [["pnpm", { platform: "linux", env, fs }], ["C:\\x\\pnpm.cmd", { platform: "win32", env, fs }], ["odd", { platform: "win32", env, fs }], ["nope", { platform: "win32", env, fs }]]) {
43
+ assert.deepEqual(resolveSpawn(bin, ["a"], opt), { bin, args: ["a"] }, bin);
44
+ }
45
+ });
@@ -9,6 +9,7 @@
9
9
  * such blob gets today's plain `git worktree add`. A failed sparse step falls back to a full checkout; never fails a lane.
10
10
  */
11
11
  import { join } from "node:path";
12
+ import { isAbsPath } from "./winspawn.mjs";
12
13
 
13
14
  export const DEFAULT_SPARSE_MAX_KB = 1024;
14
15
 
@@ -57,7 +58,8 @@ export async function addLaneWorktree(git, write, { cwd, wt, addArgs, ref, maxBl
57
58
  try {
58
59
  await g(["sparse-checkout", "set", "--no-cone", "/*"]);
59
60
  const file = String(await g(["rev-parse", "--git-path", "info/sparse-checkout"])).trim();
60
- await write(file.startsWith("/") ? file : join(wt, file), `${sparsePatterns(plan.excludes).join("\n")}\n`);
61
+ // #5825: git prints `C:/...` on Windows: a startsWith("/") test joined it under the worktree (a stray `C` folder there)
62
+ await write(isAbsPath(file) ? file : join(wt, file), `${sparsePatterns(plan.excludes).join("\n")}\n`);
61
63
  await g(["read-tree", "-mu", "HEAD"]);
62
64
  return { sparse: true, excluded: plan.excludes.length, bytes: plan.bytes };
63
65
  } catch (e) {
@@ -139,3 +139,14 @@ describe("sparse lane worktrees (#4221)", () => {
139
139
  } finally { rmSync(dir, { recursive: true, force: true }); }
140
140
  });
141
141
  });
142
+
143
+ describe("sparse pattern file path on Windows (#5825)", () => {
144
+ it("a drive-letter path from `rev-parse --git-path` is written as is, never joined under the worktree", async () => {
145
+ const big = `100644 blob ${"a".repeat(40)} ${2 * MiB}\tbig.bin`;
146
+ const wrote = [];
147
+ const fake = async (args) => (args[0] === "ls-tree" ? big : args[0] === "rev-parse" ? "C:/r/.git/worktrees/lean-5/info/sparse-checkout\n" : "");
148
+ const r = await addLaneWorktree(fake, async (p) => { wrote.push(p); }, { cwd: "C:\r", wt: "C:\r\.claude\worktrees\lean-5", addArgs: ["worktree", "add", "C:\r\.claude\worktrees\lean-5", "main"], ref: "main" });
149
+ assert.equal(r.sparse, true);
150
+ assert.deepEqual(wrote, ["C:/r/.git/worktrees/lean-5/info/sparse-checkout"]);
151
+ });
152
+ });