From 9ccc8fcc271b35dc2b5e75a8c104ec7e71db08b5 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 31 Jul 2026 10:33:51 +0800 Subject: [PATCH] test(infra): run Windows path regressions cross-platform (#116627) --- src/infra/exec-command-resolution.test.ts | 43 +++++++++++------------ src/infra/executable-path.test.ts | 26 +++++++------- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/infra/exec-command-resolution.test.ts b/src/infra/exec-command-resolution.test.ts index 2b910e9ec33e..79da75d7b201 100644 --- a/src/infra/exec-command-resolution.test.ts +++ b/src/infra/exec-command-resolution.test.ts @@ -2,6 +2,7 @@ import fs from "node:fs"; import path from "node:path"; import { describe, expect, it } from "vitest"; +import { withMockedPlatform } from "../test-utils/vitest-spies.js"; import { makeExecutable, makePathEnv, makeTempDir } from "./exec-approvals-test-helpers.js"; import { evaluateExecAllowlist, @@ -562,27 +563,25 @@ describe("exec-command-resolution", () => { }); it("does not synthesize cwd-joined allowlist candidates from drive-less windows roots", () => { - if (process.platform !== "win32") { - return; - } - - expect( - resolveAllowlistCandidatePath( - { - rawExecutable: String.raw`:\Users\demo\AI\system\openclaw`, - executableName: "openclaw", - }, - String.raw`C:\Users\demo\AI\system\openclaw`, - ), - ).toBeUndefined(); - expect( - resolveAllowlistCandidatePath( - { - rawExecutable: String.raw`:/Users/demo/AI/system/openclaw`, - executableName: "openclaw", - }, - String.raw`C:\Users\demo\AI\system\openclaw`, - ), - ).toBeUndefined(); + withMockedPlatform("win32", () => { + expect( + resolveAllowlistCandidatePath( + { + rawExecutable: String.raw`:\Users\demo\AI\system\openclaw`, + executableName: "openclaw", + }, + String.raw`C:\Users\demo\AI\system\openclaw`, + ), + ).toBeUndefined(); + expect( + resolveAllowlistCandidatePath( + { + rawExecutable: String.raw`:/Users/demo/AI/system/openclaw`, + executableName: "openclaw", + }, + String.raw`C:\Users\demo\AI\system\openclaw`, + ), + ).toBeUndefined(); + }); }); }); diff --git a/src/infra/executable-path.test.ts b/src/infra/executable-path.test.ts index 2c07f86dcf63..00c775ef8577 100644 --- a/src/infra/executable-path.test.ts +++ b/src/infra/executable-path.test.ts @@ -195,20 +195,18 @@ describe("executable path helpers", () => { ); it("does not treat drive-less rooted windows paths as cwd-relative executables", () => { - if (process.platform !== "win32") { - return; - } - - expect( - resolveExecutablePath(String.raw`:\Users\demo\AI\system\openclaw\git.exe`, { - cwd: String.raw`C:\Users\demo\AI\system\openclaw`, - }), - ).toBeUndefined(); - expect( - resolveExecutablePath(String.raw`:/Users/demo/AI/system/openclaw/git.exe`, { - cwd: String.raw`C:\Users\demo\AI\system\openclaw`, - }), - ).toBeUndefined(); + withMockedPlatform("win32", () => { + expect( + resolveExecutablePath(String.raw`:\Users\demo\AI\system\openclaw\git.exe`, { + cwd: String.raw`C:\Users\demo\AI\system\openclaw`, + }), + ).toBeUndefined(); + expect( + resolveExecutablePath(String.raw`:/Users/demo/AI/system/openclaw/git.exe`, { + cwd: String.raw`C:\Users\demo\AI\system\openclaw`, + }), + ).toBeUndefined(); + }); }); });