fix(lint): derive the root duration with the parser's timing reader (#8032)

* fix(lint): derive the root duration with the parser's timing reader

`deriveDurationFromClips` read `data-start` with a raw `Number()`, so a clip
authored at `data-start="-2"` produced an end of `-1`. `resolveCompositionDuration`
only counts positive ends, so the clip vanished from the derivation and the
composition was reported as having no duration source at all — a hard error that
blocks strict renders, even though the parser clamps the same start to zero and
renders the clip for its full length.

Read the start through `readClipTiming`, the same contract parser the renderer
uses, and keep the media-duration default for untimed images.

* fix(lint): derive the root duration with the parser's timing reader

`deriveDurationFromClips` read `data-start` with a raw `Number()`, so a clip
authored at `data-start="-2"` produced a negative end and vanished from the
derivation. Read the start through `readClipTiming`, which clamps it to zero,
and keep `readAuthoredDurationSeconds` for the authored length so a valid
`data-end` still backs an unparseable `data-duration`.
This commit is contained in:
zhengqiuyang
2026-11-17 17:08:08 +00:00
committed by GitHub
parent b22ca1a58e
commit 401991669d
2 changed files with 32 additions and 6 deletions
@@ -1978,6 +1978,32 @@ ${Array.from({ length: 10 }, (_, i) => ` <div class="clip" data-start="${i}"
expect(derived?.message).toContain("2 clip(s) whose length is only known at runtime");
});
it("falls back to a valid data-end when data-duration is not numeric", async () => {
const html = `<html><body>
<div data-composition-id="main" data-start="0" data-width="1920" data-height="1080">
<div class="clip" data-start="0" data-duration="abc" data-end="4"></div>
</div>
</body></html>`;
const result = await lintHyperframeHtml(html);
expect(find(result.findings)).toBeUndefined();
expect(
result.findings.find((f) => f.code === "root_composition_duration_derived")?.message,
).toContain("at least 4s");
});
it("derives from a negative start like the parser does", async () => {
const html = `<html><body>
<div data-composition-id="main" data-start="0" data-width="1920" data-height="1080">
<div class="clip" data-start="-2" data-duration="1"></div>
</div>
</body></html>`;
const result = await lintHyperframeHtml(html);
expect(find(result.findings)).toBeUndefined();
expect(
result.findings.find((f) => f.code === "root_composition_duration_derived")?.message,
).toContain("at least 1s");
});
it("does not count a clip whose data-end is before its start", async () => {
const html = `<html><body>
<div data-composition-id="main" data-start="0" data-width="1920" data-height="1080">
+6 -6
View File
@@ -1975,15 +1975,15 @@ function deriveDurationFromClips(tags: OpenTag[], rootTag: OpenTag) {
const clipEnds: Array<number | null> = [];
for (const tag of tags) {
if (tag === rootTag) continue;
const startRaw = readAttr(tag.raw, "data-start");
if (startRaw === null) continue;
const start = Number(startRaw);
// A reference start ("intro+2") is resolved by the runtime; here it is a clip of unknown end.
if (!Number.isFinite(start)) {
const getAttr = (name: string) => readAttr(tag.raw, name);
if (getAttr("data-start") === null) continue;
const timing = readTagTiming(tag.raw);
// A reference start is resolved by the runtime; here it is a clip of unknown end.
if (timing.start === null) {
clipEnds.push(null);
continue;
}
const getAttr = (name: string) => readAttr(tag.raw, name);
const start = timing.start;
const authored = readAuthoredDurationSeconds(getAttr, start);
if (CLIP_MEDIA_TAGS.has(tag.name)) {
const { seconds } = resolveMediaDuration({