From e61775a47022f8887cca371eb4af95de2acafa22 Mon Sep 17 00:00:00 2001 From: can1357 Date: Wed, 19 Aug 2026 01:04:58 +0200 Subject: [PATCH] fix(coding-agent): mention oauth exemption in apiKey validation error; add validation tests --- .../coding-agent/src/config/models-config.ts | 2 +- .../config/models-config-validation.test.ts | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 packages/coding-agent/test/config/models-config-validation.test.ts diff --git a/packages/coding-agent/src/config/models-config.ts b/packages/coding-agent/src/config/models-config.ts index 1c6e7b26d..f2c0fe2f6 100644 --- a/packages/coding-agent/src/config/models-config.ts +++ b/packages/coding-agent/src/config/models-config.ts @@ -71,7 +71,7 @@ export function validateProviderConfiguration( throw new Error( mode === "runtime-register" ? `Provider ${providerName}: "apiKey" or "oauth" is required when defining models.` - : `Provider ${providerName}: "apiKey" is required when defining custom models unless auth is "none".`, + : `Provider ${providerName}: "apiKey" is required when defining custom models unless auth is "none" or "oauth".`, ); } } diff --git a/packages/coding-agent/test/config/models-config-validation.test.ts b/packages/coding-agent/test/config/models-config-validation.test.ts new file mode 100644 index 000000000..c576fe416 --- /dev/null +++ b/packages/coding-agent/test/config/models-config-validation.test.ts @@ -0,0 +1,31 @@ +import { describe, expect, test } from "bun:test"; +import { validateProviderConfiguration } from "@oh-my-pi/pi-coding-agent/config/models-config"; + +const models = [{ id: "grok-4", api: "openai-completions" as const }]; +const baseUrl = "https://api.example.invalid/v1"; + +describe("validateProviderConfiguration (models-config auth)", () => { + test("auth: oauth allows custom models without apiKey", () => { + expect(() => + validateProviderConfiguration("xai-oauth", { baseUrl, auth: "oauth", models }, "models-config"), + ).not.toThrow(); + }); + + test("auth: none allows custom models without apiKey", () => { + expect(() => + validateProviderConfiguration("local", { baseUrl, auth: "none", models }, "models-config"), + ).not.toThrow(); + }); + + test("default auth (apiKey) still requires apiKey for custom models", () => { + expect(() => validateProviderConfiguration("custom", { baseUrl, models }, "models-config")).toThrow( + 'Provider custom: "apiKey" is required when defining custom models unless auth is "none" or "oauth".', + ); + }); + + test("explicit auth: apiKey with apiKey set passes", () => { + expect(() => + validateProviderConfiguration("custom", { baseUrl, auth: "apiKey", apiKey: "sk-test", models }, "models-config"), + ).not.toThrow(); + }); +});