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:
SnapOtter
2026-05-09 18:02:58 +08:00
parent 7b1f09f5d0
commit a0556772e8
76 changed files with 13112 additions and 117 deletions
+223
View File
@@ -1030,4 +1030,227 @@ describe("QR Generate", () => {
expect(dlRes.statusCode).toBe(200);
expect(dlRes.rawPayload.length).toBeGreaterThan(0);
});
// ── URL-encoded content ──────────────────────────────────────
it("generates QR code for URL with encoded characters", async () => {
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/qr-generate",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": "application/json",
},
payload: {
text: "https://example.com/search?q=hello%20world&lang=en%26fr",
},
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.downloadUrl).toBeDefined();
expect(result.processedSize).toBeGreaterThan(0);
});
// ── vCard format ─────────────────────────────────────────────
it("generates QR code for vCard contact", async () => {
const vcard = [
"BEGIN:VCARD",
"VERSION:3.0",
"N:Doe;John",
"FN:John Doe",
"TEL:+1234567890",
"EMAIL:john@example.com",
"END:VCARD",
].join("\n");
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/qr-generate",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": "application/json",
},
payload: {
text: vcard,
},
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.downloadUrl).toBeDefined();
expect(result.processedSize).toBeGreaterThan(0);
});
// ── Telephone number format ──────────────────────────────────
it("generates QR code for tel: URI", async () => {
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/qr-generate",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": "application/json",
},
payload: {
text: "tel:+1-555-123-4567",
},
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.processedSize).toBeGreaterThan(0);
});
// ── Color pixel verification ─────────────────────────────────
it("QR with custom colors contains correct foreground color", async () => {
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/qr-generate",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": "application/json",
},
payload: {
text: "color verify",
foreground: "#FF0000",
background: "#FFFFFF",
size: 200,
},
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
const dlRes = await app.inject({
method: "GET",
url: result.downloadUrl,
});
const { data, info } = await sharp(dlRes.rawPayload)
.raw()
.toBuffer({ resolveWithObject: true });
// Scan for at least one red pixel (foreground)
let foundRed = false;
for (let i = 0; i < data.length; i += info.channels) {
if (data[i] > 200 && data[i + 1] < 50 && data[i + 2] < 50) {
foundRed = true;
break;
}
}
expect(foundRed).toBe(true);
});
// ── Higher error correction means more data redundancy ───────
it("higher EC level produces larger or equal processedSize", async () => {
const resL = await app.inject({
method: "POST",
url: "/api/v1/tools/qr-generate",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": "application/json",
},
payload: {
text: "error correction size test with enough data",
errorCorrection: "L",
size: 400,
},
});
const resH = await app.inject({
method: "POST",
url: "/api/v1/tools/qr-generate",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": "application/json",
},
payload: {
text: "error correction size test with enough data",
errorCorrection: "H",
size: 400,
},
});
expect(resL.statusCode).toBe(200);
expect(resH.statusCode).toBe(200);
// H level has more modules, so same-size PNG is typically larger or equal
const sizeL = JSON.parse(resL.body).processedSize;
const sizeH = JSON.parse(resH.body).processedSize;
expect(sizeH).toBeGreaterThanOrEqual(sizeL);
});
// ── Geo location QR code ─────────────────────────────────────
it("generates QR code for geo location", async () => {
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/qr-generate",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": "application/json",
},
payload: {
text: "geo:40.7128,-74.0060",
},
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.downloadUrl).toBeDefined();
});
// ── JSON text payload ────────────────────────────────────────
it("generates QR code containing JSON text", async () => {
const jsonText = JSON.stringify({ key: "value", nested: { a: 1 } });
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/qr-generate",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": "application/json",
},
payload: {
text: jsonText,
},
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
expect(result.processedSize).toBeGreaterThan(0);
});
// ── Output is always square ──────────────────────────────────
it("output image is always square regardless of content", async () => {
for (const size of [150, 300, 500]) {
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/qr-generate",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": "application/json",
},
payload: {
text: `square test at ${size}`,
size,
},
});
expect(res.statusCode).toBe(200);
const result = JSON.parse(res.body);
const dlRes = await app.inject({
method: "GET",
url: result.downloadUrl,
});
const meta = await sharp(dlRes.rawPayload).metadata();
expect(meta.width).toBe(size);
expect(meta.height).toBe(size);
}
});
});