Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions packages/cli/src/utils/lintProject.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// fallow-ignore-file clone-families

import { describe, it, expect, afterEach } from "vitest";
import { mkdirSync, mkdtempSync, writeFileSync, rmSync } from "node:fs";
import { join } from "node:path";
Expand Down Expand Up @@ -473,6 +475,75 @@ describe("audio_src_not_found", () => {
// author can grep for it in their HTML.
expect(finding?.message).toContain("../assets/missing.mp3");
});

it("errors when <audio> src references a missing file (positive baseline)", async () => {
const html = `<html><body>
<div data-composition-id="main" data-width="1920" data-height="1080">
<audio id="music" src="missing-file.mp3" data-start="0" data-track-index="0" data-volume="1"></audio>
</div>
<script>window.__timelines = window.__timelines || {}; window.__timelines["main"] = gsap.timeline({ paused: true });</script>
</body></html>`;
const project = makeProject(html);

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();
expect(finding?.message).toContain("missing-file.mp3");
});

it("does not error when <audio> src is a deferred tts_ token placeholder", async () => {
const html = `<html><body>
<div data-composition-id="main" data-width="1920" data-height="1080">
<audio id="vo" src="<<tts_xzvv>>" data-start="0" data-track-index="0" data-volume="1"></audio>
</div>
<script>window.__timelines = window.__timelines || {}; window.__timelines["main"] = gsap.timeline({ paused: true });</script>
</body></html>`;
const project = makeProject(html);

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).toBeUndefined();
});

it("does not error when <audio> src is a deferred music_ token placeholder", async () => {
const html = `<html><body>
<div data-composition-id="main" data-width="1920" data-height="1080">
<audio id="bgm" src="<<music_bg42>>" data-start="0" data-track-index="0" data-volume="1"></audio>
</div>
<script>window.__timelines = window.__timelines || {}; window.__timelines["main"] = gsap.timeline({ paused: true });</script>
</body></html>`;
const project = makeProject(html);

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).toBeUndefined();
});

it("does not error when <audio> src is a deferred audio_ token placeholder", async () => {
const html = `<html><body>
<div data-composition-id="main" data-width="1920" data-height="1080">
<audio id="track" src="<<audio_6bwj>>" data-start="0" data-track-index="0" data-volume="1"></audio>
</div>
<script>window.__timelines = window.__timelines || {}; window.__timelines["main"] = gsap.timeline({ paused: true });</script>
</body></html>`;
const project = makeProject(html);

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).toBeUndefined();
});
});

describe("texture_mask_asset_not_found", () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/utils/lintProject.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// fallow-ignore-file complexity

import { existsSync, readFileSync, readdirSync } from "node:fs";
import { dirname, extname, isAbsolute, join, posix, relative, resolve } from "node:path";
import { lintHyperframeHtml, type HyperframeLintResult } from "@hyperframes/core/lint";
Expand Down Expand Up @@ -303,13 +305,17 @@ function lintAudioSrcNotFound(

const audioSrcRe = /<audio\b[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*>/gi;

// `<<{kind}_{id}>>` placeholders are resolved post-finish by the platform.
const deferredTokenRe = /<<(?:tts|audio|music|sfx|sound|narration)_[a-zA-Z0-9]+>>/i;

const missingSrcs: string[] = [];
for (const { html, compSrcPath } of htmlSources) {
let match: RegExpExecArray | null;
while ((match = audioSrcRe.exec(html)) !== null) {
const src = match[1]!;
if (/^(https?:|data:|blob:)/i.test(src)) continue;
if (/^__[A-Z_]+__$/.test(src)) continue; // Skip template placeholders
if (/^__[A-Z_]+__$/.test(src)) continue;
if (deferredTokenRe.test(src)) continue;
// Sub-composition srcs are written relative to the sub-composition file
// (e.g. "../assets/foo.mp3"); the bundler rewrites them to root-relative
// before serving. Mirror that rewrite here so the existence check sees
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/lint/hyperframeLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { compositionRules } from "./rules/composition";
import { adapterRules } from "./rules/adapters";
import { textureRules } from "./rules/textures";
import { fontRules } from "./rules/fonts";
import { layoutRules } from "./rules/layout";

const ALL_RULES = [
...coreRules,
Expand All @@ -19,6 +20,7 @@ const ALL_RULES = [
...adapterRules,
...textureRules,
...fontRules,
...layoutRules,
];

export async function lintHyperframeHtml(
Expand Down
Loading
Loading