From e5aa1ac3113b88e59e45eb3afc31496cef695e19 Mon Sep 17 00:00:00 2001 From: kumarabhirup Date: Mon, 2 Mar 2026 18:31:00 -0800 Subject: [PATCH] test(cli): add windows-argv unit tests --- src/cli/windows-argv.test.ts | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/cli/windows-argv.test.ts diff --git a/src/cli/windows-argv.test.ts b/src/cli/windows-argv.test.ts new file mode 100644 index 00000000000..6c05b221c9c --- /dev/null +++ b/src/cli/windows-argv.test.ts @@ -0,0 +1,38 @@ +import { describe, expect, it } from "vitest"; +import { normalizeWindowsArgv } from "./windows-argv.js"; + +describe("normalizeWindowsArgv", () => { + it("returns argv unchanged on non-windows platforms", () => { + const argv = ["node", "ironclaw", "status"]; + expect( + normalizeWindowsArgv(argv, { + platform: "darwin", + }), + ).toEqual(argv); + }); + + it("removes duplicated node executable arguments on windows", () => { + const execPath = "C:\\Program Files\\nodejs\\node.exe"; + const argv = ["node", execPath, "C:\\repo\\openclaw.mjs", execPath, "status"]; + + expect( + normalizeWindowsArgv(argv, { + platform: "win32", + execPath, + }), + ).toEqual(["node", "C:\\repo\\openclaw.mjs", "status"]); + }); + + it("strips control chars and wrapping quotes before exec-path matching", () => { + const execPath = "C:\\Program Files\\nodejs\\node.exe"; + const argv = ["node", `"\u0000${execPath}\u0000"`, "C:\\repo\\openclaw.mjs", "status"]; + + expect( + normalizeWindowsArgv(argv, { + platform: "win32", + execPath, + existsSync: () => true, + }), + ).toEqual(["node", "C:\\repo\\openclaw.mjs", "status"]); + }); +});