From 4b7a56f5df58cf56696cdc90108ab8089fc55d59 Mon Sep 17 00:00:00 2001 From: Frank Yang Date: Sun, 15 Mar 2026 16:52:26 +0800 Subject: [PATCH] test: share async TTS model fixtures (openclaw#46119 thanks @thepagent) --- src/tts/tts.test.ts | 48 ++++++++++++++------------------------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/src/tts/tts.test.ts b/src/tts/tts.test.ts index 24636104626..8b232ed034d 100644 --- a/src/tts/tts.test.ts +++ b/src/tts/tts.test.ts @@ -20,31 +20,13 @@ vi.mock("@mariozechner/pi-ai/oauth", () => ({ getOAuthApiKey: vi.fn(async () => null), })); -vi.mock("../agents/pi-embedded-runner/model.js", () => ({ - resolveModel: vi.fn((provider: string, modelId: string) => { - const resolved = { - model: { - provider, - id: modelId, - name: modelId, - api: "openai-completions", - reasoning: false, - input: ["text"], - cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, - contextWindow: 128000, - maxTokens: 8192, - }, - authStorage: { profiles: {} }, - modelRegistry: { find: vi.fn() }, - }; - return resolved; - }), - resolveModelAsync: vi.fn(async (provider: string, modelId: string) => ({ +function createResolvedModel(provider: string, modelId: string, api = "openai-completions") { + return { model: { provider, id: modelId, name: modelId, - api: "openai-completions", + api, reasoning: false, input: ["text"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, @@ -53,7 +35,16 @@ vi.mock("../agents/pi-embedded-runner/model.js", () => ({ }, authStorage: { profiles: {} }, modelRegistry: { find: vi.fn() }, - })), + }; +} + +vi.mock("../agents/pi-embedded-runner/model.js", () => ({ + resolveModel: vi.fn((provider: string, modelId: string) => + createResolvedModel(provider, modelId), + ), + resolveModelAsync: vi.fn(async (provider: string, modelId: string) => + createResolvedModel(provider, modelId), + ), })); vi.mock("../agents/model-auth.js", () => ({ @@ -434,20 +425,11 @@ describe("tts", () => { it("registers the Ollama api before direct summarization", async () => { vi.mocked(resolveModelAsync).mockResolvedValue({ + ...createResolvedModel("ollama", "qwen3:8b", "ollama"), model: { - provider: "ollama", - id: "qwen3:8b", - name: "qwen3:8b", - api: "ollama", + ...createResolvedModel("ollama", "qwen3:8b", "ollama").model, baseUrl: "http://127.0.0.1:11434", - reasoning: false, - input: ["text"], - cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, - contextWindow: 128000, - maxTokens: 8192, }, - authStorage: { profiles: {} } as never, - modelRegistry: { find: vi.fn() } as never, } as never); await summarizeText({