

















@@ -0,0 +1,72 @@
1+import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
2+import os from "node:os";
3+import path from "node:path";
4+import { afterEach, describe, expect, it } from "vitest";
5+import type { CodexAppServerStartOptions } from "./config.js";
6+import { resolveCodexAppServerSpawnInvocation } from "./transport-stdio.js";
7+8+const tempDirs: string[] = [];
9+10+async function createTempDir(): Promise<string> {
11+const dir = await mkdtemp(path.join(os.tmpdir(), "openclaw-codex-spawn-"));
12+tempDirs.push(dir);
13+return dir;
14+}
15+16+afterEach(async () => {
17+for (const dir of tempDirs.splice(0)) {
18+await rm(dir, { recursive: true, force: true });
19+}
20+});
21+22+function startOptions(command: string): CodexAppServerStartOptions {
23+return {
24+transport: "stdio",
25+ command,
26+args: ["app-server", "--listen", "stdio://"],
27+headers: {},
28+};
29+}
30+31+describe("resolveCodexAppServerSpawnInvocation", () => {
32+it("keeps non-Windows Codex app-server invocation unchanged", () => {
33+const resolved = resolveCodexAppServerSpawnInvocation(startOptions("codex"), {
34+platform: "darwin",
35+env: {},
36+execPath: "/usr/local/bin/node",
37+});
38+39+expect(resolved).toEqual({
40+command: "codex",
41+args: ["app-server", "--listen", "stdio://"],
42+shell: undefined,
43+windowsHide: undefined,
44+});
45+});
46+47+it("resolves Windows npm .cmd Codex shims through Node instead of raw spawn", async () => {
48+const binDir = await createTempDir();
49+const entryPath = path.join(binDir, "node_modules", "@openai", "codex", "bin", "codex.js");
50+const shimPath = path.join(binDir, "codex.cmd");
51+await mkdir(path.dirname(entryPath), { recursive: true });
52+await writeFile(entryPath, "console.log('codex')\n", "utf8");
53+await writeFile(
54+shimPath,
55+'@ECHO off\r\n"%~dp0\\node_modules\\@openai\\codex\\bin\\codex.js" %*\r\n',
56+"utf8",
57+);
58+59+const resolved = resolveCodexAppServerSpawnInvocation(startOptions("codex"), {
60+platform: "win32",
61+env: { PATH: binDir, PATHEXT: ".CMD;.EXE;.BAT" },
62+execPath: "C:\\node\\node.exe",
63+});
64+65+expect(resolved).toEqual({
66+command: "C:\\node\\node.exe",
67+args: [entryPath, "app-server", "--listen", "stdio://"],
68+shell: undefined,
69+windowsHide: true,
70+});
71+});
72+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。