mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-05 00:56:23 +00:00
Addresses R2 CHANGES_REQUESTED from Miga + Rames on PR #2529: 1. Sibling-surface gap (blocker): `hyperframes cloudrun render{,-batch}`, `hyperframes lambda render{,-batch}` all advertised the same tier-only aliases (`1080p` / `hd` / `4k` / `uhd`) but normalized them to `landscape` and never set `outputResolutionAspectAgnostic`. The distributed plumbing PR #2529 added received `undefined` from those callers, so portrait `1080p` still hit the original aspect-mismatch on Cloud Run / Lambda. Fix: introduce `resolveResolutionFlagPair` in `@hyperframes/parsers` (the single source of truth for the two-step normalize + aspect-agnostic detect) and route every distributed entrypoint through a shared `parseOutputResolutionFlag` CLI util so the alias signal now reaches `SerializableDistributedRenderConfig`. Studio Server keeps its canonical-only HTTP contract; that intent is now pinned in tests. 2. Preflight recompute (hardening): the earlier "downgrade aspect-mismatch" preflight cleared un-remapped mismatches, so IG 4:5 (non-preset aspect, no sibling) and portrait-4K comp + `--resolution 1080p` (remap + downsample) both slipped through to fail late in `resolveDeviceScaleFactor`. Now `checkRenderResolutionPreflight` computes the effective preset via `suggestMatchingPreset` (mirroring the compile stage's `adaptAspectAgnosticResolution`) and re-checks against that — only genuinely-fixable mismatches clear early. New tests pin both regressed input classes. 3. Docker forwarding boundary test (Miga's important #2): pinned `1080p` survives verbatim as `--resolution 1080p` in the Docker args so the in-container CLI can re-run `isAspectAgnosticResolutionAlias`. 4. Doc-nit (Miga): parsers/src/types.ts no longer references the nonexistent `resolveResolutionForComposition` — points at the actual remap helpers. Fallow: cloudrun.ts / lambda.ts share 390 lines of pre-existing structural symmetry (parallel AWS + GCP dispatchers), and lambda/render.ts + render-batch.ts declare parallel RenderArgs interfaces. Both re-flagged after threading the aspect-agnostic field through each surface; ignored with justification in .fallowrc.jsonc. lambda.ts's `run` and lambda/render.ts's `waitForCompletion` are pre-existing CRAP-score hotspots untouched by this PR — added under health.ignore. Co-Authored-By: Claude <noreply@anthropic.com> — Via
247 lines
11 KiB
TypeScript
247 lines
11 KiB
TypeScript
// @vitest-environment node
|
|
import { describe, it, expect } from "vitest";
|
|
import * as core from "./index.js";
|
|
|
|
describe("@hyperframes/core public API exports", () => {
|
|
describe("type-related constants and utilities", () => {
|
|
it("exports CANVAS_DIMENSIONS", () => {
|
|
expect(core.CANVAS_DIMENSIONS).toBeDefined();
|
|
expect(core.CANVAS_DIMENSIONS.landscape).toEqual({ width: 1920, height: 1080 });
|
|
expect(core.CANVAS_DIMENSIONS.portrait).toEqual({ width: 1080, height: 1920 });
|
|
expect(core.CANVAS_DIMENSIONS["landscape-4k"]).toEqual({ width: 3840, height: 2160 });
|
|
expect(core.CANVAS_DIMENSIONS["portrait-4k"]).toEqual({ width: 2160, height: 3840 });
|
|
expect(core.CANVAS_DIMENSIONS.square).toEqual({ width: 1080, height: 1080 });
|
|
expect(core.CANVAS_DIMENSIONS["square-4k"]).toEqual({ width: 2160, height: 2160 });
|
|
});
|
|
|
|
it("exports VALID_CANVAS_RESOLUTIONS derived from CANVAS_DIMENSIONS", () => {
|
|
expect(core.VALID_CANVAS_RESOLUTIONS).toEqual([
|
|
"landscape",
|
|
"portrait",
|
|
"landscape-4k",
|
|
"portrait-4k",
|
|
"square",
|
|
"square-4k",
|
|
]);
|
|
});
|
|
|
|
it("exports normalizeResolutionFlag with alias support", () => {
|
|
expect(core.normalizeResolutionFlag("4k")).toBe("landscape-4k");
|
|
expect(core.normalizeResolutionFlag("uhd")).toBe("landscape-4k");
|
|
expect(core.normalizeResolutionFlag("1080p")).toBe("landscape");
|
|
expect(core.normalizeResolutionFlag("landscape-4k")).toBe("landscape-4k");
|
|
expect(core.normalizeResolutionFlag("UHD")).toBe("landscape-4k");
|
|
expect(core.normalizeResolutionFlag("square")).toBe("square");
|
|
expect(core.normalizeResolutionFlag("square-4k")).toBe("square-4k");
|
|
expect(core.normalizeResolutionFlag("1080p-square")).toBe("square");
|
|
expect(core.normalizeResolutionFlag("4k-square")).toBe("square-4k");
|
|
expect(core.normalizeResolutionFlag("8k")).toBeUndefined();
|
|
expect(core.normalizeResolutionFlag(undefined)).toBeUndefined();
|
|
});
|
|
|
|
it("exports isAspectAgnosticResolutionAlias for tier-only aliases", () => {
|
|
// Tier-only aliases → true (orientation follows the composition).
|
|
expect(core.isAspectAgnosticResolutionAlias("1080p")).toBe(true);
|
|
expect(core.isAspectAgnosticResolutionAlias("hd")).toBe(true);
|
|
expect(core.isAspectAgnosticResolutionAlias("4k")).toBe(true);
|
|
expect(core.isAspectAgnosticResolutionAlias("uhd")).toBe(true);
|
|
// Case-insensitive.
|
|
expect(core.isAspectAgnosticResolutionAlias("1080P")).toBe(true);
|
|
expect(core.isAspectAgnosticResolutionAlias("UHD")).toBe(true);
|
|
// Orientation-suffixed aliases → false (user picked an orientation).
|
|
expect(core.isAspectAgnosticResolutionAlias("1080p-portrait")).toBe(false);
|
|
expect(core.isAspectAgnosticResolutionAlias("portrait-1080p")).toBe(false);
|
|
expect(core.isAspectAgnosticResolutionAlias("4k-square")).toBe(false);
|
|
expect(core.isAspectAgnosticResolutionAlias("1080p-square")).toBe(false);
|
|
// Canonical presets → false.
|
|
expect(core.isAspectAgnosticResolutionAlias("landscape")).toBe(false);
|
|
expect(core.isAspectAgnosticResolutionAlias("portrait")).toBe(false);
|
|
expect(core.isAspectAgnosticResolutionAlias("landscape-4k")).toBe(false);
|
|
// Unknown / empty / undefined → false.
|
|
expect(core.isAspectAgnosticResolutionAlias("8k")).toBe(false);
|
|
expect(core.isAspectAgnosticResolutionAlias("")).toBe(false);
|
|
expect(core.isAspectAgnosticResolutionAlias(undefined)).toBe(false);
|
|
});
|
|
|
|
it("exports resolveResolutionFlagPair — the pair every distributed entrypoint must forward", () => {
|
|
// The single source of truth every distributed adapter reads
|
|
// (`hyperframes cloudrun render`, `hyperframes lambda render`,
|
|
// `hyperframes lambda render-batch`). Divergent copies across those
|
|
// callers is what shipped the portrait-1080p failure this helper
|
|
// exists to prevent (PR #2529). Case-insensitive on the raw input.
|
|
expect(core.resolveResolutionFlagPair("1080p")).toEqual({
|
|
outputResolution: "landscape",
|
|
outputResolutionAspectAgnostic: true,
|
|
});
|
|
expect(core.resolveResolutionFlagPair("4K")).toEqual({
|
|
outputResolution: "landscape-4k",
|
|
outputResolutionAspectAgnostic: true,
|
|
});
|
|
// Canonical preset — aspect-agnostic stays false.
|
|
expect(core.resolveResolutionFlagPair("portrait")).toEqual({
|
|
outputResolution: "portrait",
|
|
outputResolutionAspectAgnostic: false,
|
|
});
|
|
// Orientation-suffixed alias — aspect-agnostic stays false.
|
|
expect(core.resolveResolutionFlagPair("1080p-portrait")).toEqual({
|
|
outputResolution: "portrait",
|
|
outputResolutionAspectAgnostic: false,
|
|
});
|
|
// Unknown / empty / undefined → both fields degrade cleanly so
|
|
// callers can produce their own "invalid" UX.
|
|
expect(core.resolveResolutionFlagPair("8k")).toEqual({
|
|
outputResolution: undefined,
|
|
outputResolutionAspectAgnostic: false,
|
|
});
|
|
expect(core.resolveResolutionFlagPair(undefined)).toEqual({
|
|
outputResolution: undefined,
|
|
outputResolutionAspectAgnostic: false,
|
|
});
|
|
});
|
|
|
|
it("exports TIMELINE_COLORS", () => {
|
|
expect(core.TIMELINE_COLORS).toBeDefined();
|
|
expect(core.TIMELINE_COLORS.video).toBeDefined();
|
|
expect(core.TIMELINE_COLORS.image).toBeDefined();
|
|
expect(core.TIMELINE_COLORS.text).toBeDefined();
|
|
expect(core.TIMELINE_COLORS.audio).toBeDefined();
|
|
expect(core.TIMELINE_COLORS.composition).toBeDefined();
|
|
});
|
|
|
|
it("exports DEFAULT_DURATIONS", () => {
|
|
expect(core.DEFAULT_DURATIONS).toBeDefined();
|
|
expect(core.DEFAULT_DURATIONS.video).toBe(5);
|
|
expect(core.DEFAULT_DURATIONS.text).toBe(2);
|
|
});
|
|
|
|
it("exports type guard functions", () => {
|
|
expect(typeof core.isTextElement).toBe("function");
|
|
expect(typeof core.isMediaElement).toBe("function");
|
|
expect(typeof core.isCompositionElement).toBe("function");
|
|
});
|
|
|
|
it("exports getDefaultStageZoom", () => {
|
|
expect(typeof core.getDefaultStageZoom).toBe("function");
|
|
const zoom = core.getDefaultStageZoom("landscape");
|
|
expect(zoom.scale).toBe(1);
|
|
expect(zoom.focusX).toBe(960);
|
|
expect(zoom.focusY).toBe(540);
|
|
});
|
|
});
|
|
|
|
describe("template exports", () => {
|
|
it("exports generateBaseHtml", () => {
|
|
expect(typeof core.generateBaseHtml).toBe("function");
|
|
});
|
|
|
|
it("exports getStageStyles", () => {
|
|
expect(typeof core.getStageStyles).toBe("function");
|
|
});
|
|
|
|
it("exports template constants", () => {
|
|
expect(core.GSAP_CDN).toBeDefined();
|
|
expect(core.BASE_STYLES).toBeDefined();
|
|
expect(core.ELEMENT_BASE_STYLES).toBeDefined();
|
|
expect(core.MEDIA_STYLES).toBeDefined();
|
|
expect(core.TEXT_STYLES).toBeDefined();
|
|
expect(core.ZOOM_CONTAINER_STYLES).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe("parser exports", () => {
|
|
it("does NOT re-export GSAP parser functions from barrel (available via gsap-parser subpath)", () => {
|
|
// GSAP AST parser functions are not re-exported from the barrel —
|
|
// use the acorn parser (gsapParserAcorn) or writer (gsapWriterAcorn) directly.
|
|
expect(typeof (core as Record<string, unknown>).parseGsapScript).toBe("undefined");
|
|
});
|
|
|
|
it("does NOT re-export GSAP constants from barrel (available via gsap-constants subpath)", () => {
|
|
expect((core as Record<string, unknown>).SUPPORTED_PROPS).toBeUndefined();
|
|
});
|
|
|
|
it("exports HTML parser functions", () => {
|
|
expect(typeof core.parseHtml).toBe("function");
|
|
expect(typeof core.updateElementInHtml).toBe("function");
|
|
expect(typeof core.addElementToHtml).toBe("function");
|
|
expect(typeof core.removeElementFromHtml).toBe("function");
|
|
expect(typeof core.validateCompositionHtml).toBe("function");
|
|
expect(typeof core.extractCompositionMetadata).toBe("function");
|
|
});
|
|
});
|
|
|
|
describe("generator exports", () => {
|
|
it("exports hyperframes generator functions", () => {
|
|
expect(typeof core.generateHyperframesHtml).toBe("function");
|
|
expect(typeof core.generateGsapTimelineScript).toBe("function");
|
|
expect(typeof core.generateHyperframesStyles).toBe("function");
|
|
});
|
|
});
|
|
|
|
describe("compiler exports", () => {
|
|
it("exports compiler functions", () => {
|
|
expect(typeof core.compileTimingAttrs).toBe("function");
|
|
expect(typeof core.injectDurations).toBe("function");
|
|
expect(typeof core.extractResolvedMedia).toBe("function");
|
|
expect(typeof core.clampDurations).toBe("function");
|
|
expect(typeof core.shouldClampMediaDuration).toBe("function");
|
|
expect(typeof core.shouldClampResolvedMediaDuration).toBe("function");
|
|
});
|
|
});
|
|
|
|
describe("lint exports", () => {
|
|
it("exposes lintHyperframeHtml via the @hyperframes/core/lint back-compat stub", async () => {
|
|
// Lint moved to @hyperframes/lint; core's main entry no longer re-exports
|
|
// it (that would cycle through the lint package). The subpath stub keeps
|
|
// existing @hyperframes/core/lint imports working.
|
|
const lint = await import("./lint/index.js");
|
|
expect(typeof lint.lintHyperframeHtml).toBe("function");
|
|
});
|
|
});
|
|
|
|
describe("media exports", () => {
|
|
it("exports parseAnimatedGifMetadata", () => {
|
|
expect(typeof core.parseAnimatedGifMetadata).toBe("function");
|
|
});
|
|
});
|
|
|
|
describe("inline-script exports", () => {
|
|
it("exports hyperframe runtime artifacts", () => {
|
|
expect(core.HYPERFRAME_RUNTIME_ARTIFACTS).toBeDefined();
|
|
expect(core.HYPERFRAME_RUNTIME_CONTRACT).toBeDefined();
|
|
expect(typeof core.loadHyperframeRuntimeSource).toBe("function");
|
|
});
|
|
|
|
it("exports runtime contract constants", () => {
|
|
expect(core.HYPERFRAME_RUNTIME_GLOBALS).toBeDefined();
|
|
expect(core.HYPERFRAME_BRIDGE_SOURCES).toBeDefined();
|
|
expect(core.HYPERFRAME_CONTROL_ACTIONS).toBeDefined();
|
|
});
|
|
|
|
it("exports buildHyperframesRuntimeScript", () => {
|
|
expect(typeof core.buildHyperframesRuntimeScript).toBe("function");
|
|
});
|
|
|
|
it("exports MEDIA_VISUAL_STYLE_PROPERTIES", () => {
|
|
expect(core.MEDIA_VISUAL_STYLE_PROPERTIES).toBeDefined();
|
|
expect(Array.isArray(core.MEDIA_VISUAL_STYLE_PROPERTIES)).toBe(true);
|
|
expect(core.MEDIA_VISUAL_STYLE_PROPERTIES).toContain("width");
|
|
expect(core.MEDIA_VISUAL_STYLE_PROPERTIES).toContain("opacity");
|
|
expect(core.MEDIA_VISUAL_STYLE_PROPERTIES).toContain("transform");
|
|
});
|
|
|
|
it("exports copyMediaVisualStyles", () => {
|
|
expect(typeof core.copyMediaVisualStyles).toBe("function");
|
|
});
|
|
|
|
it("exports quantizeTimeToFrame", () => {
|
|
expect(typeof core.quantizeTimeToFrame).toBe("function");
|
|
});
|
|
});
|
|
|
|
describe("adapter exports", () => {
|
|
it("exports createGSAPFrameAdapter", () => {
|
|
expect(typeof core.createGSAPFrameAdapter).toBe("function");
|
|
});
|
|
});
|
|
});
|