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
@@ -69,8 +69,8 @@ describe.skipIf(!ffmpegAvailable())("merge-audio (requires ffmpeg)", () => {
body,
});
expect(res.statusCode).toBe(422);
expect(res.statusCode).toBe(400);
const parsed = JSON.parse(res.body);
expect(parsed.details).toMatch(/at least two/i);
expect(parsed.error).toMatch(/at least 2 files/i);
}, 60_000);
});
@@ -39,6 +39,13 @@ async function runTool(settings: Record<string, unknown>) {
}
describe.skipIf(!ffmpegAvailable())("pitch-shift (requires ffmpeg)", () => {
it("encodes small positive shifts without MP3 frame padding errors", async () => {
const res = await runTool({ semitones: 2 });
expect(res.statusCode).toBe(200);
const envelope = JSON.parse(res.body);
expect(envelope.downloadUrl).toBeDefined();
}, 60_000);
it("shifts +12 semitones with duration roughly unchanged", async () => {
const res = await runTool({ semitones: 12 });
expect(res.statusCode).toBe(200);
@@ -77,4 +77,11 @@ describe.skipIf(!ffmpegAvailable())("ringtone-maker (requires ffmpeg)", () => {
expect(res.statusCode).toBe(422);
expect(res.body).toMatch(/beyond the end/i);
}, 60_000);
it("normalizes sub-microsecond offsets instead of emitting exponential ffmpeg syntax", async () => {
const res = await runTool({ startS: Number.MIN_VALUE, durationS: 1 });
expect(res.statusCode).toBe(200);
const envelope = JSON.parse(res.body);
expect(envelope.downloadUrl).toBeDefined();
}, 60_000);
});
@@ -1,15 +1,21 @@
/**
* Integration tests for the transcribe-audio tool (/api/v1/tools/audio/transcribe-audio).
*
* The transcription bundle (faster-whisper) is not installed locally, so the
* 501 gate is always hit. Validation paths (bad settings) are tested after
* the 501 check fires first. The bundle-gated happy path lives in a skipped
* describe for in-container-after-install runs.
* Missing-bundle contracts run only when the transcription capability is
* absent. Installed happy paths run when the capability is detected or when
* REQUIRE_AI_FEATURES makes its absence a release-gate failure.
*/
import { readFileSync } from "node:fs";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { isToolInstalled } from "../../../../apps/api/src/lib/feature-status.js";
import { fixtures } from "../../../fixtures/index.js";
import { installedAiCapabilityGate } from "../../../helpers/installed-ai-capability-gate.js";
import {
expectKnownTranscript,
expectSrtArtifact,
} from "../../../helpers/installed-ai-output-oracles.js";
import { waitForDownloadedJobArtifact } from "../../settle-job.js";
import {
buildTestApp,
createMultipartPayload,
@@ -18,6 +24,13 @@ import {
} from "../../test-server.js";
const MP3 = readFileSync(fixtures.audio.tiny("mp3"));
const SPEECH_WAV = readFileSync(fixtures.audio.speech.wav);
const REQUIRE_AI_FEATURES = process.env.REQUIRE_AI_FEATURES === "1";
const AI_CAPABILITY = installedAiCapabilityGate(
"transcribe-audio",
REQUIRE_AI_FEATURES,
isToolInstalled,
);
let testApp: TestApp;
let app: TestApp["app"];
@@ -34,68 +47,74 @@ afterAll(async () => {
}, 10_000);
describe("transcribe-audio", () => {
// -- 501 gate (always fires locally: bundle never installed) --
// -- Missing-capability contract --
it("returns 501 FEATURE_NOT_INSTALLED when bundle is absent", async () => {
const { body, contentType } = createMultipartPayload([
{
name: "file",
filename: "tiny.mp3",
contentType: "audio/mpeg",
content: MP3,
},
{ name: "settings", content: JSON.stringify({}) },
]);
it.skipIf(!AI_CAPABILITY.runUnavailableContract)(
"returns 501 FEATURE_NOT_INSTALLED when bundle is absent",
async () => {
const { body, contentType } = createMultipartPayload([
{
name: "file",
filename: "tiny.mp3",
contentType: "audio/mpeg",
content: MP3,
},
{ name: "settings", content: JSON.stringify({}) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/audio/transcribe-audio",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/audio/transcribe-audio",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(501);
const json = JSON.parse(res.body);
expect(json.code).toBe("FEATURE_NOT_INSTALLED");
expect(json.feature).toBe("transcription");
expect(json.featureName).toBe("Transcription");
expect(json.estimatedSize).toBeDefined();
});
expect(res.statusCode).toBe(501);
const json = JSON.parse(res.body);
expect(json.code).toBe("FEATURE_NOT_INSTALLED");
expect(json.feature).toBe("transcription");
expect(json.featureName).toBe("Transcription");
expect(json.estimatedSize).toBeDefined();
},
);
// -- Validation (501 fires before settings parse, so these also 501) --
it("returns 501 even with invalid outputFormat (gate fires first)", async () => {
const { body, contentType } = createMultipartPayload([
{
name: "file",
filename: "tiny.mp3",
contentType: "audio/mpeg",
content: MP3,
},
{
name: "settings",
content: JSON.stringify({ outputFormat: "doc" }),
},
]);
it.skipIf(!AI_CAPABILITY.runUnavailableContract)(
"returns 501 even with invalid outputFormat (gate fires first)",
async () => {
const { body, contentType } = createMultipartPayload([
{
name: "file",
filename: "tiny.mp3",
contentType: "audio/mpeg",
content: MP3,
},
{
name: "settings",
content: JSON.stringify({ outputFormat: "doc" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/audio/transcribe-audio",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/audio/transcribe-audio",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
// 501 because the bundle gate fires before settings validation
expect(res.statusCode).toBe(501);
const json = JSON.parse(res.body);
expect(json.code).toBe("FEATURE_NOT_INSTALLED");
});
// 501 because the bundle gate fires before settings validation
expect(res.statusCode).toBe(501);
const json = JSON.parse(res.body);
expect(json.code).toBe("FEATURE_NOT_INSTALLED");
},
);
it("rejects unauthenticated requests (401)", async () => {
const { body, contentType } = createMultipartPayload([
@@ -118,72 +137,93 @@ describe("transcribe-audio", () => {
expect(res.statusCode).toBe(401);
});
// -- Bundle-gated happy path (skipped locally, runs after bundle install) --
// -- Installed/required capability contract --
// The transcription bundle is ~600 MB and only available in Docker.
// These tests run when the bundle is installed (e.g., during Task 7 smoke).
// Locally they always skip.
describe.skip("with transcription bundle installed", () => {
it("transcribes audio to txt (202 + async)", async () => {
const { body, contentType } = createMultipartPayload([
{
name: "file",
filename: "tiny.mp3",
contentType: "audio/mpeg",
content: MP3,
},
{
name: "settings",
content: JSON.stringify({ outputFormat: "txt" }),
},
]);
describe.skipIf(!AI_CAPABILITY.runInstalledContract)(
"with transcription bundle installed",
() => {
it("transcribes audio to txt (202 + async)", async () => {
const { body, contentType } = createMultipartPayload([
{
name: "file",
filename: "speech-10s.wav",
contentType: "audio/wav",
content: SPEECH_WAV,
},
{
name: "settings",
content: JSON.stringify({ outputFormat: "txt" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/audio/transcribe-audio",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/audio/transcribe-audio",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(202);
const json = JSON.parse(res.body);
expect(json.jobId).toBeDefined();
expect(json.async).toBe(true);
}, 120_000);
expect(res.statusCode).toBe(202);
const json = JSON.parse(res.body);
expect(json.jobId).toBeDefined();
expect(json.async).toBe(true);
const artifact = await waitForDownloadedJobArtifact(
app,
adminToken,
"transcribe-audio",
json.jobId as string,
240_000,
);
expect(artifact.filename).toBe("speech-10s.txt");
expect(artifact.contentType).toBe("text/plain");
expect(artifact.result.resultPayload?.segments).toEqual(expect.any(Number));
expect(artifact.result.resultPayload?.segments as number).toBeGreaterThan(0);
expectKnownTranscript(artifact.buffer.toString("utf8"));
}, 300_000);
it("transcribes audio to srt with correct structure", async () => {
const { body, contentType } = createMultipartPayload([
{
name: "file",
filename: "tiny.mp3",
contentType: "audio/mpeg",
content: MP3,
},
{
name: "settings",
content: JSON.stringify({ outputFormat: "srt" }),
},
]);
it("transcribes audio to srt with correct structure", async () => {
const { body, contentType } = createMultipartPayload([
{
name: "file",
filename: "speech-10s.wav",
contentType: "audio/wav",
content: SPEECH_WAV,
},
{
name: "settings",
content: JSON.stringify({ outputFormat: "srt" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/audio/transcribe-audio",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/audio/transcribe-audio",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(202);
const json = JSON.parse(res.body);
expect(json.jobId).toBeDefined();
// Full SRT structure validation happens after polling completes.
// The sine tone fixture may produce empty or noise text;
// we assert mechanics (counter line "1", arrow timestamp), not words.
}, 120_000);
});
expect(res.statusCode).toBe(202);
const json = JSON.parse(res.body);
expect(json.jobId).toBeDefined();
const artifact = await waitForDownloadedJobArtifact(
app,
adminToken,
"transcribe-audio",
json.jobId as string,
240_000,
);
expect(artifact.filename).toBe("speech-10s.srt");
expect(artifact.contentType).toBe("application/x-subrip");
const subtitles = artifact.buffer.toString("utf8");
expectSrtArtifact(subtitles);
expectKnownTranscript(subtitles);
}, 300_000);
},
);
});