





















@@ -43,6 +43,22 @@ const officialEndpointValidationCases = [
4343},
4444];
454546+function firstFetchCall(fetchMock: ReturnType<typeof vi.fn>): unknown[] {
47+const call = fetchMock.mock.calls.at(0);
48+if (!call) {
49+throw new Error("expected fetch call");
50+}
51+return call;
52+}
53+54+function firstFetchInit(fetchMock: ReturnType<typeof vi.fn>): RequestInit {
55+const init = firstFetchCall(fetchMock).at(1);
56+if (!init || typeof init !== "object") {
57+throw new Error("expected fetch init");
58+}
59+return init as RequestInit;
60+}
61+4662describe("openai tts", () => {
4763const proxyReset = installDebugProxyTestResetHooks();
4864const originalFetch = globalThis.fetch;
@@ -148,7 +164,8 @@ describe("openai tts", () => {
148164timeoutMs: 5_000,
149165});
150166151-const [url, init] = fetchMock.mock.calls[0] ?? [];
167+const url = firstFetchCall(fetchMock).at(0);
168+const init = firstFetchInit(fetchMock);
152169const headers = init?.headers as Record<string, string> | undefined;
153170expect(url).toBe("https://api.openai.com/v1/audio/speech");
154171expect(headers?.originator).toBe("openclaw");
@@ -174,7 +191,7 @@ describe("openai tts", () => {
174191timeoutMs: 5_000,
175192});
176193177-const [, init] = fetchMock.mock.calls[0] ?? [];
194+const init = firstFetchInit(fetchMock);
178195if (typeof init?.body !== "string") {
179196throw new Error("expected JSON request body");
180197}
@@ -206,7 +223,7 @@ describe("openai tts", () => {
206223timeoutMs: 5_000,
207224});
208225209-const [, init] = fetchMock.mock.calls[0] ?? [];
226+const init = firstFetchInit(fetchMock);
210227if (typeof init?.body !== "string") {
211228throw new Error("expected JSON request body");
212229}
@@ -241,7 +258,7 @@ describe("openai tts", () => {
241258timeoutMs: 5_000,
242259});
243260244-const [, init] = fetchMock.mock.calls[0] ?? [];
261+const init = firstFetchInit(fetchMock);
245262if (typeof init?.body !== "string") {
246263throw new Error("expected JSON request body");
247264}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。