test: expand API and GUI test coverage across all tools

Add ~500 new E2E tests and ~300 new integration tests covering:

- 24 new GUI E2E specs: navigation, responsive layout, keyboard shortcuts,
  tool UI for all 35 non-AI tools, batch/pipeline workflows, settings/RBAC,
  visual regression, accessibility, and performance budgets
- 3 new E2E-Docker specs: batch workflows, advanced pipelines, cross-format
- 1 new adversarial integration test: memory pressure, corrupted files,
  unicode filenames, extreme dimensions, pipeline/batch edge cases
- 29 expanded integration test files: HEIC/HEIF input, large files, parameter
  boundaries, batch processing, format edge cases across all tools
- Cross-format matrix expanded: 641 tests covering every tool x 18 formats
- AI bridge unit tests expanded: lifecycle, tool modules, error propagation
- Unit test gaps filled: analytics, tool-registry, web stores

Also fixes:
- vitest.config.ts: exclude e2e-docs and e2e-landing from Vitest runner
- AI E2E specs: add sidecar health check to skip gracefully when Python
  AI backend is not running instead of timing out
This commit is contained in:
SnapOtter
2026-04-29 01:39:25 +08:00
parent 4acec0846c
commit 03f82567d0
74 changed files with 15893 additions and 14 deletions
+190
View File
@@ -772,4 +772,194 @@ describe("Find Duplicates", () => {
// The portrait should not be in any group
expect(result.uniqueImages).toBeGreaterThanOrEqual(1);
});
// ── Branch coverage: HEIF content format input ─────────────────────
it("handles portrait HEIC images in duplicate detection", async () => {
const HEIC_PORTRAIT = readFileSync(join(FIXTURES, "test-portrait.heic"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "a.heic", contentType: "image/heic", content: HEIC_PORTRAIT },
{ name: "file", filename: "b.heic", contentType: "image/heic", content: HEIC_PORTRAIT },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/find-duplicates",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.totalImages).toBe(2);
expect(result.duplicateGroups).toHaveLength(1);
});
// ── Branch coverage: threshold at max boundary (20) ────────────────
it("uses threshold at max boundary (20)", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "a.png", contentType: "image/png", content: PNG },
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", content: JPG },
{
name: "settings",
content: JSON.stringify({ threshold: 20 }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/find-duplicates",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.totalImages).toBe(2);
});
// ── Branch coverage: negative threshold rejects ────────────────────
it("rejects threshold below minimum (0)", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "a.png", contentType: "image/png", content: PNG },
{ name: "file", filename: "b.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({ threshold: -1 }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/find-duplicates",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(400);
});
// ── Branch coverage: all unique images with strict threshold ───────
it("reports all images as unique with threshold 0 and different images", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "a.png", contentType: "image/png", content: PNG },
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", content: PORTRAIT },
{
name: "settings",
content: JSON.stringify({ threshold: 0 }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/find-duplicates",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.totalImages).toBe(2);
expect(result.duplicateGroups).toHaveLength(0);
expect(result.uniqueImages).toBe(2);
expect(result.spaceSaveable).toBe(0);
});
// ── Branch coverage: exif-oriented image duplicate detection ───────
it("handles EXIF-oriented images in duplicate detection", async () => {
const EXIF = readFileSync(join(FIXTURES, "test-with-exif.jpg"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "exif1.jpg", contentType: "image/jpeg", content: EXIF },
{ name: "file", filename: "exif2.jpg", contentType: "image/jpeg", content: EXIF },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/find-duplicates",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.totalImages).toBe(2);
expect(result.duplicateGroups).toHaveLength(1);
});
// ── Branch coverage: 6+ images in batch ────────────────────────────
it("handles 6+ images in a single batch", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "a.png", contentType: "image/png", content: PNG },
{ name: "file", filename: "b.png", contentType: "image/png", content: PNG },
{ name: "file", filename: "c.jpg", contentType: "image/jpeg", content: JPG },
{ name: "file", filename: "d.jpg", contentType: "image/jpeg", content: JPG },
{ name: "file", filename: "e.webp", contentType: "image/webp", content: WEBP },
{ name: "file", filename: "f.jpg", contentType: "image/jpeg", content: PORTRAIT },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/find-duplicates",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.totalImages).toBe(6);
// PNG pair and JPG pair should be grouped
expect(result.duplicateGroups.length).toBeGreaterThanOrEqual(1);
});
// ── Branch coverage: spaceSaveable for multiple groups ─────────────
it("calculates space saveable across multiple duplicate groups", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "a.png", contentType: "image/png", content: PNG },
{ name: "file", filename: "b.png", contentType: "image/png", content: PNG },
{ name: "file", filename: "c.png", contentType: "image/png", content: PNG },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/find-duplicates",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.duplicateGroups).toHaveLength(1);
expect(result.duplicateGroups[0].files).toHaveLength(3);
// Space saveable should be the size of the 2 non-best duplicates
expect(result.spaceSaveable).toBeGreaterThan(0);
// Should be roughly 2x the file size of a single PNG
expect(result.spaceSaveable).toBeGreaterThan(PNG.length);
});
});