mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -1,15 +1,21 @@
|
||||
import { readdirSync, readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { apiToolPath, TOOLS } from "@snapotter/shared";
|
||||
import { extname, join } from "node:path";
|
||||
import { apiToolPath, PYTHON_SIDECAR_TOOLS, TOOLS } from "@snapotter/shared";
|
||||
import sharp from "sharp";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { getRegisteredToolIds, getToolConfig } from "../../../apps/api/src/routes/tool-factory.js";
|
||||
import { fixtureDir } from "../../fixtures/index.js";
|
||||
import {
|
||||
featureUnavailableDisposition,
|
||||
GeneratedCaseAccounting,
|
||||
} from "../../helpers/generated-case-accounting.js";
|
||||
import { buildGeneratedMultipartFields } from "../../helpers/generated-multipart.js";
|
||||
import { findMissingGeneratedPrerequisite } from "../../helpers/run-generated-tool.js";
|
||||
import {
|
||||
defaultSettingsFor,
|
||||
TOOL_SETTINGS_OVERRIDES,
|
||||
} from "../../helpers/tool-default-settings.js";
|
||||
import { cancelAcceptedJobAndWait } from "../settle-job.js";
|
||||
import { waitForGeneratedJobArtifact } from "../settle-job.js";
|
||||
import {
|
||||
buildTestApp,
|
||||
createMultipartPayload,
|
||||
@@ -27,13 +33,6 @@ import {
|
||||
*
|
||||
* PR runs use the core web formats; FULL_MATRIX=1 (nightly) unlocks all
|
||||
* fixtures in tests/fixtures/image/formats/.
|
||||
*
|
||||
* Split across format-matrix-generated-{1,2,3}.test.ts because vitest shards by
|
||||
* file and runs a file's tests serially in one fork, so a single 800s spec set
|
||||
* the floor for the whole Integration job. `toolsForPart` stripes TOOLS by
|
||||
* modulo, which partitions them by construction: every tool lands in exactly
|
||||
* one part, and the describe name is identical in each so the full test-name
|
||||
* set is unchanged.
|
||||
*/
|
||||
|
||||
const CORE_FORMATS = [
|
||||
@@ -45,11 +44,20 @@ const CORE_FORMATS = [
|
||||
"sample.heic",
|
||||
];
|
||||
|
||||
const fixtureFiles = process.env.FULL_MATRIX
|
||||
? readdirSync(fixtureDir.formats).filter((f) => !f.startsWith("."))
|
||||
: CORE_FORMATS;
|
||||
const ALL_FIXTURE_FILES = readdirSync(fixtureDir.formats)
|
||||
.filter((filename) => !filename.startsWith("."))
|
||||
.sort((left, right) => left.localeCompare(right));
|
||||
const fixtureFiles = process.env.FULL_MATRIX ? ALL_FIXTURE_FILES : CORE_FORMATS;
|
||||
|
||||
const ALLOWED_STATUSES = new Set([200, 202, 400, 413, 415, 422, 501]);
|
||||
const ALLOWED_STATUSES = new Set([200, 202, 400, 413, 415, 422]);
|
||||
const REQUIRE_AI_FEATURES = process.env.REQUIRE_AI_FEATURES === "1";
|
||||
const CUSTOM_ROUTE_TOOLS = new Set([
|
||||
"barcode-generate",
|
||||
"chart-maker",
|
||||
"html-to-image",
|
||||
"passport-photo",
|
||||
"qr-generate",
|
||||
]);
|
||||
|
||||
/**
|
||||
* Raster content types this libvips/Sharp build is guaranteed to decode. Used
|
||||
@@ -66,19 +74,29 @@ const SHARP_DECODABLE_TYPES = new Set([
|
||||
"image/avif",
|
||||
]);
|
||||
|
||||
const IMAGE_TOOLS = TOOLS.filter((candidate) => candidate.modality === "image");
|
||||
|
||||
export const MATRIX_PART_COUNT = 3;
|
||||
|
||||
/** Tools belonging to one part. Striped, so the parts partition TOOLS exactly. */
|
||||
/**
|
||||
* Tools belonging to one part. Striped, so the parts partition the image
|
||||
* catalog exactly. The fixtures are image formats, so only image-modality tools
|
||||
* are exercised here; other modalities have their own matrices.
|
||||
*/
|
||||
export function toolsForPart(part: number): typeof TOOLS {
|
||||
return TOOLS.filter((_, index) => index % MATRIX_PART_COUNT === part - 1);
|
||||
return IMAGE_TOOLS.filter((_, index) => index % MATRIX_PART_COUNT === part - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the matrix for one part. The registry-wide schema guards are
|
||||
* global assertions rather than per-tool ones, so they run in part 1 only.
|
||||
*/
|
||||
/**
|
||||
* Registers the matrix for one part. The registry-wide schema guards are
|
||||
* global assertions rather than per-tool ones, so they run in part 1 only.
|
||||
*/
|
||||
export function registerToolFormatMatrix(part: number): void {
|
||||
describe("tool x format matrix (generated)", () => {
|
||||
describe(`tool x format matrix (generated, part ${part})`, () => {
|
||||
let testApp: TestApp;
|
||||
let adminToken: string;
|
||||
|
||||
@@ -91,6 +109,7 @@ export function registerToolFormatMatrix(part: number): void {
|
||||
await testApp.cleanup();
|
||||
}, 10_000);
|
||||
|
||||
// Registry-wide assertions, not per-tool ones, so one part carries them.
|
||||
if (part === 1) {
|
||||
it("settings overrides only reference registered tools", () => {
|
||||
const registered = new Set(getRegisteredToolIds());
|
||||
@@ -120,28 +139,74 @@ export function registerToolFormatMatrix(part: number): void {
|
||||
|
||||
for (const tool of toolsForPart(part)) {
|
||||
const toolId = tool.id;
|
||||
it(`${toolId} handles every input format cleanly`, async () => {
|
||||
for (const fixture of fixtureFiles) {
|
||||
if (CUSTOM_ROUTE_TOOLS.has(toolId)) {
|
||||
it.skip(`${toolId} -- custom route covered outside the generated factory matrix`, () => {});
|
||||
continue;
|
||||
}
|
||||
it(`${toolId} handles every input format cleanly`, async (context) => {
|
||||
if (PYTHON_SIDECAR_TOOLS.includes(toolId) && !REQUIRE_AI_FEATURES) {
|
||||
return context.skip(
|
||||
`${toolId}: optional AI prerequisite absent; set REQUIRE_AI_FEATURES=1 after install`,
|
||||
);
|
||||
}
|
||||
const missingPrerequisite = await findMissingGeneratedPrerequisite(toolId);
|
||||
if (missingPrerequisite) return context.skip(`${toolId}: ${missingPrerequisite}`);
|
||||
|
||||
// Core mode keeps its six cross-format probes but adds one accepted
|
||||
// fixture for narrow-input tools (for example TIFF/EPS-only presets),
|
||||
// so clean rejection coverage cannot masquerade as tool execution.
|
||||
const acceptedInputs = new Set(
|
||||
tool.acceptedInputs.map((extension) => extension.toLowerCase()),
|
||||
);
|
||||
const acceptedFixture = ALL_FIXTURE_FILES.find((filename) =>
|
||||
acceptedInputs.has(extname(filename).toLowerCase()),
|
||||
);
|
||||
const toolFixtureFiles = process.env.FULL_MATRIX
|
||||
? fixtureFiles
|
||||
: [...new Set([...fixtureFiles, ...(acceptedFixture ? [acceptedFixture] : [])])];
|
||||
const accounting = new GeneratedCaseAccounting(toolId, {
|
||||
expectedAttempts: toolFixtureFiles.length,
|
||||
});
|
||||
for (const fixture of toolFixtureFiles) {
|
||||
const content = readFileSync(join(fixtureDir.formats, fixture));
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: fixture, contentType: "application/octet-stream", content },
|
||||
{ name: "settings", content: JSON.stringify(defaultSettingsFor(toolId)) },
|
||||
]);
|
||||
const { body, contentType } = createMultipartPayload(
|
||||
buildGeneratedMultipartFields({
|
||||
toolId,
|
||||
primary: { filename: fixture, content },
|
||||
settings: defaultSettingsFor(toolId),
|
||||
companions: {
|
||||
image: { filename: fixture, content },
|
||||
audio: { filename: "unused.wav", content: Buffer.alloc(0) },
|
||||
subtitle: { filename: "unused.srt", content: Buffer.alloc(0) },
|
||||
},
|
||||
}),
|
||||
);
|
||||
const res = await testApp.app.inject({
|
||||
method: "POST",
|
||||
url: apiToolPath(toolId),
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
accounting.attempt();
|
||||
|
||||
// Custom-route tools can 404 on the standard path; covered elsewhere.
|
||||
if (res.statusCode === 404) return;
|
||||
if (res.statusCode === 501 && PYTHON_SIDECAR_TOOLS.includes(toolId)) {
|
||||
const payload = JSON.parse(res.body) as { code?: unknown };
|
||||
const disposition = featureUnavailableDisposition({
|
||||
toolId,
|
||||
statusCode: res.statusCode,
|
||||
code: payload.code,
|
||||
requireAiFeatures: REQUIRE_AI_FEATURES,
|
||||
});
|
||||
if (disposition === "skip") {
|
||||
accounting.skip("optional-feature", `${String(payload.code)} for ${fixture}`);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
expect(
|
||||
ALLOWED_STATUSES.has(res.statusCode),
|
||||
`${toolId} x ${fixture}: status ${res.statusCode}: ${res.body.slice(0, 300)}`,
|
||||
).toBe(true);
|
||||
|
||||
if (res.statusCode === 200) {
|
||||
const resType = (res.headers["content-type"]?.toString() ?? "").split(";")[0];
|
||||
if (resType !== "application/json") {
|
||||
@@ -152,10 +217,26 @@ export function registerToolFormatMatrix(part: number): void {
|
||||
`${toolId} x ${fixture}: ZIP response is not a ZIP`,
|
||||
).toBe("PK");
|
||||
}
|
||||
accounting.accept();
|
||||
continue;
|
||||
}
|
||||
const payload = JSON.parse(res.body) as {
|
||||
downloadUrl?: string;
|
||||
error?: unknown;
|
||||
success?: boolean;
|
||||
};
|
||||
if (!payload.downloadUrl) {
|
||||
expect(payload.success, `${toolId} x ${fixture}: JSON reported failure`).not.toBe(
|
||||
false,
|
||||
);
|
||||
expect(
|
||||
payload.error,
|
||||
`${toolId} x ${fixture}: JSON reported an error`,
|
||||
).toBeUndefined();
|
||||
expect(Object.keys(payload).length).toBeGreaterThan(0);
|
||||
accounting.accept();
|
||||
continue;
|
||||
}
|
||||
const payload = JSON.parse(res.body) as { downloadUrl?: string };
|
||||
if (!payload.downloadUrl) continue;
|
||||
const dl = await testApp.app.inject({
|
||||
method: "GET",
|
||||
url: payload.downloadUrl,
|
||||
@@ -175,14 +256,23 @@ export function registerToolFormatMatrix(part: number): void {
|
||||
const meta = await sharp(dl.rawPayload).metadata();
|
||||
expect(meta.width, `${toolId} x ${fixture}: output not decodable`).toBeGreaterThan(0);
|
||||
}
|
||||
accounting.accept();
|
||||
}
|
||||
|
||||
if (res.statusCode === 202 && (toolId === "ocr" || toolId === "ocr-pdf")) {
|
||||
if (res.statusCode === 202) {
|
||||
const payload = JSON.parse(res.body) as { jobId?: string };
|
||||
expect(payload.jobId).toBeDefined();
|
||||
await cancelAcceptedJobAndWait(payload.jobId as string, "ai");
|
||||
await waitForGeneratedJobArtifact(
|
||||
testApp.app,
|
||||
adminToken,
|
||||
toolId,
|
||||
payload.jobId as string,
|
||||
);
|
||||
accounting.accept();
|
||||
}
|
||||
if (res.statusCode !== 200 && res.statusCode !== 202) accounting.reject();
|
||||
}
|
||||
expect(accounting.assertCovered().accepted).toBeGreaterThan(0);
|
||||
// The nightly avif converters run many slow encodes per test; a busy runner
|
||||
// intermittently overran the old 240s cap, so allow the job's full budget.
|
||||
}, 600_000);
|
||||
|
||||
Reference in New Issue
Block a user