Files
SnapOtter/tests/unit/web/feature-install-prompt.test.tsx
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

137 lines
4.1 KiB
TypeScript

// @vitest-environment jsdom
import type { FeatureBundleState } from "@snapotter/shared";
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { FeatureInstallPrompt } from "@/components/features/feature-install-prompt";
import { useFeaturesStore } from "@/stores/features-store";
function makeBundleState(overrides: Partial<FeatureBundleState> = {}): FeatureBundleState {
return {
id: "background-removal",
name: "Background Removal",
description: "Remove backgrounds",
status: "not_installed",
installedVersion: null,
estimatedSize: "4-5 GB",
enablesTools: ["remove-background", "passport-photo"],
progress: null,
error: null,
...overrides,
};
}
describe("FeatureInstallPrompt", () => {
beforeEach(() => {
useFeaturesStore.setState({
bundles: [],
loaded: true,
loadError: false,
installing: {},
errors: {},
queued: [],
installAllActive: false,
startTimes: {},
});
});
afterEach(() => {
cleanup();
vi.restoreAllMocks();
});
it("uses the tool-aware install action when a tool id is provided", () => {
const installTool = vi.fn();
const installBundle = vi.fn();
useFeaturesStore.setState({ installTool, installBundle });
render(
<FeatureInstallPrompt
bundle={makeBundleState()}
isAdmin
toolId="passport-photo"
toolName="Passport Photo"
/>,
);
fireEvent.click(screen.getByRole("button", { name: "Enable Passport Photo" }));
expect(installTool).toHaveBeenCalledWith("passport-photo");
expect(installBundle).not.toHaveBeenCalled();
});
it("shows every required bundle and keeps installed dependencies clear", () => {
const installTool = vi.fn();
const installBundle = vi.fn();
const backgroundRemoval = makeBundleState({ status: "installed" });
const faceDetection = makeBundleState({
id: "face-detection",
name: "Face Detection",
description: "Detect faces",
status: "not_installed",
estimatedSize: "200-300 MB",
enablesTools: ["blur-faces", "red-eye-removal", "smart-crop"],
});
useFeaturesStore.setState({
bundles: [backgroundRemoval, faceDetection],
installTool,
installBundle,
});
render(
<FeatureInstallPrompt
bundle={faceDetection}
isAdmin
toolId="passport-photo"
toolName="Passport Photo"
/>,
);
expect(screen.getByText("Background Removal")).toBeTruthy();
expect(screen.getByText("Face Detection")).toBeTruthy();
expect(screen.getByText("Installed")).toBeTruthy();
expect(screen.getByText("Not installed")).toBeTruthy();
expect(screen.getByText("200-300 MB")).toBeTruthy();
fireEvent.click(screen.getByRole("button", { name: "Enable Passport Photo" }));
expect(installTool).toHaveBeenCalledWith("passport-photo");
expect(installBundle).not.toHaveBeenCalled();
});
it("keeps the multi-bundle breakdown visible when one bundle is in the error/repair state", () => {
const backgroundRemoval = makeBundleState({
status: "error",
error: "Checksum mismatch",
});
const faceDetection = makeBundleState({
id: "face-detection",
name: "Face Detection",
description: "Detect faces",
status: "installed",
estimatedSize: "200-300 MB",
enablesTools: ["blur-faces", "red-eye-removal", "smart-crop"],
});
useFeaturesStore.setState({
bundles: [backgroundRemoval, faceDetection],
installTool: vi.fn(),
installBundle: vi.fn(),
});
render(
<FeatureInstallPrompt
bundle={backgroundRemoval}
isAdmin
toolId="passport-photo"
toolName="Passport Photo"
/>,
);
// The breakdown must still render during repair so the user can see the
// sibling bundle's state, not just the single failed one.
expect(screen.getByText("Background Removal")).toBeTruthy();
expect(screen.getByText("Face Detection")).toBeTruthy();
expect(screen.getByText("Installed")).toBeTruthy();
});
});