mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
fix(core): root-cause id-less media wash in timingCompiler getAttr, drop the band-aid (#1792)
* fix(core): root-cause the id-less media wash in getAttr, drop the band-aid The blank-wash/dropped-audio fix in #1790 added assignMissingMediaIds in the producer to stamp ids onto id-less timed media. That was a band-aid: the real cause is timingCompiler's getAttr, whose regex had no name boundary at all, so getAttr(tag, "id") matched the trailing id="…" inside data-hf-id="…". compileTag saw a phantom id and skipped its existing hf-video-N/hf-audio-N injection, leaving the element with no real el.id — which the render pipeline keys off of. Fix getAttr with the same (?<![\w-]) lookbehind used for the lint readAttr fix. compileTag's auto-id injection now fires for data-hf-id-only media, in both the main composition and sub-compositions (parseSubCompositions runs the same compileTimingAttrs pass), so assignMissingMediaIds is removed entirely. Extends the regression fixture with a standalone id-less <audio> (the dropped- audio side, previously untested) and raises minAudioCorrelation to 0.9. Adds a timingCompiler test for the data-hf-id/id boundary. * test(producer): use seeded pink noise (not a pure sine) for fixture audio A continuous sine anti-aligns under the audio cross-correlation (correlation -1.0 from a sub-period offset). Broadband seeded noise correlates robustly. * test: cover audio-side id injection via unit test; keep render fixture video-only The audio render-baseline used synthetic sine/noise, which anti-aligns under the harness audio cross-correlation (deterministic -1.0). Real audio fixtures are unaffected. Cover the audio side of the boundary fix with a deterministic timingCompiler unit test (id-less <audio> gets hf-audio-N) instead, and keep the render fixture video-only. * test(producer): regenerate baseline under the root fix (hf-video-N from compileTag)
This commit is contained in:
@@ -16,6 +16,29 @@ describe("compileTimingAttrs", () => {
|
||||
expect(unresolved).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("injects a real id when the element has only data-hf-id (not a phantom match)", () => {
|
||||
// Regression: getAttr(tag, "id") matched the trailing id="…" inside
|
||||
// data-hf-id="…" and returned a phantom, so compileTag skipped its
|
||||
// hf-video-N injection — leaving no real el.id and a blank-wash render.
|
||||
const html = '<video data-hf-id="hf-bgvideo01" src="a.mp4" data-start="0" data-duration="2">';
|
||||
const { html: compiled } = compileTimingAttrs(html);
|
||||
|
||||
expect(compiled).toContain('id="hf-video-0"');
|
||||
expect(compiled).toContain('data-hf-id="hf-bgvideo01"');
|
||||
expect(compiled).toContain('data-end="2"');
|
||||
});
|
||||
|
||||
it("injects a real id on an audio element that has only data-hf-id", () => {
|
||||
// Audio side of the same bug: the mixer selects `audio[id][src]`, so a
|
||||
// phantom-id match meant the element was dropped (silent). compileTag must
|
||||
// inject a real hf-audio-N so the mixer can find it.
|
||||
const html = '<audio data-hf-id="hf-bgaudio01" src="a.mp3" data-start="0" data-duration="2">';
|
||||
const { html: compiled } = compileTimingAttrs(html);
|
||||
|
||||
expect(compiled).toContain('id="hf-audio-0"');
|
||||
expect(compiled).toContain('data-hf-id="hf-bgaudio01"');
|
||||
});
|
||||
|
||||
it("leaves data-end unchanged when already present", () => {
|
||||
const html = '<video id="v1" src="a.mp4" data-start="0" data-end="3">';
|
||||
const { html: compiled, unresolved } = compileTimingAttrs(html);
|
||||
|
||||
@@ -60,7 +60,13 @@ export function shouldClampMediaDuration(declaredDuration: number, maxDuration:
|
||||
// ── Helpers ──────────────────────────────────────────────────────────────
|
||||
|
||||
function getAttr(tag: string, attr: string): string | null {
|
||||
const match = tag.match(new RegExp(`${attr}=["']([^"']+)["']`));
|
||||
// `(?<![\w-])` anchors the attribute name to a fresh start. Without it,
|
||||
// `getAttr(tag, "id")` matches the trailing `id="…"` inside `data-hf-id="…"`
|
||||
// (and "src" inside `data-src`, etc.) and returns a phantom value. That bug
|
||||
// made compileTag believe a Studio-stamped `data-hf-id`-only element already
|
||||
// had an `id`, so it skipped its `hf-video-N` injection — leaving the element
|
||||
// with no real `el.id`, which the render pipeline keys off of (blank wash).
|
||||
const match = tag.match(new RegExp(`(?<![\\w-])${attr}=["']([^"']+)["']`));
|
||||
return match ? (match[1] ?? null) : null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user