Files
SnapOtter/tests/unit/api/install-watchdog.test.ts
T
SnapOtterandGitHub a731c3d1fe fix: reliable, self-healing AI feature-bundle installs (#472)
Make on-demand AI feature-bundle installs reliable and self-healing, closing
the failure modes behind most "some tool doesn't work" reports.

Multi-bundle installs: tools needing more than one bundle (Passport Photo,
Enhance Faces) install every required bundle from one action and stay
not-installed until all are present. Verified across all 19 AI tools.

Downloads: self-heal the accelerated Hugging Face (Xet) client so an upgraded
venv no longer silently falls back to slow urllib; restart instead of
corrupting a resumed partial when a proxy ignores Range and returns 200;
verify the completed size; fail fast on disk-full and HTTP 4xx; retry
transient errors five times; add hf_transfer fallback and document Xet egress.

Install integrity: crash-atomic venv writes so a killed or out-of-space
install can no longer tear the shared venv and break other tools; a boot
breadcrumb reseeds a torn venv to a clean state automatically; a post-install
smoke import test refuses to record a bundle whose libraries cannot load; an
install watchdog stops a wedged installer that would otherwise hold the venv
writer lock forever.

Adds unit and end-to-end tests for every failure mode above.
2026-07-10 07:32:48 +00:00

53 lines
2.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { evaluateInstallWatchdog } from "../../../apps/api/src/lib/install-watchdog.js";
const STALL = 20 * 60_000; // 20 min
const MAX = 120 * 60_000; // 2 h
describe("evaluateInstallWatchdog", () => {
it("does not kill an install making steady progress", () => {
const now = 1_000_000;
const v = evaluateInstallWatchdog(now, now - 5_000, now - 60_000, STALL, MAX);
expect(v.kill).toBe(false);
expect(v.reason).toBeNull();
});
it("kills when no progress frame has arrived within the stall budget", () => {
const now = 1_000_000;
const v = evaluateInstallWatchdog(now, now - (STALL + 1), now - (STALL + 1), STALL, MAX);
expect(v.kill).toBe(true);
expect(v.reason).toContain("no progress");
});
it("does not kill exactly at the stall boundary (strictly greater than)", () => {
const now = 1_000_000;
const v = evaluateInstallWatchdog(now, now - STALL, now - STALL, STALL, MAX);
expect(v.kill).toBe(false);
});
it("kills when the absolute time ceiling is exceeded even if progress is recent", () => {
const now = 1_000_000;
// Progress 1s ago (not stalled) but the install started > MAX ago.
const v = evaluateInstallWatchdog(now, now - 1_000, now - (MAX + 1), STALL, MAX);
expect(v.kill).toBe(true);
expect(v.reason).toContain("time limit");
});
it("prefers the absolute-ceiling reason when both conditions hold", () => {
const now = 1_000_000;
const v = evaluateInstallWatchdog(now, now - (STALL + 1), now - (MAX + 1), STALL, MAX);
expect(v.kill).toBe(true);
expect(v.reason).toContain("time limit");
});
it("treats 0 as disabled for each check independently", () => {
const now = 1_000_000;
// Stall disabled, max active: a long stall alone must not kill.
expect(evaluateInstallWatchdog(now, now - 10 * STALL, now - 1_000, 0, MAX).kill).toBe(false);
// Max disabled, stall active: an old start alone must not kill.
expect(evaluateInstallWatchdog(now, now - 1_000, now - 10 * MAX, STALL, 0).kill).toBe(false);
// Both disabled: never kills.
expect(evaluateInstallWatchdog(now, now - 10 * STALL, now - 10 * MAX, 0, 0).kill).toBe(false);
});
});