mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(lint): don't look for audio on another computer's share (#7572)
The audio-missing check resolved every <audio src> on disk, including a src naming a share on another host (\\host\share, //host/share). On Windows that lookup opens a connection to that host, and Studio runs lint as soon as a project opens. The check now skips a src whose root is a network share other than the project's own, as the other lint rules already do. Media on the project's own share, local absolute paths and project files are checked as before; the render still reports a file it cannot find. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6cc734fd24
commit
7ba8f85075
@@ -0,0 +1,62 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
|
||||
vi.mock("node:child_process", () => {
|
||||
const mocked = { ChildProcess: class {}, execFile: vi.fn(), execSync: vi.fn() };
|
||||
return { ...mocked, default: mocked };
|
||||
});
|
||||
|
||||
// Which srcs name another computer's share is Windows path logic, tested in parsers; here any src on
|
||||
// `attacker.example` does, and every src lint resolves on disk is recorded.
|
||||
const resolved = vi.hoisted(() => [] as string[]);
|
||||
vi.mock("@hyperframes/parsers/asset-resolution", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@hyperframes/parsers/asset-resolution")>();
|
||||
return {
|
||||
...actual,
|
||||
srcOnAnotherNetworkRoot: (_projectDir: string, src: string) => src.includes("attacker.example"),
|
||||
resolveProjectRelativeSrc: (src: string, ...rest: [string, string?]) => {
|
||||
resolved.push(src);
|
||||
return actual.resolveProjectRelativeSrc(src, ...rest);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const { lintProject } = await import("./project.js");
|
||||
|
||||
let project: string | undefined;
|
||||
afterEach(() => {
|
||||
if (project) rmSync(project, { recursive: true, force: true });
|
||||
project = undefined;
|
||||
resolved.length = 0;
|
||||
});
|
||||
|
||||
async function lintAudio(src: string): Promise<string[]> {
|
||||
project = mkdtempSync(join(tmpdir(), "hf-lint-network-root-"));
|
||||
writeFileSync(
|
||||
join(project, "index.html"),
|
||||
`<html><body>
|
||||
<div data-composition-id="main" data-width="1920" data-height="1080" data-start="0" data-duration="10">
|
||||
<audio id="voice" src="${src}" data-start="0" data-duration="5" data-track-index="0"></audio>
|
||||
</div>
|
||||
<script>window.__timelines = {}; window.__timelines["main"] = gsap.timeline({ paused: true });</script>
|
||||
</body></html>`,
|
||||
);
|
||||
const { results } = await lintProject(project);
|
||||
return results.flatMap((result) => result.result.findings.map((finding) => finding.code));
|
||||
}
|
||||
|
||||
describe("audio on another computer's share", () => {
|
||||
it("is not looked for or reported", async () => {
|
||||
const codes = await lintAudio("\\\\attacker.example\\share\\voice.wav");
|
||||
expect(resolved.filter((src) => src.includes("attacker.example"))).toEqual([]);
|
||||
expect(codes).not.toContain("audio_src_not_found");
|
||||
});
|
||||
|
||||
it("leaves a missing project audio file reported", async () => {
|
||||
const codes = await lintAudio("assets/gone.wav");
|
||||
expect(resolved).toContain("assets/gone.wav");
|
||||
expect(codes).toContain("audio_src_not_found");
|
||||
});
|
||||
});
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
resolveExistingLocalAsset,
|
||||
resolveLocalAssetCandidates,
|
||||
resolveProjectRelativeSrc,
|
||||
srcOnAnotherNetworkRoot,
|
||||
readTextFile,
|
||||
} from "@hyperframes/parsers/asset-resolution";
|
||||
import { encodeUrlPath } from "@hyperframes/parsers";
|
||||
@@ -555,6 +556,7 @@ function lintAudioSrcNotFound(
|
||||
const rootRelative = compSrcPath
|
||||
? rewriteAssetPath(compSrcPath, src, (path) => existsSync(join(projectDir, path)))
|
||||
: src;
|
||||
if (srcOnAnotherNetworkRoot(projectDir, rootRelative)) continue;
|
||||
if (!existsSync(resolveProjectRelativeSrc(rootRelative, projectDir))) {
|
||||
const safe = urlSafeSrcOf(projectDir, rootRelative);
|
||||
if (safe) urlSafe.set(src, safe);
|
||||
|
||||
@@ -138,6 +138,11 @@ export function namesAnotherNetworkRoot(base: string, target: string): boolean {
|
||||
return /^[\\/]{2}/.test(root) && root.toLowerCase() !== parse(resolve(base)).root.toLowerCase();
|
||||
}
|
||||
|
||||
export function srcOnAnotherNetworkRoot(projectDir: string, src: string): boolean {
|
||||
const path = fileUrlAsPath(cleanAssetUrl(src));
|
||||
return isAbsolute(path) && namesAnotherNetworkRoot(projectDir, path);
|
||||
}
|
||||
|
||||
const LEADING_PARENT_SEGMENT = /^\.\.(?:[\\/]|$)/;
|
||||
|
||||
function staysInsideProject(projectDir: string, path: string): boolean {
|
||||
|
||||
@@ -22,6 +22,7 @@ const {
|
||||
resolveAuthoredAssetFile,
|
||||
resolveCompositionSrc,
|
||||
resolveLocalAssetCandidates,
|
||||
srcOnAnotherNetworkRoot,
|
||||
} = await import("./assetResolution.js");
|
||||
const { resolve } = await import("node:path");
|
||||
|
||||
@@ -142,3 +143,27 @@ describe("localAbsoluteAssetFile under Windows rules", () => {
|
||||
expect(localAbsoluteAssetFile(PROJECT, "C:\\media\\gone.mp4")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("srcOnAnotherNetworkRoot under Windows rules", () => {
|
||||
it.each([
|
||||
"\\\\attacker.example\\share\\x.wav",
|
||||
"//attacker.example/share/x.wav",
|
||||
"/\\attacker.example\\share\\x.wav",
|
||||
"\\\\attacker.example\\share\\x.wav?v=2",
|
||||
])("is true for %s", (src) => {
|
||||
touched.length = 0;
|
||||
expect(srcOnAnotherNetworkRoot(PROJECT, src)).toBe(true);
|
||||
expect(touched).toEqual([]);
|
||||
});
|
||||
|
||||
it.each(["C:\\media\\voice.wav", "assets\\voice.wav", "/assets/voice.wav", "../voice.wav"])(
|
||||
"is false for %s",
|
||||
(src) => {
|
||||
expect(srcOnAnotherNetworkRoot(PROJECT, src)).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it("is false for a file on the share the project itself lives on", () => {
|
||||
expect(srcOnAnotherNetworkRoot("\\\\nas\\films\\project", "//NAS/films/voice.wav")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user