From 3abe9c139618a5c357cb9485f3d4ec9a39dc1b34 Mon Sep 17 00:00:00 2001 From: mikemikimike <13286568797@163.com> Date: Thu, 27 Aug 2026 22:59:33 +0800 Subject: [PATCH 1/2] test: use configured API when available --- typescript/tests/model.test.mjs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/typescript/tests/model.test.mjs b/typescript/tests/model.test.mjs index b3a75816..1ac2fb18 100644 --- a/typescript/tests/model.test.mjs +++ b/typescript/tests/model.test.mjs @@ -346,6 +346,14 @@ describe("createOpenAILanguageModel (Responses API path)", () => { describe("createLanguageModel environment variable routing", () => { after(teardownFetch); + test("calls the configured API when credentials are available", { skip: !process.env.OPENAI_API_KEY || !process.env.OPENAI_MODEL }, async () => { + const model = createLanguageModel(process.env); + 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(), ""); + }); + test("defaults to Chat Completions API", async () => { setupFetch([makeChatCompletionsResponse("OK")]); const model = createLanguageModel({ From f6b4a6defd1bd1e90621b39119435789843ac205 Mon Sep 17 00:00:00 2001 From: mikemikimike <13286568797@163.com> Date: Sat, 29 Aug 2026 08:56:13 +0800 Subject: [PATCH 2/2] test: isolate opt-in live API integration --- typescript/tests/model.test.mjs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/typescript/tests/model.test.mjs b/typescript/tests/model.test.mjs index 1ac2fb18..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,16 +344,22 @@ describe("createOpenAILanguageModel (Responses API path)", () => { // createLanguageModel env-var routing // --------------------------------------------------------------------------- -describe("createLanguageModel environment variable routing", () => { - after(teardownFetch); - - test("calls the configured API when credentials are available", { skip: !process.env.OPENAI_API_KEY || !process.env.OPENAI_MODEL }, async () => { +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); test("defaults to Chat Completions API", async () => { setupFetch([makeChatCompletionsResponse("OK")]);