






















1+import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
2+import { afterEach, describe, expect, it, vi } from "vitest";
3+4+const fetchWithSsrFGuardMock = vi.hoisted(() => vi.fn());
5+6+vi.mock("openclaw/plugin-sdk/ssrf-runtime", async (importOriginal) => {
7+const actual = await importOriginal<typeof import("openclaw/plugin-sdk/ssrf-runtime")>();
8+return {
9+ ...actual,
10+fetchWithSsrFGuard: (...args: unknown[]) => fetchWithSsrFGuardMock(...args),
11+};
12+});
13+14+import { minimaxTTS } from "./tts.js";
15+16+describe("minimaxTTS", () => {
17+afterEach(() => {
18+fetchWithSsrFGuardMock.mockReset();
19+vi.restoreAllMocks();
20+});
21+22+it("caps oversized request timeout before arming abort timers", async () => {
23+const timeoutSpy = vi.spyOn(globalThis, "setTimeout");
24+fetchWithSsrFGuardMock.mockResolvedValue({
25+response: new Response(
26+JSON.stringify({ data: { audio: Buffer.from("audio").toString("hex") } }),
27+{ status: 200, headers: { "content-type": "application/json" } },
28+),
29+release: vi.fn(async () => undefined),
30+});
31+32+const audio = await minimaxTTS({
33+text: "hello",
34+apiKey: "sk-test",
35+baseUrl: "https://api.minimax.io",
36+model: "speech-2.8-hd",
37+voiceId: "English_expressive_narrator",
38+timeoutMs: Number.MAX_SAFE_INTEGER,
39+});
40+41+expect(audio.toString()).toBe("audio");
42+expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
43+expect(fetchWithSsrFGuardMock.mock.calls[0]?.[0]).toMatchObject({
44+timeoutMs: MAX_TIMER_TIMEOUT_MS,
45+});
46+expect(fetchWithSsrFGuardMock.mock.calls[0]?.[0]?.init?.signal).toBeInstanceOf(AbortSignal);
47+});
48+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。