mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -716,6 +716,442 @@ test.describe("Pipeline with various tools", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Pipeline: Resize -> Compress -> Convert Chain ─────────────
|
||||
|
||||
test.describe("Pipeline: resize -> compress -> convert chain", () => {
|
||||
test("three-step chain: resize, compress, convert to WebP", 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: "resize", settings: { width: 400, fit: "contain" } },
|
||||
{ toolId: "compress", settings: { quality: 60 } },
|
||||
{ toolId: "convert", settings: { format: "webp" } },
|
||||
],
|
||||
}),
|
||||
},
|
||||
});
|
||||
expect(res.ok()).toBe(true);
|
||||
const body = await res.json();
|
||||
expect(body.downloadUrl).toBeTruthy();
|
||||
expect(body.downloadUrl).toContain(".webp");
|
||||
expect(body.processedSize).toBeGreaterThan(0);
|
||||
expect(body.processedSize).toBeLessThan(body.originalSize);
|
||||
});
|
||||
|
||||
test("three-step chain: resize, compress, convert to AVIF", 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: "resize", settings: { width: 300, fit: "contain" } },
|
||||
{ toolId: "compress", settings: { quality: 50 } },
|
||||
{ toolId: "convert", settings: { format: "avif" } },
|
||||
],
|
||||
}),
|
||||
},
|
||||
});
|
||||
expect(res.ok()).toBe(true);
|
||||
const body = await res.json();
|
||||
expect(body.downloadUrl).toBeTruthy();
|
||||
expect(body.downloadUrl).toContain(".avif");
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Pipeline: Output Download Verification ───────────────────────
|
||||
|
||||
test.describe("Pipeline output verification", () => {
|
||||
test("pipeline output can be downloaded and is valid", 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: "resize", settings: { width: 80, fit: "contain" } },
|
||||
{ toolId: "border", settings: { size: 5, color: "#FF0000" } },
|
||||
],
|
||||
}),
|
||||
},
|
||||
});
|
||||
expect(res.ok()).toBe(true);
|
||||
const body = await res.json();
|
||||
expect(body.downloadUrl).toBeTruthy();
|
||||
|
||||
// Download and verify
|
||||
const dlRes = await request.get(body.downloadUrl, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
expect(dlRes.ok()).toBe(true);
|
||||
const buffer = Buffer.from(await dlRes.body());
|
||||
expect(buffer.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("pipeline output dimensions match expected", 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: "resize", settings: { width: 100, height: 75, fit: "fill" } }],
|
||||
}),
|
||||
},
|
||||
});
|
||||
expect(res.ok()).toBe(true);
|
||||
const body = await res.json();
|
||||
|
||||
const dlRes = await request.get(body.downloadUrl, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
expect(dlRes.ok()).toBe(true);
|
||||
const buffer = Buffer.from(await dlRes.body());
|
||||
|
||||
// Verify dimensions via info
|
||||
const infoRes = await request.post("/api/v1/tools/info", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
multipart: {
|
||||
file: { name: "output.png", mimeType: "image/png", buffer: buffer },
|
||||
},
|
||||
});
|
||||
expect(infoRes.ok()).toBe(true);
|
||||
const infoBody = await infoRes.json();
|
||||
expect(infoBody.width).toBe(100);
|
||||
expect(infoBody.height).toBe(75);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Pipeline: 4+ Step Chains ─────────────────────────────────────
|
||||
|
||||
test.describe("Pipeline: 4+ step chains", () => {
|
||||
test("five-step pipeline: resize, adjust-colors, sharpening, watermark, convert", 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: "resize", settings: { width: 500, fit: "contain" } },
|
||||
{ toolId: "adjust-colors", settings: { brightness: 5, contrast: 10, saturation: 5 } },
|
||||
{ toolId: "sharpening", settings: { sigma: 1.0 } },
|
||||
{
|
||||
toolId: "watermark-text",
|
||||
settings: {
|
||||
text: "SnapOtter",
|
||||
fontSize: 16,
|
||||
color: "#808080",
|
||||
opacity: 15,
|
||||
position: "bottom-right",
|
||||
},
|
||||
},
|
||||
{ toolId: "convert", settings: { format: "webp" } },
|
||||
],
|
||||
}),
|
||||
},
|
||||
});
|
||||
expect(res.ok()).toBe(true);
|
||||
const body = await res.json();
|
||||
expect(body.downloadUrl).toBeTruthy();
|
||||
expect(body.downloadUrl).toContain(".webp");
|
||||
expect(body.processedSize).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("four-step pipeline: crop, rotate, border, compress", 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: 100, height: 100 } },
|
||||
{ toolId: "rotate", settings: { angle: 45, background: "#000000" } },
|
||||
{ toolId: "border", settings: { size: 10, color: "#FFFFFF" } },
|
||||
{ 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("six-step pipeline: full web optimization workflow", 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: "resize", settings: { width: 800, fit: "contain" } },
|
||||
{ toolId: "image-enhancement", settings: { preset: "auto" } },
|
||||
{ toolId: "adjust-colors", settings: { brightness: 3, contrast: 5 } },
|
||||
{ toolId: "sharpening", settings: { sigma: 0.5 } },
|
||||
{ toolId: "strip-metadata", settings: {} },
|
||||
{ toolId: "compress", settings: { quality: 75 } },
|
||||
],
|
||||
}),
|
||||
},
|
||||
});
|
||||
expect(res.ok()).toBe(true);
|
||||
const body = await res.json();
|
||||
expect(body.downloadUrl).toBeTruthy();
|
||||
expect(body.processedSize).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Pipeline: HEIC Input Through Chain ───────────────────────────
|
||||
|
||||
test.describe("Pipeline: HEIC input through chain", () => {
|
||||
test("HEIC through resize, watermark, convert chain", async ({ request }) => {
|
||||
const heic = fixture("test-200x150.heic");
|
||||
const res = await request.post("/api/v1/pipeline/execute", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
multipart: {
|
||||
file: { name: "test.heic", mimeType: "image/heic", buffer: heic },
|
||||
pipeline: JSON.stringify({
|
||||
steps: [
|
||||
{ toolId: "resize", settings: { width: 150, fit: "contain" } },
|
||||
{
|
||||
toolId: "watermark-text",
|
||||
settings: {
|
||||
text: "HEIC",
|
||||
fontSize: 20,
|
||||
color: "#FF0000",
|
||||
opacity: 50,
|
||||
position: "center",
|
||||
},
|
||||
},
|
||||
{ toolId: "convert", settings: { format: "png" } },
|
||||
],
|
||||
}),
|
||||
},
|
||||
});
|
||||
expect(res.ok()).toBe(true);
|
||||
const body = await res.json();
|
||||
expect(body.downloadUrl).toBeTruthy();
|
||||
expect(body.downloadUrl).toContain(".png");
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Pipeline: Save and Execute Saved ─────────────────────────────
|
||||
|
||||
test.describe("Pipeline: save and execute", () => {
|
||||
test("save pipeline then list and verify it exists", async ({ request }) => {
|
||||
// Save
|
||||
const saveRes = await request.post("/api/v1/pipeline/save", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
data: {
|
||||
name: "Web Optimization Pipeline",
|
||||
description: "Resize, compress, convert for web",
|
||||
steps: [
|
||||
{ toolId: "resize", settings: { width: 800, fit: "contain" } },
|
||||
{ toolId: "compress", settings: { quality: 75 } },
|
||||
{ toolId: "convert", settings: { format: "webp" } },
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(saveRes.ok()).toBe(true);
|
||||
const { id } = await saveRes.json();
|
||||
expect(id).toBeTruthy();
|
||||
|
||||
// List and verify
|
||||
const listRes = await request.get("/api/v1/pipeline/list", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
expect(listRes.ok()).toBe(true);
|
||||
const listBody = await listRes.json();
|
||||
const pipelines = listBody.pipelines ?? listBody;
|
||||
const saved = pipelines.find((p: { id: string }) => p.id === id);
|
||||
expect(saved).toBeTruthy();
|
||||
expect(saved.name).toBe("Web Optimization Pipeline");
|
||||
|
||||
// Clean up
|
||||
const delRes = await request.delete(`/api/v1/pipeline/${id}`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
expect(delRes.ok()).toBe(true);
|
||||
});
|
||||
|
||||
test("save pipeline with all field variations", async ({ request }) => {
|
||||
const saveRes = await request.post("/api/v1/pipeline/save", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
data: {
|
||||
name: "Full Field Pipeline",
|
||||
description: "Pipeline with diverse tools",
|
||||
steps: [
|
||||
{ toolId: "resize", settings: { width: 600, fit: "inside" } },
|
||||
{ toolId: "adjust-colors", settings: { brightness: 10, contrast: 5 } },
|
||||
{ toolId: "sharpening", settings: { sigma: 1.5 } },
|
||||
{ toolId: "border", settings: { size: 5, color: "#333333" } },
|
||||
{ toolId: "compress", settings: { quality: 80 } },
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(saveRes.ok()).toBe(true);
|
||||
const { id } = await saveRes.json();
|
||||
expect(id).toBeTruthy();
|
||||
|
||||
// Clean up
|
||||
await request.delete(`/api/v1/pipeline/${id}`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Pipeline: Batch + Pipeline Combo ─────────────────────────────
|
||||
|
||||
test.describe("Pipeline: batch + pipeline combo", () => {
|
||||
test("batch pipeline on 4 images (resize + compress)", 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,
|
||||
},
|
||||
{
|
||||
filename: "d.heic",
|
||||
contentType: "image/heic",
|
||||
buffer: fixture("test-200x150.heic"),
|
||||
},
|
||||
];
|
||||
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: 80, fit: "contain" } },
|
||||
{ toolId: "compress", settings: { quality: 50 } },
|
||||
],
|
||||
})}\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),
|
||||
});
|
||||
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 only accept single file
|
||||
const body = await res.json();
|
||||
expect(body.error).toBeDefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Pipeline: Replace-Color + Resize + Convert ──────────────────
|
||||
|
||||
test.describe("Pipeline: tool combination chains", () => {
|
||||
test("replace-color, resize, convert to PNG pipeline", async ({ request }) => {
|
||||
const res = await request.post("/api/v1/pipeline/execute", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
multipart: {
|
||||
file: { name: "test.jpg", mimeType: "image/jpeg", buffer: JPG_100x100 },
|
||||
pipeline: JSON.stringify({
|
||||
steps: [
|
||||
{
|
||||
toolId: "replace-color",
|
||||
settings: {
|
||||
targetColor: "#FFFFFF",
|
||||
replacementColor: "#FFFF00",
|
||||
tolerance: 30,
|
||||
},
|
||||
},
|
||||
{ toolId: "resize", settings: { width: 200, fit: "fill" } },
|
||||
{ toolId: "convert", settings: { format: "png" } },
|
||||
],
|
||||
}),
|
||||
},
|
||||
});
|
||||
expect(res.ok()).toBe(true);
|
||||
const body = await res.json();
|
||||
expect(body.downloadUrl).toBeTruthy();
|
||||
expect(body.downloadUrl).toContain(".png");
|
||||
});
|
||||
|
||||
test("text-overlay, border, compress, convert 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: "text-overlay",
|
||||
settings: {
|
||||
text: "TEST",
|
||||
fontSize: 24,
|
||||
color: "#FFFFFF",
|
||||
position: "center",
|
||||
},
|
||||
},
|
||||
{ toolId: "border", settings: { size: 10, color: "#333333" } },
|
||||
{ toolId: "compress", settings: { quality: 70 } },
|
||||
{ toolId: "convert", settings: { format: "jpg" } },
|
||||
],
|
||||
}),
|
||||
},
|
||||
});
|
||||
expect(res.ok()).toBe(true);
|
||||
const body = await res.json();
|
||||
expect(body.downloadUrl).toBeTruthy();
|
||||
expect(body.downloadUrl).toContain(".jpg");
|
||||
});
|
||||
|
||||
test("strip-metadata, resize, border, convert pipeline", 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: "strip-metadata", settings: {} },
|
||||
{ toolId: "resize", settings: { width: 300, fit: "contain" } },
|
||||
{ toolId: "border", settings: { size: 5, color: "#FFFFFF" } },
|
||||
{ toolId: "convert", settings: { format: "webp" } },
|
||||
],
|
||||
}),
|
||||
},
|
||||
});
|
||||
expect(res.ok()).toBe(true);
|
||||
const body = await res.json();
|
||||
expect(body.downloadUrl).toBeTruthy();
|
||||
expect(body.downloadUrl).toContain(".webp");
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Pipeline Auth Failure ──────────────────────────────────────
|
||||
|
||||
test.describe("Pipeline auth failure", () => {
|
||||
|
||||
Reference in New Issue
Block a user