Files
SnapOtterandGitHub d10d0f544f 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.
2026-07-27 15:37:30 +08:00

117 lines
4.0 KiB
TypeScript

import { resize, type Sharp } from "@snapotter/image-engine";
import { ToolInputError } from "@snapotter/shared";
import { describe, expect, it, vi } from "vitest";
const MAX_RESIZE_PERCENTAGE = 1000;
const MAX_RESIZE_OUTPUT_DIMENSION = 16383;
const MAX_RESIZE_OUTPUT_PIXELS = 67_108_864;
function imageWithMetadata(width: number, height: number) {
const resized = { operation: "resize" } as unknown as Sharp;
const resizeCall = vi.fn(() => resized);
const metadata = vi.fn(async () => ({ width, height }));
const image = { metadata, resize: resizeCall } as unknown as Sharp;
return { image, metadata, resizeCall, resized };
}
describe("resize output allocation limits", () => {
it("rejects the deterministic fuzz counterexample as typed input before resize", async () => {
const { image, resizeCall } = imageWithMetadata(200, 150);
await expect(resize(image, { percentage: 896202.8004871072 })).rejects.toBeInstanceOf(
ToolInputError,
);
expect(resizeCall).not.toHaveBeenCalled();
});
it("preserves percentage semantics at the product boundary", async () => {
const { image, resizeCall, resized } = imageWithMetadata(640, 320);
await expect(resize(image, { percentage: MAX_RESIZE_PERCENTAGE })).resolves.toBe(resized);
expect(resizeCall).toHaveBeenCalledWith({
width: 6400,
height: 3200,
fit: "cover",
withoutEnlargement: false,
});
});
it("rejects a percentage immediately above the product boundary", async () => {
const { image, resizeCall } = imageWithMetadata(1, 1);
await expect(
resize(image, { percentage: MAX_RESIZE_PERCENTAGE + Number.EPSILON * 1024 }),
).rejects.toBeInstanceOf(ToolInputError);
expect(resizeCall).not.toHaveBeenCalled();
});
it("uses actual metadata to reject a percentage-derived oversized side", async () => {
const { image, metadata, resizeCall } = imageWithMetadata(2000, 1000);
await expect(resize(image, { percentage: MAX_RESIZE_PERCENTAGE })).rejects.toBeInstanceOf(
ToolInputError,
);
expect(metadata).toHaveBeenCalledOnce();
expect(resizeCall).not.toHaveBeenCalled();
});
it("allows the exact output dimension boundary and rejects one pixel above it", async () => {
const atBoundary = imageWithMetadata(MAX_RESIZE_OUTPUT_DIMENSION, 1);
await expect(
resize(atBoundary.image, {
width: MAX_RESIZE_OUTPUT_DIMENSION,
height: 1,
fit: "fill",
}),
).resolves.toBe(atBoundary.resized);
const aboveBoundary = imageWithMetadata(MAX_RESIZE_OUTPUT_DIMENSION, 1);
await expect(
resize(aboveBoundary.image, {
width: MAX_RESIZE_OUTPUT_DIMENSION + 1,
height: 1,
fit: "fill",
}),
).rejects.toBeInstanceOf(ToolInputError);
expect(aboveBoundary.resizeCall).not.toHaveBeenCalled();
});
it("allows the exact output pixel boundary and rejects one row above it", async () => {
const boundarySide = Math.sqrt(MAX_RESIZE_OUTPUT_PIXELS);
expect(Number.isInteger(boundarySide)).toBe(true);
const atBoundary = imageWithMetadata(boundarySide, boundarySide);
await expect(
resize(atBoundary.image, { width: boundarySide, height: boundarySide, fit: "fill" }),
).resolves.toBe(atBoundary.resized);
const aboveBoundary = imageWithMetadata(boundarySide, boundarySide + 1);
await expect(
resize(aboveBoundary.image, {
width: boundarySide,
height: boundarySide + 1,
fit: "fill",
}),
).rejects.toBeInstanceOf(ToolInputError);
expect(aboveBoundary.resizeCall).not.toHaveBeenCalled();
});
it("applies withoutEnlargement before validating the effective output", async () => {
const { image, resizeCall, resized } = imageWithMetadata(200, 150);
await expect(
resize(image, {
percentage: MAX_RESIZE_PERCENTAGE,
withoutEnlargement: true,
}),
).resolves.toBe(resized);
expect(resizeCall).toHaveBeenCalledWith({
width: 200,
height: 150,
fit: "cover",
withoutEnlargement: true,
});
});
});