| 1 | import * as NodeAssert from "node:assert/strict"; |
| 2 | |
| 3 | import { describe, it } from "vite-plus/test"; |
| 4 | |
| 5 | import { |
| 6 | codexAppServerArgs, |
| 7 | codexExecLaunchArgs, |
| 8 | resolveCodexLaunchArgs, |
| 9 | } from "./codexLaunchArgs.ts"; |
| 10 | |
| 11 | describe("resolveCodexLaunchArgs", () => { |
| 12 | it("uses T3CODE_CODEX_LAUNCH_ARGS before configured settings", () => { |
| 13 | NodeAssert.equal( |
| 14 | resolveCodexLaunchArgs(" --strict-config ", { T3CODE_CODEX_LAUNCH_ARGS: "--enable foo" }), |
| 15 | "--enable foo", |
| 16 | ); |
| 17 | }); |
| 18 | |
| 19 | it("uses configured settings when T3CODE_CODEX_LAUNCH_ARGS is empty", () => { |
| 20 | NodeAssert.equal( |
| 21 | resolveCodexLaunchArgs(" --strict-config ", { T3CODE_CODEX_LAUNCH_ARGS: " " }), |
| 22 | "--strict-config", |
| 23 | ); |
| 24 | }); |
| 25 | |
| 26 | it("ignores whitespace-only environment values", () => { |
| 27 | NodeAssert.equal(resolveCodexLaunchArgs("", { T3CODE_CODEX_LAUNCH_ARGS: " " }), ""); |
| 28 | }); |
| 29 | }); |
| 30 | |
| 31 | describe("codexAppServerArgs", () => { |
| 32 | it("returns the app-server command for empty launch args", () => { |
| 33 | NodeAssert.deepStrictEqual(codexAppServerArgs(""), ["app-server"]); |
| 34 | }); |
| 35 | |
| 36 | it("appends parsed launch args after app-server", () => { |
| 37 | NodeAssert.deepStrictEqual(codexAppServerArgs("--strict-config --enable foo"), [ |
| 38 | "app-server", |
| 39 | "--strict-config", |
| 40 | "--enable", |
| 41 | "foo", |
| 42 | ]); |
| 43 | }); |
| 44 | }); |
| 45 | |
| 46 | describe("codexExecLaunchArgs", () => { |
| 47 | it("keeps shared codex flags and omits app-server-only flags", () => { |
| 48 | NodeAssert.deepStrictEqual( |
| 49 | codexExecLaunchArgs('--strict-config --enable foo --listen off --config model="gpt 5"'), |
| 50 | ["--strict-config", "--enable", "foo", "--config", "model=gpt 5"], |
| 51 | ); |
| 52 | }); |
| 53 | |
| 54 | it("does not pair value-taking flags with adjacent flags", () => { |
| 55 | NodeAssert.deepStrictEqual(codexExecLaunchArgs("--config --strict-config --enable --disable"), [ |
| 56 | "--strict-config", |
| 57 | ]); |
| 58 | }); |
| 59 | }); |