caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

36 lines
1.5 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { withReadRetry } from "@/src/shared/api/client";
const res = (status: number) => new Response("{}", { status });
describe("withReadRetry (showcase and every GET during an API restart)", () => {
it("retries network errors and edge 502s, then returns the good response", async () => {
const run = vi
.fn<() => Promise<Response>>()
.mockRejectedValueOnce(new TypeError("Failed to fetch"))
.mockResolvedValueOnce(res(502))
.mockResolvedValueOnce(res(200));
const out = await withReadRetry(run, [0, 0]);
expect(out.status).toBe(200);
expect(run).toHaveBeenCalledTimes(3);
});
it("does not retry client errors or app 503s and gives up after the last delay", async () => {
for (const status of [404, 503]) {
const once = vi.fn<() => Promise<Response>>().mockResolvedValue(res(status));
expect((await withReadRetry(once, [0, 0])).status).toBe(status);
expect(once).toHaveBeenCalledTimes(1);
}
const down = vi.fn<() => Promise<Response>>().mockRejectedValue(new TypeError("Failed to fetch"));
await expect(withReadRetry(down, [0, 0])).rejects.toThrow("Failed to fetch");
expect(down).toHaveBeenCalledTimes(3);
});
it("never retries an aborted request", async () => {
const aborted = vi.fn<() => Promise<Response>>().mockRejectedValue(new DOMException("x", "AbortError"));
await expect(withReadRetry(aborted, [0, 0])).rejects.toThrow();
expect(aborted).toHaveBeenCalledTimes(1);
});
});