Files
vfxreview/lib/render-pipeline/high-res.test.ts
T
twotalesanimation 9660cdc21c
Deploy / deploy (push) Successful in 3m23s
feat(review): High quality playback switch and per-version ProRes download
Worker 1.7.0 (preview.highQuality, default on) now, after the AE render:
- encodes a High quality MP4 from the delivery MOV (full-res H.264 High,
  CRF 14 capped at 100 Mbps) -> Version.hqFileUrl
- uploads the MOV itself -> Version.highResKey/Filename/Size
Both best-effort (the preview never fails over them), with a lease
keep-alive during the long encode/uploads; the export timeline records
what was attached.

Player: HQ switch when a High quality source exists; keeps frame, play
state, speed and zoom, remembered per browser, falls back to Standard if
the file won't load. ProRes itself stays download-only (browser support).

Downloads: the client portal's High Res button serves the version's
ProRes (client-code filename), falling back to the shot's manual file;
staff get a ProRes button on the review page.

Housekeeping (lib/render-pipeline/high-res.ts): HQ MP4 + ProRes are kept
while a version is latest, client-shared, approved or younger than
preview.highResRetentionDays (14); otherwise deleted from storage. Runs
per task after finalize and hourly from the reaper; deleting a version or
a reslate removes its files. The Standard MP4 is never touched.

Also: ProRes/Handles top-bar buttons go icon-only below lg so they don't
overlap the version selector.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 16:32:18 +02:00

55 lines
2.2 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
vi.mock("@/lib/db", () => ({ db: {} }));
vi.mock("@/lib/storage", () => ({ deleteFromHetzner: vi.fn() }));
import { highResStorageKeys, shouldKeepHighRes } from "./high-res";
const now = new Date("2026-09-22T12:00:00Z");
const daysAgo = (d: number) => new Date(now.getTime() - d * 24 * 3600 * 1000);
const old = { isLatest: false, isClientVisible: false, approvalStatus: "PENDING_REVIEW", createdAt: daysAgo(30) };
describe("shouldKeepHighRes", () => {
it("prunes an old, superseded, unshared, unapproved version", () => {
expect(shouldKeepHighRes(old, now, 14)).toBe(false);
});
it("keeps the latest version however old", () => {
expect(shouldKeepHighRes({ ...old, isLatest: true }, now, 14)).toBe(true);
});
it("keeps anything shared with the client — they may download it", () => {
expect(shouldKeepHighRes({ ...old, isClientVisible: true }, now, 14)).toBe(true);
});
it("keeps the approved version of record", () => {
expect(shouldKeepHighRes({ ...old, approvalStatus: "APPROVED" }, now, 14)).toBe(true);
});
it("keeps recent superseded versions inside the retention window", () => {
expect(shouldKeepHighRes({ ...old, createdAt: daysAgo(13) }, now, 14)).toBe(true);
expect(shouldKeepHighRes({ ...old, createdAt: daysAgo(15) }, now, 14)).toBe(false);
});
it("treats needs-changes and rejected versions as prunable", () => {
expect(shouldKeepHighRes({ ...old, approvalStatus: "NEEDS_CHANGES" }, now, 14)).toBe(false);
expect(shouldKeepHighRes({ ...old, approvalStatus: "REJECTED" }, now, 14)).toBe(false);
});
it("prunes superseded versions straight away with a zero-day window", () => {
expect(shouldKeepHighRes({ ...old, createdAt: daysAgo(0.01) }, now, 0)).toBe(false);
});
});
describe("highResStorageKeys", () => {
it("returns the ProRes key and the HQ MP4's storage key", () => {
expect(
highResStorageKeys({ highResKey: "highres/a.mov", hqFileUrl: "/api/files/videos/b_HQ.mp4" })
).toEqual(["highres/a.mov", "videos/b_HQ.mp4"]);
});
it("is empty when there is nothing to delete", () => {
expect(highResStorageKeys({ highResKey: null, hqFileUrl: null })).toEqual([]);
});
});