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
+1 -1
View File
@@ -55,7 +55,7 @@ test.describe("Analytics consent page", () => {
expect(sessionData.user?.analyticsEnabled ?? true).toBe(true);
});
test.skip("settings toggle works after accepting analytics", async ({ page }) => {
test("settings toggle works after accepting analytics", async ({ page }) => {
// User already accepted in previous test — login should go straight to home
await loginAndGetToHome(page);
await expect(page).toHaveURL("/");
+2
View File
@@ -1,3 +1,4 @@
import { mkdirSync } from "node:fs";
import path from "node:path";
import { expect, test as setup } from "@playwright/test";
@@ -25,5 +26,6 @@ setup("authenticate", async ({ page }) => {
// At this point we should be on the home page
await expect(page).toHaveURL("/");
mkdirSync(path.dirname(authFile), { recursive: true });
await page.context().storageState({ path: authFile });
});
+558
View File
@@ -0,0 +1,558 @@
import type { APIRequestContext } from "@playwright/test";
import { expect, test } from "@playwright/test";
// ---- Helpers ---------------------------------------------------------------
const API = process.env.API_URL || "http://localhost:1349";
/** Minimal 1x1 transparent PNG used for tool endpoint checks. */
const pngBuffer = Buffer.from(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==",
"base64",
);
const VALID_STATUSES = ["not_installed", "installed", "installing", "error"];
let _token: string | undefined;
async function getToken(request: APIRequestContext): Promise<string> {
if (_token) return _token;
const res = await request.post(`${API}/api/auth/login`, {
data: { username: "admin", password: "admin" },
});
const body = await res.json();
_token = body.token as string;
return _token;
}
async function authHeaders(request: APIRequestContext) {
return { Authorization: `Bearer ${await getToken(request)}` };
}
async function getBundleStatus(request: APIRequestContext, bundleId: string): Promise<string> {
const headers = await authHeaders(request);
const res = await request.get(`${API}/api/v1/features`, { headers });
const data = await res.json();
const bundle = data.bundles.find((b: any) => b.id === bundleId);
return bundle?.status ?? "unknown";
}
async function getBundle(request: APIRequestContext, bundleId: string): Promise<any> {
const headers = await authHeaders(request);
const res = await request.get(`${API}/api/v1/features`, { headers });
const data = await res.json();
return data.bundles.find((b: any) => b.id === bundleId) ?? null;
}
async function waitForInstallComplete(
request: APIRequestContext,
bundleId: string,
timeoutMs = 600_000,
): Promise<void> {
const start = Date.now();
while (Date.now() - start < timeoutMs) {
const status = await getBundleStatus(request, bundleId);
if (status === "installed") return;
if (status === "error") throw new Error(`Install failed for ${bundleId}`);
await new Promise((r) => setTimeout(r, 3000));
}
throw new Error(`Install timeout for ${bundleId} after ${timeoutMs}ms`);
}
async function ensureUninstalled(request: APIRequestContext, bundleId: string): Promise<void> {
const status = await getBundleStatus(request, bundleId);
if (status === "installed") {
const headers = await authHeaders(request);
await request.post(`${API}/api/v1/admin/features/${bundleId}/uninstall`, {
headers,
});
}
}
async function ensureInstalled(request: APIRequestContext, bundleId: string): Promise<void> {
const status = await getBundleStatus(request, bundleId);
if (status !== "installed") {
const headers = await authHeaders(request);
await request.post(`${API}/api/v1/admin/features/${bundleId}/install`, {
headers,
});
await waitForInstallComplete(request, bundleId);
}
}
/** POST a tool endpoint with a minimal PNG and return the response. */
async function callTool(
request: APIRequestContext,
toolId: string,
settings: Record<string, unknown> = {},
) {
const headers = await authHeaders(request);
return request.post(`${API}/api/v1/tools/${toolId}`, {
headers,
multipart: {
file: {
name: "test.png",
mimeType: "image/png",
buffer: pngBuffer,
},
settings: JSON.stringify(settings),
},
});
}
// ---- 1. Feature listing baseline -------------------------------------------
test.describe("Feature listing baseline", () => {
test.describe.configure({ mode: "serial" });
test("GET /api/v1/features returns all 6 bundles", async ({ request }) => {
const headers = await authHeaders(request);
const res = await request.get(`${API}/api/v1/features`, { headers });
expect(res.ok()).toBeTruthy();
const data = await res.json();
expect(data.bundles).toHaveLength(6);
const expectedIds = [
"background-removal",
"face-detection",
"object-eraser-colorize",
"upscale-enhance",
"photo-restoration",
"ocr",
];
const ids = data.bundles.map((b: any) => b.id);
for (const id of expectedIds) {
expect(ids).toContain(id);
}
});
test("each bundle has complete shape", async ({ request }) => {
const headers = await authHeaders(request);
const res = await request.get(`${API}/api/v1/features`, { headers });
const data = await res.json();
for (const bundle of data.bundles) {
expect(typeof bundle.id).toBe("string");
expect(typeof bundle.name).toBe("string");
expect(bundle.name.length).toBeGreaterThan(0);
expect(typeof bundle.description).toBe("string");
expect(bundle.description.length).toBeGreaterThan(0);
expect(typeof bundle.estimatedSize).toBe("string");
expect(bundle.estimatedSize.length).toBeGreaterThan(0);
expect(Array.isArray(bundle.enablesTools)).toBeTruthy();
expect(bundle.enablesTools.length).toBeGreaterThan(0);
expect(typeof bundle.status).toBe("string");
// progress and error may be null
expect("progress" in bundle).toBeTruthy();
expect("error" in bundle).toBeTruthy();
}
});
test("all statuses are valid enum values", async ({ request }) => {
const headers = await authHeaders(request);
const res = await request.get(`${API}/api/v1/features`, { headers });
const data = await res.json();
for (const bundle of data.bundles) {
expect(VALID_STATUSES).toContain(bundle.status);
}
});
test("GET /api/v1/admin/features/disk-usage returns totalBytes", async ({ request }) => {
const headers = await authHeaders(request);
const res = await request.get(`${API}/api/v1/admin/features/disk-usage`, {
headers,
});
expect(res.ok()).toBeTruthy();
const data = await res.json();
expect(typeof data.totalBytes).toBe("number");
expect(data.totalBytes).toBeGreaterThanOrEqual(0);
});
});
// ---- 2. Auth and permission guards -----------------------------------------
test.describe("Auth and permission guards", () => {
test.describe.configure({ mode: "serial" });
test("install without auth returns 401", async ({ request }) => {
const res = await request.post(`${API}/api/v1/admin/features/face-detection/install`);
expect(res.status()).toBe(401);
});
test("uninstall without auth returns 401", async ({ request }) => {
const res = await request.post(`${API}/api/v1/admin/features/face-detection/uninstall`);
expect(res.status()).toBe(401);
});
test("install as non-admin returns 403", async ({ request }) => {
const headers = await authHeaders(request);
// Create a test user with role "user"
const createRes = await request.post(`${API}/api/auth/register`, {
headers,
data: {
username: "lifecycle_test_user",
password: "TestPass123",
role: "user",
},
});
expect(createRes.status()).toBe(201);
const created = await createRes.json();
try {
// Login as the test user
const loginRes = await request.post(`${API}/api/auth/login`, {
data: { username: "lifecycle_test_user", password: "TestPass123" },
});
expect(loginRes.ok()).toBeTruthy();
const loginBody = await loginRes.json();
const userHeaders = { Authorization: `Bearer ${loginBody.token}` };
// Attempt install -- should be denied
const installRes = await request.post(`${API}/api/v1/admin/features/face-detection/install`, {
headers: userHeaders,
});
expect(installRes.status()).toBe(403);
} finally {
// Cleanup: delete the test user
await request.delete(`${API}/api/auth/users/${created.id}`, { headers });
}
});
});
// ---- 3. Validation guards --------------------------------------------------
test.describe("Validation guards", () => {
test.describe.configure({ mode: "serial" });
test("install unknown bundle returns 404", async ({ request }) => {
const headers = await authHeaders(request);
const res = await request.post(`${API}/api/v1/admin/features/nonexistent-bundle/install`, {
headers,
});
expect(res.status()).toBe(404);
});
test("uninstall unknown bundle returns 404", async ({ request }) => {
const headers = await authHeaders(request);
const res = await request.post(`${API}/api/v1/admin/features/nonexistent-bundle/uninstall`, {
headers,
});
expect(res.status()).toBe(404);
});
test("uninstall not-installed bundle returns 409", async ({ request }) => {
// Ensure face-detection is not installed for this check
await ensureUninstalled(request, "face-detection");
const headers = await authHeaders(request);
const res = await request.post(`${API}/api/v1/admin/features/face-detection/uninstall`, {
headers,
});
expect(res.status()).toBe(409);
});
});
// ---- 4. Install lifecycle - face-detection ---------------------------------
test.describe("Install lifecycle - face-detection", () => {
test.describe.configure({ mode: "serial" });
let diskUsageBefore: number;
test.beforeAll(async ({ request }) => {
await ensureUninstalled(request, "face-detection");
});
test("POST install returns 202 with jobId", async ({ request }) => {
test.setTimeout(600_000);
// Record disk usage before install
const headers = await authHeaders(request);
const diskRes = await request.get(`${API}/api/v1/admin/features/disk-usage`, { headers });
const diskData = await diskRes.json();
diskUsageBefore = diskData.totalBytes;
const res = await request.post(`${API}/api/v1/admin/features/face-detection/install`, {
headers,
});
expect(res.status()).toBe(202);
const body = await res.json();
expect(typeof body.jobId).toBe("string");
// Validate UUID format (8-4-4-4-12)
expect(body.jobId).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
});
test("install progress is available via features endpoint", async ({ request }) => {
// Give the installer a moment to start
await new Promise((r) => setTimeout(r, 2000));
const bundle = await getBundle(request, "face-detection");
expect(bundle).toBeTruthy();
// Status should be "installing" while the install is in progress
// (or "installed" if the install was very fast)
expect(["installing", "installed"]).toContain(bundle.status);
});
test("second install of same bundle returns 409 during install", async ({ request }) => {
const status = await getBundleStatus(request, "face-detection");
if (status === "installing") {
const headers = await authHeaders(request);
const res = await request.post(`${API}/api/v1/admin/features/face-detection/install`, {
headers,
});
expect(res.status()).toBe(409);
}
// If already installed (fast download), this test is a no-op
});
test("install of different bundle returns 409 during install", async ({ request }) => {
const status = await getBundleStatus(request, "face-detection");
if (status === "installing") {
const headers = await authHeaders(request);
const res = await request.post(`${API}/api/v1/admin/features/ocr/install`, { headers });
expect(res.status()).toBe(409);
}
// If already installed (fast download), this test is a no-op
});
test("after install completes, status is installed with version", async ({ request }) => {
test.setTimeout(600_000);
await waitForInstallComplete(request, "face-detection");
const bundle = await getBundle(request, "face-detection");
expect(bundle.status).toBe("installed");
});
test("after install, disk usage increased", async ({ request }) => {
const headers = await authHeaders(request);
const diskRes = await request.get(`${API}/api/v1/admin/features/disk-usage`, { headers });
const diskData = await diskRes.json();
expect(diskData.totalBytes).toBeGreaterThan(diskUsageBefore);
});
test("POST install already-installed returns 409", async ({ request }) => {
const headers = await authHeaders(request);
const res = await request.post(`${API}/api/v1/admin/features/face-detection/install`, {
headers,
});
expect(res.status()).toBe(409);
});
test("installed bundle has installedVersion string", async ({ request }) => {
const bundle = await getBundle(request, "face-detection");
expect(bundle.status).toBe("installed");
// installedVersion should be a string (or null for bundles without versioning)
expect(
typeof bundle.installedVersion === "string" || bundle.installedVersion === null,
).toBeTruthy();
});
});
// ---- 5. Tool availability after install ------------------------------------
test.describe("Tool availability after install", () => {
test.describe.configure({ mode: "serial" });
test.beforeAll(async ({ request }) => {
await ensureInstalled(request, "face-detection");
});
test("blur-faces returns 200 after face-detection installed", async ({ request }) => {
test.setTimeout(60_000);
const res = await callTool(request, "blur-faces");
expect(res.status()).toBe(200);
});
test("red-eye-removal returns 200 after face-detection installed", async ({ request }) => {
test.setTimeout(60_000);
const res = await callTool(request, "red-eye-removal");
expect(res.status()).toBe(200);
});
test("smart-crop face mode returns 200 after face-detection installed", async ({ request }) => {
test.setTimeout(60_000);
const res = await callTool(request, "smart-crop", {
mode: "face",
width: 100,
height: 100,
});
expect(res.status()).toBe(200);
});
test("resize still works (non-AI tool unaffected)", async ({ request }) => {
const res = await callTool(request, "resize", {
width: 100,
height: 100,
method: "fit",
});
// Should succeed or fail with a processing error, NOT 501
expect(res.status()).not.toBe(501);
});
});
// ---- 6. Uninstall lifecycle ------------------------------------------------
test.describe("Uninstall lifecycle", () => {
test.describe.configure({ mode: "serial" });
test.beforeAll(async ({ request }) => {
await ensureInstalled(request, "face-detection");
});
test("POST uninstall face-detection returns 200", async ({ request }) => {
const headers = await authHeaders(request);
const res = await request.post(`${API}/api/v1/admin/features/face-detection/uninstall`, {
headers,
});
expect(res.ok()).toBeTruthy();
const body = await res.json();
expect(body.ok).toBe(true);
});
test("status is not_installed after uninstall", async ({ request }) => {
const status = await getBundleStatus(request, "face-detection");
expect(status).toBe("not_installed");
});
test("blur-faces returns 501 after uninstall", async ({ request }) => {
const res = await callTool(request, "blur-faces");
expect(res.status()).toBe(501);
});
test("501 response has FEATURE_NOT_INSTALLED code and bundle info", async ({ request }) => {
const res = await callTool(request, "blur-faces");
expect(res.status()).toBe(501);
const body = await res.json();
expect(body.code).toBe("FEATURE_NOT_INSTALLED");
expect(body.feature).toBe("face-detection");
expect(body.featureName).toBeTruthy();
expect(body.estimatedSize).toBeTruthy();
});
test("POST uninstall again returns 409", async ({ request }) => {
const headers = await authHeaders(request);
const res = await request.post(`${API}/api/v1/admin/features/face-detection/uninstall`, {
headers,
});
expect(res.status()).toBe(409);
});
});
// ---- 7. Reinstall round-trip -----------------------------------------------
test.describe("Reinstall round-trip", () => {
test.describe.configure({ mode: "serial" });
test("reinstall after uninstall returns 202", async ({ request }) => {
test.setTimeout(600_000);
await ensureUninstalled(request, "face-detection");
const headers = await authHeaders(request);
const res = await request.post(`${API}/api/v1/admin/features/face-detection/install`, {
headers,
});
expect(res.status()).toBe(202);
await waitForInstallComplete(request, "face-detection");
});
test("tools work again after reinstall", async ({ request }) => {
test.setTimeout(60_000);
const res = await callTool(request, "blur-faces");
expect(res.status()).toBe(200);
});
test("uninstall after reinstall succeeds", async ({ request }) => {
const headers = await authHeaders(request);
const res = await request.post(`${API}/api/v1/admin/features/face-detection/uninstall`, {
headers,
});
expect(res.ok()).toBeTruthy();
const status = await getBundleStatus(request, "face-detection");
expect(status).toBe("not_installed");
});
});
// ---- 8. Shared model protection --------------------------------------------
test.describe("Shared model protection", () => {
test.describe.configure({ mode: "serial" });
test("install both face-detection and photo-restoration", async ({ request }) => {
test.setTimeout(600_000);
await ensureInstalled(request, "face-detection");
await ensureInstalled(request, "photo-restoration");
const fdStatus = await getBundleStatus(request, "face-detection");
const prStatus = await getBundleStatus(request, "photo-restoration");
expect(fdStatus).toBe("installed");
expect(prStatus).toBe("installed");
});
test("uninstall face-detection, photo-restoration tools still work", async ({ request }) => {
test.setTimeout(120_000);
const headers = await authHeaders(request);
// Uninstall face-detection
const uninstallRes = await request.post(
`${API}/api/v1/admin/features/face-detection/uninstall`,
{ headers },
);
expect(uninstallRes.ok()).toBeTruthy();
// Verify face-detection is gone
const fdStatus = await getBundleStatus(request, "face-detection");
expect(fdStatus).toBe("not_installed");
// photo-restoration tools should still work (shared models preserved)
const res = await callTool(request, "restore-photo");
expect(res.status()).toBe(200);
});
test("cleanup: uninstall photo-restoration", async ({ request }) => {
const headers = await authHeaders(request);
const res = await request.post(`${API}/api/v1/admin/features/photo-restoration/uninstall`, {
headers,
});
expect(res.ok()).toBeTruthy();
const status = await getBundleStatus(request, "photo-restoration");
expect(status).toBe("not_installed");
});
});
// ---- 9. Container restart recovery -----------------------------------------
test.describe("Container restart recovery", () => {
test.describe.configure({ mode: "serial" });
test("no stale installing state after container restart", async ({ request }) => {
const headers = await authHeaders(request);
const res = await request.get(`${API}/api/v1/features`, { headers });
expect(res.ok()).toBeTruthy();
const data = await res.json();
// After all previous uninstalls, no bundle should be stuck in "installing"
for (const bundle of data.bundles) {
expect(bundle.status).not.toBe("installing");
}
});
test("install works after restart", async ({ request }) => {
test.setTimeout(600_000);
// Install face-detection from clean state
await ensureInstalled(request, "face-detection");
// Verify it works
const res = await callTool(request, "blur-faces");
expect(res.status()).toBe(200);
// Cleanup: uninstall
const headers = await authHeaders(request);
await request.post(`${API}/api/v1/admin/features/face-detection/uninstall`, { headers });
const status = await getBundleStatus(request, "face-detection");
expect(status).toBe("not_installed");
});
});
+83 -76
View File
@@ -31,15 +31,6 @@ async function fetchBundleStatuses(
return data.bundles as BundleInfo[];
}
async function isBundleInstalled(
request: import("@playwright/test").APIRequestContext,
bundleId: string,
): Promise<boolean> {
const bundles = await fetchBundleStatuses(request);
const bundle = bundles.find((b) => b.id === bundleId);
return bundle?.status === "installed";
}
// ─── Feature API tests ─────────────────────────────────────────────
test.describe("Feature API", () => {
@@ -102,16 +93,6 @@ test.describe("Feature API", () => {
expect(response.status()).toBe(404);
});
test("POST uninstall returns 409 for not-installed bundle", async ({ request }) => {
const installed = await isBundleInstalled(request, "background-removal");
if (installed) {
test.skip();
return;
}
const response = await request.post("/api/v1/admin/features/background-removal/uninstall");
expect(response.status()).toBe(409);
});
test("GET disk-usage returns totalBytes", async ({ request }) => {
const token = await getToken(request);
const response = await request.get("/api/v1/admin/features/disk-usage", {
@@ -123,20 +104,70 @@ test.describe("Feature API", () => {
});
});
// ─── Tool route guard tests ─────────────────────────────────────────
// ─── Tool route guard tests (serial: manages ocr bundle lifecycle) ──
test.describe("Tool route guards", () => {
test.describe.configure({ mode: "serial" });
const pngBuffer = Buffer.from(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==",
"base64",
);
const aiTools = [
test.beforeAll(async ({ request }) => {
const token = await getToken(request);
const bundles = await fetchBundleStatuses(request);
const ocr = bundles.find((b) => b.id === "ocr");
if (ocr?.status === "installed") {
await request.post("/api/v1/admin/features/ocr/uninstall", {
headers: { Authorization: `Bearer ${token}` },
});
for (let i = 0; i < 30; i++) {
const updated = await fetchBundleStatuses(request);
if (updated.find((b) => b.id === "ocr")?.status === "not_installed") break;
await new Promise((r) => setTimeout(r, 2000));
}
}
});
test.afterAll(async ({ request }) => {
const token = await getToken(request);
await request.post("/api/v1/admin/features/ocr/install", {
headers: { Authorization: `Bearer ${token}` },
});
for (let i = 0; i < 60; i++) {
const updated = await fetchBundleStatuses(request);
if (updated.find((b) => b.id === "ocr")?.status === "installed") break;
await new Promise((r) => setTimeout(r, 5000));
}
});
// ocr bundle is uninstalled -- expect 501
test("ocr returns 501 FEATURE_NOT_INSTALLED with correct bundle", async ({ request }) => {
const response = await request.post("/api/v1/tools/ocr", {
multipart: {
file: {
name: "test.png",
mimeType: "image/png",
buffer: pngBuffer,
},
settings: JSON.stringify({}),
},
});
expect(response.status()).toBe(501);
const body = await response.json();
expect(body.code).toBe("FEATURE_NOT_INSTALLED");
expect(body.feature).toBe("ocr");
expect(body.featureName).toBeTruthy();
expect(body.estimatedSize).toBeTruthy();
});
// All other AI tools have their bundles installed -- expect 200 (guard allows through)
const installedAiTools = [
{ tool: "remove-background", bundle: "background-removal" },
{ tool: "upscale", bundle: "upscale-enhance" },
{ tool: "blur-faces", bundle: "face-detection" },
{ tool: "erase-object", bundle: "object-eraser-colorize" },
{ tool: "ocr", bundle: "ocr" },
{ tool: "colorize", bundle: "object-eraser-colorize" },
{ tool: "enhance-faces", bundle: "upscale-enhance" },
{ tool: "noise-removal", bundle: "upscale-enhance" },
@@ -145,13 +176,8 @@ test.describe("Tool route guards", () => {
{ tool: "passport-photo", bundle: "background-removal" },
];
for (const { tool, bundle } of aiTools) {
test(`${tool} returns 501 FEATURE_NOT_INSTALLED with correct bundle`, async ({ request }) => {
const installed = await isBundleInstalled(request, bundle);
if (installed) {
test.skip();
return;
}
for (const { tool } of installedAiTools) {
test(`${tool} returns 200 when bundle is installed`, async ({ request }) => {
const response = await request.post(`/api/v1/tools/${tool}`, {
multipart: {
file: {
@@ -162,12 +188,7 @@ test.describe("Tool route guards", () => {
settings: JSON.stringify({}),
},
});
expect(response.status()).toBe(501);
const body = await response.json();
expect(body.code).toBe("FEATURE_NOT_INSTALLED");
expect(body.feature).toBe(bundle);
expect(body.featureName).toBeTruthy();
expect(body.estimatedSize).toBeTruthy();
expect(response.status()).toBe(200);
});
}
@@ -185,23 +206,18 @@ test.describe("Tool route guards", () => {
// Should succeed or fail with a processing error, NOT 501
expect(response.status()).not.toBe(501);
});
});
// ─── Batch and pipeline guard tests ─────────────────────────────────
// ─── Uninstall conflict (ocr is not installed at this point) ──────
test.describe("Batch and pipeline guards", () => {
const pngBuffer = Buffer.from(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==",
"base64",
);
test("POST uninstall returns 409 for not-installed bundle", async ({ request }) => {
const response = await request.post("/api/v1/admin/features/ocr/uninstall");
expect(response.status()).toBe(409);
});
// ─── Batch guard (ocr is not installed at this point) ─────────────
test("batch endpoint returns 501 for uninstalled AI tool", async ({ request }) => {
const installed = await isBundleInstalled(request, "background-removal");
if (installed) {
test.skip();
return;
}
const response = await request.post("/api/v1/tools/remove-background/batch", {
const response = await request.post("/api/v1/tools/ocr/batch", {
multipart: {
"files[]": {
name: "test.png",
@@ -215,25 +231,33 @@ test.describe("Batch and pipeline guards", () => {
const body = await response.json();
expect(body.code).toBe("FEATURE_NOT_INSTALLED");
});
});
// ─── GUI tests (Playwright page interactions) ───────────────────────
// ─── GUI tests (ocr is not installed at this point) ───────────────
test.describe("Feature install UI", () => {
test("uninstalled AI tool page shows install prompt", async ({ page, request }) => {
const installed = await isBundleInstalled(request, "background-removal");
if (installed) {
test.skip();
return;
}
await page.goto("/remove-background");
await expect(page.getByText("Background Removal")).toBeVisible({
test("uninstalled AI tool page shows install prompt", async ({ page }) => {
await page.goto("/ocr");
await expect(page.getByText("OCR")).toBeVisible({
timeout: 10000,
});
await expect(page.getByText("additional download")).toBeVisible();
await expect(page.getByRole("button", { name: /enable/i })).toBeVisible();
});
test("AI tools show download badge in sidebar", async ({ page }) => {
await page.goto("/resize");
// Wait for the sidebar to load
await expect(page.locator("[data-testid='tool-panel']").or(page.locator("nav"))).toBeVisible({
timeout: 10000,
});
// The download icon should be visible near the OCR tool
const ocrLink = page.locator("a[href='/ocr']");
await expect(ocrLink).toBeVisible();
});
});
// ─── GUI tests (no bundle state dependency) ─────────────────────────
test.describe("Feature install UI", () => {
test("non-AI tool page loads normally", async ({ page }) => {
await page.goto("/resize");
// Should show the normal tool UI, not an install prompt
@@ -242,23 +266,6 @@ test.describe("Feature install UI", () => {
});
});
test("AI tools show download badge in sidebar", async ({ page, request }) => {
const installed = await isBundleInstalled(request, "background-removal");
if (installed) {
test.skip();
return;
}
await page.goto("/resize");
// Wait for the sidebar to load
await expect(page.locator("[data-testid='tool-panel']").or(page.locator("nav"))).toBeVisible({
timeout: 10000,
});
// The download icon should be visible near AI tools
// Note: we can't easily test for the exact Download icon, but we can check the tool links exist
const removeBackgroundLink = page.locator("a[href='/remove-background']");
await expect(removeBackgroundLink).toBeVisible();
});
test("settings dialog has AI Features section", async ({ page }) => {
await page.goto("/resize");
// Open settings - look for a settings button/gear icon
+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);