From ba23d2b1fe542d541aba8497f8a85cb1869997fc Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 23:49:11 +0000 Subject: [PATCH] test(onboard): table-drive custom api flag rejection cases --- src/commands/onboard-custom.e2e.test.ts | 69 +++++++++++++------------ 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/src/commands/onboard-custom.e2e.test.ts b/src/commands/onboard-custom.e2e.test.ts index f360b018c..c1bf8aa0d 100644 --- a/src/commands/onboard-custom.e2e.test.ts +++ b/src/commands/onboard-custom.e2e.test.ts @@ -198,27 +198,30 @@ describe("promptCustomApiConfig", () => { }); describe("applyCustomApiConfig", () => { - it("rejects invalid compatibility values at runtime", () => { - expect(() => - applyCustomApiConfig({ + it.each([ + { + name: "invalid compatibility values at runtime", + params: { config: {}, baseUrl: "https://llm.example.com/v1", modelId: "foo-large", compatibility: "invalid" as unknown as "openai", - }), - ).toThrow('Custom provider compatibility must be "openai" or "anthropic".'); - }); - - it("rejects explicit provider ids that normalize to empty", () => { - expect(() => - applyCustomApiConfig({ + }, + expectedMessage: 'Custom provider compatibility must be "openai" or "anthropic".', + }, + { + name: "explicit provider ids that normalize to empty", + params: { config: {}, baseUrl: "https://llm.example.com/v1", modelId: "foo-large", - compatibility: "openai", + compatibility: "openai" as const, providerId: "!!!", - }), - ).toThrow("Custom provider ID must include letters, numbers, or hyphens."); + }, + expectedMessage: "Custom provider ID must include letters, numbers, or hyphens.", + }, + ])("rejects $name", ({ params, expectedMessage }) => { + expect(() => applyCustomApiConfig(params)).toThrow(expectedMessage); }); }); @@ -240,31 +243,31 @@ describe("parseNonInteractiveCustomApiFlags", () => { }); }); - it("rejects missing required flags", () => { - expect(() => - parseNonInteractiveCustomApiFlags({ - baseUrl: "https://llm.example.com/v1", - }), - ).toThrow('Auth choice "custom-api-key" requires a base URL and model ID.'); - }); - - it("rejects invalid compatibility values", () => { - expect(() => - parseNonInteractiveCustomApiFlags({ + it.each([ + { + name: "missing required flags", + flags: { baseUrl: "https://llm.example.com/v1" }, + expectedMessage: 'Auth choice "custom-api-key" requires a base URL and model ID.', + }, + { + name: "invalid compatibility values", + flags: { baseUrl: "https://llm.example.com/v1", modelId: "foo-large", compatibility: "xmlrpc", - }), - ).toThrow('Invalid --custom-compatibility (use "openai" or "anthropic").'); - }); - - it("rejects invalid explicit provider ids", () => { - expect(() => - parseNonInteractiveCustomApiFlags({ + }, + expectedMessage: 'Invalid --custom-compatibility (use "openai" or "anthropic").', + }, + { + name: "invalid explicit provider ids", + flags: { baseUrl: "https://llm.example.com/v1", modelId: "foo-large", providerId: "!!!", - }), - ).toThrow("Custom provider ID must include letters, numbers, or hyphens."); + }, + expectedMessage: "Custom provider ID must include letters, numbers, or hyphens.", + }, + ])("rejects $name", ({ flags, expectedMessage }) => { + expect(() => parseNonInteractiveCustomApiFlags(flags)).toThrow(expectedMessage); }); });