



















@@ -531,6 +531,54 @@ describe("fetchWithTimeoutGuarded", () => {
531531expect(getFirstGuardedFetchCall().pinDns).toBe(false);
532532});
533533534+it("does not retry transcription POST requests by default", async () => {
535+fetchWithSsrFGuardMock.mockReset();
536+fetchWithSsrFGuardMock
537+.mockRejectedValueOnce(Object.assign(new Error("socket hang up"), { code: "ECONNRESET" }))
538+.mockResolvedValueOnce({
539+response: new Response(null, { status: 200 }),
540+finalUrl: "https://api.example.com",
541+release: async () => {},
542+});
543+544+await expect(
545+postTranscriptionRequest({
546+url: "https://api.example.com/v1/transcriptions",
547+headers: new Headers(),
548+body: "audio-bytes",
549+fetchFn: fetch,
550+}),
551+).rejects.toThrow("socket hang up");
552+553+expect(fetchWithSsrFGuardMock).toHaveBeenCalledTimes(1);
554+});
555+556+it("retries transcription POST requests only when marked as read operations", async () => {
557+fetchWithSsrFGuardMock.mockReset();
558+const sleep = vi.fn(async () => undefined);
559+fetchWithSsrFGuardMock
560+.mockRejectedValueOnce(Object.assign(new Error("socket hang up"), { code: "ECONNRESET" }))
561+.mockResolvedValueOnce({
562+response: new Response(null, { status: 200 }),
563+finalUrl: "https://api.example.com",
564+release: async () => {},
565+});
566+567+await expect(
568+postTranscriptionRequest({
569+url: "https://api.example.com/v1/transcriptions",
570+headers: new Headers(),
571+body: "audio-bytes",
572+fetchFn: fetch,
573+retryStage: "read",
574+retry: { attempts: 2, baseDelayMs: 0, maxDelayMs: 0, sleep },
575+}),
576+).resolves.toEqual(expect.objectContaining({ finalUrl: "https://api.example.com" }));
577+578+expect(fetchWithSsrFGuardMock).toHaveBeenCalledTimes(2);
579+expect(sleep).toHaveBeenCalledWith(0, undefined);
580+});
581+534582it("does not set a guarded fetch mode when no HTTP proxy env is configured", async () => {
535583shouldUseEnvHttpProxyForUrlMock.mockReturnValue(false);
536584fetchWithSsrFGuardMock.mockResolvedValue({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。