From dcb37a39b3f5df180d1d0a69c44516c84a3d6256 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 11 May 2026 10:12:38 +0100 Subject: [PATCH] test: tighten setup command assertions --- src/cli/program/register.setup.test.ts | 48 +++++++++++--------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/src/cli/program/register.setup.test.ts b/src/cli/program/register.setup.test.ts index a293ea35f51..2e437547b51 100644 --- a/src/cli/program/register.setup.test.ts +++ b/src/cli/program/register.setup.test.ts @@ -16,6 +16,14 @@ const setupCommandMock = mocks.setupCommandMock; const setupWizardCommandMock = mocks.setupWizardCommandMock; const runtime = mocks.runtime; +function lastSetupOptions(): Record | undefined { + return setupCommandMock.mock.calls.at(-1)?.[0] as Record | undefined; +} + +function lastWizardOptions(): Record | undefined { + return setupWizardCommandMock.mock.calls.at(-1)?.[0] as Record | undefined; +} + vi.mock("../../commands/setup.js", () => ({ setupCommand: mocks.setupCommandMock, })); @@ -44,38 +52,26 @@ describe("registerSetupCommand", () => { it("runs setup command by default", async () => { await runCli(["setup", "--workspace", "/tmp/ws"]); - expect(setupCommandMock).toHaveBeenCalledWith( - expect.objectContaining({ - workspace: "/tmp/ws", - }), - runtime, - ); + expect(setupCommandMock).toHaveBeenCalledWith(lastSetupOptions(), runtime); + expect(lastSetupOptions()?.workspace).toBe("/tmp/ws"); expect(setupWizardCommandMock).not.toHaveBeenCalled(); }); it("runs setup wizard command when --wizard is set", async () => { await runCli(["setup", "--wizard", "--mode", "remote", "--remote-url", "wss://example"]); - expect(setupWizardCommandMock).toHaveBeenCalledWith( - expect.objectContaining({ - mode: "remote", - remoteUrl: "wss://example", - }), - runtime, - ); + expect(setupWizardCommandMock).toHaveBeenCalledWith(lastWizardOptions(), runtime); + expect(lastWizardOptions()?.mode).toBe("remote"); + expect(lastWizardOptions()?.remoteUrl).toBe("wss://example"); expect(setupCommandMock).not.toHaveBeenCalled(); }); it("runs setup wizard command when wizard-only flags are passed explicitly", async () => { await runCli(["setup", "--mode", "remote", "--non-interactive"]); - expect(setupWizardCommandMock).toHaveBeenCalledWith( - expect.objectContaining({ - mode: "remote", - nonInteractive: true, - }), - runtime, - ); + expect(setupWizardCommandMock).toHaveBeenCalledWith(lastWizardOptions(), runtime); + expect(lastWizardOptions()?.mode).toBe("remote"); + expect(lastWizardOptions()?.nonInteractive).toBe(true); expect(setupCommandMock).not.toHaveBeenCalled(); }); @@ -89,14 +85,10 @@ describe("registerSetupCommand", () => { "--import-secrets", ]); - expect(setupWizardCommandMock).toHaveBeenCalledWith( - expect.objectContaining({ - importFrom: "hermes", - importSource: "/tmp/hermes", - importSecrets: true, - }), - runtime, - ); + expect(setupWizardCommandMock).toHaveBeenCalledWith(lastWizardOptions(), runtime); + expect(lastWizardOptions()?.importFrom).toBe("hermes"); + expect(lastWizardOptions()?.importSource).toBe("/tmp/hermes"); + expect(lastWizardOptions()?.importSecrets).toBe(true); expect(setupCommandMock).not.toHaveBeenCalled(); });