Skip to content

Commit 253ad3e

Browse files
ly85206559steipete
andauthored
fix(canvas): preserve Windows pnpm shim arguments (#133395)
* fix(canvas): preserve Windows pnpm shim arguments * test(canvas): exercise cmd arguments on native Windows CI Route the Canvas pnpm runner and its real child-process regression through the existing Windows test inventory. Temporarily retain the upstream serializer to capture the regression failure before restoring the reviewed repair. This proof baseline is not a landing candidate. Co-authored-by: ben.li <[email protected]> * fix(canvas): preserve literal arguments through Windows pnpm shims Use the existing cmd.exe and CRT quoting contract, preserving empty arguments, carets, trailing backslashes and embedded quotes. Keep the unsafe-character guard and direct executable path while removing conditional quoting. The original serializer reproduced exact argv corruption on the native Windows regression. Co-authored-by: ben.li <[email protected]> * fix(canvas): preserve Windows pnpm shim arguments * test(canvas): exercise cmd arguments on native Windows CI Route the Canvas pnpm runner and its real child-process regression through the existing Windows test inventory. Temporarily retain the upstream serializer to capture the regression failure before restoring the reviewed repair. This proof baseline is not a landing candidate. Co-authored-by: ben.li <[email protected]> * fix(canvas): preserve literal arguments through Windows pnpm shims Use the existing cmd.exe and CRT quoting contract, preserving empty arguments, carets, trailing backslashes and embedded quotes. Keep the unsafe-character guard and direct executable path while removing conditional quoting. The original serializer reproduced exact argv corruption on the native Windows regression. Co-authored-by: ben.li <[email protected]> * fix(ci): route Canvas regression to Windows --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: ben.li <[email protected]>
1 parent e45ba01 commit 253ad3e

5 files changed

Lines changed: 59 additions & 16 deletions

File tree

‎extensions/canvas/scripts/pnpm-runner.mjs‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,21 @@ function isNodeRunnablePnpmExecPath(value) {
106106
return hasNodeShebang(value);
107107
}
108108

109-
function escapeForCmdExe(arg) {
110-
if (WINDOWS_UNSAFE_CMD_CHARS_RE.test(arg)) {
111-
throw new Error(`unsafe Windows cmd.exe argument detected: ${JSON.stringify(arg)}`);
112-
}
113-
const escaped = arg.replace(/\^/g, "^^");
114-
if (!escaped.includes(" ") && !escaped.includes('"')) {
115-
return escaped;
116-
}
117-
return `"${escaped.replace(/"/g, '""')}"`;
118-
}
119-
120109
function buildCmdExeCommandLine(command, args) {
121-
const escapedCommand = escapeForCmdExe(command);
122-
const commandLine = [escapedCommand, ...args.map(escapeForCmdExe)].join(" ");
123-
return escapedCommand.startsWith('"') ? `"${commandLine}"` : commandLine;
110+
const escaped = [command, ...args].map((arg) => {
111+
if (WINDOWS_UNSAFE_CMD_CHARS_RE.test(arg)) {
112+
throw new Error(`unsafe Windows cmd.exe argument detected: ${JSON.stringify(arg)}`);
113+
}
114+
// Quote through cmd and the CRT; consume backslash runs once to avoid quadratic scans.
115+
const quoted = arg
116+
.replace(/\\+/g, (backslashes, offset) => {
117+
const next = arg[offset + backslashes.length];
118+
return next === '"' || next === undefined ? backslashes.repeat(2) : backslashes;
119+
})
120+
.replace(/"/g, '""');
121+
return `"${quoted}"`;
122+
});
123+
return `"${escaped.join(" ")}"`;
124124
}
125125

126126
function windowsCmdSpec(command, args, comSpec) {

‎extensions/canvas/scripts/pnpm-runner.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,33 @@ describe("canvas pnpm runner", () => {
188188
}
189189
},
190190
);
191+
192+
it.runIf(process.platform === "win32")(
193+
"preserves literal arguments through spaced cmd wrappers",
194+
() => {
195+
const tempDir = mkdtempSync(path.join(os.tmpdir(), "canvas pnpm argv "));
196+
try {
197+
const capturePath = path.join(tempDir, "capture.cjs");
198+
writeFileSync(
199+
capturePath,
200+
"process.stdout.write(JSON.stringify(process.argv.slice(2)));\n",
201+
);
202+
const cmdPath = path.join(tempDir, "pnpm.cmd");
203+
writeFileSync(cmdPath, `@echo off\r\n"${process.execPath}" "${capturePath}" %*\r\n`);
204+
const expected = ["", "left ^ right", "C:\\two words\\", 'say "hi"'];
205+
const spec = resolvePnpmRunner({ npmExecPath: cmdPath, pnpmArgs: expected });
206+
207+
const result = spawnSync(spec.command, spec.args, {
208+
encoding: "utf8",
209+
shell: spec.shell,
210+
windowsVerbatimArguments: spec.windowsVerbatimArguments,
211+
});
212+
213+
expect(result.status, result.stderr).toBe(0);
214+
expect(JSON.parse(result.stdout)).toEqual(expected);
215+
} finally {
216+
rmSync(tempDir, { recursive: true, force: true });
217+
}
218+
},
219+
);
191220
});

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@
19921992
"test:voicecall:closedloop": "node --import ./scripts/tsx.mjs scripts/test-voicecall-closedloop.mts",
19931993
"test:watch": "node --import ./scripts/tsx.mjs scripts/test-projects.mts --watch",
19941994
"test:windows:ci": "pnpm test:windows:ci:1 && pnpm test:windows:ci:2",
1995-
"test:windows:ci:1": "node --import ./scripts/tsx.mjs scripts/test-projects.mts test/scripts/ci-platform-checkout.test.ts src/state/openclaw-state-ownership.test.ts src/snapshot/local-repository.windows.test.ts src/state/openclaw-database-paths.windows.test.ts src/node-host/invoke-system-run-allowlist.test.ts src/node-host/node-worker-transfer-client.test.ts packages/terminal-core/src/display-string.test.ts src/config/sessions/session-accessor.sqlite-archive.worker.test.ts src/commands/doctor-gateway-auth-token.windows.test.ts src/infra/state-migrations.audit-logs.windows.test.ts src/commands/backup-verify.test.ts src/commands/agents.commands.list.test.ts test/e2e/windows-cron-process-identity.e2e.test.ts src/shared/runtime-import.test.ts src/shared/worker-bundle-archive.test.ts src/node-host/node-worker-bundle-installer.test.ts test/scripts/direct-run-entrypoints.test.ts test/scripts/format-generated-module.test.ts test/scripts/install-ps1.test.ts test/scripts/openclaw-cross-os-installer.windows.test.ts test/scripts/openclaw-cross-os-release-workflow.test.ts test/scripts/pnpm-runner.test.ts test/scripts/run-with-env.test.ts test/scripts/ui.test.ts test/scripts/vitest-process-group.test.ts test/scripts/vitest-worker-artifacts.test.ts test/scripts/write-plugin-sdk-entry-dts.test.ts src/agents/tools/media-tool-file-url.windows.test.ts extensions/memory-core/src/memory-extra-file-path.windows.test.ts src/daemon/schtasks.startup-fallback.test.ts src/plugin-sdk/node-host.test.ts test/e2e/qa-lab/runtime/package-openclaw-for-docker.e2e.test.ts extensions/lobster/src/lobster-runner.test.ts src/gateway/worker-environments/workspace-quiescence.windows.test.ts",
1995+
"test:windows:ci:1": "node --import ./scripts/tsx.mjs scripts/test-projects.mts test/scripts/ci-platform-checkout.test.ts src/state/openclaw-state-ownership.test.ts src/snapshot/local-repository.windows.test.ts src/state/openclaw-database-paths.windows.test.ts src/node-host/invoke-system-run-allowlist.test.ts src/node-host/node-worker-transfer-client.test.ts packages/terminal-core/src/display-string.test.ts src/config/sessions/session-accessor.sqlite-archive.worker.test.ts src/commands/doctor-gateway-auth-token.windows.test.ts src/infra/state-migrations.audit-logs.windows.test.ts src/commands/backup-verify.test.ts src/commands/agents.commands.list.test.ts test/e2e/windows-cron-process-identity.e2e.test.ts src/shared/runtime-import.test.ts src/shared/worker-bundle-archive.test.ts src/node-host/node-worker-bundle-installer.test.ts test/scripts/direct-run-entrypoints.test.ts test/scripts/format-generated-module.test.ts test/scripts/install-ps1.test.ts test/scripts/openclaw-cross-os-installer.windows.test.ts test/scripts/openclaw-cross-os-release-workflow.test.ts test/scripts/pnpm-runner.test.ts extensions/canvas/scripts/pnpm-runner.test.ts test/scripts/run-with-env.test.ts test/scripts/ui.test.ts test/scripts/vitest-process-group.test.ts test/scripts/vitest-worker-artifacts.test.ts test/scripts/write-plugin-sdk-entry-dts.test.ts src/agents/tools/media-tool-file-url.windows.test.ts extensions/memory-core/src/memory-extra-file-path.windows.test.ts src/daemon/schtasks.startup-fallback.test.ts src/plugin-sdk/node-host.test.ts test/e2e/qa-lab/runtime/package-openclaw-for-docker.e2e.test.ts extensions/lobster/src/lobster-runner.test.ts src/gateway/worker-environments/workspace-quiescence.windows.test.ts",
19961996
"test:windows:ci:2": "node --import ./scripts/tsx.mjs scripts/test-projects.mts src/infra/sqlite-snapshot.test.ts src/infra/ports.test.ts src/infra/advertised-lan-host.windows.test.ts src/infra/update-managed-service-handoff-command.test.ts src/infra/update-managed-service-handoff-lifecycle.test.ts src/infra/executable-path.test.ts src/infra/fs-safe-remove.test.ts src/infra/state-migrations.legacy-session-store.test.ts src/infra/windows-install-roots.test.ts src/infra/ssh-client.windows.test.ts src/infra/exec-allowlist-pattern.test.ts src/infra/process-env.test.ts src/infra/openclaw-cli-shim.windows.test.ts src/agents/sessions/windows-git-bash-path.test.ts test/scripts/npm-runner.test.ts test/scripts/ts-topology.test.ts src/test-utils/openclaw-test-state.test.ts src/utils.test.ts src/media/local-media-path.windows.test.ts src/media/web-media.file-url.windows.test.ts src/process/exec.windows.test.ts src/process/exec.windows.integration.test.ts src/agents/sessions/exec.real.test.ts src/process/windows-command.test.ts src/process/terminal-pty.test.ts src/process/supervisor/supervisor.anchored-shell.real.test.ts src/tui/tui.resolve-codex-bin.test.ts src/media-understanding/attachments.file-url.windows.test.ts src/cli/daemon-cli/status.print.test.ts src/cli/mcp-cli.path-case.windows.test.ts src/auto-reply/usage-bar/template.windows.test.ts src/auto-reply/reply.triggers.trigger-handling.stages-inbound-media-into-sandbox-workspace.test.ts src/agents/provider-local-service.env-case.test.ts src/agents/bash-tools.exec.script-preflight.test.ts src/agents/agent-tools.read.windows.test.ts src/agents/agent-tools.read.host-operations.test.ts src/agents/sandbox/fs-paths.test.ts src/agents/sessions/tools/render-utils.test.ts src/agents/sessions/tools/path-utils.test.ts extensions/msteams/src/media-helpers.test.ts extensions/msteams/src/messenger.test.ts extensions/mxc/test/mxc-backend.test.ts extensions/mxc/test/sandbox-policy-loader.test.ts",
19971997
"test:windows:schtasks:integration": "node --import ./scripts/tsx.mjs scripts/run-with-env.mts CI_WINDOWS_SCHTASKS_INTEGRATION=1 OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_VERBOSE=1 OPENCLAW_VITEST_MAX_WORKERS=1 -- node scripts/run-vitest.mjs src/daemon/schtasks.integration.e2e.test.ts",
19981998
"tool-display:check": "node --import ./scripts/tsx.mjs scripts/tool-display.ts --check",

‎scripts/ci-changed-scope.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const WINDOWS_PROCESS_IDENTITY_SCOPE_RE =
7474
const WINDOWS_FILE_URL_SCOPE_RE =
7575
/^(?:src\/agents\/tools\/(?:media-tool-file-url\.windows\.test|media-tool-shared(?:\.test)?|pdf-tool(?:\.test)?)|src\/auto-reply\/(?:reply\/stage-sandbox-media|reply\.triggers\.trigger-handling\.stages-inbound-media-into-sandbox-workspace\.test)|src\/media\/(?:local-media-path(?:\.windows\.test)?|local-roots(?:\.test)?|web-media(?:\.file-url\.windows\.test)?)|src\/channels\/inbound-event\/media(?:\.test)?|src\/gateway\/managed-image-attachments(?:\.test)?|extensions\/msteams\/src\/(?:media-helpers|messenger)(?:\.test)?)\.ts$/;
7676
const WINDOWS_SCOPE_RE =
77-
/^(extensions\/mxc\/|src\/agents\/(?:bash-tools\.exec-script-(?:preflight|target)|bash-tools\.exec\.script-preflight\.test)\.ts$|src\/config\/sessions\/(?:session-accessor\.sqlite-archive(?:\.worker(?:\.test)?)?|store\.session-lifecycle-mutation\.test)\.ts$|src\/process\/|src\/infra\/(?:(?:exec-allowlist-pattern|fs-safe-remove)(?:\.windows)?(?:\.test)?|ports(?:-inspect|\.test)|ssh-client(?:\.windows\.test)?|update-managed-service-handoff(?:-(?:command|lifecycle)\.test)?|windows-install-roots)\.ts$|src\/shared\/(?:import-specifier|runtime-import)(?:\.test)?\.ts$|src\/test-utils\/openclaw-test-state(?:\.test)?\.ts$|scripts\/(?:android-(?:app-i18n|pin-version)\.ts|ci-run-timings\.mjs|e2e\/lib\/package-compat\.mjs|generate-bundled-channel-config-metadata\.ts|install\.ps1|openclaw-cross-os-release-checks\.ts|plan-release-workflow-matrix\.mjs|run-additional-boundary-checks\.mts|verify-docker-attestations\.mjs|github\/run-openclaw-cross-os-release-checks\.sh|tsx\.mjs|(?:npm-runner|pnpm-runner|ui|vitest-process-group)\.(?:mjs|mts|js)|lib\/(?:direct-run\.(?:mjs|mts)|format-generated-module\.mts|tsx-cli-shim\.mjs|cross-os-release-checks\/[^/]+\.ts))$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|install-ps1|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$|package\.json$|pnpm-lock\.yaml$|pnpm-workspace\.yaml$|\.github\/workflows\/(?:ci|openclaw-cross-os-release-checks-reusable)\.yml$|\.github\/actions\/setup-node-env\/action\.yml$|\.github\/actions\/setup-pnpm-store-cache\/action\.yml$)/;
77+
/^(extensions\/canvas\/scripts\/pnpm-runner\.(?:mjs|test\.ts)$|extensions\/mxc\/|src\/agents\/(?:bash-tools\.exec-script-(?:preflight|target)|bash-tools\.exec\.script-preflight\.test)\.ts$|src\/config\/sessions\/(?:session-accessor\.sqlite-archive(?:\.worker(?:\.test)?)?|store\.session-lifecycle-mutation\.test)\.ts$|src\/process\/|src\/infra\/(?:(?:exec-allowlist-pattern|fs-safe-remove)(?:\.windows)?(?:\.test)?|ports(?:-inspect|\.test)|ssh-client(?:\.windows\.test)?|update-managed-service-handoff(?:-(?:command|lifecycle)\.test)?|windows-install-roots)\.ts$|src\/shared\/(?:import-specifier|runtime-import)(?:\.test)?\.ts$|src\/test-utils\/openclaw-test-state(?:\.test)?\.ts$|scripts\/(?:android-(?:app-i18n|pin-version)\.ts|ci-run-timings\.mjs|e2e\/lib\/package-compat\.mjs|generate-bundled-channel-config-metadata\.ts|install\.ps1|openclaw-cross-os-release-checks\.ts|plan-release-workflow-matrix\.mjs|run-additional-boundary-checks\.mts|verify-docker-attestations\.mjs|github\/run-openclaw-cross-os-release-checks\.sh|tsx\.mjs|(?:npm-runner|pnpm-runner|ui|vitest-process-group)\.(?:mjs|mts|js)|lib\/(?:direct-run\.(?:mjs|mts)|format-generated-module\.mts|tsx-cli-shim\.mjs|cross-os-release-checks\/[^/]+\.ts))$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|install-ps1|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$|package\.json$|pnpm-lock\.yaml$|pnpm-workspace\.yaml$|\.github\/workflows\/(?:ci|openclaw-cross-os-release-checks-reusable)\.yml$|\.github\/actions\/setup-node-env\/action\.yml$|\.github\/actions\/setup-pnpm-store-cache\/action\.yml$)/;
7878
const WINDOWS_LAN_ADVERTISEMENT_SCOPE_RE =
7979
/^src\/infra\/advertised-lan-host(?:\.windows)?(?:\.test)?\.ts$/;
8080
const WINDOWS_SECRETREF_SCOPE_RE =

‎src/scripts/ci-changed-scope.windows.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ import { describe, expect, it } from "vitest";
44
const { detectChangedScope } = await import("../../scripts/ci-changed-scope.mjs");
55

66
describe("detectChangedScope Windows routing", () => {
7+
it("routes the Canvas pnpm runner and its native regression to Windows", () => {
8+
for (const runnerPath of [
9+
"extensions/canvas/scripts/pnpm-runner.mjs",
10+
"extensions/canvas/scripts/pnpm-runner.test.ts",
11+
]) {
12+
expect(detectChangedScope([runnerPath]), runnerPath).toMatchObject({
13+
runNode: true,
14+
runWindows: true,
15+
});
16+
}
17+
18+
expect(detectChangedScope(["extensions/canvas/src/a2ui-jsonl.ts"]).runWindows).toBe(false);
19+
});
20+
721
it("routes source CLI invocation owners and their native proof to Windows", () => {
822
for (const sourceCliPath of [
923
"src/infra/openclaw-cli-invocation.ts",

0 commit comments

Comments
 (0)