test: expand coverage across all layers -- 1,268 new tests, fix replace-color div-by-zero

14-agent parallel test expansion covering integration, unit, E2E, E2E-Docker,
cross-format matrix, adversarial, GUI navigation/tools/settings/visual/a11y/perf.

- Integration: expand 23 tool test files with HEIC, stress, batch, edge cases
- Unit: close coverage gaps in image-engine, stores, lib (metadata, auto-enhance,
  connection-store, lazy-with-retry, collage/file-store HEIC preview)
- AI bridge: 141 new tests for dispatcher buffering, crash recovery, OOM/segfault
- Cross-format: 794 parameterized tests (16 formats x 12 tools + no-crash matrix)
- Adversarial: memory stress (50x large file), zero-byte, corrupted headers, unicode
- E2E-Docker: expand 8 spec files with dimension verification, pipeline chains
- GUI E2E: tool UI settings/interactions for all 47 tools, remove all test.skip,
  RBAC per-role verification, visual screenshot naming, cross-browser smoke tests,
  a11y ARIA/focus/contrast, performance budgets, 15-tool stability test
- Fix: replace-color.ts tolerance=0 caused division-by-zero producing NaN pixels

Total: 8,958 tests passing across 202 files. Zero failures, zero skips.
This commit is contained in:
SnapOtter
2026-05-09 18:02:58 +08:00
parent 7b1f09f5d0
commit a0556772e8
76 changed files with 13112 additions and 117 deletions
+88
View File
@@ -453,4 +453,92 @@ describe("seamCarve", () => {
// shortest side is 400
expect(caireCall?.[1]).toContain("400");
});
it("propagates sharp metadata error", async () => {
const { seamCarve } = await importFresh();
vi.mocked(sharp).mockImplementation(
() =>
({
png: vi.fn().mockReturnThis(),
jpeg: vi.fn().mockReturnThis(),
toBuffer: vi.fn().mockResolvedValue(Buffer.from("mock-jpeg-data")),
metadata: vi.fn().mockRejectedValue(new Error("Corrupt file header")),
}) as unknown as ReturnType<typeof sharp>,
);
await expect(seamCarve(FAKE_INPUT, FAKE_OUTPUT_DIR)).rejects.toThrow("Corrupt file header");
});
it("propagates sharp jpeg conversion error", async () => {
const { seamCarve } = await importFresh();
vi.mocked(sharp).mockImplementation(
() =>
({
png: vi.fn().mockReturnThis(),
jpeg: vi.fn().mockReturnThis(),
toBuffer: vi.fn().mockRejectedValue(new Error("JPEG encode failed")),
metadata: vi.fn().mockResolvedValue({ width: 800, height: 600 }),
}) as unknown as ReturnType<typeof sharp>,
);
await expect(seamCarve(FAKE_INPUT, FAKE_OUTPUT_DIR)).rejects.toThrow("JPEG encode failed");
});
it("propagates readFile error when reading caire output", async () => {
const { seamCarve } = await importFresh();
vi.mocked(readFile).mockRejectedValueOnce(new Error("ENOENT: caire output missing"));
await expect(seamCarve(FAKE_INPUT, FAKE_OUTPUT_DIR)).rejects.toThrow("caire output missing");
});
it("propagates writeFile error when writing input", async () => {
const { seamCarve } = await importFresh();
vi.mocked(writeFile).mockRejectedValueOnce(new Error("ENOSPC: disk full"));
await expect(seamCarve(FAKE_INPUT, FAKE_OUTPUT_DIR)).rejects.toThrow("disk full");
});
it("uses default width and height when no options are specified", async () => {
const { seamCarve } = await importFresh();
// With 800x600, no width/height options, targetW = 800, targetH = 600
// wRatio = 1, hRatio = 1, so no 75% check triggers
await seamCarve(FAKE_INPUT, FAKE_OUTPUT_DIR);
const calls = mockExecFileAsync.mock.calls;
const caireCall = calls.find(
(c: unknown[]) => Array.isArray(c[1]) && c[1].includes("-preview=false"),
);
expect(caireCall).toBeDefined();
// No -width or -height when defaults match original
expect(caireCall?.[1]).not.toContain("-width");
expect(caireCall?.[1]).not.toContain("-height");
});
it("accepts 75% reduction exactly (ratio = 0.25)", async () => {
vi.mocked(sharp).mockImplementation(
() =>
({
png: vi.fn().mockReturnThis(),
jpeg: vi.fn().mockReturnThis(),
toBuffer: vi.fn().mockResolvedValue(Buffer.from("mock-jpeg-data")),
metadata: vi.fn().mockResolvedValue({ width: 800, height: 600 }),
}) as unknown as ReturnType<typeof sharp>,
);
const { seamCarve } = await importFresh();
// 200/800 = 0.25, exactly at boundary -- should NOT throw
await expect(seamCarve(FAKE_INPUT, FAKE_OUTPUT_DIR, { width: 200 })).resolves.toBeDefined();
});
it("uses unique UUID in temp file names to prevent collisions", async () => {
const { seamCarve } = await importFresh();
await seamCarve(FAKE_INPUT, FAKE_OUTPUT_DIR);
await seamCarve(FAKE_INPUT, FAKE_OUTPUT_DIR);
const writeCalls = vi.mocked(writeFile).mock.calls;
const paths = writeCalls.map((c) => c[0] as string);
// Each call generates a different UUID in the filename
expect(paths[0]).not.toBe(paths[1]);
});
});