























@@ -823,6 +823,17 @@ describe("resolveApiKeyForProvider – synthetic local auth for custom providers
823823expect(auth.source).toContain("synthetic local key");
824824});
825825826+it("synthesizes a local auth marker for private LAN custom providers with no apiKey", async () => {
827+const auth = await resolveCustomProviderAuth(
828+"custom-192-168-0-222-11434",
829+"http://192.168.0.222:11434/v1",
830+"qwen3.5:9b",
831+"Qwen 3.5 9B",
832+);
833+expect(auth.apiKey).toBe(CUSTOM_LOCAL_AUTH_MARKER);
834+expect(auth.source).toContain("synthetic local key");
835+});
836+826837it("synthesizes a local auth marker for localhost custom providers", async () => {
827838const auth = await resolveCustomProviderAuth("my-local", "http://localhost:11434/v1");
828839expect(auth.apiKey).toBe(CUSTOM_LOCAL_AUTH_MARKER);
@@ -912,6 +923,72 @@ describe("resolveApiKeyForProvider – synthetic local auth for custom providers
912923});
913924});
914925926+it("accepts non-secret local markers for private LAN custom OpenAI-compatible providers", async () => {
927+const auth = await resolveApiKeyForProvider({
928+provider: "custom-192-168-0-222-11434",
929+cfg: {
930+models: {
931+providers: {
932+"custom-192-168-0-222-11434": {
933+baseUrl: "http://192.168.0.222:11434/v1",
934+api: "openai-completions",
935+apiKey: "ollama-local",
936+models: [
937+{
938+id: "qwen3.5:9b",
939+name: "Qwen 3.5 9B",
940+reasoning: false,
941+input: ["text"],
942+cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
943+contextWindow: 8192,
944+maxTokens: 4096,
945+},
946+],
947+},
948+},
949+},
950+},
951+store: { version: 1, profiles: {} },
952+});
953+954+expect(auth).toMatchObject({
955+apiKey: CUSTOM_LOCAL_AUTH_MARKER,
956+source: "models.json (local marker)",
957+mode: "api-key",
958+});
959+});
960+961+it("does not accept non-secret local markers for remote custom providers", async () => {
962+await expect(
963+resolveApiKeyForProvider({
964+provider: "custom-remote",
965+cfg: {
966+models: {
967+providers: {
968+"custom-remote": {
969+baseUrl: "https://api.example.com/v1",
970+api: "openai-completions",
971+apiKey: "ollama-local",
972+models: [
973+{
974+id: "qwen3.5:9b",
975+name: "Qwen 3.5 9B",
976+reasoning: false,
977+input: ["text"],
978+cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
979+contextWindow: 8192,
980+maxTokens: 4096,
981+},
982+],
983+},
984+},
985+},
986+},
987+store: { version: 1, profiles: {} },
988+}),
989+).rejects.toThrow('No API key found for provider "custom-remote"');
990+});
991+915992it("does not synthesize local auth when apiKey is explicitly configured but unresolved", async () => {
916993const previous = process.env.OPENAI_API_KEY;
917994delete process.env.OPENAI_API_KEY;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。