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
+310
View File
@@ -1033,4 +1033,314 @@ describe("Stitch", () => {
const result = JSON.parse(res.body);
expect(result.error).toMatch(/json/i);
});
// ── Branch coverage: invalid file validation (line 157 area) ────────
it("rejects an invalid/corrupt image file", async () => {
const corruptBuffer = Buffer.from("this is not a valid image file");
const { body, contentType } = createMultipartPayload([
{ name: "f1", filename: "corrupt.png", contentType: "image/png", content: corruptBuffer },
{ name: "f2", filename: "b.jpg", contentType: "image/jpeg", content: JPG },
{
name: "settings",
content: JSON.stringify({ direction: "horizontal" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/stitch",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(400);
const result = JSON.parse(res.body);
expect(result.error).toMatch(/invalid file/i);
});
// ── Branch coverage: horizontal fit when image already matches min height (line 300) ──
it("stitches horizontally with fit mode when images have same height", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "f1", filename: "a.jpg", contentType: "image/jpeg", content: JPG },
{ name: "f2", filename: "b.jpg", contentType: "image/jpeg", content: JPG },
{
name: "settings",
content: JSON.stringify({ direction: "horizontal", resizeMode: "fit" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/stitch",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
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();
// Both 100x100, same height: no resizing needed, combined = 200x100
expect(meta.width).toBe(200);
expect(meta.height).toBe(100);
});
// ── Branch coverage: vertical fit when image already matches min width (line 338) ──
it("stitches vertically with fit mode when images have same width", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "f1", filename: "a.jpg", contentType: "image/jpeg", content: JPG },
{ name: "f2", filename: "b.jpg", contentType: "image/jpeg", content: JPG },
{
name: "settings",
content: JSON.stringify({ direction: "vertical", resizeMode: "fit" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/stitch",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
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();
// Both 100x100, same width: no resizing needed, combined = 100x200
expect(meta.width).toBe(100);
expect(meta.height).toBe(200);
});
// ── Branch coverage: grid fit with large image (line 377 area) ──────
it("stitches in grid mode with fit resize where images already fit", async () => {
// All same-size images: scale factor >= 1 means no resizing
const { body, contentType } = createMultipartPayload([
{ name: "f1", filename: "a.jpg", contentType: "image/jpeg", content: JPG },
{ name: "f2", filename: "b.jpg", contentType: "image/jpeg", content: JPG },
{ name: "f3", filename: "c.jpg", contentType: "image/jpeg", content: JPG },
{ name: "f4", filename: "d.jpg", contentType: "image/jpeg", content: JPG },
{
name: "settings",
content: JSON.stringify({
direction: "grid",
gridColumns: 2,
resizeMode: "fit",
}),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/stitch",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
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();
// 2 cols, 2 rows of 100x100; no gap, no border
expect(meta.width).toBe(200);
expect(meta.height).toBe(200);
});
// ── Branch coverage: corner radius with webp output ─────────────────
it("applies corner radius with webp output format", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "f1", filename: "a.png", contentType: "image/png", content: PNG },
{ name: "f2", filename: "b.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({
direction: "horizontal",
cornerRadius: 30,
format: "webp",
quality: 80,
}),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/stitch",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
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");
});
// ── Branch coverage: corner radius with avif output ─────────────────
it("applies corner radius with avif output format", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "f1", filename: "a.png", contentType: "image/png", content: PNG },
{ name: "f2", filename: "b.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({
direction: "horizontal",
cornerRadius: 20,
format: "avif",
quality: 70,
}),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/stitch",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
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("heif");
});
// ── Branch coverage: corner radius with jpeg output (flatten) ───────
it("applies corner radius with jpeg output format (flattens alpha)", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "f1", filename: "a.png", contentType: "image/png", content: PNG },
{ name: "f2", filename: "b.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({
direction: "horizontal",
cornerRadius: 15,
format: "jpeg",
quality: 85,
}),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/stitch",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
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("jpeg");
});
// ── Branch coverage: 1x1 tiny images ────────────────────────────────
it("handles 1x1 pixel input images", async () => {
const TINY = readFileSync(join(FIXTURES, "test-1x1.png"));
const { body, contentType } = createMultipartPayload([
{ name: "f1", filename: "a.png", contentType: "image/png", content: TINY },
{ name: "f2", filename: "b.png", contentType: "image/png", content: TINY },
{
name: "settings",
content: JSON.stringify({ direction: "horizontal" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/stitch",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.processedSize).toBeGreaterThan(0);
});
// ── Branch coverage: large file handling ────────────────────────────
it("handles a large content image in stitching", async () => {
const LARGE = readFileSync(join(FIXTURES, "content", "stress-large.jpg"));
const { body, contentType } = createMultipartPayload([
{ name: "f1", filename: "large.jpg", contentType: "image/jpeg", content: LARGE },
{ name: "f2", filename: "b.jpg", contentType: "image/jpeg", content: JPG },
{
name: "settings",
content: JSON.stringify({ direction: "horizontal", resizeMode: "fit" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/stitch",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.processedSize).toBeGreaterThan(0);
});
});