From c919f503aa3a3d74b8e0ed5857ff3263b2dac72b Mon Sep 17 00:00:00 2001 From: Mohammed Alkindi Date: Fri, 18 Sep 2026 09:01:54 -0700 Subject: [PATCH] test(model): cover createAzureOpenAILanguageModel auth headers The Azure factory sets both an Authorization Bearer header, needed for managed identity, and an api-key header. Nothing asserted either, so a regression to the pre-#139 single-header shape would have gone unnoticed. --- typescript/tests/model.test.mjs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/typescript/tests/model.test.mjs b/typescript/tests/model.test.mjs index b3a75816..81b08f64 100644 --- a/typescript/tests/model.test.mjs +++ b/typescript/tests/model.test.mjs @@ -9,7 +9,7 @@ import { test, describe, after } from "node:test"; import assert from "node:assert/strict"; // Load the compiled module from dist -import { createOpenAILanguageModel, createLanguageModel } from "../dist/index.js"; +import { createOpenAILanguageModel, createAzureOpenAILanguageModel, createLanguageModel } from "../dist/index.js"; // --------------------------------------------------------------------------- // Helpers: build mock Response objects @@ -273,6 +273,28 @@ describe("createOpenAILanguageModel (Chat Completions API)", () => { }); }); +// --------------------------------------------------------------------------- +// createAzureOpenAILanguageModel +// --------------------------------------------------------------------------- + +describe("createAzureOpenAILanguageModel", () => { + after(teardownFetch); + + test("sends both Authorization Bearer and api-key headers", async () => { + setupFetch([makeChatCompletionsResponse("Hello from Azure!")]); + const model = createAzureOpenAILanguageModel( + "azure-test-key", + "https://example.openai.azure.com/openai/deployments/gpt-4/chat/completions?api-version=2023-05-15" + ); + const result = await model.complete("Say hello"); + assert.equal(result.success, true); + assert.equal(result.data, "Hello from Azure!"); + const headers = capturedRequests[0].options.headers; + assert.equal(headers["Authorization"], "Bearer azure-test-key"); + assert.equal(headers["api-key"], "azure-test-key"); + }); +}); + // --------------------------------------------------------------------------- // Responses API via createOpenAILanguageModel // ---------------------------------------------------------------------------