Files
hyperframes/packages/producer/scripts/validate-fast-video.ts
Vance IngallsandClaude Fable 5 1d0dbcd3b2 feat(producer): fast-capture render stages + remote bg-image localizer (#1920)
* feat(engine): drawElementImage capture service

* feat(engine): 3D projection + compositor-effect risk gate

* fix(engine): gate filter drop-shadow wherever blur gates (review)

detectCssEffectRisk documented drop-shadow as a ~29dB damage case but only
detected blur( in its three scan paths — a drop-shadow comp stayed on the
fast path despite the gate's own correctness contract. Detect drop-shadow(
in computed styles, stylesheet rules, and GSAP tween vars, pinned by a
focused test that runs the real page-side closure against a DOM shim
(computed / stylesheet / tween coverage + blur regression + effect-free
null).

Addresses miguel-heygen's blocker on #1918.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(engine): frame-capture core — fast-capture routing, worker-encode, dedup extension

# Conflicts:
#	packages/engine/src/services/screenshotService.ts

* fix(engine): document HF_FORCE_DRAWELEMENT as diagnostic-only; make armStaticDedup idempotent (review)

Addresses miguel-heygen's blockers on #1919:

- HF_FORCE_DRAWELEMENT promoted from a stale "SCRATCH/Uncommitted" comment to
  a documented diagnostic flag: it exists for upstream-Chromium repro work
  (gate-vs-API isolation, crbug 521861819 149-vs-151) and R&D on gated effect
  classes; renders under it may be damaged BY DESIGN since it bypasses gates
  whose thresholds encode measured damage. Never production; the safety-net
  blank guard also stands down under it so diagnostic frames arrive unmodified.
- armStaticDedup is now idempotent: the drawElement init path arms dedup
  before canvas injection, then initializeSession called it again — the
  second run overwrote the armed state with skipReason="capture_mode"
  (captureMode is "drawelement" by then), producing contradictory telemetry
  (armed frames + a skip reason), and re-ran the verification seeks on the
  fallback path. It now no-ops once staticFrames or a skip decision exists.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(producer): fast-capture render stages + remote bg-image localizer

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-06 16:21:39 -07:00

80 lines
3.1 KiB
TypeScript

/**
* Validate the fast-capture (drawElementImage) VIDEO path on real Linux.
*
* drawElementImage draws a snapshot taken at the paint event; capturing video
* needs a fresh per-frame paint. On Linux headless-shell that paint comes from
* the per-frame HeadlessExperimental.beginFrame — so video should capture
* correctly there (see docs/fast-capture-limitations.md, Limitation 2). This
* could not be validated under Docker-on-rosetta (renders hung); this script is
* meant to run on a native amd64 Linux runner inside Dockerfile.test.
*
* Renders a video composition twice — baseline (screenshot) and fast
* (drawElement) — and asserts the fast output matches the baseline (PSNR above
* threshold), proving the video was captured and not dropped to black.
*
* PRODUCER_VALIDATE_COMP=sub-composition-video \
* bunx tsx scripts/validate-fast-video.ts
*
* Exit 0 = fast video matches baseline; exit 1 = regression (black/stale video).
*/
import { execFileSync } from "node:child_process";
import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { createRenderJob, executeRenderJob } from "../src/index.js";
// `||` not `??` — the workflow passes empty strings on a push trigger (inputs
// are only populated for workflow_dispatch), and "" must fall through to the default.
const COMP = process.env.PRODUCER_VALIDATE_COMP || "sub-composition-video";
const MIN_PSNR = Number.parseFloat(process.env.PRODUCER_VALIDATE_MIN_PSNR || "25");
const work = mkdtempSync(join(tmpdir(), "fastvideo-"));
process.env.PRODUCER_ENABLE_BROWSER_POOL = "false";
async function render(mode: "baseline" | "fast", out: string): Promise<void> {
process.env.PRODUCER_EXPERIMENTAL_FAST_CAPTURE = mode === "fast" ? "true" : "false";
const job = createRenderJob({
fps: 30,
quality: "high",
format: "mp4",
workers: 1,
useGpu: false,
hdrMode: "force-sdr",
});
await executeRenderJob(job, resolve("tests", COMP, "src"), out);
}
function psnr(a: string, b: string): number {
const out = execFileSync(
"bash",
["-c", `ffmpeg -y -i "${a}" -i "${b}" -lavfi psnr -f null - 2>&1`],
{ encoding: "utf8" },
);
const m = out.match(/average:(\S+)/);
if (!m) throw new Error(`ffmpeg psnr produced no average:\n${out}`);
return m[1] === "inf" ? Number.POSITIVE_INFINITY : Number.parseFloat(m[1]);
}
async function main(): Promise<void> {
const baseline = join(work, "baseline.mp4");
const fast = join(work, "fast.mp4");
console.log(`[validate-fast-video] comp=${COMP} minPsnr=${MIN_PSNR}`);
await render("baseline", baseline);
await render("fast", fast);
const db = psnr(baseline, fast);
console.log(`[validate-fast-video] fast-vs-baseline PSNR = ${db} dB`);
if (db < MIN_PSNR) {
console.error(
`[validate-fast-video] FAIL — ${db} dB < ${MIN_PSNR} dB. Fast capture dropped video ` +
`(stale/black snapshot). The Linux BeginFrame paint path is not capturing video.`,
);
process.exit(1);
}
console.log("[validate-fast-video] PASS — fast video matches baseline.");
}
main().catch((e) => {
console.error(e);
process.exit(1);
});