Files
HealthLog/src/app/__tests__/error-chunk-reload-guard.test.ts
T
Marc-André Bombeck b5e799c2d6 fix(charts): degrade chart failures to one card and heal stale shells per version
The update poller and the chunk-error reload guard key on the target
version instead of disarming for the whole session, so a second deploy
re-arms the self-heal and a stale shell can no longer strand with
404ing chunks. Lazy chart imports retry once and mount inside a
per-card error boundary with a reload affordance — a failed chunk
degrades to one card instead of replacing the page. The JSON API
client attaches a fifteen-second timeout unless the caller brings its
own signal (the raw streaming path is exempt), chart queries surface
errors with a retry instead of rendering as an empty period, per-type
fetch failures reject instead of caching an empty series as fresh, and
the session and snapshot queries retry once on transient network or
server errors.
2026-06-11 21:17:27 +02:00

42 lines
1.7 KiB
TypeScript

/**
* Unit tests for the chunk-error auto-reload guard in `src/app/error.tsx`.
*
* The guard is keyed on the running shell's build version: one reload
* attempt per BROKEN SHELL, not one per session. After a successful
* heal the reloaded page carries the new version and the guard re-arms
* by construction; the pre-v1.16.8 once-per-session key exhausted on
* multi-deploy days and stranded the user on the error page.
*/
import { describe, expect, it } from "vitest";
import { chunkReloadGuardValue, shouldAttemptChunkReload } from "../error";
describe("shouldAttemptChunkReload", () => {
it("reloads when no attempt is recorded", () => {
expect(shouldAttemptChunkReload(null, "1.16.8")).toBe(true);
});
it("suppresses a second reload for the SAME shell version", () => {
const stored = chunkReloadGuardValue("1.16.8");
expect(shouldAttemptChunkReload(stored, "1.16.8")).toBe(false);
});
it("re-arms after a deploy — the reloaded shell carries a NEW version", () => {
const stored = chunkReloadGuardValue("1.16.8");
expect(shouldAttemptChunkReload(stored, "1.16.9")).toBe(true);
});
it("treats a legacy timestamp guard value as no attempt", () => {
// Pre-v1.16.8 sessions stored `String(Date.now())`; it never matches
// a guard value, so a stranded session heals on its next chunk error.
expect(shouldAttemptChunkReload("1765400000000", "1.16.8")).toBe(true);
});
it("degrades to once-per-shell-lifetime when no version is injected", () => {
expect(chunkReloadGuardValue("")).toBe("unversioned");
expect(shouldAttemptChunkReload(null, "")).toBe(true);
expect(shouldAttemptChunkReload("unversioned", "")).toBe(false);
});
});