feat: add deployment reload controls

This commit is contained in:
2026-08-23 14:33:26 +00:00 Unverified
parent 25dccdfa4f
commit a630e0cc2f
11 changed files with 341 additions and 32 deletions
+37
View File
@@ -0,0 +1,37 @@
import { describe, expect, test } from "bun:test";
import {
checkDeploymentVersion,
normalizeReloadPrefix,
shouldReloadPath,
} from "@/lib/realtime/deployment-refresh";
describe("deployment refresh policy", () => {
test("uses the first version as a baseline and detects later changes", () => {
expect(checkDeploymentVersion(null, "build-a")).toEqual({
version: "build-a",
hasUpdate: false,
});
expect(checkDeploymentVersion("build-a", "build-a")).toEqual({
version: "build-a",
hasUpdate: false,
});
expect(checkDeploymentVersion("build-a", "build-b")).toEqual({
version: "build-b",
hasUpdate: true,
});
});
test("matches global and pathname-prefix reloads", () => {
expect(shouldReloadPath(null, "/profile")).toBeTrue();
expect(shouldReloadPath("/admin", "/admin/backend")).toBeTrue();
expect(shouldReloadPath("/form", "/profile")).toBeFalse();
});
test("normalizes valid prefixes and rejects invalid ones", () => {
expect(normalizeReloadPrefix(null)).toBeNull();
expect(normalizeReloadPrefix(" /admin ")).toBe("/admin");
expect(() => normalizeReloadPrefix("admin")).toThrow(
"Reload path must start with /",
);
});
});