From c37beba1e01635aa7b1b36a175048cfa25d2eae3 Mon Sep 17 00:00:00 2001 From: ndycode Date: Sat, 21 Mar 2026 04:19:46 +0800 Subject: [PATCH 1/2] refactor: extract check command wrapper --- lib/codex-manager.ts | 4 ++-- lib/codex-manager/commands/check.ts | 8 ++++++++ test/codex-manager-check-command.test.ts | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 lib/codex-manager/commands/check.ts create mode 100644 test/codex-manager-check-command.test.ts 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..829c8487 --- /dev/null +++ b/test/codex-manager-check-command.test.ts @@ -0,0 +1,18 @@ +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).toHaveBeenCalledWith({ liveProbe: true }); + }); +}); From 9ac02b69f0129aa2741533f11c6b784cadee3005 Mon Sep 17 00:00:00 2001 From: ndycode Date: Sat, 21 Mar 2026 04:30:41 +0800 Subject: [PATCH 2/2] test(check): cover wrapper rejection path --- test/codex-manager-check-command.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/codex-manager-check-command.test.ts b/test/codex-manager-check-command.test.ts index 829c8487..ecd753ab 100644 --- a/test/codex-manager-check-command.test.ts +++ b/test/codex-manager-check-command.test.ts @@ -13,6 +13,20 @@ describe("runCheckCommand", () => { 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 }); }); });