test: add comprehensive AI feature install/uninstall test coverage

- Add 55 unit tests for feature-status.ts (installed.json CRUD, cache
  behavior, install lock, model verification, crash recovery, composite
  state) using real temp directories
- Add 36 integration tests for full install/uninstall lifecycle against
  Docker containers (face-detection bundle, SSE progress, tool gates,
  shared model protection, concurrent install prevention, auth guards,
  container restart recovery)
- Fix noise-removal CPU timeout by adding megapixel-based timeout
  calculation (120s/MP, min 5 minutes)
- Fix Playwright auth storage state race condition (mkdirSync before
  saving analytics-user.json)
- Fix 2 skipped tests in fixes-verification.spec.ts by replacing
  external ~/Downloads/sample dependency with existing test fixtures
- Enable skipped analytics-consent settings toggle test
- Restructure features.spec.ts to manage bundle state (uninstall/
  reinstall OCR) so 501 guard tests run instead of skipping
- Update noise-removal test mock to include sharp metadata() method
This commit is contained in:
SnapOtter
2026-04-28 13:27:54 +08:00
parent 60eb3abaa7
commit 4acec0846c
8 changed files with 1183 additions and 107 deletions
+5 -29
View File
@@ -1,16 +1,8 @@
import fs from "node:fs";
import path from "node:path";
import { expect, type Page, test } from "@playwright/test";
const SAMPLES_DIR = path.join(process.env.HOME ?? "/Users/sidd", "Downloads", "sample");
const FIXTURES_DIR = path.join(process.cwd(), "tests", "fixtures");
function getSampleImage(name: string): string {
const p = path.join(SAMPLES_DIR, name);
if (fs.existsSync(p)) return p;
throw new Error(`Sample image not found: ${p}`);
}
function getFixture(name: string): string {
return path.join(FIXTURES_DIR, name);
}
@@ -207,17 +199,10 @@ test.describe("Batch processing fixes", () => {
test("blur-faces processes multiple files", async ({ page }) => {
await page.goto("/blur-faces");
// Use sample portraits
const portrait = path.join(
SAMPLES_DIR,
"free-photo-of-black-and-white-portrait-of-a-smiling-woman.jpeg",
);
if (!fs.existsSync(portrait)) {
test.skip();
return;
}
await uploadFiles(page, [portrait, getFixture("test-portrait.jpg")]);
await uploadFiles(page, [
getFixture("content/multi-face.webp"),
getFixture("content/portrait-color.jpg"),
]);
const processBtn = page.getByRole("button", { name: /blur|process/i });
await expect(processBtn).toBeEnabled({ timeout: 5000 });
@@ -272,17 +257,8 @@ test.describe("Passport photo", () => {
});
test("passport photo works with real portrait", async ({ page }) => {
const portrait = path.join(
SAMPLES_DIR,
"free-photo-of-black-and-white-portrait-of-a-smiling-woman.jpeg",
);
if (!fs.existsSync(portrait)) {
test.skip();
return;
}
await page.goto("/passport-photo");
await uploadFiles(page, [portrait]);
await uploadFiles(page, [getFixture("content/portrait-color.jpg")]);
// Wait for face analysis (uses MediaPipe + rembg, can be slow on CPU)
await page.waitForTimeout(5000);