fix: release QA hardening across processing, media, security, and CI gates (#649)

A release-readiness QA pass over the whole product. The commits split into
defects a user would hit and gates that were reporting green while measuring
nothing.

## Fixes that change behaviour

Rate limiting was bypassable on every install: TRUST_PROXY defaulted to true, so
request.ip came from a client-set header and a forged X-Forwarded-For got past
the login limiter. The default is now a private-network trust list.

A transient Postgres outage stranded in-flight jobs, leaving finished output on
disk with no row pointing at it. A reconciler now resolves those rows and adopts
the bytes rather than dropping the work.

A Redis connection that moved to a new address wedged every read-blocked
consumer, so completions stopped signalling while health still answered 200.
Socket timeouts plus subscriber pings recover it.

Installing more than one AI bundle left the shared venv multi-versioned and
silently broke three tools. The installer now reconciles distributions to one
version each.

Converting an image to JXL at quality 1 through 4 returned a 500, because
libjxl 0.7 rejects the distance those values compute. The quality is floored at
what the encoder honours. A missing ffmpeg was also reported to the user as a
corrupt upload; it now says the engine is unavailable.

RAW uploads reached an unpatched LibRaw on arm64, so it is built from source at
0.22.2, and the release scan was split so it can fail on an unfixed critical
instead of hiding it behind ignore-unfixed.

## Gates that could not fail

Two mutation lanes ran zero mutants because Stryker crawled the gitignored docs
build; coverage discarded its whole report on any failing test; the lint gate
skipped root tests, scripts, and two workspaces; and several generated matrices
counted a host missing ffmpeg as a passing tool. Each now measures what it
claims.

Full evidence and the outstanding release items are tracked locally and are not
part of this branch.
This commit is contained in:
SnapOtter
2026-07-27 15:37:30 +08:00
committed by GitHub
parent bc32f86a07
commit d10d0f544f
855 changed files with 54564 additions and 13092 deletions
@@ -59,8 +59,9 @@ describe.skipIf(!sofficeAvailable())("convert-document (requires soffice)", () =
expect(res.statusCode).toBe(202);
const { jobId } = JSON.parse(res.body);
const row = await pollJob(jobId);
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const dl = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,
@@ -75,8 +76,9 @@ describe.skipIf(!sofficeAvailable())("convert-document (requires soffice)", () =
expect(res.statusCode).toBe(202);
const { jobId } = JSON.parse(res.body);
const row = await pollJob(jobId);
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const dl = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,
@@ -91,8 +93,9 @@ describe.skipIf(!sofficeAvailable())("convert-document (requires soffice)", () =
expect(res.statusCode).toBe(202);
const { jobId } = JSON.parse(res.body);
const row = await pollJob(jobId);
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const dl = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,
@@ -58,8 +58,9 @@ describe.skipIf(!sofficeAvailable())("convert-presentation (requires soffice)",
expect(res.statusCode).toBe(202);
const { jobId } = JSON.parse(res.body);
const row = await pollJob(jobId);
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const dl = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,
@@ -58,8 +58,9 @@ describe.skipIf(!sofficeAvailable())("convert-spreadsheet (requires soffice)", (
expect(res.statusCode).toBe(202);
const { jobId } = JSON.parse(res.body);
const row = await pollJob(jobId);
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const dl = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,
@@ -75,8 +76,9 @@ describe.skipIf(!sofficeAvailable())("convert-spreadsheet (requires soffice)", (
expect(res.statusCode).toBe(202);
const { jobId } = JSON.parse(res.body);
const row = await pollJob(jobId);
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const dl = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,
@@ -201,8 +201,9 @@ describe.skipIf(!pandocAvailable() || !pythonWith("weasyprint"))(
if (row && ["completed", "failed", "canceled"].includes(row.status)) break;
await new Promise((r) => setTimeout(r, 500));
}
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const dl = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,
@@ -54,8 +54,9 @@ describe.skipIf(!sofficeAvailable())("excel-to-pdf (requires soffice)", () => {
if (row && ["completed", "failed", "canceled"].includes(row.status)) break;
await new Promise((r) => setTimeout(r, 500));
}
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const dl = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,
@@ -55,8 +55,9 @@ describe.skipIf(!hasWeasyprint)("html-to-pdf (requires weasyprint)", () => {
if (row && ["completed", "failed", "canceled"].includes(row.status)) break;
await new Promise((r) => setTimeout(r, 500));
}
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const dl = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,
@@ -57,8 +57,9 @@ describe.skipIf(!hasWeasyprint || !hasMarkdownMod)(
if (row && ["completed", "failed", "canceled"].includes(row.status)) break;
await new Promise((r) => setTimeout(r, 500));
}
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const dl = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,
@@ -62,7 +62,7 @@ describe.skipIf(!qpdfAvailable())("merge-pdf (requires qpdf)", () => {
}
}, 60_000);
it("returns 422 when only one PDF is provided", async () => {
it("returns 400 before enqueue when only one PDF is provided", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "only.pdf", contentType: "application/pdf", content: PDF },
{ name: "settings", content: JSON.stringify({}) },
@@ -73,11 +73,8 @@ describe.skipIf(!qpdfAvailable())("merge-pdf (requires qpdf)", () => {
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
// The worker throws "Merging needs at least two PDFs" which surfaces as 422
// with a generic "Processing failed" error (the factory strips internal details)
expect(res.statusCode).toBe(422);
expect(res.statusCode).toBe(400);
const parsed = JSON.parse(res.body);
expect(parsed.error).toBe("Processing failed");
expect(parsed.details).toMatch(/at least two/i);
expect(parsed.error).toMatch(/at least 2 files/i);
}, 60_000);
});
@@ -158,33 +158,33 @@ describe("OCR PDF path-backed batch and pipeline ingress", () => {
}
});
it.each([
"file-first",
"field-first",
] as const)("rejects oversized pipeline OCR PDFs with %s multipart ordering", async (ordering) => {
const originalLimit = env.MAX_UPLOAD_SIZE_MB;
env.MAX_UPLOAD_SIZE_MB = 1 / (1024 * 1024);
try {
const oversized = {
name: "file",
filename: "oversized.pdf",
contentType: "application/pdf",
content: Buffer.from("12"),
};
const pipelinePart = { name: "pipeline", content: OCR_PIPELINE };
const parts =
ordering === "file-first" ? [oversized, pipelinePart] : [pipelinePart, oversized];
it.each(["file-first", "field-first"] as const)(
"rejects oversized pipeline OCR PDFs with %s multipart ordering",
async (ordering) => {
const originalLimit = env.MAX_UPLOAD_SIZE_MB;
env.MAX_UPLOAD_SIZE_MB = 1 / (1024 * 1024);
try {
const oversized = {
name: "file",
filename: "oversized.pdf",
contentType: "application/pdf",
content: Buffer.from("12"),
};
const pipelinePart = { name: "pipeline", content: OCR_PIPELINE };
const parts =
ordering === "file-first" ? [oversized, pipelinePart] : [pipelinePart, oversized];
const execute = await postMultipart("/api/v1/pipeline/execute", parts);
const batch = await postMultipart("/api/v1/pipeline/batch", parts);
const execute = await postMultipart("/api/v1/pipeline/execute", parts);
const batch = await postMultipart("/api/v1/pipeline/batch", parts);
expect(execute.statusCode).toBe(413);
expect(batch.statusCode).toBe(413);
expect(prepareSpy).not.toHaveBeenCalled();
} finally {
env.MAX_UPLOAD_SIZE_MB = originalLimit;
}
});
expect(execute.statusCode).toBe(413);
expect(batch.statusCode).toBe(413);
expect(prepareSpy).not.toHaveBeenCalled();
} finally {
env.MAX_UPLOAD_SIZE_MB = originalLimit;
}
},
);
it("enforces the OCR stream cap before a trailing pipeline field reveals the modality", async () => {
const originalLimit = env.MAX_UPLOAD_SIZE_MB;
@@ -254,39 +254,39 @@ describe("OCR PDF path-backed batch and pipeline ingress", () => {
expect(prepareSpy).not.toHaveBeenCalled();
});
it.each([
"file-first",
"field-first",
] as const)("validates execute-pipeline OCR PDF input by path with %s multipart ordering", async (ordering) => {
const pipelinePart = { name: "pipeline", content: OCR_PIPELINE };
const parts =
ordering === "file-first"
? [invalidPdfPart(), pipelinePart]
: [pipelinePart, invalidPdfPart()];
it.each(["file-first", "field-first"] as const)(
"validates execute-pipeline OCR PDF input by path with %s multipart ordering",
async (ordering) => {
const pipelinePart = { name: "pipeline", content: OCR_PIPELINE };
const parts =
ordering === "file-first"
? [invalidPdfPart(), pipelinePart]
: [pipelinePart, invalidPdfPart()];
const response = await postMultipart("/api/v1/pipeline/execute", parts);
const response = await postMultipart("/api/v1/pipeline/execute", parts);
expect(response.statusCode).toBe(400);
expect(JSON.parse(response.body).error).toMatch(/PDF header/i);
expect(prepareSpy).not.toHaveBeenCalled();
});
expect(response.statusCode).toBe(400);
expect(JSON.parse(response.body).error).toMatch(/PDF header/i);
expect(prepareSpy).not.toHaveBeenCalled();
},
);
it.each([
"file-first",
"field-first",
] as const)("validates batch-pipeline OCR PDF files by path with %s multipart ordering", async (ordering) => {
const pipelinePart = { name: "pipeline", content: OCR_PIPELINE };
const parts =
ordering === "file-first"
? [invalidPdfPart(), pipelinePart]
: [pipelinePart, invalidPdfPart()];
it.each(["file-first", "field-first"] as const)(
"validates batch-pipeline OCR PDF files by path with %s multipart ordering",
async (ordering) => {
const pipelinePart = { name: "pipeline", content: OCR_PIPELINE };
const parts =
ordering === "file-first"
? [invalidPdfPart(), pipelinePart]
: [pipelinePart, invalidPdfPart()];
const response = await postMultipart("/api/v1/pipeline/batch", parts);
const response = await postMultipart("/api/v1/pipeline/batch", parts);
expect(response.statusCode).toBe(422);
expect(JSON.parse(response.body).errors[0].error).toMatch(/PDF header/i);
expect(prepareSpy).not.toHaveBeenCalled();
});
expect(response.statusCode).toBe(422);
expect(JSON.parse(response.body).errors[0].error).toMatch(/PDF header/i);
expect(prepareSpy).not.toHaveBeenCalled();
},
);
it("rolls back tool-batch OCR objects when BullMQ rejects the flow handoff", async () => {
mocks.flowAdd.mockRejectedValueOnce(new Error("Redis unavailable"));
@@ -61,8 +61,9 @@ async function downloadCompletedDocx(
if (row && ["completed", "failed", "canceled"].includes(row.status)) break;
await new Promise((resolve) => setTimeout(resolve, 500));
}
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const download = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,
@@ -54,8 +54,9 @@ describe.skipIf(!sofficeAvailable())("powerpoint-to-pdf (requires soffice)", ()
if (row && ["completed", "failed", "canceled"].includes(row.status)) break;
await new Promise((r) => setTimeout(r, 500));
}
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const dl = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,
@@ -52,6 +52,11 @@ describe.skipIf(!pdfcpuAvailable())("watermark-pdf (requires pdfcpu)", () => {
});
describe("watermark-pdf validation (ungated)", () => {
it("rejects whitespace-only watermark text with 400", async () => {
const res = await runTool({ text: " \t" });
expect(res.statusCode).toBe(400);
}, 30_000);
it("rejects text longer than 200 characters with 400", async () => {
const longText = "A".repeat(201);
const res = await runTool({ text: longText });
@@ -54,8 +54,9 @@ describe.skipIf(!sofficeAvailable())("word-to-pdf (requires soffice)", () => {
if (row && ["completed", "failed", "canceled"].includes(row.status)) break;
await new Promise((r) => setTimeout(r, 500));
}
expect(row?.status).toBe("completed");
const outName = (row?.outputRefs as string[])[0].split("/").pop() as string;
if (!row) throw new Error("job row not found after polling");
expect(row.status).toBe("completed");
const outName = (row.outputRefs as string[])[0].split("/").pop() as string;
const dl = await testApp.app.inject({
method: "GET",
url: `/api/v1/download/${jobId}/${encodeURIComponent(outName)}`,