From 4656dcef05d1edfb3a4b7ac9d37f130014e055bd Mon Sep 17 00:00:00 2001 From: lploc94 Date: Tue, 27 Jan 2026 19:08:35 +0700 Subject: [PATCH] test(models): add tests for baseUrl and api inheritance Add test cases to verify: - baseUrl is inherited from provider when model does not specify it - api is inherited from provider when model does not specify it - model-level api takes precedence over provider-level api - both baseUrl and api can be inherited together Co-Authored-By: Claude (claude-opus-4.5) --- src/agents/pi-embedded-runner/model.test.ts | 66 ++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/src/agents/pi-embedded-runner/model.test.ts b/src/agents/pi-embedded-runner/model.test.ts index b59735623b..e7416e3da2 100644 --- a/src/agents/pi-embedded-runner/model.test.ts +++ b/src/agents/pi-embedded-runner/model.test.ts @@ -22,8 +22,70 @@ describe("buildInlineProviderModels", () => { const result = buildInlineProviderModels(providers); expect(result).toEqual([ - { ...makeModel("alpha-model"), provider: "alpha" }, - { ...makeModel("beta-model"), provider: "beta" }, + { ...makeModel("alpha-model"), provider: "alpha", baseUrl: undefined, api: undefined }, + { ...makeModel("beta-model"), provider: "beta", baseUrl: undefined, api: undefined }, ]); }); + + it("inherits baseUrl from provider when model does not specify it", () => { + const providers = { + custom: { + baseUrl: "http://localhost:8000", + models: [makeModel("custom-model")], + }, + }; + + const result = buildInlineProviderModels(providers); + + expect(result).toHaveLength(1); + expect(result[0].baseUrl).toBe("http://localhost:8000"); + }); + + it("inherits api from provider when model does not specify it", () => { + const providers = { + custom: { + api: "anthropic-messages", + models: [makeModel("custom-model")], + }, + }; + + const result = buildInlineProviderModels(providers); + + expect(result).toHaveLength(1); + expect(result[0].api).toBe("anthropic-messages"); + }); + + it("model-level api takes precedence over provider-level api", () => { + const providers = { + custom: { + api: "openai-chat", + models: [{ ...makeModel("custom-model"), api: "anthropic-messages" as const }], + }, + }; + + const result = buildInlineProviderModels(providers); + + expect(result).toHaveLength(1); + expect(result[0].api).toBe("anthropic-messages"); + }); + + it("inherits both baseUrl and api from provider config", () => { + const providers = { + custom: { + baseUrl: "http://localhost:10000", + api: "anthropic-messages", + models: [makeModel("claude-opus-4.5")], + }, + }; + + const result = buildInlineProviderModels(providers); + + expect(result).toHaveLength(1); + expect(result[0]).toMatchObject({ + provider: "custom", + baseUrl: "http://localhost:10000", + api: "anthropic-messages", + name: "claude-opus-4.5", + }); + }); });