From b9da7cbf01b865ff0a2a6c3c2126b8e2571c9ed6 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 25 Apr 2026 04:57:11 +0100 Subject: [PATCH] test: strip live gateway reasoning wrappers --- .../gateway-models.profiles.live.test.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/gateway/gateway-models.profiles.live.test.ts b/src/gateway/gateway-models.profiles.live.test.ts index 108528c469a..b865b492fb4 100644 --- a/src/gateway/gateway-models.profiles.live.test.ts +++ b/src/gateway/gateway-models.profiles.live.test.ts @@ -351,7 +351,14 @@ function maybeStripAssistantScaffoldingForLiveModel(text: string, modelKey?: str if (!shouldStripAssistantScaffoldingForLiveModel(modelKey)) { return text; } - return stripAssistantInternalScaffolding(text).trim(); + return stripAssistantInternalScaffolding(stripKnownLiveReasoningWrappers(text)).trim(); +} + +function stripKnownLiveReasoningWrappers(text: string): string { + return text + .replace(/<\s*think\b[^<>]*>[\s\S]*?<\s*\/\s*think\s*>/gi, "") + .replace(/^[\s\S]*?<\s*\/\s*think\s*>\s*/i, "") + .replace(/<\s*final\b[^<>]*>([\s\S]*?)<\s*\/\s*final\s*>/gi, "$1"); } function shouldSkipExecReadNonceMissForLiveModel(modelKey?: string): boolean { @@ -425,6 +432,20 @@ describe("maybeStripAssistantScaffoldingForLiveModel", () => { "google/gemini-3.1-pro-preview-customtools", ), ).toBe("Visible"); + expect( + maybeStripAssistantScaffoldingForLiveModel( + [ + "", + "1. Inspect", + "```", + "draft", + "```", + "2. Draft the explanation", + "The event loop drains the microtask queue before the next macrotask.", + ].join("\n"), + "google/gemini-3-flash-preview", + ), + ).toBe("The event loop drains the microtask queue before the next macrotask."); }); it("strips scaffolding for known OpenAI transcript wrappers", () => {