mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
fix(core): give the preview bundler the render's expansion budget (#8306)
* fix(core): give the preview bundler the render's expansion budget The preview bundler inlined every sub-composition mount with only a depth limit, so a few small files that mount each other many times assembled a page without bound. The producer's expansion budget now lives in core, and the bundler charges every mount and the scripts and styles generated for it to that budget, and checks each file's size before reading it. Studio preview shows the refusal instead of falling back to the raw page, whose mounts the browser would expand the same way. * refactor: drop comments the names already carry * test(core): give the preview fan-out budget test a 30 s timeout The flake gate saw it pass 9 of 10 runs under CPU contention, timing out at the default 5 s. The neighbouring scoper bound tests use 30 s too.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { STUDIO_PREVIEW_ERRORS } from "@hyperframes/core/studio-preview-mark";
|
||||
import { createStudioServer, type StudioServer } from "./studioServer.js";
|
||||
import { cleanupStudioServerRoot, makeStudioServerRoot } from "./studioServerTestFixture.js";
|
||||
|
||||
const mounts = (src: string, count: number) =>
|
||||
`<div data-composition-id="scene" data-composition-src="${src}" data-start="0" data-duration="1"></div>`.repeat(
|
||||
count,
|
||||
);
|
||||
|
||||
let root: string;
|
||||
let projectDir: string;
|
||||
let server: StudioServer;
|
||||
|
||||
beforeEach(() => {
|
||||
({ root, projectDir } = makeStudioServerRoot("hf-preview-too-large-"));
|
||||
// Four levels of ten: 11,110 mounts from five small files.
|
||||
fs.writeFileSync(
|
||||
path.join(projectDir, "index.html"),
|
||||
`<!doctype html><html><body><div data-composition-id="main" data-width="320" data-height="180">${mounts("level-0.html", 10)}</div></body></html>`,
|
||||
);
|
||||
for (let level = 0; level < 3; level += 1) {
|
||||
fs.writeFileSync(
|
||||
path.join(projectDir, `level-${level}.html`),
|
||||
`<template><div data-composition-id="scene">${mounts(`level-${level + 1}.html`, 10)}</div></template>`,
|
||||
);
|
||||
}
|
||||
fs.writeFileSync(
|
||||
path.join(projectDir, "level-3.html"),
|
||||
`<template><div data-composition-id="scene"><h1>Leaf</h1></div></template>`,
|
||||
);
|
||||
server = createStudioServer({ projectDir, projectName: "film" });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanupStudioServerRoot(server, root);
|
||||
});
|
||||
|
||||
describe("studio preview of a project over the mount limit", () => {
|
||||
it("serves the refusal, not the raw page that would expand the mounts in the browser", async () => {
|
||||
const response = await server.app.request("/api/projects/film/preview");
|
||||
const html = await response.text();
|
||||
|
||||
expect(html).toContain(`window.${STUDIO_PREVIEW_ERRORS}=[`);
|
||||
expect(html).toContain("Mount large or repeated scenes fewer times");
|
||||
expect(html).not.toContain("<h1>Leaf</h1>");
|
||||
expect(html).not.toContain('data-composition-src="level-0.html"');
|
||||
});
|
||||
});
|
||||
@@ -613,6 +613,8 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
|
||||
);
|
||||
return html;
|
||||
} catch (err) {
|
||||
const { isCompositionTooLargeError } = await import("@hyperframes/core/compiler");
|
||||
if (isCompositionTooLargeError(err)) throw err;
|
||||
console.error("[studio] Bundle failed:", err);
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user