Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(lint): a missing image, audio or mask file names the composition that references it (#4616)
Miguel Ángel7eb00137a22e
diff --git a/packages/cli/src/utils/lintProject.test.ts b/packages/cli/src/utils/lintProject.test.tsindex ba4fd8dd07..9e5e959076 100644--- a/packages/cli/src/utils/lintProject.test.ts+++ b/packages/cli/src/utils/lintProject.test.ts@@ -514,7 +514,7 @@ describe("audio_src_not_found", () => {expect(finding).toBeDefined();});- it("deduplicates missing files across compositions", async () => {+ it("reports a missing file once per composition that references it", async () => {const project = makeProject(validHtmlWithAudio(), {"captions.html": validHtmlWithAudio("captions"),});@@ -522,13 +522,13 @@ describe("audio_src_not_found", () => {const { results } = await lintProject(project);- const first = results[0];- expect(first).toBeDefined();- const finding = first?.result.findings.find((f) => f.code === "audio_src_not_found");- expect(finding).toBeDefined();- // Should mention song.mp3 only once despite two references- const occurrences = (finding?.message.match(/song\.mp3/g) ?? []).length;- expect(occurrences).toBe(1);+ const findings = results+ .flatMap((entry) => entry.result.findings)+ .filter((f) => f.code === "audio_src_not_found");+ expect(findings.map((f) => f.file).sort()).toEqual(+ [join(project, "compositions", "captions.html"), join(project, "index.html")].sort(),+ );+ for (const finding of findings) expect(finding.message.match(/song\.mp3/g)).toHaveLength(1);});it("resolves sub-composition src relative to the sub-composition file (../assets/...)", async () => {@@ -715,7 +715,7 @@ describe("missing_local_asset", () => {expect(finding).toBeUndefined();});- it("deduplicates the same missing src across multiple compositions", async () => {+ it("reports the same missing src once per composition that references it", async () => {const project = makeProject(`<html><body><div data-composition-id="main" data-width="1920" data-height="1080">@@ -741,11 +741,17 @@ describe("missing_local_asset", () => {const { results } = await lintProject(project);- const finding = results[0]?.result.findings.find((f) => f.code === "missing_local_asset");- expect(finding).toBeDefined();- // x.png mentioned only once despite three references- const occurrences = (finding?.message.match(/x\.png/g) ?? []).length;- expect(occurrences).toBe(1);+ const findings = results+ .flatMap((entry) => entry.result.findings)+ .filter((f) => f.code === "missing_local_asset");+ expect(findings.map((f) => f.file).sort()).toEqual(+ [+ join(project, "compositions", "scene-a.html"),+ join(project, "compositions", "scene-b.html"),+ join(project, "index.html"),+ ].sort(),+ );+ for (const finding of findings) expect(finding.message.match(/x\.png/g)).toHaveLength(1);});it("emits separate findings per tag type (img + video) for clear messaging", async () => {diff --git a/packages/lint/src/project.test.ts b/packages/lint/src/project.test.tsindex bc3f38ccdb..5e60cca0a3 100644--- a/packages/lint/src/project.test.ts+++ b/packages/lint/src/project.test.ts@@ -663,6 +663,40 @@ describe("video_media_start_at_or_past_eof", () => {});});+describe("missing asset findings name the file that references them", () => {+ it("points a draft section's missing image, audio and mask at the draft, not the film", async () => {+ const project = makeProject(+ `<html><body>+ <div data-composition-id="main" data-width="1920" data-height="1080" data-start="0" data-duration="10">+ <img src="assets/missing-in-film.png" />+ <div data-composition-src="compositions/draft.html" data-composition-id="draft" data-start="0" data-duration="5"></div>+ </div>+</body></html>`,+ {+ "draft.html": `<!doctype html><html><body>+ <div data-composition-id="draft" data-width="1920" data-height="1080">+ <style>.masked { mask-image: url(../assets/missing-mask.png); }</style>+ <img src="../assets/missing-in-draft.png" />+ <audio src="../assets/missing-in-draft.mp3" data-start="0" data-duration="5"></audio>+ </div>+</body></html>`,+ },+ );++ const { results } = await lintProject(project);+ const fileOf = (code: string, name: string) =>+ results+ .flatMap((entry) => entry.result.findings)+ .find((finding) => finding.code === code && finding.message.includes(name))?.file;++ const draft = join(project, "compositions", "draft.html");+ expect(fileOf("missing_local_asset", "missing-in-draft.png")).toBe(draft);+ expect(fileOf("audio_src_not_found", "missing-in-draft.mp3")).toBe(draft);+ expect(fileOf("texture_mask_asset_not_found", "missing-mask.png")).toBe(draft);+ expect(fileOf("missing_local_asset", "missing-in-film.png")).toBe(join(project, "index.html"));+ });+});+describe("audio_src_not_found with templating tokens", () => {// A src carrying an unresolved templating placeholder is late-bound before render,// so the static linter cannot resolve it to a file and must not report it missing.diff --git a/packages/lint/src/project.ts b/packages/lint/src/project.tsindex d4d996e575..fa7738b54f 100644--- a/packages/lint/src/project.ts+++ b/packages/lint/src/project.ts@@ -35,6 +35,10 @@ function parseSubCompHtml(html: string): ParsableDocumentLike {return parseHTML(html).document as unknown as ParsableDocumentLike;}+/** The file a source was read from, as per-file findings carry it. */+const sourceFile = (projectDir: string, compSrcPath?: string) =>+ resolve(projectDir, compSrcPath ?? "index.html");+interface HtmlSource {html: string;compSrcPath?: string;@@ -357,7 +361,7 @@ function lintAudioSrcNotFound(const audioSrcRe = mediaSrcTagRe("audio");- const missingSrcs: string[] = [];+ const missingByFile = new Map<string, Set<string>>();for (const { html, compSrcPath } of htmlSources) {let match: RegExpExecArray | null;while ((match = audioSrcRe.exec(html)) !== null) {@@ -368,16 +372,18 @@ function lintAudioSrcNotFound(? rewriteAssetPath(compSrcPath, src, (path) => existsSync(join(projectDir, path))): src;if (!existsSync(resolveProjectRelativeSrc(rootRelative, projectDir))) {- missingSrcs.push(src);+ const file = sourceFile(projectDir, compSrcPath);+ missingByFile.set(file, (missingByFile.get(file) ?? new Set()).add(src));}}}- if (missingSrcs.length > 0) {- const unique = [...new Set(missingSrcs)];+ for (const [file, srcs] of missingByFile) {+ const unique = [...srcs];findings.push({code: "audio_src_not_found",severity: "error",+ file,message: `<audio> element references file(s) not found in the project: ${unique.join(", ")}. The rendered video will be silent.`,fixHint:unique.length === 1@@ -398,7 +404,10 @@ function lintMissingLocalAsset(const localAssetSrcRe = mediaSrcTagRe("video|img|source");- const missingByTag = new Map<string, Map<string, string>>();+ const missingByTag = new Map<+ string,+ { file: string; tagName: string; byResolved: Map<string, string> }+ >();for (const { html, compSrcPath } of htmlSources) {const scannable = maskNonScannableRanges(html);@@ -419,20 +428,23 @@ function lintMissingLocalAsset(if (resolvedAsset) continue;const resolvedKey = resolve(projectDir, rootRelative);- let bucket = missingByTag.get(tagName);+ const file = sourceFile(projectDir, compSrcPath);+ const bucketKey = `${file}\0${tagName}`;+ let bucket = missingByTag.get(bucketKey);if (!bucket) {- bucket = new Map<string, string>();- missingByTag.set(tagName, bucket);+ bucket = { file, tagName, byResolved: new Map<string, string>() };+ missingByTag.set(bucketKey, bucket);}- if (!bucket.has(resolvedKey)) bucket.set(resolvedKey, src);+ if (!bucket.byResolved.has(resolvedKey)) bucket.byResolved.set(resolvedKey, src);}}- for (const [tagName, byResolved] of missingByTag) {+ for (const { file, tagName, byResolved } of missingByTag.values()) {const unique = [...byResolved.values()];findings.push({code: "missing_local_asset",severity: "error",+ file,message:`<${tagName}> element references local file(s) not found in the project: ${unique.join(", ")}. ` +"The renderer will silently skip these and produce a video with missing visuals.",@@ -453,9 +465,10 @@ function lintTextureMaskAssetNotFound(projectDir: string,htmlSources: HtmlSource[],): HyperframeLintFinding[] {- const missing = new Map<string, string>();+ const missingByFile = new Map<string, Set<string>>();for (const { html, compSrcPath } of htmlSources) {+ const file = sourceFile(projectDir, compSrcPath);for (const cssSource of collectCssSources(projectDir, html, compSrcPath)) {let match: RegExpExecArray | null;const pattern = new RegExp(MASK_IMAGE_URL_RE.source, MASK_IMAGE_URL_RE.flags);@@ -473,24 +486,24 @@ function lintTextureMaskAssetNotFound(cssSource.rootRelativePath,);if (candidates.some(existsSync)) continue;- missing.set(url, candidates[0] ?? resolve(projectDir, url));+ missingByFile.set(file, (missingByFile.get(file) ?? new Set()).add(url));}}}- if (missing.size === 0) return [];- const urls = [...missing.keys()];- return [- {+ return [...missingByFile].map(([file, found]): HyperframeLintFinding => {+ const urls = [...found];+ return {code: "texture_mask_asset_not_found",severity: "error",+ file,message: `CSS mask-image references file(s) not found in the project: ${urls.join(", ")}.`,fixHint:urls.length === 1? `Add "${urls[0]}" to the project, or update the mask-image URL to point to an existing texture mask.`: "Add the missing texture mask files to the project, or update the mask-image URLs to point to existing files.",- },- ];+ };+ });}function lintMultipleRootCompositions(projectDir: string): HyperframeLintFinding[] {