From 510f481298d9e686cd010cfe84e045e14b2f1313 Mon Sep 17 00:00:00 2001 From: ndycode <405533+ndycode@users.noreply.github.com> Date: Sun, 22 Mar 2026 13:55:58 +0800 Subject: [PATCH 1/2] test: cover codex-multi-auth wrapper --- test/codex-multi-auth-wrapper.test.ts | 68 +++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/codex-multi-auth-wrapper.test.ts diff --git a/test/codex-multi-auth-wrapper.test.ts b/test/codex-multi-auth-wrapper.test.ts new file mode 100644 index 00000000..84c9f65f --- /dev/null +++ b/test/codex-multi-auth-wrapper.test.ts @@ -0,0 +1,68 @@ +import { spawnSync } from "node:child_process"; +import { + copyFileSync, + mkdirSync, + mkdtempSync, + readFileSync, + rmSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { afterEach, describe, expect, it } from "vitest"; + +const tempRoots: string[] = []; + +afterEach(() => { + while (tempRoots.length > 0) { + const root = tempRoots.pop(); + if (root) rmSync(root, { recursive: true, force: true }); + } +}); + +describe("codex-multi-auth wrapper", () => { + it("loads the built CLI entry and forwards args with package version env", () => { + const root = mkdtempSync(path.join(tmpdir(), "codex-multi-auth-wrapper-")); + tempRoots.push(root); + const scriptsDir = path.join(root, "scripts"); + const distLibDir = path.join(root, "dist", "lib"); + mkdirSync(scriptsDir, { recursive: true }); + mkdirSync(distLibDir, { recursive: true }); + + copyFileSync( + path.join(process.cwd(), "scripts", "codex-multi-auth.js"), + path.join(scriptsDir, "codex-multi-auth.js"), + ); + writeFileSync( + path.join(root, "package.json"), + JSON.stringify({ version: "9.9.9-test" }, null, 2), + "utf8", + ); + writeFileSync( + path.join(distLibDir, "codex-manager.js"), + [ + "export async function runCodexMultiAuthCli(args) {", + " console.log('version=' + process.env.CODEX_MULTI_AUTH_CLI_VERSION);", + " console.log('args=' + args.join(' '));", + " return 0;", + "}", + ].join("\n"), + "utf8", + ); + + const result = spawnSync( + process.execPath, + [path.join(scriptsDir, "codex-multi-auth.js"), "auth", "--help"], + { cwd: root, encoding: "utf8" }, + ); + + expect(result.status).toBe(0); + expect(result.stdout).toContain("version=9.9.9-test"); + expect(result.stdout).toContain("args=auth --help"); + const scriptText = readFileSync( + path.join(scriptsDir, "codex-multi-auth.js"), + "utf8", + ); + expect(scriptText).toContain("runCodexMultiAuthCli"); + }); +}); From 26cdb9e1643399d04b6cd8e37eabf7ef69454e32 Mon Sep 17 00:00:00 2001 From: ndycode <405533+ndycode@users.noreply.github.com> Date: Sun, 22 Mar 2026 14:05:51 +0800 Subject: [PATCH 2/2] Use retry-safe cleanup in wrapper smoke test --- test/codex-multi-auth-wrapper.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/codex-multi-auth-wrapper.test.ts b/test/codex-multi-auth-wrapper.test.ts index 84c9f65f..ebd726d5 100644 --- a/test/codex-multi-auth-wrapper.test.ts +++ b/test/codex-multi-auth-wrapper.test.ts @@ -4,19 +4,21 @@ import { mkdirSync, mkdtempSync, readFileSync, - rmSync, writeFileSync, } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; +import { removeWithRetry } from "./helpers/remove-with-retry.js"; const tempRoots: string[] = []; -afterEach(() => { +afterEach(async () => { while (tempRoots.length > 0) { const root = tempRoots.pop(); - if (root) rmSync(root, { recursive: true, force: true }); + if (root) { + await removeWithRetry(root, { recursive: true, force: true }); + } } });