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
+196
View File
@@ -481,4 +481,200 @@ describe("Barcode Read", () => {
expect(result.barcodes).toHaveLength(0);
expect(result.annotatedUrl).toBeNull();
});
// ── Branch coverage: HEIC input (lines 49-152, ensureSharpCompat) ───
it("reads barcodes from a HEIC image", async () => {
const HEIC = readFileSync(join(FIXTURES, "test-200x150.heic"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "photo.heic", contentType: "image/heic", content: HEIC },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/barcode-read",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.filename).toBe("photo.heic");
expect(Array.isArray(result.barcodes)).toBe(true);
// No barcodes in a plain image, but no errors either
expect(result.barcodes).toHaveLength(0);
});
// ── Branch coverage: invalid file validation (line 49-152) ──────────
it("rejects an invalid/corrupt image file", async () => {
const corruptBuffer = Buffer.from("this is not a valid image file at all");
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "corrupt.png", contentType: "image/png", content: corruptBuffer },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/barcode-read",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(400);
const result = JSON.parse(res.body);
expect(result.error).toMatch(/invalid image/i);
});
// ── Branch coverage: large image handling ───────────────────────────
it("reads barcodes from a large stress image", async () => {
const LARGE = readFileSync(join(FIXTURES, "content", "stress-large.jpg"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "large.jpg", contentType: "image/jpeg", content: LARGE },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/barcode-read",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.filename).toBe("large.jpg");
expect(Array.isArray(result.barcodes)).toBe(true);
});
// ── Branch coverage: no settings field (uses defaults) ──────────────
it("reads barcodes with no settings field (uses defaults)", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "qr.png", contentType: "image/png", content: qrCodePng },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/barcode-read",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
// Default tryHarder is true, should detect the QR code
expect(result.barcodes.length).toBeGreaterThanOrEqual(1);
expect(result.barcodes[0].text).toBe(QR_TEXT);
});
// ── Branch coverage: portrait HEIC (with exif orientation) ──────────
it("reads barcodes from portrait HEIC image", async () => {
const HEIC_PORTRAIT = readFileSync(join(FIXTURES, "test-portrait.heic"));
const { body, contentType } = createMultipartPayload([
{
name: "file",
filename: "portrait.heic",
contentType: "image/heic",
content: HEIC_PORTRAIT,
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/barcode-read",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.filename).toBe("portrait.heic");
expect(Array.isArray(result.barcodes)).toBe(true);
});
// ── Branch coverage: multiple barcodes in one image ─────────────────
it("detects multiple QR codes when composited together", async () => {
// Create an image with 2 QR codes side by side
const qrMeta = await sharp(qrCodePng).metadata();
const qrW = qrMeta.width ?? 400;
const qrH = qrMeta.height ?? 400;
const doubleQr = await sharp({
create: {
width: qrW * 2 + 20,
height: qrH,
channels: 4,
background: { r: 255, g: 255, b: 255, alpha: 1 },
},
})
.composite([
{ input: qrCodePng, left: 0, top: 0 },
{ input: qrCodePng, left: qrW + 20, top: 0 },
])
.png()
.toBuffer();
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "double-qr.png", contentType: "image/png", content: doubleQr },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/barcode-read",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
// Should detect at least 1 QR code (2 if detection is good enough)
expect(result.barcodes.length).toBeGreaterThanOrEqual(1);
expect(result.annotatedUrl).toBeDefined();
expect(result.annotatedUrl).not.toBeNull();
});
// ── Branch coverage: blank image → no barcodes found (line 229) ─────
it("handles a blank white image gracefully", async () => {
const BLANK = readFileSync(join(FIXTURES, "test-blank.png"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "blank.png", contentType: "image/png", content: BLANK },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/barcode-read",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.barcodes).toHaveLength(0);
expect(result.annotatedUrl).toBeNull();
expect(result.previewUrl).toBeNull();
});
});