
























@@ -124,6 +124,7 @@ vi.mock("../plugins/provider-runtime.js", async () => {
124124let applyAuthHeaderOverride: typeof import("./model-auth.js").applyAuthHeaderOverride;
125125let applyLocalNoAuthHeaderOverride: typeof import("./model-auth.js").applyLocalNoAuthHeaderOverride;
126126let hasUsableCustomProviderApiKey: typeof import("./model-auth.js").hasUsableCustomProviderApiKey;
127+let hasSyntheticLocalProviderAuthConfig: typeof import("./model-auth.js").hasSyntheticLocalProviderAuthConfig;
127128let requireApiKey: typeof import("./model-auth.js").requireApiKey;
128129let resolveApiKeyForProvider: typeof import("./model-auth.js").resolveApiKeyForProvider;
129130let resolveAwsSdkEnvVarName: typeof import("./model-auth.js").resolveAwsSdkEnvVarName;
@@ -140,6 +141,7 @@ beforeAll(async () => {
140141({
141142 applyAuthHeaderOverride,
142143 applyLocalNoAuthHeaderOverride,
144+ hasSyntheticLocalProviderAuthConfig,
143145 hasUsableCustomProviderApiKey,
144146 requireApiKey,
145147 resolveApiKeyForProvider,
@@ -862,6 +864,33 @@ describe("resolveApiKeyForProvider", () => {
862864});
863865864866describe("resolveApiKeyForProvider – synthetic local auth for custom providers", () => {
867+it("recognizes local baseUrl variants for synthetic auth config", () => {
868+const localBaseUrls = [
869+"http://127.0.0.1:8080/v1",
870+"http://192.168.0.222:11434/v1",
871+"http://localhost:11434/v1",
872+"http://[::1]:8080/v1",
873+"http://0.0.0.0:11434/v1",
874+"http://[::ffff:127.0.0.1]:8080/v1",
875+];
876+877+for (const baseUrl of localBaseUrls) {
878+expect(
879+hasSyntheticLocalProviderAuthConfig({
880+provider: "custom-local",
881+cfg: {
882+models: {
883+providers: {
884+"custom-local": createCustomProviderConfig(baseUrl),
885+},
886+},
887+},
888+}),
889+baseUrl,
890+).toBe(true);
891+}
892+});
893+865894it("synthesizes a local auth marker for custom providers with a local baseUrl and no apiKey", async () => {
866895const auth = await resolveCustomProviderAuth(
867896"custom-127-0-0-1-8080",
@@ -873,43 +902,20 @@ describe("resolveApiKeyForProvider – synthetic local auth for custom providers
873902expect(auth.source).toContain("synthetic local key");
874903});
875904876-it("synthesizes a local auth marker for private LAN custom providers with no apiKey", async () => {
877-const auth = await resolveCustomProviderAuth(
878-"custom-192-168-0-222-11434",
879-"http://192.168.0.222:11434/v1",
880-"qwen3.5:9b",
881-"Qwen 3.5 9B",
882-);
883-expect(auth.apiKey).toBe(CUSTOM_LOCAL_AUTH_MARKER);
884-expect(auth.source).toContain("synthetic local key");
885-});
886-887-it("synthesizes a local auth marker for localhost custom providers", async () => {
888-const auth = await resolveCustomProviderAuth("my-local", "http://localhost:11434/v1");
889-expect(auth.apiKey).toBe(CUSTOM_LOCAL_AUTH_MARKER);
890-});
891-892-it("synthesizes a local auth marker for IPv6 loopback (::1)", async () => {
893-const auth = await resolveCustomProviderAuth("my-ipv6", "http://[::1]:8080/v1");
894-expect(auth.apiKey).toBe(CUSTOM_LOCAL_AUTH_MARKER);
895-});
896-897-it("synthesizes a local auth marker for 0.0.0.0", async () => {
898-const auth = await resolveCustomProviderAuth(
899-"my-wildcard",
900-"http://0.0.0.0:11434/v1",
901-"qwen",
902-"Qwen",
903-);
904-expect(auth.apiKey).toBe(CUSTOM_LOCAL_AUTH_MARKER);
905-});
906-907-it("synthesizes a local auth marker for IPv4-mapped IPv6 (::ffff:127.0.0.1)", async () => {
908-const auth = await resolveCustomProviderAuth("my-mapped", "http://[::ffff:127.0.0.1]:8080/v1");
909-expect(auth.apiKey).toBe(CUSTOM_LOCAL_AUTH_MARKER);
910-});
911-912905it("does not synthesize auth for remote custom providers without apiKey", async () => {
906+expect(
907+hasSyntheticLocalProviderAuthConfig({
908+provider: "my-remote",
909+cfg: {
910+models: {
911+providers: {
912+"my-remote": createCustomProviderConfig("https://api.example.com/v1"),
913+},
914+},
915+},
916+}),
917+).toBe(false);
918+913919await expect(
914920resolveApiKeyForProvider({
915921provider: "my-remote",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。