From 426a4906397602e86276eabae8719aeb39d45f1f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 11 May 2026 04:22:01 +0100 Subject: [PATCH] test: tighten models cli assertions --- src/cli/models-cli.test.ts | 41 +++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/cli/models-cli.test.ts b/src/cli/models-cli.test.ts index 252b2c08aa68..719f462bad5a 100644 --- a/src/cli/models-cli.test.ts +++ b/src/cli/models-cli.test.ts @@ -106,6 +106,20 @@ describe("models cli", () => { return command; } + function expectCommandOptions( + command: ReturnType, + expected: Record, + ) { + expect(command).toHaveBeenCalledTimes(1); + const options = command.mock.calls[0]?.[0] as Record | undefined; + const context = command.mock.calls[0]?.[1]; + for (const [key, value] of Object.entries(expected)) { + expect(options?.[key]).toEqual(value); + } + expect(typeof context).toBe("object"); + expect(context).not.toBeNull(); + } + it("registers github-copilot login command", async () => { const program = createProgram(); const models = requireCommand(program, "models"); @@ -118,15 +132,12 @@ describe("models cli", () => { ); expect(modelsAuthLoginCommand).toHaveBeenCalledTimes(1); - expect(modelsAuthLoginCommand).toHaveBeenCalledWith( - expect.objectContaining({ - provider: "github-copilot", - method: "device", - yes: true, - agent: "poe", - }), - expect.any(Object), - ); + expectCommandOptions(modelsAuthLoginCommand, { + provider: "github-copilot", + method: "device", + yes: true, + agent: "poe", + }); }); it.each([ @@ -134,10 +145,7 @@ describe("models cli", () => { { label: "parent flag", args: ["models", "--agent", "poe", "status"] }, ])("passes --agent to models status ($label)", async ({ args }) => { await runModelsCommand(args); - expect(modelsStatusCommand).toHaveBeenCalledWith( - expect.objectContaining({ agent: "poe" }), - expect.any(Object), - ); + expectCommandOptions(modelsStatusCommand, { agent: "poe" }); }); it.each([ @@ -180,16 +188,13 @@ describe("models cli", () => { ])("passes parent --agent to models auth $label", async ({ args, command, expected }) => { await runModelsCommand(args); - expect(command).toHaveBeenCalledWith(expect.objectContaining(expected), expect.any(Object)); + expectCommandOptions(command, expected); }); it("passes list-specific --agent and --json to models auth list", async () => { await runModelsCommand(["models", "auth", "list", "--agent", "poe", "--json"]); - expect(modelsAuthListCommand).toHaveBeenCalledWith( - expect.objectContaining({ agent: "poe", json: true }), - expect.any(Object), - ); + expectCommandOptions(modelsAuthListCommand, { agent: "poe", json: true }); }); it.each([