/* Tests for install/mcp-codex module behavior. */ import { afterEach, beforeEach, describe, expect, test } from "bun:test"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { codexMcpHasServer, readCodexMcpEntry, resolveCodexConfigPath } from "./mcp-codex.ts"; let home: string; let prevTestHome: string | undefined; beforeEach(() => { home = mkdtempSync(join(tmpdir(), "argsbarg-codex-")); prevTestHome = process.env.TEST_USER_HOME; process.env.TEST_USER_HOME = home; }); afterEach(() => { if (prevTestHome === undefined) delete process.env.TEST_USER_HOME; else process.env.TEST_USER_HOME = prevTestHome; rmSync(home, { recursive: true, force: true }); }); /** Tests for codex mcp config. */ describe("codex mcp config", () => { /** ReadCodexMcpEntry parses simple command/args. */ test("readCodexMcpEntry parses simple command/args", () => { const path = resolveCodexConfigPath(home); mkdirSync(join(home, ".codex"), { recursive: true }); writeFileSync( path, `[mcp_servers.testapp] command = "testapp" args = ["mcp"] `, "utf8", ); expect(readCodexMcpEntry(path, "testapp")).toEqual({ command: "testapp", args: ["mcp"], }); expect(codexMcpHasServer(home, "testapp")).toBe(true); }); /** ReadCodexMcpEntry parses transport stdio block. */ test("readCodexMcpEntry parses transport stdio block", () => { const path = resolveCodexConfigPath(home); mkdirSync(join(home, ".codex"), { recursive: true }); writeFileSync( path, `[mcp_servers.testapp] enabled = true transport = { type = "stdio", command = "testapp", args = ["mcp"] } `, "utf8", ); expect(readCodexMcpEntry(path, "testapp")).toEqual({ command: "testapp", args: ["mcp"], }); }); });