Skip to content

Write HTML. Render video. Built for agents.

fix(lint): Studio's lint panel and the CLI label a finding by the composition it names (#4618)

Miguel Ángel27f1cfd23eac
diff --git a/packages/cli/src/utils/lintFormat.test.ts b/packages/cli/src/utils/lintFormat.test.ts
index cb625ba4cc..1c31b5417b 100644
--- a/packages/cli/src/utils/lintFormat.test.ts
+++ b/packages/cli/src/utils/lintFormat.test.ts
@@ -1,7 +1,10 @@
-import { describe, expect, it } from "vitest";
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { describe, expect, it, onTestFinished } from "vitest";
import type { HyperframeLintFinding } from "@hyperframes/core/lint";
import { formatLintFindings, formatLintStartupMessage } from "./lintFormat.js";
-import type { ProjectLintResult } from "./lintProject.js";
+import { lintProject, type ProjectLintResult } from "./lintProject.js";
function finding(
severity: HyperframeLintFinding["severity"],
@@ -246,3 +249,24 @@ it("prints source coordinates for a single-file finding", () => {
]);
expect(formatLintFindings(result)[0]).toContain("index.html:5:3");
});
+
+describe("formatLintFindings on a real project", () => {
+ it("labels a draft section's missing image with the draft, not index.html", async () => {
+ const dir = mkdtempSync(join(tmpdir(), "hf-lint-format-draft-"));
+ onTestFinished(() => rmSync(dir, { recursive: true, force: true }));
+ mkdirSync(join(dir, "compositions"));
+ writeFileSync(
+ join(dir, "index.html"),
+ `<html><body><div data-composition-id="main" data-width="1920" data-height="1080"><div data-composition-src="compositions/draft.html" data-composition-id="draft" data-start="0" data-duration="5"></div></div></body></html>`,
+ );
+ writeFileSync(
+ join(dir, "compositions", "draft.html"),
+ `<html><body><div data-composition-id="draft" data-width="1920" data-height="1080"><img src="../assets/missing.png" /></div></body></html>`,
+ );
+
+ const lines = formatLintFindings(await lintProject(dir));
+
+ const line = lines.find((l) => l.includes("missing.png"));
+ expect(line).toContain("[compositions/draft.html]");
+ });
+});
diff --git a/packages/cli/src/utils/lintProject.test.ts b/packages/cli/src/utils/lintProject.test.ts
index 9e5e959076..d468a66bb3 100644
--- a/packages/cli/src/utils/lintProject.test.ts
+++ b/packages/cli/src/utils/lintProject.test.ts
@@ -37,6 +37,10 @@ function htmlWithPreloadNone(): string {
let dirs: string[] = [];
+// Project-wide findings are filed under the composition they name, so look across every entry.
+const allFindings = (results: Array<{ result: { findings: HyperframeLintFinding[] } }>) =>
+ results.flatMap((entry) => entry.result.findings);
+
function makeProject(indexHtml: string, subComps?: Record<string, string>): string {
const dir = tmpProject("lint");
dirs.push(dir);
@@ -403,9 +407,7 @@ describe("audio_src_not_found", () => {
const { totalErrors, results } = await lintProject(project);
expect(totalErrors).toBeGreaterThan(0);
- const first = results[0];
- expect(first).toBeDefined();
- const finding = first?.result.findings.find((f) => f.code === "audio_src_not_found");
+ const finding = allFindings(results).find((f) => f.code === "audio_src_not_found");
expect(finding).toBeDefined();
expect(finding?.severity).toBe("error");
expect(finding?.message).toContain("song.mp3");
@@ -417,9 +419,7 @@ 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");
+ const finding = allFindings(results).find((f) => f.code === "audio_src_not_found");
expect(finding).toBeUndefined();
});
@@ -434,9 +434,7 @@ 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");
+ const finding = allFindings(results).find((f) => f.code === "audio_src_not_found");
expect(finding).toBeUndefined();
});
@@ -449,9 +447,7 @@ describe("audio_src_not_found", () => {
const { totalErrors, results } = await lintProject(project);
expect(totalErrors).toBeGreaterThan(0);
- const first = results[0];
- expect(first).toBeDefined();
- const finding = first?.result.findings.find((f) => f.code === "audio_src_not_found");
+ const finding = allFindings(results).find((f) => f.code === "audio_src_not_found");
expect(finding).toBeDefined();
});
@@ -468,9 +464,7 @@ 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");
+ const finding = allFindings(results).find((f) => f.code === "audio_src_not_found");
expect(finding).toBeUndefined();
});
@@ -483,9 +477,7 @@ 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");
+ const finding = allFindings(results).find((f) => f.code === "audio_src_not_found");
expect(finding).toBeUndefined();
});
@@ -497,9 +489,7 @@ 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");
+ const finding = allFindings(results).find((f) => f.code === "audio_src_not_found");
expect(finding).toBeUndefined();
});
@@ -510,7 +500,7 @@ describe("audio_src_not_found", () => {
const { results } = await lintProject(project);
- const finding = results[0]?.result.findings.find((f) => f.code === "audio_src_not_found");
+ const finding = allFindings(results).find((f) => f.code === "audio_src_not_found");
expect(finding).toBeDefined();
});
@@ -547,9 +537,7 @@ 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");
+ const finding = allFindings(results).find((f) => f.code === "audio_src_not_found");
expect(finding).toBeUndefined();
});
@@ -565,9 +553,7 @@ 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");
+ const finding = allFindings(results).find((f) => f.code === "audio_src_not_found");
expect(finding).toBeDefined();
// The original (un-rewritten) src is what surfaces in the message so the
// author can grep for it in their HTML.
@@ -588,7 +574,7 @@ describe("missing_local_asset", () => {
const { totalErrors, results } = await lintProject(project);
expect(totalErrors).toBeGreaterThan(0);
- const finding = results[0]?.result.findings.find((f) => f.code === "missing_local_asset");
+ const finding = allFindings(results).find((f) => f.code === "missing_local_asset");
expect(finding).toBeDefined();
expect(finding?.severity).toBe("error");
expect(finding?.message).toContain("hero.png");
@@ -607,7 +593,7 @@ describe("missing_local_asset", () => {
const { totalErrors, results } = await lintProject(project);
expect(totalErrors).toBeGreaterThan(0);
- const finding = results[0]?.result.findings.find((f) => f.code === "missing_local_asset");
+ const finding = allFindings(results).find((f) => f.code === "missing_local_asset");
expect(finding).toBeDefined();
expect(finding?.message).toContain("clip.mp4");
expect(finding?.message).toContain("<video>");
@@ -625,7 +611,7 @@ describe("missing_local_asset", () => {
const { totalErrors, results } = await lintProject(project);
expect(totalErrors).toBeGreaterThan(0);
- const finding = results[0]?.result.findings.find((f) => f.code === "missing_local_asset");
+ const finding = allFindings(results).find((f) => f.code === "missing_local_asset");
expect(finding).toBeDefined();
expect(finding?.message).toContain("clip.webm");
expect(finding?.message).toContain("<source>");
@@ -642,8 +628,8 @@ describe("missing_local_asset", () => {
const { results } = await lintProject(project);
- const localAsset = results[0]?.result.findings.find((f) => f.code === "missing_local_asset");
- const audio = results[0]?.result.findings.find((f) => f.code === "audio_src_not_found");
+ const localAsset = allFindings(results).find((f) => f.code === "missing_local_asset");
+ const audio = allFindings(results).find((f) => f.code === "audio_src_not_found");
expect(localAsset).toBeUndefined();
expect(audio).toBeDefined();
});
@@ -661,7 +647,7 @@ describe("missing_local_asset", () => {
const { results } = await lintProject(project);
- const finding = results[0]?.result.findings.find((f) => f.code === "missing_local_asset");
+ const finding = allFindings(results).find((f) => f.code === "missing_local_asset");
expect(finding).toBeUndefined();
});
@@ -676,7 +662,7 @@ describe("missing_local_asset", () => {
const { results } = await lintProject(project);
- const finding = results[0]?.result.findings.find((f) => f.code === "missing_local_asset");
+ const finding = allFindings(results).find((f) => f.code === "missing_local_asset");
expect(finding).toBeUndefined();
});
@@ -694,7 +680,7 @@ describe("missing_local_asset", () => {
const { results } = await lintProject(project);
- const finding = results[0]?.result.findings.find((f) => f.code === "missing_local_asset");
+ const finding = allFindings(results).find((f) => f.code === "missing_local_asset");
expect(finding).toBeUndefined();
});
@@ -711,7 +697,7 @@ describe("missing_local_asset", () => {
const { results } = await lintProject(project);
- const finding = results[0]?.result.findings.find((f) => f.code === "missing_local_asset");
+ const finding = allFindings(results).find((f) => f.code === "missing_local_asset");
expect(finding).toBeUndefined();
});
@@ -766,7 +752,7 @@ describe("missing_local_asset", () => {
const { results } = await lintProject(project);
- const findings = results[0]?.result.findings.filter((f) => f.code === "missing_local_asset");
+ const findings = allFindings(results).filter((f) => f.code === "missing_local_asset");
expect(findings).toHaveLength(2);
expect(findings?.some((f) => f.message.includes("<img>"))).toBe(true);
expect(findings?.some((f) => f.message.includes("<video>"))).toBe(true);
@@ -785,7 +771,7 @@ describe("missing_local_asset", () => {
const { results } = await lintProject(project);
- const findings = results[0]?.result.findings.filter((f) => f.code === "missing_local_asset");
+ const findings = allFindings(results).filter((f) => f.code === "missing_local_asset");
expect(findings).toEqual([]);
});
});
@@ -807,7 +793,7 @@ describe("texture_mask_asset_not_found", () => {
const project = makeProject(html);
const { totalErrors, results } = await lintProject(project);
- const finding = results[0]?.result.findings.find(
+ const finding = allFindings(results).find(
(item) => item.code === "texture_mask_asset_not_found",
);
@@ -835,7 +821,7 @@ describe("texture_mask_asset_not_found", () => {
writeFileSync(join(project, "masks", "lava.png"), "fake");
const { results } = await lintProject(project);
- const finding = results[0]?.result.findings.find(
+ const finding = allFindings(results).find(
(item) => item.code === "texture_mask_asset_not_found",
);
@@ -859,7 +845,7 @@ describe("texture_mask_asset_not_found", () => {
writeFileSync(join(project, "compositions", "masks", "lava.png"), "fake");
const { results } = await lintProject(project);
- const finding = results[0]?.result.findings.find(
+ const finding = allFindings(results).find(
(item) => item.code === "texture_mask_asset_not_found",
);
@@ -882,7 +868,7 @@ describe("texture_mask_asset_not_found", () => {
);
const { results } = await lintProject(project);
- const finding = results[0]?.result.findings.find(
+ const finding = allFindings(results).find(
(item) => item.code === "texture_mask_asset_not_found",
);
@@ -910,7 +896,7 @@ describe("texture_mask_asset_not_found", () => {
writeFileSync(join(project, "assets", "texture-mask-text", "masks", "lava.png"), "fake");
const { results } = await lintProject(project);
- const finding = results[0]?.result.findings.find(
+ const finding = allFindings(results).find(
(item) => item.code === "texture_mask_asset_not_found",
);
@@ -924,7 +910,7 @@ describe("texture_mask_asset_not_found", () => {
writeFileSync(join(project, "assets", decodeURIComponent(encodedFilename)), "fake");
const { results } = await lintProject(project);
- const finding = results[0]?.result.findings.find(
+ const finding = allFindings(results).find(
(item) => item.code === "texture_mask_asset_not_found",
);
@@ -937,7 +923,7 @@ describe("texture_mask_asset_not_found", () => {
);
const { results } = await lintProject(project);
- const finding = results[0]?.result.findings.find(
+ const finding = allFindings(results).find(
(item) => item.code === "texture_mask_asset_not_found",
);
diff --git a/packages/lint/src/project.test.ts b/packages/lint/src/project.test.ts
index 5e60cca0a3..61b12e0add 100644
--- a/packages/lint/src/project.test.ts
+++ b/packages/lint/src/project.test.ts
@@ -694,6 +694,12 @@ describe("missing asset findings name the file that references them", () => {
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"));
+ const entryOf = (name: string) =>
+ results.find((entry) => entry.result.findings.some((f) => f.message.includes(name)))?.file;
+ expect(entryOf("missing-in-draft.png")).toBe("compositions/draft.html");
+ expect(entryOf("missing-in-draft.mp3")).toBe("compositions/draft.html");
+ expect(entryOf("missing-mask.png")).toBe("compositions/draft.html");
+ expect(entryOf("missing-in-film.png")).toBe("index.html");
});
});
diff --git a/packages/lint/src/project.ts b/packages/lint/src/project.ts
index fa7738b54f..9a116086bb 100644
--- a/packages/lint/src/project.ts
+++ b/packages/lint/src/project.ts
@@ -258,20 +258,21 @@ export async function lintProject(
...(await lintVideoMediaStartPastEof(projectDir, allHtmlSources)),
...(await lintHevcPreviewCodec(collectLocalVideoCandidates(projectDir, allHtmlSources))),
];
- if (projectFindings.length > 0) {
- for (const finding of projectFindings) {
- rootResult.findings.push(finding);
- if (finding.severity === "error") {
- rootResult.errorCount++;
- rootResult.ok = false;
- totalErrors++;
- } else if (finding.severity === "warning") {
- rootResult.warningCount++;
- totalWarnings++;
- } else {
- rootResult.infoCount++;
- totalInfos++;
- }
+ for (const finding of projectFindings) {
+ const ownFile = finding.file && resolve(projectDir, finding.file);
+ const owner =
+ results.find((entry) => resolve(projectDir, entry.file) === ownFile)?.result ?? rootResult;
+ owner.findings.push(finding);
+ if (finding.severity === "error") {
+ owner.errorCount++;
+ owner.ok = false;
+ totalErrors++;
+ } else if (finding.severity === "warning") {
+ owner.warningCount++;
+ totalWarnings++;
+ } else {
+ owner.infoCount++;
+ totalInfos++;
}
}