|
2 | 2 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 3 | import { readFileSync } from "node:fs"; |
4 | 4 | import { initSandboxRuntimeModular } from "./init"; |
| 5 | +import { collectRuntimeTimelinePayload } from "./timeline"; |
5 | 6 | import { TYPEGPU_PRESENT_HEARTBEAT_MS } from "./adapters/typegpu"; |
6 | 7 | import { WebAudioTransport } from "./webAudioTransport"; |
7 | 8 | import type { RuntimeTimelineLike } from "./types"; |
@@ -2199,6 +2200,83 @@ describe("initSandboxRuntimeModular", () => { |
2199 | 2200 | expect(pipVideo.style.visibility).toBe("hidden"); |
2200 | 2201 | }); |
2201 | 2202 |
|
| 2203 | + // The clip manifest the studio timeline draws and the runtime that actually |
| 2204 | + // plays the media must resolve a media element's absolute start through the |
| 2205 | + // same function. When they disagree the editor is a lie: the clip is drawn at |
| 2206 | + // one time and plays at another, and nothing fails. |
| 2207 | + // |
| 2208 | + // Both cases below are read from the SAME DOM the runtime just initialised, |
| 2209 | + // so the expected value is whatever playback uses, never a hardcoded number. |
| 2210 | + it("reports the same media start in the clip manifest as the runtime plays at", () => { |
| 2211 | + const root = document.createElement("div"); |
| 2212 | + root.setAttribute("data-composition-id", "main"); |
| 2213 | + root.setAttribute("data-root", "true"); |
| 2214 | + root.setAttribute("data-start", "0"); |
| 2215 | + document.body.appendChild(root); |
| 2216 | + |
| 2217 | + const host = document.createElement("div"); |
| 2218 | + host.setAttribute("data-composition-id", "scene-pip"); |
| 2219 | + host.setAttribute("data-composition-file", "compositions/pip.html"); |
| 2220 | + host.setAttribute("data-start", "45.40"); |
| 2221 | + host.setAttribute("data-duration", "7.06"); |
| 2222 | + root.appendChild(host); |
| 2223 | + |
| 2224 | + // Legacy root-global authoring: data-start is already absolute, so the host |
| 2225 | + // offset must NOT be added on top of it. |
| 2226 | + const pipVideo = document.createElement("video"); |
| 2227 | + pipVideo.id = "pip"; |
| 2228 | + pipVideo.setAttribute("data-start", "45.40"); |
| 2229 | + pipVideo.setAttribute("data-hf-media-start-basis", "global"); |
| 2230 | + pipVideo.setAttribute("data-duration", "7.06"); |
| 2231 | + host.appendChild(pipVideo); |
| 2232 | + |
| 2233 | + window.__timelines = { |
| 2234 | + main: createMockTimeline(60), |
| 2235 | + "scene-pip": createMockTimeline(7.06), |
| 2236 | + }; |
| 2237 | + initSandboxRuntimeModular(); |
| 2238 | + |
| 2239 | + const runtimeStart = window.__hfResolveMediaStartSeconds?.(pipVideo); |
| 2240 | + const manifestClip = collectRuntimeTimelinePayload({ canonicalFps: 30 }).clips.find( |
| 2241 | + (clip) => clip.id === "pip", |
| 2242 | + ); |
| 2243 | + expect(runtimeStart).toBeCloseTo(45.4); |
| 2244 | + expect(manifestClip?.start).toBeCloseTo(runtimeStart!); |
| 2245 | + }); |
| 2246 | + |
| 2247 | + it("keeps a composition-local media clip in the manifest at the time it plays", () => { |
| 2248 | + const root = document.createElement("div"); |
| 2249 | + root.setAttribute("data-composition-id", "main"); |
| 2250 | + root.setAttribute("data-root", "true"); |
| 2251 | + root.setAttribute("data-start", "0"); |
| 2252 | + document.body.appendChild(root); |
| 2253 | + |
| 2254 | + // No data-duration and no registered timeline anywhere, so the media window |
| 2255 | + // IS the composition's duration — which is what the second, attribute-only |
| 2256 | + // start derivation used to get wrong. |
| 2257 | + const host = document.createElement("div"); |
| 2258 | + host.setAttribute("data-composition-id", "scene-a"); |
| 2259 | + host.setAttribute("data-start", "10"); |
| 2260 | + root.appendChild(host); |
| 2261 | + |
| 2262 | + const nested = document.createElement("video"); |
| 2263 | + nested.id = "nested"; |
| 2264 | + nested.setAttribute("data-start", "2"); |
| 2265 | + nested.setAttribute("data-duration", "3"); |
| 2266 | + host.appendChild(nested); |
| 2267 | + |
| 2268 | + window.__timelines = {}; |
| 2269 | + initSandboxRuntimeModular(); |
| 2270 | + |
| 2271 | + const runtimeStart = window.__hfResolveMediaStartSeconds?.(nested); |
| 2272 | + const manifestClip = collectRuntimeTimelinePayload({ canonicalFps: 30 }).clips.find( |
| 2273 | + (clip) => clip.id === "nested", |
| 2274 | + ); |
| 2275 | + expect(runtimeStart).toBeCloseTo(12); |
| 2276 | + expect(manifestClip?.start).toBeCloseTo(runtimeStart!); |
| 2277 | + expect(manifestClip?.duration).toBeCloseTo(3); |
| 2278 | + }); |
| 2279 | + |
2202 | 2280 | it("shows auto-injected video at host time, not at t=0", () => { |
2203 | 2281 | const root = document.createElement("div"); |
2204 | 2282 | root.setAttribute("data-composition-id", "main"); |
|
0 commit comments