Skip to content

Commit a62c140

Browse files
committed
fix(ci): preserve the trusted PR helper closure
1 parent 4a79c12 commit a62c140

8 files changed

Lines changed: 272 additions & 49 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
2-
import { runTsxCliShim } from "./lib/tsx-cli-shim.mjs";
2+
import { runNodeCliShim } from "./lib/tsx-cli-shim.mjs";
33

4-
await runTsxCliShim(import.meta.url, { implementation: "./check-changelog-attributions.mts" });
4+
await runNodeCliShim(import.meta.url, { implementation: "./check-changelog-attributions.mts" });

‎scripts/lib/tsx-cli-shim.mjs‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function signalChild(child, signal, detached) {
9191
}
9292
}
9393

94-
async function runTsxCliShimInner(moduleUrl, options) {
94+
async function runCliShimInner(moduleUrl, options, nodeArgs) {
9595
const detached = options.detached ?? (process.platform !== "win32" && !process.stdin.isTTY);
9696
const forceKillDelayMs = options.forceKillDelayMs ?? DEFAULT_FORCE_KILL_DELAY_MS;
9797
let child = null;
@@ -126,18 +126,13 @@ async function runTsxCliShimInner(moduleUrl, options) {
126126
try {
127127
const implementationUrl = new URL(options.implementation, moduleUrl);
128128
const implementationPath = fileURLToPath(implementationUrl);
129-
const tsxImport = new URL("../tsx.mjs", import.meta.url).href;
130129
const nodeExecutable = process.versions.bun ? "node" : process.execPath;
131-
child = spawn(
132-
nodeExecutable,
133-
["--import", tsxImport, implementationPath, ...process.argv.slice(2)],
134-
{
135-
cwd: process.cwd(),
136-
detached,
137-
env: process.env,
138-
stdio: "inherit",
139-
},
140-
);
130+
child = spawn(nodeExecutable, [...nodeArgs, implementationPath, ...process.argv.slice(2)], {
131+
cwd: process.cwd(),
132+
detached,
133+
env: process.env,
134+
stdio: "inherit",
135+
});
141136
const result = await new Promise((resolve, reject) => {
142137
child.once("error", reject);
143138
child.once("close", (code, signal) => resolve({ code, signal }));
@@ -160,12 +155,20 @@ async function runTsxCliShimInner(moduleUrl, options) {
160155
}
161156
}
162157

163-
export async function runTsxCliShim(moduleUrl, options = {}) {
158+
async function runCliShim(moduleUrl, options, nodeArgs) {
164159
try {
165-
await runTsxCliShimInner(moduleUrl, options);
160+
await runCliShimInner(moduleUrl, options, nodeArgs);
166161
} catch (error) {
167162
console.error(error);
168163
writeFailureTrailer(options.failureTool, 1);
169164
process.exitCode = 1;
170165
}
171166
}
167+
168+
export function runNodeCliShim(moduleUrl, options = {}) {
169+
return runCliShim(moduleUrl, options, []);
170+
}
171+
172+
export function runTsxCliShim(moduleUrl, options = {}) {
173+
return runCliShim(moduleUrl, options, ["--import", new URL("../tsx.mjs", import.meta.url).href]);
174+
}

‎scripts/pr‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ pr_wrapper_components=(
5050
scripts/lib/plain-gh.sh
5151
scripts/lib/plain-gh.mjs
5252
scripts/lib/direct-run.mjs
53+
scripts/lib/record-shared.mjs
54+
scripts/lib/arg-utils.mts
55+
scripts/lib/arg-utils.runtime.mjs
5356
scripts/lib/tsx-cli-shim.mjs
5457
scripts/lib/local-check-runtime.mts
5558
scripts/tsx.mjs
@@ -59,6 +62,10 @@ pr_wrapper_components=(
5962
scripts/verify-pr-hosted-gates.mts
6063
scripts/watch-pr-ci.mjs
6164
scripts/watch-pr-ci.mts
65+
scripts/check-changelog-attributions.mjs
66+
scripts/check-changelog-attributions.mts
67+
packages/normalization-core/package.json
68+
packages/normalization-core/src/record-coerce.ts
6269
.github/workflows/pr-crabbox-gate-publisher.yml
6370
)
6471
# Anchor-exec handoff: this process was exec'd from wrapper bytes materialized
@@ -172,6 +179,15 @@ elif common_git_dir=$(git -C "$script_parent_dir" rev-parse --path-format=absolu
172179
fi
173180
if [ "$anchor_extraction_valid" = "1" ] &&
174181
grep -q "OPENCLAW_PR_ANCHOR_REPO_ROOT" "$anchor_exec_dir/scripts/pr" 2>/dev/null; then
182+
# Copied helpers retain the canonical checkout's installed toolchain.
183+
# The shared owner creates a Windows junction instead of Git Bash's ln copy.
184+
(
185+
cd "$anchor_exec_dir"
186+
node --input-type=module - "$canonical_repo_root/node_modules" <<'EOF_NODE'
187+
import { ensureRepoNodeModulesLink } from "./scripts/lib/local-check-runtime.mts";
188+
ensureRepoNodeModulesLink(process.argv[2]);
189+
EOF_NODE
190+
)
175191
# Not cleaned by trap: exec replaces this shell, and bash re-reads
176192
# the script file during execution, so the copy must outlive the
177193
# whole supervised run. OS tmp reaping owns the ~200 KiB dir.

‎scripts/verify-pr-hosted-gates.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
2-
import { runTsxCliShim } from "./lib/tsx-cli-shim.mjs";
2+
import { runNodeCliShim } from "./lib/tsx-cli-shim.mjs";
33

4-
await runTsxCliShim(import.meta.url, { implementation: "./verify-pr-hosted-gates.mts" });
4+
await runNodeCliShim(import.meta.url, { implementation: "./verify-pr-hosted-gates.mts" });

‎scripts/verify-pr-hosted-gates.mts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import { execFileSync, spawnSync } from "node:child_process";
33
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
44
import path from "node:path";
5-
import { isRecord, readStringField } from "@openclaw/normalization-core/record-coerce";
65
import { minimatch } from "minimatch";
76
import { parse } from "yaml";
7+
// Materialized PR wrappers must use the verified source, not the caller's tsconfig aliases.
8+
import { isRecord, readStringField } from "../packages/normalization-core/src/record-coerce.ts";
89
import {
910
booleanFlag,
1011
classifyBoundedUnsignedDecimal,

‎scripts/watch-pr-ci.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
2-
import { runTsxCliShim } from "./lib/tsx-cli-shim.mjs";
2+
import { runNodeCliShim } from "./lib/tsx-cli-shim.mjs";
33

4-
await runTsxCliShim(import.meta.url, { implementation: "./watch-pr-ci.mts" });
4+
await runNodeCliShim(import.meta.url, { implementation: "./watch-pr-ci.mts" });

‎test/scripts/local-check-runtime.test.ts‎

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,39 @@ describe("local-check-runtime", () => {
6363
).toBe(localPath);
6464
});
6565

66-
it("links dependency-less worktrees to the selected checkout's modules", () => {
67-
const primaryRoot = createTempDir("openclaw-primary-toolchain-");
68-
const cwd = path.join(primaryRoot, ".codex", "worktrees", "task", "openclaw");
69-
const commonDir = path.join(primaryRoot, ".git");
70-
const primaryTsgo = path.join(primaryRoot, "node_modules", ".bin", "tsgo");
71-
const primaryNodeModules = path.join(primaryRoot, "node_modules");
72-
const localNodeModules = path.join(cwd, "node_modules");
73-
fs.mkdirSync(path.dirname(primaryTsgo), { recursive: true });
74-
fs.mkdirSync(cwd, { recursive: true });
75-
76-
expect(
77-
ensureRepoToolNodeModulesLink(primaryTsgo, {
66+
it.each([
67+
{ platform: "linux" as const, linkType: "dir" },
68+
{ platform: "win32" as const, linkType: "junction" },
69+
])(
70+
"links dependency-less $platform worktrees to the selected checkout's modules",
71+
({ platform, linkType }) => {
72+
const primaryRoot = createTempDir("openclaw-primary-toolchain-");
73+
const cwd = path.join(primaryRoot, ".codex", "worktrees", "task", "openclaw");
74+
const commonDir = path.join(primaryRoot, ".git");
75+
const primaryTsgo = path.join(primaryRoot, "node_modules", ".bin", "tsgo");
76+
const primaryNodeModules = path.join(primaryRoot, "node_modules");
77+
const localNodeModules = path.join(cwd, "node_modules");
78+
fs.mkdirSync(path.dirname(primaryTsgo), { recursive: true });
79+
fs.mkdirSync(cwd, { recursive: true });
80+
const linkTypes: Array<Parameters<typeof fs.symlinkSync>[2]> = [];
81+
const linkOptions = {
7882
cwd,
7983
resolveCommonDir: () => commonDir,
80-
}),
81-
).toBe(localNodeModules);
82-
expect(fs.realpathSync(localNodeModules)).toBe(fs.realpathSync(primaryNodeModules));
84+
platform,
85+
symlink: (...args: Parameters<typeof fs.symlinkSync>) => {
86+
linkTypes.push(args[2]);
87+
fs.symlinkSync(...args);
88+
},
89+
};
8390

84-
// The stable link is idempotent for concurrent and later local runners.
85-
expect(
86-
ensureRepoToolNodeModulesLink(primaryTsgo, {
87-
cwd,
88-
resolveCommonDir: () => commonDir,
89-
}),
90-
).toBe(localNodeModules);
91-
});
91+
expect(ensureRepoToolNodeModulesLink(primaryTsgo, linkOptions)).toBe(localNodeModules);
92+
expect(fs.realpathSync(localNodeModules)).toBe(fs.realpathSync(primaryNodeModules));
93+
94+
// The stable link is idempotent for concurrent and later local runners.
95+
expect(ensureRepoToolNodeModulesLink(primaryTsgo, linkOptions)).toBe(localNodeModules);
96+
expect(linkTypes).toEqual([linkType]);
97+
},
98+
);
9299

93100
it("leaves existing worktree node_modules directories locally owned", () => {
94101
const primaryRoot = createTempDir("openclaw-primary-toolchain-");

0 commit comments

Comments
 (0)