import { fetchAgentRuntimeHealth } from "./agentRuntime"; const apiFetch = jest.fn(); jest.mock("@/lib/apiFetch", () => ({ apiFetch: (...args: unknown[]) => apiFetch(...args), })); describe("fetchAgentRuntimeHealth", () => { beforeEach(() => { apiFetch.mockReset(); }); it("reports ready only after runtime warmup is complete", async () => { apiFetch.mockResolvedValueOnce({ ok: true, json: async () => ({ ok: true, ready: true, warmed_up: true, runtime: { healthy: true }, }), }); await expect(fetchAgentRuntimeHealth()).resolves.toBe(true); expect(apiFetch).toHaveBeenCalledWith( expect.stringContaining("/health"), expect.objectContaining({ method: "GET", projectHeaderMode: "omit", skipAuthRedirect: true, }), ); }); it("reports unavailable when runtime health is not ready", async () => { apiFetch.mockResolvedValueOnce({ ok: false, json: async () => ({ ok: false, ready: false, warmed_up: true }), }); await expect(fetchAgentRuntimeHealth()).resolves.toBe(false); }); });