mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-07 01:56:04 +00:00
* feat: initial code port from hyperframes-internal Port all OSS-ready packages from the internal monorepo: - @hyperframes/core — shared types, HTML generation, GSAP utilities, runtime - @hyperframes/cli — CLI for creating, previewing, and rendering compositions - @hyperframes/engine — framework-agnostic rendering engine (BeginFrame + FFmpeg) - @hyperframes/producer — video rendering pipeline (Puppeteer + FFmpeg) - @hyperframes/ui-player — browser-based video player component - @hyperframes/studio — composition editor (React frontend + Hono backend) Includes regression test suite with Docker-based test harness. All HeyGen-internal references, deployment infrastructure, and proprietary assets have been removed. Package names migrated from @app/* to @hyperframes/*. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: scrub internal codenames and stale references from OSS port - Replace static.heygen.ai runtime URLs in test fixtures - Remove internal CDN publish script (publish-hyperframe-runtime.ts) - Replace sandbox-studio, sandbox-interceptor, __magicEditRuntime with neutral names (studio, hyperframe-runtime, __hyperframeRuntime) - Fix stale Vault API / localhost references in docs - Remove broken deprecated_studio link Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: remove remaining internal codenames and stale references - Delete stale producer README.md and PIPELINE.md (referenced nonexistent files) - Replace "Cerberus" codename with "HyperFrames" in test design reviews - Replace magic-edit postMessage identifiers with hf-preview/hf-parent - Rename debug-magic-edit-timeline.ts to debug-timeline.ts - Replace "Motion Cut" with "HyperFrames" in Timeline comments - Fix studio/CLI references to nonexistent archive package (use local data/projects/ dir, stub render proxy) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
119 lines
4.0 KiB
TypeScript
119 lines
4.0 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { installRuntimeControlBridge } from "./bridge";
|
|
|
|
function createMockDeps() {
|
|
return {
|
|
onPlay: vi.fn(),
|
|
onPause: vi.fn(),
|
|
onSeek: vi.fn(),
|
|
onSetMuted: vi.fn(),
|
|
onSetPlaybackRate: vi.fn(),
|
|
onEnablePickMode: vi.fn(),
|
|
onDisablePickMode: vi.fn(),
|
|
};
|
|
}
|
|
|
|
function makeControlMessage(action: string, extra?: Record<string, unknown>) {
|
|
return new MessageEvent("message", {
|
|
data: { source: "hf-parent", type: "control", action, ...extra },
|
|
});
|
|
}
|
|
|
|
describe("installRuntimeControlBridge", () => {
|
|
it("dispatches play command", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
handler(makeControlMessage("play"));
|
|
expect(deps.onPlay).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("dispatches pause command", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
handler(makeControlMessage("pause"));
|
|
expect(deps.onPause).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("dispatches seek command with frame and mode", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
handler(makeControlMessage("seek", { frame: 150, seekMode: "drag" }));
|
|
expect(deps.onSeek).toHaveBeenCalledWith(150, "drag");
|
|
});
|
|
|
|
it("seek defaults frame to 0 and seekMode to commit", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
handler(makeControlMessage("seek"));
|
|
expect(deps.onSeek).toHaveBeenCalledWith(0, "commit");
|
|
});
|
|
|
|
it("dispatches set-muted command", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
handler(makeControlMessage("set-muted", { muted: true }));
|
|
expect(deps.onSetMuted).toHaveBeenCalledWith(true);
|
|
});
|
|
|
|
it("dispatches set-playback-rate command", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
handler(makeControlMessage("set-playback-rate", { playbackRate: 2 }));
|
|
expect(deps.onSetPlaybackRate).toHaveBeenCalledWith(2);
|
|
});
|
|
|
|
it("defaults playbackRate to 1", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
handler(makeControlMessage("set-playback-rate"));
|
|
expect(deps.onSetPlaybackRate).toHaveBeenCalledWith(1);
|
|
});
|
|
|
|
it("dispatches enable-pick-mode", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
handler(makeControlMessage("enable-pick-mode"));
|
|
expect(deps.onEnablePickMode).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("dispatches disable-pick-mode", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
handler(makeControlMessage("disable-pick-mode"));
|
|
expect(deps.onDisablePickMode).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("ignores messages from wrong source", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
handler(new MessageEvent("message", {
|
|
data: { source: "other", type: "control", action: "play" },
|
|
}));
|
|
expect(deps.onPlay).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("ignores messages with wrong type", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
handler(new MessageEvent("message", {
|
|
data: { source: "hf-parent", type: "state", action: "play" },
|
|
}));
|
|
expect(deps.onPlay).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("ignores null data", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
handler(new MessageEvent("message", { data: null }));
|
|
expect(deps.onPlay).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("handles flash-elements command without crashing", () => {
|
|
const deps = createMockDeps();
|
|
const handler = installRuntimeControlBridge(deps);
|
|
expect(() =>
|
|
handler(makeControlMessage("flash-elements", { selectors: [".test"], duration: 500 }))
|
|
).not.toThrow();
|
|
});
|
|
});
|