From 3d2f4aea6357191746064ecd49bdd52a20488fce Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 20:12:29 +0000 Subject: [PATCH] test(cli): add setup registrar coverage for wizard dispatch --- src/cli/program/register.setup.test.ts | 89 ++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/cli/program/register.setup.test.ts diff --git a/src/cli/program/register.setup.test.ts b/src/cli/program/register.setup.test.ts new file mode 100644 index 000000000..2ac5ec1ec --- /dev/null +++ b/src/cli/program/register.setup.test.ts @@ -0,0 +1,89 @@ +import { Command } from "commander"; +import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; + +const setupCommandMock = vi.fn(); +const onboardCommandMock = vi.fn(); +const runtime = { + log: vi.fn(), + error: vi.fn(), + exit: vi.fn(), +}; + +vi.mock("../../commands/setup.js", () => ({ + setupCommand: setupCommandMock, +})); + +vi.mock("../../commands/onboard.js", () => ({ + onboardCommand: onboardCommandMock, +})); + +vi.mock("../../runtime.js", () => ({ + defaultRuntime: runtime, +})); + +let registerSetupCommand: typeof import("./register.setup.js").registerSetupCommand; + +beforeAll(async () => { + ({ registerSetupCommand } = await import("./register.setup.js")); +}); + +describe("registerSetupCommand", () => { + async function runCli(args: string[]) { + const program = new Command(); + registerSetupCommand(program); + await program.parseAsync(args, { from: "user" }); + } + + beforeEach(() => { + vi.clearAllMocks(); + setupCommandMock.mockResolvedValue(undefined); + onboardCommandMock.mockResolvedValue(undefined); + }); + + it("runs setup command by default", async () => { + await runCli(["setup", "--workspace", "/tmp/ws"]); + + expect(setupCommandMock).toHaveBeenCalledWith( + expect.objectContaining({ + workspace: "/tmp/ws", + }), + runtime, + ); + expect(onboardCommandMock).not.toHaveBeenCalled(); + }); + + it("runs onboard command when --wizard is set", async () => { + await runCli(["setup", "--wizard", "--mode", "remote", "--remote-url", "wss://example"]); + + expect(onboardCommandMock).toHaveBeenCalledWith( + expect.objectContaining({ + mode: "remote", + remoteUrl: "wss://example", + }), + runtime, + ); + expect(setupCommandMock).not.toHaveBeenCalled(); + }); + + it("runs onboard command when wizard-only flags are passed explicitly", async () => { + await runCli(["setup", "--mode", "remote", "--non-interactive"]); + + expect(onboardCommandMock).toHaveBeenCalledWith( + expect.objectContaining({ + mode: "remote", + nonInteractive: true, + }), + runtime, + ); + expect(setupCommandMock).not.toHaveBeenCalled(); + }); + + it("reports setup errors through runtime", async () => { + setupCommandMock.mockRejectedValueOnce(new Error("setup failed")); + + await runCli(["setup"]); + + expect(runtime.error).toHaveBeenCalledWith("Error: setup failed"); + expect(runtime.exit).toHaveBeenCalledWith(1); + }); +});