test: major coverage expansion — 18 new test files, ~830 new tests

Unit tests: 1354 → 1781 (+427)
- 11 new AI bridge module tests (packages/ai/ from 2/13 → 13/13 files)
- files-page-store (0% → full), pdf-to-image-store, features-store expanded
- saturation and edit-metadata image-engine operations
- analytics route, features route, web analytics lib, api-extended

Integration tests: ~2070 → 2320 (+250)
- 31 integration files expanded with branch-coverage-targeted tests
- progress.ts SSE endpoints (28% → comprehensive, +18 tests)
- gif-tools all modes (+18), pdf-to-image format variants (+13)
- Cross-format matrix expanded to 17 tools × 17 formats (467 tests)
- Adversarial: concurrent, memory pressure, unicode filenames, pipeline limits

E2E-Docker: +1020 lines across 6 spec files
- Info, colors, sharpening, base64, QR read, JXL/ICO/SVG formats
- Strip-metadata, image-enhancement, content-aware-resize expanded
- Batch pipelines, multi-format batches, HEIC input coverage
This commit is contained in:
SnapOtter
2026-04-26 12:03:08 +08:00
parent dee9452c48
commit 733ebe8010
61 changed files with 12791 additions and 4 deletions
+129
View File
@@ -489,3 +489,132 @@ test.describe("Pipeline edge cases", () => {
expect(body.processedSize).toBeLessThan(body.originalSize);
});
});
// ─── Batch Pipeline Execution ──────────────────────────────────────
test.describe("Batch pipeline execution", () => {
test("batch pipeline resize+compress on 3 images", async ({ request }) => {
const boundary = `----PlaywrightBoundary${Date.now()}`;
const files = [
{ filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
{ filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
{ filename: "c.jpg", contentType: "image/jpeg", buffer: JPG_SAMPLE },
];
const parts: Buffer[] = [];
for (const file of files) {
parts.push(
Buffer.from(
`--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="${file.filename}"\r\nContent-Type: ${file.contentType}\r\n\r\n`,
),
);
parts.push(file.buffer);
parts.push(Buffer.from("\r\n"));
}
parts.push(
Buffer.from(
`--${boundary}\r\nContent-Disposition: form-data; name="pipeline"\r\n\r\n${JSON.stringify({
steps: [
{ toolId: "resize", settings: { width: 100, fit: "contain" } },
{ toolId: "compress", settings: { quality: 60 } },
],
})}\r\n`,
),
);
parts.push(Buffer.from(`--${boundary}--\r\n`));
const res = await request.post("/api/v1/pipeline/execute", {
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": `multipart/form-data; boundary=${boundary}`,
},
data: Buffer.concat(parts),
});
// Batch pipeline may return ZIP or JSON depending on implementation
if (res.ok()) {
const ct = res.headers()["content-type"] ?? "";
if (ct.includes("application/json")) {
const body = await res.json();
expect(body.downloadUrl || body.results).toBeTruthy();
} else {
const buffer = Buffer.from(await res.body());
expect(buffer.length).toBeGreaterThan(0);
}
} else {
// Batch pipeline may not be supported — single-file only
// Verify the error is coherent, not a crash
const body = await res.json();
expect(body.error).toBeDefined();
}
});
});
// ─── Pipeline with Crop Dimensions ─────────────────────────────────
test.describe("Pipeline with various tools", () => {
test("crop then border then compress pipeline", async ({ request }) => {
const res = await request.post("/api/v1/pipeline/execute", {
headers: { Authorization: `Bearer ${token}` },
multipart: {
file: { name: "sample.jpg", mimeType: "image/jpeg", buffer: JPG_SAMPLE },
pipeline: JSON.stringify({
steps: [
{ toolId: "crop", settings: { left: 0, top: 0, width: 200, height: 200 } },
{ toolId: "border", settings: { size: 10, color: "#ff0000" } },
{ toolId: "compress", settings: { quality: 70 } },
],
}),
},
});
expect(res.ok()).toBe(true);
const body = await res.json();
expect(body.downloadUrl).toBeTruthy();
expect(body.processedSize).toBeGreaterThan(0);
});
test("replace-color then resize pipeline", async ({ request }) => {
const res = await request.post("/api/v1/pipeline/execute", {
headers: { Authorization: `Bearer ${token}` },
multipart: {
file: { name: "test.png", mimeType: "image/png", buffer: PNG_200x150 },
pipeline: JSON.stringify({
steps: [
{
toolId: "replace-color",
settings: {
targetColor: "#ffffff",
replacementColor: "#f0f0f0",
tolerance: 20,
},
},
{ toolId: "resize", settings: { width: 100, fit: "contain" } },
],
}),
},
});
expect(res.ok()).toBe(true);
const body = await res.json();
expect(body.downloadUrl).toBeTruthy();
});
test("edit-metadata then strip-metadata roundtrip", async ({ request }) => {
const jpgExif = fixture("test-with-exif.jpg");
const res = await request.post("/api/v1/pipeline/execute", {
headers: { Authorization: `Bearer ${token}` },
multipart: {
file: { name: "photo.jpg", mimeType: "image/jpeg", buffer: jpgExif },
pipeline: JSON.stringify({
steps: [
{
toolId: "edit-metadata",
settings: { artist: "Pipeline Author", copyright: "CC0" },
},
{ toolId: "strip-metadata", settings: {} },
],
}),
},
});
expect(res.ok()).toBe(true);
const body = await res.json();
expect(body.downloadUrl).toBeTruthy();
});
});