From bd8b3cd15e06b3b10022b2be47e45a3ebd14a3fd Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 20:11:52 +0000 Subject: [PATCH] test(cli): add configure registrar coverage --- src/cli/program/register.configure.test.ts | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/cli/program/register.configure.test.ts diff --git a/src/cli/program/register.configure.test.ts b/src/cli/program/register.configure.test.ts new file mode 100644 index 00000000000..d5b341fa9c3 --- /dev/null +++ b/src/cli/program/register.configure.test.ts @@ -0,0 +1,52 @@ +import { Command } from "commander"; +import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; + +const configureCommandFromSectionsArgMock = vi.fn(); +const runtime = { + log: vi.fn(), + error: vi.fn(), + exit: vi.fn(), +}; + +vi.mock("../../commands/configure.js", () => ({ + CONFIGURE_WIZARD_SECTIONS: ["auth", "channels", "gateway", "agent"], + configureCommandFromSectionsArg: configureCommandFromSectionsArgMock, +})); + +vi.mock("../../runtime.js", () => ({ + defaultRuntime: runtime, +})); + +let registerConfigureCommand: typeof import("./register.configure.js").registerConfigureCommand; + +beforeAll(async () => { + ({ registerConfigureCommand } = await import("./register.configure.js")); +}); + +describe("registerConfigureCommand", () => { + async function runCli(args: string[]) { + const program = new Command(); + registerConfigureCommand(program); + await program.parseAsync(args, { from: "user" }); + } + + beforeEach(() => { + vi.clearAllMocks(); + configureCommandFromSectionsArgMock.mockResolvedValue(undefined); + }); + + it("forwards repeated --section values", async () => { + await runCli(["configure", "--section", "auth", "--section", "channels"]); + + expect(configureCommandFromSectionsArgMock).toHaveBeenCalledWith(["auth", "channels"], runtime); + }); + + it("reports errors through runtime when configure command fails", async () => { + configureCommandFromSectionsArgMock.mockRejectedValueOnce(new Error("configure failed")); + + await runCli(["configure"]); + + expect(runtime.error).toHaveBeenCalledWith("Error: configure failed"); + expect(runtime.exit).toHaveBeenCalledWith(1); + }); +});