|
1 | 1 | import { describe, expect, it, vi } from "vitest"; |
| 2 | +import { CUSTOM_LOCAL_AUTH_MARKER } from "../agents/model-auth-markers.js"; |
2 | 3 | import { VERSION } from "../version.js"; |
3 | 4 | import { |
4 | 5 | createRequestCaptureJsonFetch, |
@@ -72,6 +73,46 @@ describe("transcribeOpenAiCompatibleAudio", () => { |
72 | 73 | expect((file as File).name).toBe("voice-note.m4a"); |
73 | 74 | }); |
74 | 75 |
|
| 76 | + it("omits bearer auth for explicit no-auth requests", async () => { |
| 77 | + const { fetchFn, getRequest } = createRequestCaptureJsonFetch({ text: "ok" }); |
| 78 | + |
| 79 | + await transcribeOpenAiCompatibleAudio({ |
| 80 | + buffer: Buffer.from("audio"), |
| 81 | + fileName: "note.mp3", |
| 82 | + apiKey: CUSTOM_LOCAL_AUTH_MARKER, |
| 83 | + auth: { kind: "none", source: "local provider" }, |
| 84 | + timeoutMs: 1000, |
| 85 | + fetchFn, |
| 86 | + provider: "local-audio", |
| 87 | + baseUrl: "https://audio.example.com/v1", |
| 88 | + defaultBaseUrl: "https://audio.example.com/v1", |
| 89 | + defaultModel: "whisper-local", |
| 90 | + }); |
| 91 | + |
| 92 | + const headers = new Headers(getRequest().init?.headers); |
| 93 | + expect(headers.get("authorization")).toBeNull(); |
| 94 | + }); |
| 95 | + |
| 96 | + it("uses typed api-key auth for bearer headers", async () => { |
| 97 | + const { fetchFn, getRequest } = createRequestCaptureJsonFetch({ text: "ok" }); |
| 98 | + |
| 99 | + await transcribeOpenAiCompatibleAudio({ |
| 100 | + buffer: Buffer.from("audio"), |
| 101 | + fileName: "note.mp3", |
| 102 | + apiKey: "legacy-key", |
| 103 | + auth: { kind: "api-key", apiKey: "typed-key", source: "test" }, |
| 104 | + timeoutMs: 1000, |
| 105 | + fetchFn, |
| 106 | + provider: "local-audio", |
| 107 | + baseUrl: "https://audio.example.com/v1", |
| 108 | + defaultBaseUrl: "https://audio.example.com/v1", |
| 109 | + defaultModel: "whisper-local", |
| 110 | + }); |
| 111 | + |
| 112 | + const headers = new Headers(getRequest().init?.headers); |
| 113 | + expect(headers.get("authorization")).toBe("Bearer typed-key"); |
| 114 | + }); |
| 115 | + |
75 | 116 | it("wraps malformed transcription JSON with a stable provider error", async () => { |
76 | 117 | const fetchFn = vi.fn<typeof fetch>().mockResolvedValueOnce(new Response("{ nope")); |
77 | 118 |
|
|
0 commit comments