diff --git a/typescript/tests/model.test.mjs b/typescript/tests/model.test.mjs index b3a75816..e4a510da 100644 --- a/typescript/tests/model.test.mjs +++ b/typescript/tests/model.test.mjs @@ -78,6 +78,7 @@ function makeErrorResponse(status, statusText, retryAfterSec = null) { let capturedRequests = []; let mockResponses = []; +const nativeFetch = globalThis.fetch; function setupFetch(responses) { capturedRequests = []; @@ -91,7 +92,7 @@ function setupFetch(responses) { } function teardownFetch() { - delete globalThis.fetch; + globalThis.fetch = nativeFetch; capturedRequests = []; mockResponses = []; } @@ -343,6 +344,20 @@ describe("createOpenAILanguageModel (Responses API path)", () => { // createLanguageModel env-var routing // --------------------------------------------------------------------------- +describe("createLanguageModel live API integration", () => { + test("calls the configured API when live tests are explicitly enabled", { + skip: process.env.TYPECHAT_LIVE_TESTS !== "1" || !process.env.OPENAI_API_KEY || !process.env.OPENAI_MODEL, + }, async () => { + const model = createLanguageModel(process.env); + model.timeoutMs = 30_000; + model.retryMaxAttempts = 0; + const result = await model.complete("Reply with the single word: pong"); + assert.equal(result.success, true, result.message); + assert.equal(typeof result.data, "string"); + assert.notEqual(result.data.trim(), ""); + }); +}); + describe("createLanguageModel environment variable routing", () => { after(teardownFetch);