Exports only knew aspect ratios, so a cut could still be rejected or degraded on upload: too long for the platform, over its size limit, or far off its loudness. export_video now takes platforms (TikTok, Instagram Reels and Feed, YouTube Shorts and YouTube, Facebook Reels, LinkedIn, X, Pinterest, Snapchat Spotlight), up to six targets with the presets. Each platform is rendered to its frame with the export's fit, its frame rate cap, a bitrate cap that also keeps the file under the size limit, and its loudness target in one loudnorm pass. Every render is probed and measured afterwards. A file over the size limit is encoded once more at a bitrate scaled from what it averaged, and audio more than 2 LU off the target gets one linear loudness pass. The result is stored on the output as a pass, warn or fail check with language-neutral issue codes. A platform the video is too long or too short for is not rendered: the card lists it with the reason, the other targets still render, and the bot is told to trim first. The limits come from the earlier profile research, with its sources, review date and unverified flag; content, disclosure and caption rules are left out because they need inference or a review flow. Preset definitions move to their own module so the platform schemas can use their aspect ratios without an import cycle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u
84 lines
3.1 KiB
TypeScript
84 lines
3.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { EditVideoInputSchema, ExportVideoInputSchema } from "./media-video.js";
|
|
|
|
const edit = (steps: unknown[]) =>
|
|
EditVideoInputSchema.safeParse({ artifact_id: "a", title: "Reel", steps });
|
|
|
|
describe("edit_video input", () => {
|
|
it("accepts ordered steps and fills defaults", () => {
|
|
const parsed = EditVideoInputSchema.parse({
|
|
artifact_id: "a",
|
|
title: " Reel ",
|
|
steps: [
|
|
{ op: "trim", start: 1, end: 5 },
|
|
{ op: "reframe", preset: "vertical" },
|
|
{ op: "extract_audio" },
|
|
],
|
|
});
|
|
expect(parsed.title).toBe("Reel");
|
|
expect(parsed.steps[1]).toEqual({ op: "reframe", preset: "vertical", fit: "crop" });
|
|
// The job stores the parsed input and parses it again when it runs.
|
|
expect(EditVideoInputSchema.parse(parsed)).toEqual(parsed);
|
|
});
|
|
|
|
it("rejects malformed step lists", () => {
|
|
expect(edit([]).success).toBe(false);
|
|
expect(edit([{ op: "trim", start: 5, end: 5 }]).success).toBe(false);
|
|
expect(edit([{ op: "keep", segments: [{ start: 3, end: 1 }] }]).success).toBe(false);
|
|
expect(edit([{ op: "speed", factor: 8 }]).success).toBe(false);
|
|
expect(edit([{ op: "extract_audio" }, { op: "mute" }]).success).toBe(false);
|
|
expect(edit([{ op: "poster", at: 1 }, { op: "extract_audio" }]).success).toBe(false);
|
|
expect(
|
|
edit([
|
|
{ op: "poster", at: 1 },
|
|
{ op: "poster", at: 2 },
|
|
]).success,
|
|
).toBe(false);
|
|
expect(edit([{ op: "blur" }]).success).toBe(false);
|
|
expect(
|
|
EditVideoInputSchema.safeParse({ artifact_id: "a", steps: [{ op: "mute" }] }).success,
|
|
).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("export_video input", () => {
|
|
it("needs at least one preset or platform and defaults to cropping", () => {
|
|
expect(ExportVideoInputSchema.parse({ artifact_id: "a", presets: ["square"] })).toEqual({
|
|
artifact_id: "a",
|
|
presets: ["square"],
|
|
fit: "crop",
|
|
});
|
|
expect(ExportVideoInputSchema.parse({ artifact_id: "a", platforms: ["tiktok"] })).toEqual({
|
|
artifact_id: "a",
|
|
platforms: ["tiktok"],
|
|
fit: "crop",
|
|
});
|
|
expect(ExportVideoInputSchema.safeParse({ artifact_id: "a", presets: [] }).success).toBe(false);
|
|
expect(ExportVideoInputSchema.safeParse({ artifact_id: "a" }).success).toBe(false);
|
|
expect(ExportVideoInputSchema.safeParse({ artifact_id: "a", presets: ["imax"] }).success).toBe(
|
|
false,
|
|
);
|
|
expect(
|
|
ExportVideoInputSchema.safeParse({ artifact_id: "a", platforms: ["myspace"] }).success,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("takes at most six targets across platforms and presets", () => {
|
|
const platforms = ["tiktok", "youtube-shorts", "instagram-reels", "linkedin"];
|
|
expect(
|
|
ExportVideoInputSchema.safeParse({
|
|
artifact_id: "a",
|
|
platforms,
|
|
presets: ["square", "portrait"],
|
|
}).success,
|
|
).toBe(true);
|
|
const tooMany = ExportVideoInputSchema.safeParse({
|
|
artifact_id: "a",
|
|
platforms,
|
|
presets: ["square", "portrait", "classic"],
|
|
});
|
|
expect(tooMany.success).toBe(false);
|
|
expect(tooMany.error?.issues[0]?.path).toEqual(["platforms"]);
|
|
});
|
|
});
|