test: massive test coverage expansion (+1,437 tests, 22 new files)

Expand test coverage across all layers via 14 parallel agents:

Unit tests (3,378 total, +534):
- First-ever AI sidecar tests (157 tests covering bridge lifecycle, all 12 tool modules)
- API route infrastructure (auth, pipeline, batch, settings, teams, roles, audit, api-keys, files, docs)
- Lib coverage improvements (audit 7%->95%, worker-pool 33%->100%)
- Web store/lib gap fills (features-store, tool-registry)

Integration tests (4,403 total, +903):
- Expanded 19 tool test files with parameter variations, format edge cases, boundary values
- Cross-format matrix: 290 tests covering 14 tools x 17 formats
- Adversarial/edge cases: 63 tests for extreme inputs, concurrent requests, corrupted files

E2E-Docker (125 new tests):
- Expanded 8 spec files + 1 new file covering all 49 tools
- Added HEIC/format handling, auth failures, download verification

GUI E2E (expanded 28 spec files):
- Navigation, responsive layout, keyboard shortcuts
- All 51 tool UIs with settings, processing, display modes
- Batch/pipeline workflows, settings/RBAC, visual regression
- Resilience, accessibility (ARIA, contrast, focus), performance budgets
This commit is contained in:
SnapOtter
2026-05-09 09:02:29 +08:00
parent 4f0fbade6d
commit 649ad5db9e
138 changed files with 22105 additions and 327 deletions
+233
View File
@@ -667,3 +667,236 @@ describe("Selective correction edge cases", () => {
expect(res.statusCode).toBe(200);
});
});
// ── Partial corrections object ──────────────────────────────────
describe("Partial corrections object", () => {
it("accepts corrections with only some fields specified", async () => {
const res = await postTool({
corrections: {
exposure: true,
contrast: false,
},
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.downloadUrl).toBeDefined();
});
it("accepts empty corrections object (all defaults)", async () => {
const res = await postTool({
corrections: {},
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.downloadUrl).toBeDefined();
});
});
// ── Output format verification for different inputs ─────────────
describe("Output format for different input formats", () => {
it("preserves WebP format for WebP input", async () => {
const res = await postTool({ mode: "auto" }, WEBP, "test.webp", "image/webp");
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
const dlRes = await app.inject({
method: "GET",
url: result.downloadUrl,
headers: { authorization: `Bearer ${adminToken}` },
});
const meta = await sharp(dlRes.rawPayload).metadata();
expect(meta.format).toBe("webp");
});
it("preserves PNG format for PNG input", async () => {
const res = await postTool({ mode: "auto" }, PNG, "test.png", "image/png");
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
const dlRes = await app.inject({
method: "GET",
url: result.downloadUrl,
headers: { authorization: `Bearer ${adminToken}` },
});
const meta = await sharp(dlRes.rawPayload).metadata();
expect(meta.format).toBe("png");
});
});
// ── Output dimension verification ───────────────────────────────
describe("Output dimension verification", () => {
it("preserves JPEG input dimensions", async () => {
const res = await postTool({ mode: "auto" }, JPG, "test.jpg", "image/jpeg");
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
const dlRes = await app.inject({
method: "GET",
url: result.downloadUrl,
headers: { authorization: `Bearer ${adminToken}` },
});
const meta = await sharp(dlRes.rawPayload).metadata();
expect(meta.width).toBe(100);
expect(meta.height).toBe(100);
});
it("preserves WebP input dimensions", async () => {
const res = await postTool({ mode: "landscape" }, WEBP, "test.webp", "image/webp");
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
const dlRes = await app.inject({
method: "GET",
url: result.downloadUrl,
headers: { authorization: `Bearer ${adminToken}` },
});
const meta = await sharp(dlRes.rawPayload).metadata();
expect(meta.width).toBe(50);
expect(meta.height).toBe(50);
});
});
// ── Response structure ──────────────────────────────────────────
describe("Response structure", () => {
it("returns all expected fields in 200 response", async () => {
const res = await postTool({ mode: "auto" });
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result).toHaveProperty("jobId");
expect(result).toHaveProperty("downloadUrl");
expect(result).toHaveProperty("originalSize");
expect(result).toHaveProperty("processedSize");
expect(typeof result.jobId).toBe("string");
expect(typeof result.downloadUrl).toBe("string");
expect(typeof result.originalSize).toBe("number");
expect(typeof result.processedSize).toBe("number");
expect(result.processedSize).toBeGreaterThan(0);
});
});
// ── Analyze endpoint with different formats ─────────────────────
describe("Analyze endpoint format coverage", () => {
it("analyze works with PNG input", async () => {
const { body: payload, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/image-enhancement/analyze",
payload,
headers: {
"content-type": contentType,
authorization: `Bearer ${adminToken}`,
},
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.corrections).toBeDefined();
expect(typeof result.corrections).toBe("object");
});
it("analyze returns consistent structure across formats", async () => {
const formats = [
{ buf: JPG, name: "test.jpg", ct: "image/jpeg" },
{ buf: PNG, name: "test.png", ct: "image/png" },
];
for (const fmt of formats) {
const { body: payload, contentType } = createMultipartPayload([
{ name: "file", filename: fmt.name, contentType: fmt.ct, content: fmt.buf },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/image-enhancement/analyze",
payload,
headers: {
"content-type": contentType,
authorization: `Bearer ${adminToken}`,
},
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.corrections).toBeDefined();
}
});
});
// ── Mode with selective corrections ─────────────────────────────
describe("Mode with selective corrections", () => {
it("document mode with only sharpness enabled", async () => {
const res = await postTool({
mode: "document",
intensity: 80,
corrections: {
exposure: false,
contrast: false,
whiteBalance: false,
saturation: false,
sharpness: true,
denoise: false,
},
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.downloadUrl).toBeDefined();
});
it("landscape mode with denoise and exposure only", async () => {
const res = await postTool({
mode: "landscape",
intensity: 60,
corrections: {
exposure: true,
contrast: false,
whiteBalance: false,
saturation: false,
sharpness: false,
denoise: true,
},
});
expect(res.statusCode).toBe(200);
});
});
// ── Invalid image data ──────────────────────────────────────────
describe("Invalid image data", () => {
it("returns 400 for corrupt image data on main endpoint", async () => {
const res = await postTool(
{ mode: "auto" },
Buffer.from("not an image file at all"),
"garbage.png",
"image/png",
);
expect(res.statusCode).toBe(400);
});
});
// ── Large file with specific modes ──────────────────────────────
describe("Large file with modes", () => {
it("enhances large image in low-light mode", async () => {
const large = readFileSync(join(FIXTURES, "content", "stress-large.jpg"));
const res = await postTool(
{ mode: "low-light", intensity: 70 },
large,
"stress-large.jpg",
"image/jpeg",
);
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.processedSize).toBeGreaterThan(0);
});
it("enhances large image in document mode", async () => {
const large = readFileSync(join(FIXTURES, "content", "stress-large.jpg"));
const res = await postTool(
{ mode: "document", intensity: 90 },
large,
"stress-large.jpg",
"image/jpeg",
);
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.processedSize).toBeGreaterThan(0);
});
});