Skip to content

Write HTML. Render video. Built for agents.

test(studio): a script-hidden backdrop stays hidden over the A-roll while the preview plays (#5475)

Miguel Ángel83b6419e9755
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 420dffcd16..86b8f6fc95 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -882,6 +882,8 @@ jobs:
packages/studio/data/projects/inline-text-caret
cp -R packages/studio/tests/e2e/fixtures/undo-socket-pool \
packages/studio/data/projects/undo-socket-pool
+ cp -R packages/studio/tests/e2e/fixtures/aroll-backdrop \
+ packages/studio/data/projects/aroll-backdrop
- name: Build the base the viewport gate compares against
# The first parent of the checked-out commit, as in base-file.sh. Measured only when the head misses a budget.
run: |
@@ -1000,7 +1002,7 @@ jobs:
node packages/studio/tests/e2e/perf-ratchet.mjs check \
packages/studio/tests/e2e/perf-ceilings.json studio-open /tmp/studio-open-counts.json \
/tmp/base-perf-ceilings.json
- - name: Check fade handles, render selects, thumbnail connection release and trim snapping
+ - name: Check fade handles, render selects, thumbnail connection release, trim snapping and a script-hidden backdrop
if: success() || failure()
run: |
set -euo pipefail
@@ -1030,6 +1032,8 @@ jobs:
packages/studio/data/projects/timeline-trim-snap
STUDIO_URL="http://localhost:5316/#project/timeline-trim-snap" \
node packages/studio/tests/e2e/timeline-snap-release.mjs || rc=1
+ STUDIO_URL="http://localhost:5316/#project/aroll-backdrop" \
+ node packages/studio/tests/e2e/aroll-backdrop.mjs || rc=1
exit "$rc"
- name: Measure the caret of a text edited in place
if: success() || failure()
diff --git a/packages/studio/tests/e2e/aroll-backdrop.mjs b/packages/studio/tests/e2e/aroll-backdrop.mjs
new file mode 100644
index 0000000000..5b3bc6e999
--- /dev/null
+++ b/packages/studio/tests/e2e/aroll-backdrop.mjs
@@ -0,0 +1,163 @@
+#!/usr/bin/env node
+// The A-roll must show in Studio's preview while playing: the untimed #plate backdrop above it is
+// one the film's own script keeps hidden outside 6-8 s, and the preview must not force it visible.
+import { writeFileSync } from "node:fs";
+import { launchStudioChrome } from "./chrome-executable.mjs";
+
+const STUDIO_URL = process.env.STUDIO_URL;
+const OUT_DIR = process.env.OUT_DIR;
+const PLATE_START_S = 6;
+const PLATE_END_S = 8;
+
+if (!STUDIO_URL) {
+ console.error("STUDIO_URL is required and must point at the aroll-backdrop fixture");
+ process.exit(2);
+}
+const { browser } = await launchStudioChrome();
+const failures = [];
+const evidence = {};
+try {
+ const page = await browser.newPage();
+ await page.setViewport({ width: 1440, height: 900 });
+ await page.goto(STUDIO_URL, { waitUntil: "domcontentloaded" });
+ // Ready when Play is enabled and the preview's A-roll has a frame to paint.
+ await page.waitForSelector('button[aria-label="Play"]:not([disabled])', { timeout: 60_000 });
+ const iframe = await page.waitForFunction(
+ () => document.querySelector("hyperframes-player")?.shadowRoot?.querySelector("iframe"),
+ { timeout: 60_000 },
+ );
+ await page.waitForFunction(
+ (frame) => frame.contentDocument.getElementById("aroll")?.readyState >= 2,
+ { timeout: 60_000, polling: 50 },
+ iframe,
+ );
+
+ // Playhead, the element on top at the frame's centre, and the plate's own state, in the preview.
+ const readPreview = () =>
+ page.evaluate(() => {
+ const frame = document.querySelector("hyperframes-player").shadowRoot.querySelector("iframe");
+ const doc = frame.contentDocument;
+ const player = frame.contentWindow.__player;
+ const film = doc.getElementById("film").getBoundingClientRect();
+ const plate = doc.getElementById("plate");
+ const video = doc.getElementById("aroll");
+ const box = frame.getBoundingClientRect();
+ return {
+ box: [box.x, box.y, box.width, box.height].map(Math.round).join(","),
+ time: player.getTime(),
+ playing: player.isPlaying(),
+ topId: doc.elementFromPoint(film.x + film.width / 2, film.y + film.height * 0.45)?.id,
+ plateVisibility: plate.style.visibility,
+ plateStamped: plate.getAttribute("data-hf-autostamped"),
+ videoReady: video.readyState >= 2 && !video.seeking,
+ };
+ });
+ // Mean chroma (max-min channel) and luma of the frame's centre: the A-roll is colour bars, the plate
+ // near black. Studio can re-fit the preview just after a pause, so a shot across that reflow is retaken.
+ const shoot = async (name) => {
+ let before;
+ let png;
+ let after;
+ let attempts = 0;
+ do {
+ attempts++;
+ before = await readPreview();
+ png = await iframe.screenshot({ encoding: "base64" });
+ after = await readPreview();
+ } while (before.box !== after.box && attempts < 5);
+ if (OUT_DIR) writeFileSync(`${OUT_DIR}/${name}.png`, Buffer.from(png, "base64"));
+ const pixels = await page.evaluate(async (data) => {
+ const img = new Image();
+ img.src = `data:image/png;base64,${data}`;
+ await img.decode();
+ const canvas = new OffscreenCanvas(img.width, img.height);
+ const ctx = canvas.getContext("2d");
+ ctx.drawImage(img, 0, 0);
+ const x = Math.round(img.width * 0.3);
+ const y = Math.round(img.height * 0.35);
+ const { data: rgba } = ctx.getImageData(
+ x,
+ y,
+ Math.round(img.width * 0.4),
+ Math.round(img.height * 0.25),
+ );
+ let chroma = 0;
+ let luma = 0;
+ for (let i = 0; i < rgba.length; i += 4) {
+ const [r, g, b] = [rgba[i], rgba[i + 1], rgba[i + 2]];
+ chroma += Math.max(r, g, b) - Math.min(r, g, b);
+ luma += 0.2126 * r + 0.7152 * g + 0.0722 * b;
+ }
+ const n = rgba.length / 4;
+ return { chroma: Math.round(chroma / n), luma: Math.round(luma / n) };
+ }, png);
+ evidence[name] = { attempts, before, after, pixels };
+ return { before, after, pixels };
+ };
+ const expectAroll = (name, shot) => {
+ if (shot.pixels.chroma < 100 || shot.after.topId !== "aroll")
+ failures.push(
+ `${name}: A-roll hidden (chroma ${shot.pixels.chroma}, on top "${shot.after.topId}", plate ${shot.after.plateVisibility})`,
+ );
+ };
+ const outsidePlate = (t) => t < PLATE_START_S || t >= PLATE_END_S;
+ const playheadIn = (from, to) =>
+ page.waitForFunction(
+ (lo, hi) => {
+ const frame = document
+ .querySelector("hyperframes-player")
+ .shadowRoot.querySelector("iframe");
+ const player = frame.contentWindow.__player;
+ const t = player.getTime();
+ return player.isPlaying() && t >= lo && t < hi;
+ },
+ { timeout: 30_000, polling: "raf" },
+ from,
+ to,
+ );
+
+ evidence.step = "paused at the start";
+ expectAroll("paused-start", await shoot("paused-start"));
+
+ evidence.step = "playing before the plate";
+ await page.click('button[aria-label="Play"]');
+ await playheadIn(1, PLATE_START_S - 1);
+ const playing = await shoot("playing");
+ if (!playing.after.playing || playing.after.time >= PLATE_START_S)
+ failures.push(
+ `playing: sampled at ${playing.after.time.toFixed(2)} s, not playing outside the plate`,
+ );
+ expectAroll("playing", playing);
+
+ // Without this the test would pass on a plate that never shows.
+ evidence.step = "playing inside the plate's window";
+ await playheadIn(PLATE_START_S + 0.1, PLATE_END_S - 0.5);
+ const plate = await shoot("playing-plate");
+ if (outsidePlate(plate.before.time) || outsidePlate(plate.after.time))
+ failures.push(`playing-plate: sample left the plate window (${plate.after.time.toFixed(2)} s)`);
+ if (plate.pixels.luma > 30 || plate.after.topId !== "plate")
+ failures.push(
+ `playing-plate: plate not shown (luma ${plate.pixels.luma}, on top "${plate.after.topId}")`,
+ );
+
+ evidence.step = "paused after the plate";
+ await playheadIn(PLATE_END_S + 0.2, 10);
+ await page.click('button[aria-label="Pause"]');
+ await page.waitForFunction(
+ () => {
+ const frame = document.querySelector("hyperframes-player").shadowRoot.querySelector("iframe");
+ const video = frame.contentDocument.getElementById("aroll");
+ return !frame.contentWindow.__player.isPlaying() && video.readyState >= 2 && !video.seeking;
+ },
+ { timeout: 10_000, polling: "raf" },
+ );
+ expectAroll("paused", await shoot("paused"));
+ evidence.step = "done";
+} catch (error) {
+ failures.push(`walk stopped at "${evidence.step}": ${error.message}`);
+ if (OUT_DIR) await (await browser.pages()).at(-1)?.screenshot({ path: `${OUT_DIR}/failed.png` });
+} finally {
+ await browser.close();
+}
+console.log(JSON.stringify({ evidence, failures }, null, 2));
+if (failures.length > 0) process.exit(1);
diff --git a/packages/studio/tests/e2e/fixtures/aroll-backdrop/assets/aroll.mp4 b/packages/studio/tests/e2e/fixtures/aroll-backdrop/assets/aroll.mp4
new file mode 100644
index 0000000000..2f24de9aae
Binary files /dev/null and b/packages/studio/tests/e2e/fixtures/aroll-backdrop/assets/aroll.mp4 differ
diff --git a/packages/studio/tests/e2e/fixtures/aroll-backdrop/compositions/outro-card.html b/packages/studio/tests/e2e/fixtures/aroll-backdrop/compositions/outro-card.html
new file mode 100644
index 0000000000..0a59f5602c
--- /dev/null
+++ b/packages/studio/tests/e2e/fixtures/aroll-backdrop/compositions/outro-card.html
@@ -0,0 +1,33 @@
+<template>
+ <div
+ id="outro-card-root"
+ data-composition-id="outro-card"
+ data-width="1080"
+ data-height="240"
+ data-start="0"
+ data-duration="5"
+ >
+ <style>
+ #outro-card-root {
+ position: absolute;
+ inset: 0;
+ font-family: Arial, sans-serif;
+ }
+ #outro-card-label {
+ position: absolute;
+ right: 60px;
+ top: 80px;
+ margin: 0;
+ font-size: 56px;
+ color: #fff;
+ }
+ </style>
+ <h2 id="outro-card-label">Chapter two</h2>
+ <script>
+ window.__timelines = window.__timelines || {};
+ window.__timelines["outro-card"] = gsap
+ .timeline({ paused: true })
+ .from("#outro-card-label", { y: -80, opacity: 0, duration: 0.6 }, 0);
+ </script>
+ </div>
+</template>
diff --git a/packages/studio/tests/e2e/fixtures/aroll-backdrop/compositions/title-card.html b/packages/studio/tests/e2e/fixtures/aroll-backdrop/compositions/title-card.html
new file mode 100644
index 0000000000..298c64599d
--- /dev/null
+++ b/packages/studio/tests/e2e/fixtures/aroll-backdrop/compositions/title-card.html
@@ -0,0 +1,33 @@
+<template>
+ <div
+ id="title-card-root"
+ data-composition-id="title-card"
+ data-width="1080"
+ data-height="240"
+ data-start="0"
+ data-duration="5"
+ >
+ <style>
+ #title-card-root {
+ position: absolute;
+ inset: 0;
+ font-family: Arial, sans-serif;
+ }
+ #title-card-label {
+ position: absolute;
+ left: 60px;
+ top: 80px;
+ margin: 0;
+ font-size: 56px;
+ color: #fff;
+ }
+ </style>
+ <h2 id="title-card-label">Chapter one</h2>
+ <script>
+ window.__timelines = window.__timelines || {};
+ window.__timelines["title-card"] = gsap
+ .timeline({ paused: true })
+ .from("#title-card-label", { x: -200, opacity: 0, duration: 0.6 }, 0);
+ </script>
+ </div>
+</template>
diff --git a/packages/studio/tests/e2e/fixtures/aroll-backdrop/hyperframes.json b/packages/studio/tests/e2e/fixtures/aroll-backdrop/hyperframes.json
new file mode 100644
index 0000000000..5fb1d6d872
--- /dev/null
+++ b/packages/studio/tests/e2e/fixtures/aroll-backdrop/hyperframes.json
@@ -0,0 +1,9 @@
+{
+ "$schema": "https://hyperframes.heygen.com/schema/hyperframes.json",
+ "registry": "https://raw.githubusercontent.com/heygen-com/hyperframes/main/registry",
+ "paths": {
+ "blocks": "compositions",
+ "components": "compositions/components",
+ "assets": "assets"
+ }
+}
diff --git a/packages/studio/tests/e2e/fixtures/aroll-backdrop/index.html b/packages/studio/tests/e2e/fixtures/aroll-backdrop/index.html
new file mode 100644
index 0000000000..55f5abb1e0
--- /dev/null
+++ b/packages/studio/tests/e2e/fixtures/aroll-backdrop/index.html
@@ -0,0 +1,126 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8" />
+ <title>A-roll under a script-hidden backdrop</title>
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js"></script>
+ <style>
+ html,
+ body {
+ width: 1080px;
+ height: 1920px;
+ margin: 0;
+ overflow: hidden;
+ background: #000;
+ }
+ #film {
+ position: relative;
+ width: 1080px;
+ height: 1920px;
+ overflow: hidden;
+ }
+ #aroll {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ z-index: 1;
+ }
+ #plate {
+ position: absolute;
+ inset: 0;
+ background: #0b0b0f;
+ z-index: 2;
+ visibility: hidden;
+ }
+ .card {
+ position: absolute;
+ left: 0;
+ top: 0;
+ width: 1080px;
+ height: 240px;
+ z-index: 3;
+ }
+ #caption {
+ position: absolute;
+ left: 60px;
+ right: 60px;
+ bottom: 160px;
+ z-index: 4;
+ margin: 0;
+ font:
+ 700 64px Arial,
+ sans-serif;
+ color: #fff;
+ text-align: center;
+ text-shadow: 0 4px 12px #000;
+ }
+ </style>
+ </head>
+ <body>
+ <div
+ id="film"
+ data-composition-id="aroll-film"
+ data-width="1080"
+ data-height="1920"
+ data-start="0"
+ data-duration="10"
+ data-fps="30"
+ >
+ <video
+ id="aroll"
+ class="clip"
+ src="assets/aroll.mp4"
+ loop
+ muted
+ playsinline
+ data-start="0"
+ data-duration="10"
+ data-track-index="0"
+ ></video>
+ <!-- Untimed full-frame backdrop above the A-roll; the script shows it from 6 s to 8 s only. -->
+ <div id="plate"></div>
+ <div
+ id="title-card"
+ class="card"
+ data-composition-id="title-card"
+ data-composition-src="compositions/title-card.html"
+ data-start="0"
+ data-duration="5"
+ data-track-index="1"
+ ></div>
+ <div
+ id="outro-card"
+ class="card"
+ data-composition-id="outro-card"
+ data-composition-src="compositions/outro-card.html"
+ data-start="5"
+ data-duration="5"
+ data-track-index="1"
+ ></div>
+ <p id="caption" class="clip" data-start="0" data-duration="10" data-track-index="2">
+ Captions stay above the backdrop
+ </p>
+ </div>
+ <script>
+ const plate = document.getElementById("plate");
+ const frame = { t: 0 };
+ const tl = gsap.timeline({ paused: true });
+ tl.to(frame, {
+ t: 10,
+ duration: 10,
+ ease: "none",
+ modifiers: {
+ t: (t) => {
+ plate.style.visibility = t >= 6 && t < 8 ? "visible" : "hidden";
+ return t;
+ },
+ },
+ });
+ tl.fromTo("#caption", { y: 40 }, { y: 0, duration: 0.5 }, 0);
+ window.__timelines = window.__timelines || {};
+ window.__timelines["aroll-film"] = tl;
+ </script>
+ </body>
+</html>