diff --git a/packages/cli/src/commands/cloud/render.missingEntry.test.ts b/packages/cli/src/commands/cloud/render.missingEntry.test.ts
new file mode 100644
index 0000000000..ad1732fc85
--- /dev/null
+++ b/packages/cli/src/commands/cloud/render.missingEntry.test.ts
@@ -0,0 +1,65 @@
+import { describe, expect, it, onTestFinished } from "vitest";
+import { spawnSync } from "node:child_process";
+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { join, resolve } from "node:path";
+import { tmpdir } from "node:os";
+import { fileURLToPath } from "node:url";
+
+const cliEntry = resolve(fileURLToPath(import.meta.url), "..", "..", "..", "cli.ts");
+
+const page = (body: string) =>
+ `
${body}
`;
+
+/** A project whose index.html and alternate.html do not mount each other. */
+function project(index: string, alternate: string): string {
+ const dir = mkdtempSync(join(tmpdir(), "hf-cloud-missing-entry-"));
+ onTestFinished(() => rmSync(dir, { recursive: true, force: true }));
+ writeFileSync(join(dir, "index.html"), page(index));
+ writeFileSync(join(dir, "alternate.html"), page(alternate));
+ return dir;
+}
+
+function dryRunAlternate(dir: string) {
+ return spawnSync(
+ "bun",
+ [
+ "run",
+ cliEntry,
+ "cloud",
+ "render",
+ dir,
+ "--composition",
+ "alternate.html",
+ "--dry-run",
+ "--json",
+ ],
+ {
+ encoding: "utf-8",
+ timeout: 30_000,
+ env: {
+ ...process.env,
+ CI: "1",
+ HEYGEN_API_URL: "http://127.0.0.1:1",
+ HYPERFRAMES_NO_UPDATE_CHECK: "1",
+ HYPERFRAMES_NO_TELEMETRY: "1",
+ HOME: dir,
+ },
+ },
+ );
+}
+
+const MISSING = 'The composition references "missing.png", which is not in the project folder.';
+
+describe("cloud render --composition checks missing files from the page it renders", () => {
+ it("refuses a missing image on the selected page", () => {
+ const result = dryRunAlternate(project("", `
`));
+ expect(result.status).not.toBe(0);
+ expect(result.stdout + result.stderr).toContain(MISSING);
+ });
+
+ it("allows a missing image on an index.html the selected page does not play", () => {
+ const result = dryRunAlternate(project(`
`, ""));
+ expect(result.stdout + result.stderr).not.toContain(MISSING);
+ expect(result.status).toBe(0);
+ });
+});
diff --git a/packages/cli/src/commands/cloud/render.ts b/packages/cli/src/commands/cloud/render.ts
index ddb360ca96..34bc3d228c 100644
--- a/packages/cli/src/commands/cloud/render.ts
+++ b/packages/cli/src/commands/cloud/render.ts
@@ -790,13 +790,19 @@ function stageProjectFiles(
onOutsideFile: OnOutsideFile,
): { fileMap: Map; entryPath: string } {
try {
- const fileMap = stagePublishFiles(project.dir, OFFLOAD_MIN_BYTES, onLeftOut, onOutsideFile);
const entryPath = archiveKey(
relative(project.dir, resolvePath(project.dir, composition ?? "index.html")).replaceAll(
"\\",
"/",
),
);
+ const fileMap = stagePublishFiles(
+ project.dir,
+ OFFLOAD_MIN_BYTES,
+ onLeftOut,
+ onOutsideFile,
+ entryPath,
+ );
if (!fileMap.has(entryPath)) {
throw new Error(
`Composition "${composition ?? "index.html"}" is excluded from the archive. Check .hyperframesignore.`,
diff --git a/packages/cli/src/utils/publishProject.missing.test.ts b/packages/cli/src/utils/publishProject.missing.test.ts
new file mode 100644
index 0000000000..bed25e31b0
--- /dev/null
+++ b/packages/cli/src/utils/publishProject.missing.test.ts
@@ -0,0 +1,108 @@
+import { execFileSync } from "node:child_process";
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { dirname, join } from "node:path";
+import { afterEach, describe, expect, it } from "vitest";
+import { stagePublishFiles } from "./publishProject.js";
+
+const dirs: string[] = [];
+afterEach(() => dirs.splice(0).forEach((dir) => rmSync(dir, { recursive: true, force: true })));
+
+const FILM = ``;
+
+/** Writes `files` under a fresh project folder and stages it as the cloud would upload it. */
+function stage(files: Record, prepare?: (dir: string) => void) {
+ const dir = mkdtempSync(join(tmpdir(), "hf-missing-"));
+ dirs.push(dir);
+ for (const [name, body] of Object.entries({ "index.html": FILM, ...files })) {
+ mkdirSync(dirname(join(dir, name)), { recursive: true });
+ writeFileSync(join(dir, name), body);
+ }
+ prepare?.(dir);
+ return () => stagePublishFiles(dir, Infinity);
+}
+
+const refusal = (name: string) =>
+ `The composition references "${name}", which is not in the project folder.`;
+
+describe("a file a page names that the folder lacks", () => {
+ // fails without the fix: a storyboard page beside the video blocked the cloud render of a video that has every file
+ it("is no refusal when the page is one the video never plays", () => {
+ const staged = stage({
+ "compositions/intro.html": ``,
+ "compositions/clip.mp4": "mp4",
+ "boards/storyboard.html": `
`,
+ "drafts/old.html": ``,
+ })();
+ expect(staged.has("boards/storyboard.html")).toBe(true);
+ expect(staged.has("compositions/clip.mp4")).toBe(true);
+ });
+
+ it("is still refused when the video's own page names it", () => {
+ const staged = stage({
+ "index.html": ``,
+ });
+ expect(staged).toThrow(refusal("assets/gone.mp4"));
+ });
+
+ it("is still refused when a composition the video loads names it", () => {
+ const staged = stage({ "compositions/intro.html": `
` });
+ expect(staged).toThrow(refusal("assets/logo.png"));
+ });
+
+ it("is still refused on a played page however deep the compositions nest", () => {
+ const chain: Record = {};
+ for (let i = 0; i < 300; i++)
+ chain[`compositions/c${i}.html`] =
+ ``;
+ chain["compositions/c300.html"] = `
`;
+ const staged = stage({
+ ...chain,
+ "index.html": ``,
+ });
+ expect(staged).toThrow(refusal("assets/deep.png"));
+ });
+
+ it("is still refused on a page mounted by one whose name is written in another Unicode form", () => {
+ const staged = stage({
+ "index.html": ``,
+ "compositions/cafe\u0301.html": ``,
+ "compositions/inner.html": `
`,
+ });
+ expect(staged).toThrow(refusal("assets/logo.png"));
+ });
+
+ it("is still refused on a page a UTF-16 index.html mounts", () => {
+ const index = ``;
+ const staged = stage({
+ "index.html": Buffer.concat([Buffer.from([0xff, 0xfe]), Buffer.from(index, "utf16le")]),
+ "compositions/intro.html": `
`,
+ });
+ expect(staged).toThrow(refusal("assets/logo.png"));
+ });
+
+ it("is refused on any page when a page the video loads is not in the upload", () => {
+ const staged = stage({
+ "compositions/intro.html": ``,
+ ".hyperframesignore": "compositions/intro.html\n",
+ "boards/storyboard.html": `
`,
+ });
+ expect(staged).toThrow(refusal("stills/at-1.2s.png"));
+ });
+
+ it.skipIf(process.platform === "win32")(
+ "is refused on any page, without waiting, when the video loads a named pipe",
+ () => {
+ const staged = stage(
+ { "boards/storyboard.html": `
` },
+ (dir) => {
+ mkdirSync(join(dir, "compositions"));
+ execFileSync("mkfifo", [join(dir, "compositions/intro.html")]);
+ },
+ );
+ expect(staged).toThrow(refusal("stills/at-1.2s.png"));
+ },
+ );
+});
diff --git a/packages/cli/src/utils/publishProject.ts b/packages/cli/src/utils/publishProject.ts
index 77a33a8df2..1eb52ce0dc 100644
--- a/packages/cli/src/utils/publishProject.ts
+++ b/packages/cli/src/utils/publishProject.ts
@@ -39,6 +39,11 @@ import {
outsideFileReference,
} from "./leftOutReference.js";
import { isUploadedOutsideFileType } from "./outsideFileType.js";
+import {
+ collectSubCompositionSrcs,
+ decodeTextHonoringBom,
+ resolveCompositionSrc,
+} from "@hyperframes/parsers/asset-resolution";
const IGNORED_DIRS = new Set([".git", "node_modules", "dist", ".next", "coverage"]);
const IGNORED_FILES = new Set([".DS_Store", "Thumbs.db"]);
@@ -411,6 +416,7 @@ interface ExternalAssetContext {
onLeftOut?: OnLeftOut;
onOutsideFile?: OnOutsideFile;
received: (path: string) => boolean;
+ filmPages: Set | null;
}
function addExternalAsset(
@@ -488,7 +494,7 @@ function includeReferencedProjectFile(
throw new Error(`The composition references "${rawPath}", which is not in the project folder.`);
}
-/** References with no fallback: a missing file here cannot render. */
+/** References with no fallback: on a page the video plays, a missing file here cannot render. */
const HARD_REFERENCES = new Set(["video[src]", "audio[src]", "img[src]", "video[poster]"]);
const relativeToProject = (ctx: ExternalAssetContext, absPath: string) =>
@@ -690,7 +696,9 @@ function localizeHtmlEntry(ctx: ExternalAssetContext, entryPath: string, content
val,
dir,
entryPath,
- ref !== undefined && HARD_REFERENCES.has(`${ref.tag}[${ref.attr}]`),
+ (ctx.filmPages?.has(entryPath) ?? true) &&
+ ref !== undefined &&
+ HARD_REFERENCES.has(`${ref.tag}[${ref.attr}]`),
);
const attrsChanged = rewriteHtmlAttributes(document, referrerAbsDir, entryPath, resolveTarget, {
attrs: ["src", "href", "poster"],
@@ -714,6 +722,27 @@ function localizeCssEntry(ctx: ExternalAssetContext, entryPath: string, content:
}
}
+/** Staged pages played from `entry`, as the renderer mounts them; null (check every page) when one is not staged. */
+function filmPagesOf(
+ absProjectDir: string,
+ fileContents: Map,
+ entry: string,
+): Set | null {
+ const pages = new Set();
+ const queue = [entry];
+ for (const page of queue) {
+ if (pages.has(page)) continue;
+ const file = fileContents.get(page);
+ if (!Buffer.isBuffer(file)) return null;
+ pages.add(page);
+ for (const src of collectSubCompositionSrcs(decodeTextHonoringBom(file))) {
+ const absPath = resolveCompositionSrc(absProjectDir, src);
+ if (absPath) queue.push(archiveKey(relative(absProjectDir, absPath).replaceAll("\\", "/")));
+ }
+ }
+ return pages;
+}
+
/**
* Scan HTML and CSS files for asset references that resolve outside the
* project directory. Copy those files into the archive under `_ext/` and
@@ -725,6 +754,7 @@ export function localizeExternalAssets(
onDiskMinBytes = Infinity,
onLeftOut?: OnLeftOut,
onOutsideFile?: OnOutsideFile,
+ entry = "index.html",
): number {
const ctx: ExternalAssetContext = {
absProjectDir,
@@ -736,6 +766,7 @@ export function localizeExternalAssets(
onLeftOut,
onOutsideFile,
received: receivedFiles(absProjectDir),
+ filmPages: filmPagesOf(absProjectDir, fileContents, entry),
};
for (const [entryPath, content] of [...fileContents.entries()]) {
@@ -805,12 +836,16 @@ function walkedFileLeftOut(
return null;
}
-/** {@link buildPublishFileMap}, but non-text files of `onDiskMinBytes` or more stay on disk. */
+/**
+ * {@link buildPublishFileMap}, but non-text files of `onDiskMinBytes` or more stay on disk.
+ * `entry` is the archive key of the page that will render.
+ */
export function stagePublishFiles(
projectDir: string,
onDiskMinBytes: number,
onLeftOut?: OnLeftOut,
onOutsideFile?: OnOutsideFile,
+ entry = "index.html",
): Map {
const absProjectDir = resolve(projectDir);
const filePaths: string[] = [];
@@ -847,7 +882,14 @@ export function stagePublishFiles(
}
composeNamesInText(fileContents, filePaths);
- localizeExternalAssets(absProjectDir, fileContents, onDiskMinBytes, onLeftOut, onOutsideFile);
+ localizeExternalAssets(
+ absProjectDir,
+ fileContents,
+ onDiskMinBytes,
+ onLeftOut,
+ onOutsideFile,
+ entry,
+ );
return fileContents;
}