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
@@ -0,0 +1,170 @@
import { readFileSync } from "node:fs";
import sharp from "sharp";
import { describe, expect, it } from "vitest";
import { createGradientBackground } from "../../../apps/api/src/lib/bg-effects.js";
import {
expectBackgroundBlurEnergyReduced,
expectConfiguredBackground,
expectForegroundPreserved,
expectKnownTranscript,
expectObservablePixelChange,
expectSrtArtifact,
expectVttArtifact,
} from "../../helpers/installed-ai-output-oracles.js";
describe("installed AI output oracles", () => {
it("recognizes the committed speech fixture transcript without exact wording", () => {
expect(() =>
expectKnownTranscript("The quick brown fox transcribes audio files reliably."),
).not.toThrow();
expect(() => expectKnownTranscript("unrelated noise with no fixture vocabulary")).toThrow();
});
it("requires real SRT and VTT timing structures", () => {
expect(() =>
expectSrtArtifact("1\n00:00:00,000 --> 00:00:01,250\nThe quick brown fox.\n"),
).not.toThrow();
expect(() =>
expectVttArtifact("WEBVTT\n\n00:00:00.000 --> 00:00:01.250\nThe quick brown fox.\n"),
).not.toThrow();
expect(() => expectSrtArtifact("not subtitles")).toThrow();
expect(() => expectVttArtifact("not subtitles")).toThrow();
});
it("requires observable decoded changes in the background region", async () => {
const input = await sharp({
create: { width: 100, height: 100, channels: 3, background: "#000000" },
})
.png()
.toBuffer();
const changed = await sharp(input)
.composite([
{
input: await sharp({
create: { width: 100, height: 12, channels: 3, background: "#ffffff" },
})
.png()
.toBuffer(),
left: 0,
top: 0,
},
])
.webp({ lossless: true })
.toBuffer();
const centerOnly = await sharp(input)
.composite([
{
input: await sharp({
create: { width: 30, height: 30, channels: 3, background: "#ffffff" },
})
.png()
.toBuffer(),
left: 35,
top: 35,
},
])
.png()
.toBuffer();
await expect(expectObservablePixelChange(input, changed)).resolves.toBeUndefined();
await expect(expectObservablePixelChange(input, centerOnly)).rejects.toThrow();
await expect(expectObservablePixelChange(input, input)).rejects.toThrow();
});
it("requires real high-frequency energy loss in the background region", async () => {
const checker = Buffer.alloc(200 * 200 * 3);
for (let y = 0; y < 200; y += 1) {
for (let x = 0; x < 200; x += 1) {
const value = (x + y) % 2 === 0 ? 0 : 255;
const offset = (y * 200 + x) * 3;
checker[offset] = value;
checker[offset + 1] = value;
checker[offset + 2] = value;
}
}
const input = await sharp(checker, { raw: { width: 200, height: 200, channels: 3 } })
.png()
.toBuffer();
const blurred = await sharp(input).blur(12).webp({ lossless: true }).toBuffer();
await expect(expectBackgroundBlurEnergyReduced(input, blurred)).resolves.toBeUndefined();
await expect(expectBackgroundBlurEnergyReduced(input, input)).rejects.toThrow();
});
it("is calibrated against the committed portrait fixture used in production QA", async () => {
const portrait = readFileSync("tests/fixtures/image/valid/portrait-color.jpg");
const blurred = await sharp(portrait).blur(37.75).webp({ lossless: true }).toBuffer();
const reencoded = await sharp(portrait).webp({ lossless: true }).toBuffer();
await expect(expectBackgroundBlurEnergyReduced(portrait, blurred)).resolves.toBeUndefined();
await expect(expectBackgroundBlurEnergyReduced(portrait, reencoded)).rejects.toThrow(
"background high-frequency energy ratio",
);
});
it("requires the known central foreground region to remain recognizable", async () => {
const input = await sharp({
create: { width: 100, height: 100, channels: 3, background: "#808080" },
})
.composite([
{
input: await sharp({
create: { width: 20, height: 40, channels: 3, background: "#2080e0" },
})
.png()
.toBuffer(),
left: 40,
top: 33,
},
])
.png()
.toBuffer();
const backgroundChanged = await sharp(input)
.composite([
{
input: await sharp({
create: { width: 100, height: 20, channels: 3, background: "#ff0000" },
})
.png()
.toBuffer(),
left: 0,
top: 0,
},
])
.webp({ lossless: true })
.toBuffer();
const foregroundDestroyed = await sharp(input)
.composite([
{
input: await sharp({
create: { width: 20, height: 40, channels: 3, background: "#ff0000" },
})
.png()
.toBuffer(),
left: 40,
top: 33,
},
])
.png()
.toBuffer();
await expect(expectForegroundPreserved(input, backgroundChanged)).resolves.toBeUndefined();
await expect(expectForegroundPreserved(input, foregroundDestroyed)).rejects.toThrow();
});
it("requires configured solid and gradient background colors", async () => {
const red = await sharp({
create: { width: 20, height: 20, channels: 3, background: "#ff0000" },
})
.png()
.toBuffer();
const gradient = await createGradientBackground(200, 200, "#ff0000", "#0000ff", 45);
await expect(expectConfiguredBackground(red, "solid-red")).resolves.toBeUndefined();
await expect(
expectConfiguredBackground(gradient, "red-blue-gradient"),
).resolves.toBeUndefined();
await expect(expectConfiguredBackground(red, "red-blue-gradient")).rejects.toThrow();
});
});