diff --git a/lib/codex-manager.ts b/lib/codex-manager.ts index d413d116..4ed0bea2 100644 --- a/lib/codex-manager.ts +++ b/lib/codex-manager.ts @@ -36,6 +36,7 @@ import { loadCodexCliState, } from "./codex-cli/state.js"; import { setCodexCliActiveSelection } from "./codex-cli/writer.js"; +import { runCheckCommand } from "./codex-manager/commands/check.js"; import { runFeaturesCommand, runStatusCommand, @@ -5547,8 +5548,7 @@ export async function runCodexMultiAuthCli(rawArgs: string[]): Promise { return runSwitch(rest); } if (command === "check") { - await runHealthCheck({ liveProbe: true }); - return 0; + return runCheckCommand({ runHealthCheck }); } if (command === "features") { return runFeaturesReport(); diff --git a/lib/codex-manager/commands/check.ts b/lib/codex-manager/commands/check.ts new file mode 100644 index 00000000..69a8dc93 --- /dev/null +++ b/lib/codex-manager/commands/check.ts @@ -0,0 +1,8 @@ +export interface CheckCommandDeps { + runHealthCheck: (options: { liveProbe: boolean }) => Promise; +} + +export async function runCheckCommand(deps: CheckCommandDeps): Promise { + await deps.runHealthCheck({ liveProbe: true }); + return 0; +} diff --git a/test/codex-manager-check-command.test.ts b/test/codex-manager-check-command.test.ts new file mode 100644 index 00000000..ecd753ab --- /dev/null +++ b/test/codex-manager-check-command.test.ts @@ -0,0 +1,32 @@ +import { describe, expect, it, vi } from "vitest"; +import { + type CheckCommandDeps, + runCheckCommand, +} from "../lib/codex-manager/commands/check.js"; + +describe("runCheckCommand", () => { + it("runs health check with live probing enabled", async () => { + const deps: CheckCommandDeps = { + runHealthCheck: vi.fn(async () => undefined), + }; + + const result = await runCheckCommand(deps); + + expect(result).toBe(0); + expect(deps.runHealthCheck).toHaveBeenCalledTimes(1); + expect(deps.runHealthCheck).toHaveBeenCalledWith({ liveProbe: true }); + }); + + it("propagates rejection from runHealthCheck", async () => { + const error = new Error("probe failed"); + const deps: CheckCommandDeps = { + runHealthCheck: vi.fn(async () => { + throw error; + }), + }; + + await expect(runCheckCommand(deps)).rejects.toThrow("probe failed"); + expect(deps.runHealthCheck).toHaveBeenCalledTimes(1); + expect(deps.runHealthCheck).toHaveBeenCalledWith({ liveProbe: true }); + }); +});