Files
hyperframes/packages/lint/src/project.windowsAbsolute.test.ts
T
Michael WangandClaude Opus 5.5 5a88c9938e fix(parsers,lint,producer,cli): confine composition path lookups to the project (#7534)
* fix(parsers,lint,producer,cli): confine composition path lookups to the project

- The local asset resolver offers only files inside the project: a path
  that is still absolute after its leading `../` is clamped (an encoded
  `//`, a drive letter, a leading backslash) yields no candidate.
- Lint, the catalog-usage walk and `keyframes` read a
  data-composition-src only inside the project. Lint and the catalog
  walk resolve it with the render's own resolver, now shared from
  `@hyperframes/parsers/asset-resolution`, and lint reports one outside
  the project as the render pre-flight does.
- The render compile step does not look at a media, gsap script or image
  path on another UNC or device root, and the GIF and HEIC preparation
  treats a `//host/...` image src as a URL rather than a share.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(parsers,lint): keep Windows absolute asset paths that render copies in

The shared asset resolver now offers only files inside the project. On
Windows a drive-letter src such as C:\media\clip.mp4 used to reach the
real file through the old fallback, and render still copies that file in.
Lint now accepts such a file for media and for CSS written in the page,
so it raises no new missing_local_asset or texture_mask_asset_not_found
error. The media-treatment and normalize-audio commands find it again.

The check never looks at another computer's share, and on macOS and
Linux a src that starts with / is still a project URL, so nothing
changes there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(parsers): expect a drive-letter sub-composition src to be refused on Windows

On Windows an absolute src outside the project is a drive-letter path,
which resolveCompositionSrc refuses, as the render pre-flight already
does. On POSIX the same src is a project URL and resolves inside the
project. The test now expects each platform's result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(lint): do not report a missing timeline registry a script outside the project may hold

Lint no longer reads a script outside the project. When a root
composition loads such a script, lint cannot know whether the script
registers the timeline, so it no longer reports missing_timeline_registry
for that composition. Render still loads the script. A composition whose
scripts are all in the project is checked as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 04:14:45 +00:00

69 lines
2.8 KiB
TypeScript

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 };
});
// A Windows disk on any host: these drive-letter files exist, as render would find them.
const ON_DISK = new Set(["C:\\media\\clip.png", "C:\\media\\grain.png"]);
vi.mock("@hyperframes/parsers/asset-resolution", async (importOriginal) => {
const actual = await importOriginal<typeof import("@hyperframes/parsers/asset-resolution")>();
return {
...actual,
localAbsoluteAssetFile: (_projectDir: string, src: string) => (ON_DISK.has(src) ? src : null),
};
});
const { lintProject } = await import("./project.js");
let project: string | undefined;
afterEach(() => {
if (project) rmSync(project, { recursive: true, force: true });
project = undefined;
});
async function lintCodes(body: string, files: Record<string, string> = {}): Promise<string[]> {
project = mkdtempSync(join(tmpdir(), "hf-lint-windows-absolute-"));
writeFileSync(
join(project, "index.html"),
`<html><body>
<div data-composition-id="main" data-width="1920" data-height="1080" data-start="0" data-duration="10">${body}</div>
<script>window.__timelines = {}; window.__timelines["main"] = gsap.timeline({ paused: true });</script>
</body></html>`,
);
for (const [name, text] of Object.entries(files)) writeFileSync(join(project, name), text);
const { results } = await lintProject(project);
return results.flatMap((result) => result.result.findings.map((finding) => finding.code));
}
describe("local absolute paths that render copies in", () => {
it("are not reported as missing media", async () => {
expect(await lintCodes('<img src="C:\\media\\clip.png" />')).not.toContain(
"missing_local_asset",
);
});
it("are still reported when the file is not there", async () => {
expect(await lintCodes('<img src="C:\\media\\gone.png" />')).toContain("missing_local_asset");
});
it("are not reported as a missing texture mask in the page's own CSS", async () => {
const codes = await lintCodes(
'<style>.grain { mask-image: url("C:\\media\\grain.png"); }</style><div class="grain"></div>',
);
expect(codes).not.toContain("texture_mask_asset_not_found");
});
it("are still reported from a linked stylesheet, where url() stays a browser URL", async () => {
const codes = await lintCodes(
'<link rel="stylesheet" href="styles.css" /><div class="grain"></div>',
{ "styles.css": '.grain { mask-image: url("C:\\media\\grain.png"); }' },
);
expect(codes).toContain("texture_mask_asset_not_found");
});
});