test: share async TTS model fixtures (openclaw#46119 thanks @thepagent)

This commit is contained in:
Frank Yang 2026-03-15 16:52:26 +08:00
parent 4afcb4859b
commit 4b7a56f5df
1 changed files with 15 additions and 33 deletions

View File

@ -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({