mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
test: add regression coverage for the video QA fixes
friendlyError unit test (incl. the false-positive guard); gated integration tests for multi-file video batch and a multi-step video pipeline (regression for the modality-aware batch/pipeline fix). All pass locally; existing image batch (36) and pipeline (37) suites remain green, and the existing gif-to-video webm test now passes with the pix_fmt fix.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { ffmpegAvailable } from "@snapotter/media-engine";
|
||||
import AdmZip from "adm-zip";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { sharedRedis } from "../../apps/api/src/jobs/connection.js";
|
||||
@@ -19,6 +20,8 @@ const FIXTURES = join(__dirname, "..", "fixtures");
|
||||
const PNG = readFileSync(join(FIXTURES, "test-200x150.png"));
|
||||
const JPG = readFileSync(join(FIXTURES, "test-100x100.jpg"));
|
||||
const WEBP = readFileSync(join(FIXTURES, "test-50x50.webp"));
|
||||
const TINY_MP4 = readFileSync(join(FIXTURES, "media", "tiny.mp4"));
|
||||
const TINY_MOV = readFileSync(join(FIXTURES, "media", "tiny.mov"));
|
||||
|
||||
let testApp: TestApp;
|
||||
let app: TestApp["app"];
|
||||
@@ -581,3 +584,33 @@ describe("Legacy batch SSE wire parity", () => {
|
||||
expect(parsed.type).toBe("batch");
|
||||
});
|
||||
});
|
||||
|
||||
// ── Non-image modality (regression) ─────────────────────────────
|
||||
// Batch used to hardcode image validation (validateImageBuffer + Sharp), so
|
||||
// every video/audio/document input failed with "Invalid image". The route now
|
||||
// validates via the per-modality input handler.
|
||||
describe.skipIf(!ffmpegAvailable())("Non-image modality batch", () => {
|
||||
it("processes multiple video files through a video tool and returns a ZIP", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "a.mp4", contentType: "video/mp4", content: TINY_MP4 },
|
||||
{ name: "file", filename: "b.mov", contentType: "video/quicktime", content: TINY_MOV },
|
||||
{ name: "settings", content: JSON.stringify({ transform: "cw90" }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/rotate-video/batch",
|
||||
headers: { "content-type": contentType, authorization: `Bearer ${adminToken}` },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.headers["content-type"]).toBe("application/zip");
|
||||
const zip = new AdmZip(res.rawPayload);
|
||||
expect(zip.getEntries().length).toBe(2);
|
||||
// Regression guard: a real video must not be rejected as "Invalid image".
|
||||
const fileResults = JSON.parse(decodeURIComponent(res.headers["x-file-results"] as string));
|
||||
expect(fileResults["0"]).toBeDefined();
|
||||
expect(fileResults["1"]).toBeDefined();
|
||||
}, 60_000);
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { ffmpegAvailable } from "@snapotter/media-engine";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { buildTestApp, createMultipartPayload, loginAsAdmin, type TestApp } from "./test-server.js";
|
||||
|
||||
@@ -15,6 +16,7 @@ import { buildTestApp, createMultipartPayload, loginAsAdmin, type TestApp } from
|
||||
// ---------------------------------------------------------------------------
|
||||
const FIXTURES = join(__dirname, "..", "fixtures");
|
||||
const PNG_200x150 = readFileSync(join(FIXTURES, "test-200x150.png"));
|
||||
const TINY_MP4 = readFileSync(join(FIXTURES, "media", "tiny.mp4"));
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Shared state
|
||||
@@ -792,3 +794,45 @@ describe("Pipeline execution response", () => {
|
||||
expect(dlRes.rawPayload.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// NON-IMAGE PIPELINE (regression)
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// Pipeline execute used to hardcode image validation and rejected video inputs
|
||||
// with "Invalid image". It now validates via the first step's modality handler.
|
||||
describe.skipIf(!ffmpegAvailable())("Non-image pipeline (video)", () => {
|
||||
it("runs a multi-step video pipeline and returns a downloadable result", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "tiny.mp4", content: TINY_MP4, contentType: "video/mp4" },
|
||||
{
|
||||
name: "pipeline",
|
||||
content: JSON.stringify({
|
||||
steps: [
|
||||
{ toolId: "rotate-video", settings: { transform: "cw90" } },
|
||||
{ toolId: "mute-video", settings: {} },
|
||||
],
|
||||
}),
|
||||
},
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/pipeline/execute",
|
||||
headers: { "content-type": contentType, authorization: `Bearer ${adminToken}` },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
const json = JSON.parse(res.body);
|
||||
expect(json.downloadUrl).toBeDefined();
|
||||
expect(json.stepsCompleted).toBe(2);
|
||||
|
||||
const dlRes = await app.inject({
|
||||
method: "GET",
|
||||
url: json.downloadUrl,
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
});
|
||||
expect(dlRes.statusCode).toBe(200);
|
||||
expect(dlRes.rawPayload.length).toBeGreaterThan(0);
|
||||
}, 60_000);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { friendlyError } from "../../apps/api/src/lib/errors.js";
|
||||
|
||||
const GENERIC = "Processing failed. The file may be in an unsupported or corrupted format.";
|
||||
|
||||
describe("friendlyError", () => {
|
||||
it("collapses raw ffmpeg stderr dumps to a safe sentence", () => {
|
||||
const dump =
|
||||
"ffmpeg exited 234: Input #0, gif ... Pixel format 'gbrap' is not widely supported. Conversion failed!";
|
||||
expect(friendlyError(dump)).toBe(GENERIC);
|
||||
});
|
||||
|
||||
it("collapses raw ffprobe stderr dumps", () => {
|
||||
expect(friendlyError("ffprobe exited 1: moov atom not found")).toBe(GENERIC);
|
||||
});
|
||||
|
||||
it("collapses python tracebacks", () => {
|
||||
expect(friendlyError("Traceback (most recent call last):\n File x\nValueError: boom")).toBe(
|
||||
GENERIC,
|
||||
);
|
||||
});
|
||||
|
||||
it("collapses very long (>280 char) messages", () => {
|
||||
expect(friendlyError("x".repeat(400))).toBe(GENERIC);
|
||||
});
|
||||
|
||||
it("collapses multi-line dumps (>3 lines)", () => {
|
||||
expect(friendlyError("l1\nl2\nl3\nl4\nl5")).toBe(GENERIC);
|
||||
});
|
||||
|
||||
it("preserves intentional, user-facing validation messages", () => {
|
||||
for (const msg of [
|
||||
"This video has no audio track to normalize",
|
||||
"Reverse is limited to clips up to 5 minutes",
|
||||
"Crop rectangle 9999x9999+0+0 exceeds video size 640x360",
|
||||
"No subtitle track found in this video",
|
||||
]) {
|
||||
expect(friendlyError(msg)).toBe(msg);
|
||||
}
|
||||
});
|
||||
|
||||
it("does NOT collapse clean messages that merely contain tool-ish words (false-positive guard)", () => {
|
||||
// The old regex matched "conversion failed" / "pixel format" and would have
|
||||
// wrongly collapsed these legitimate messages.
|
||||
expect(friendlyError("SVG conversion failed")).toBe("SVG conversion failed");
|
||||
expect(friendlyError("PDF conversion failed")).toBe("PDF conversion failed");
|
||||
expect(friendlyError("Unsupported pixel format in source")).toBe(
|
||||
"Unsupported pixel format in source",
|
||||
);
|
||||
});
|
||||
|
||||
it("scrubs internal filesystem paths", () => {
|
||||
expect(friendlyError("decode failed at /data/ai/models/whisper")).toBe(
|
||||
"decode failed at [internal]",
|
||||
);
|
||||
expect(friendlyError("wrote /tmp/workspace/out.mp4")).toBe("wrote [internal]");
|
||||
});
|
||||
|
||||
it("is idempotent (safe to apply at every error surface)", () => {
|
||||
const dump = "ffmpeg exited 1: boom";
|
||||
expect(friendlyError(friendlyError(dump))).toBe(friendlyError(dump));
|
||||
const ok = "Region exceeds image bounds";
|
||||
expect(friendlyError(friendlyError(ok))).toBe(ok);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user