fix(engine,producer): render-network setting reads like a switch; render-service probes stay on checked inputs (#7807)

* fix(engine): read PRODUCER_RESTRICT_PAGE_NETWORK's usual spellings and restrict on an unknown value

true, 1, yes and on turn the render network restriction on and false, 0,
no and off leave it off, in any letter case and with surrounding
whitespace. Unset or blank stays off for local renders. Any other value
now restricts and logs a warning once, instead of leaving the render
browser and ffmpeg URL inputs unrestricted.

* fix(producer): on a render service the audio probe reads a composition URL from a downloaded copy

With PRODUCER_RESTRICT_PAGE_NETWORK on, a video URL the composition
names is fetched through the shared downloader (resolved-address check,
pinned connection, per-hop redirect checks) before ffprobe reads it, and
skipped if the download is refused. In a distributed audio step the copy
lands in the mixer's work folder, so the mix reuses it instead of
downloading again. Without the flag the probe reads the URL as before.

* fix(engine): on a render service a URL that ffmpeg reads in place must be a self-contained container

With PRODUCER_RESTRICT_PAGE_NETWORK on, every https input ffmpeg or
ffprobe opens directly (such as a signed storage URL for a project's
video or audio sidecar) also gets -format_whitelist with the same
self-contained containers the Studio media helpers allow. A playlist,
manifest or concat list stored under a media file name can no longer
make ffmpeg open other network locations. Local renders are unchanged.

* fix(producer): the render-service audio probe skips only refused URLs and downloads once

A composition URL is skipped, with one warning, only when the download
address rules refuse it. Timeouts, HTTP errors and a cancelled render
fail the probe as before. Videos without sound, muted or hidden are not
downloaded. The in-process extract stage passes the render's abort
signal and the mixer's work folder, so the mix reuses the copy.

* fix(producer): unit tests load the orchestrator again; raise the engine size budget

audioWorkDir moves to render/shared.ts, so tests that replace the audio
stage module still load the orchestrator. The format-whitelist test
probe ends its options with -- as the ffprobe argv contract requires.
The engine packed size budget rises to 500000 bytes.
This commit is contained in:
Michael Wang
2026-11-15 07:34:08 +00:00
committed by GitHub
parent b7c26ff844
commit be740d0215
14 changed files with 368 additions and 52 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ The handler uses `@sparticuz/chromium` by default, with a build-time fallback fo
The handler sets `PRODUCER_RESTRICT_PAGE_NETWORK=true` unless the function already sets it, so a rendered page reaches only its own project files and public internet addresses. Loopback, private, link-local and IPv6 addresses are refused for anything the page loads. An asset on a VPC-only host or behind private DNS is missing from the video.
Keep it on when you render compositions you did not write. To turn it off, set `PRODUCER_RESTRICT_PAGE_NETWORK=false` in the function's environment.
Keep it on when you render compositions you did not write. To turn it off, set `PRODUCER_RESTRICT_PAGE_NETWORK=false` in the function's environment. Only `false`, `0`, `no` or `off` turn it off. Any other value keeps it on, and a value the handler does not recognise logs a warning.
## Using the SDK
+9
View File
@@ -207,6 +207,15 @@ address a name resolves to and connects to the address it checked. A refused req
fails like any other unreachable asset. Leave it unset for local renders that load
assets from your own machine or network.
The setting accepts `true`, `1`, `yes` or `on` to turn the restriction on and `false`, `0`,
`no` or `off` to leave it off, in any letter case. Any other value turns it on and logs a
warning, so a misspelled value never leaves a render service open.
With the restriction on, a video or audio URL is downloaded through the same address
checks before FFmpeg reads it. A file FFmpeg does read by URL, such as a signed storage
URL for a project's video, must be a self-contained container like MP4, WebM or WAV. A
playlist, manifest or concat list under a media file name is refused.
If your network routes a range that is not a private one, such as a cluster's pod range,
add it with `PRODUCER_NON_PUBLIC_CIDRS`, a comma-separated list like `192.160.0.0/16`. Asset
downloads and the render browser then refuse those addresses too. A malformed entry
+33 -1
View File
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { join } from "node:path";
import { tmpdir } from "node:os";
import {
@@ -14,6 +14,7 @@ import {
defaultExtractCacheDir,
EXTRACT_CACHE_DIR_DISABLED_ALIASES,
validateEngineConfigSnapshot,
resolveRestrictPageNetwork,
} from "./config.js";
import type { EngineConfig } from "./config.js";
import { isLowMemorySystem } from "./services/systemMemory.js";
@@ -1009,3 +1010,34 @@ describe("validateEngineConfigSnapshot fps", () => {
expect(() => validateEngineConfigSnapshot({ ...resolveConfig(), fps: 50 })).toThrow(/fps/);
});
});
describe("resolveRestrictPageNetwork", () => {
afterEach(() => {
vi.unstubAllEnvs();
vi.restoreAllMocks();
});
it.each(["true", "1", "TRUE", "yes", "On", " true\n"])("restricts for %j", (value) => {
vi.stubEnv("PRODUCER_RESTRICT_PAGE_NETWORK", value);
expect(resolveRestrictPageNetwork()).toBe(true);
});
it.each(["", " ", "false", "0", "NO", "off\n"])("stays open for %j", (value) => {
vi.stubEnv("PRODUCER_RESTRICT_PAGE_NETWORK", value);
expect(resolveRestrictPageNetwork()).toBe(false);
});
it("stays open when unset", () => {
vi.stubEnv("PRODUCER_RESTRICT_PAGE_NETWORK", undefined);
expect(resolveRestrictPageNetwork()).toBe(false);
});
it("restricts for an unrecognised value and warns once", () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
vi.stubEnv("PRODUCER_RESTRICT_PAGE_NETWORK", "maybe");
expect(resolveRestrictPageNetwork()).toBe(true);
expect(resolveRestrictPageNetwork()).toBe(true);
expect(warn).toHaveBeenCalledTimes(1);
expect(warn).toHaveBeenCalledWith(expect.stringContaining("PRODUCER_RESTRICT_PAGE_NETWORK"));
});
});
+17 -1
View File
@@ -819,12 +819,28 @@ export function resolvePageNavigationTimeout(): number {
return Number.isFinite(parsed) ? parsed : DEFAULT_CONFIG.pageNavigationTimeout;
}
const RESTRICT_PAGE_NETWORK_ON = new Set(["true", "1", "yes", "on"]);
const RESTRICT_PAGE_NETWORK_OFF = new Set(["false", "0", "no", "off"]);
let warnedRestrictPageNetworkValue: string | undefined;
/**
* `PRODUCER_RESTRICT_PAGE_NETWORK=true`: the render page may reach only its own server and public addresses.
* Unset or blank is off. `true`, `1`, `yes` and `on` turn it on and `false`, `0`, `no` and `off` turn it off,
* in any letter case and with surrounding whitespace. Any other value restricts and logs a warning once.
* A property of the host (a shared render service), not of one render, so it stays out of EngineConfig snapshots.
*/
export function resolveRestrictPageNetwork(): boolean {
return process.env.PRODUCER_RESTRICT_PAGE_NETWORK === "true";
const raw = process.env.PRODUCER_RESTRICT_PAGE_NETWORK ?? "";
const value = raw.trim().toLowerCase();
if (value === "" || RESTRICT_PAGE_NETWORK_OFF.has(value)) return false;
if (RESTRICT_PAGE_NETWORK_ON.has(value)) return true;
if (warnedRestrictPageNetworkValue !== raw) {
warnedRestrictPageNetworkValue = raw;
console.warn(
`[hyperframes] PRODUCER_RESTRICT_PAGE_NETWORK=${JSON.stringify(raw)} is neither true nor false; the render network stays restricted.`,
);
}
return true;
}
export function resolveConfig(overrides?: Partial<EngineConfig>): EngineConfig {
+2
View File
@@ -60,6 +60,7 @@ export type {
export {
resolveConfig,
resolvePageNavigationTimeout,
resolveRestrictPageNetwork,
validateEngineConfigSnapshot,
DEFAULT_CONFIG,
scaleProtocolTimeoutForComposition,
@@ -426,6 +427,7 @@ export {
fetchPublicHttpsText,
isHttpUrl,
safeDownloadUrlIdentity,
isUrlNotPermittedError,
writeUrlDownloadTelemetry,
type SafeDownloadUrlIdentity,
type UrlDownloadOptions,
+20 -12
View File
@@ -144,6 +144,24 @@ export class UrlDownloadError extends Error {
}
}
const URL_NOT_PERMITTED = "Download URL is not permitted";
const REDIRECT_NOT_PERMITTED = "Download redirect target is not permitted";
function notPermittedError(redirect: boolean): UrlDownloadError {
return new UrlDownloadError(
"http_rejected",
false,
redirect ? REDIRECT_NOT_PERMITTED : URL_NOT_PERMITTED,
);
}
export function isUrlNotPermittedError(error: unknown): boolean {
return (
error instanceof UrlDownloadError &&
(error.message === URL_NOT_PERMITTED || error.message === REDIRECT_NOT_PERMITTED)
);
}
function classifyHttpFailure(status: number): UrlDownloadError {
// Response.statusText is remote-controlled and some CDNs/proxies echo the
// signed request URL into it. The numeric status is sufficient and bounded.
@@ -473,11 +491,7 @@ function assertAllowedDownloadUrl(url: string, redirect: boolean): void {
try {
assertPublicHttpsUrl(url);
} catch {
throw new UrlDownloadError(
"http_rejected",
false,
redirect ? "Download redirect target is not permitted" : "Download URL is not permitted",
);
throw notPermittedError(redirect);
}
}
@@ -525,13 +539,7 @@ async function fetchWithValidatedRedirects(
headers: { "accept-encoding": "identity" },
}).catch((error: unknown) => {
if (!refusedNonPublicAddress(error)) throw error;
throw new UrlDownloadError(
"http_rejected",
false,
redirects > 0
? "Download redirect target is not permitted"
: "Download URL is not permitted",
);
throw notPermittedError(redirects > 0);
});
if (!REDIRECT_STATUSES.has(response.status)) return { response, finalUrl: currentUrl };
+57 -12
View File
@@ -1,5 +1,10 @@
import { spawnSync } from "node:child_process";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, it, vi } from "vitest";
import { VideoSourceExtractionError } from "../services/videoFrameExtractor.js";
import { getFfmpegBinary, getFfprobeBinary } from "./ffmpegBinaries.js";
import { redactUrlQueriesInError, urlInputArgs } from "./urlInput.js";
const signed =
@@ -32,19 +37,59 @@ describe("urlInputArgs", () => {
expect(urlInputArgs(signed, { tool: "ffprobe", caBundles })).toEqual(verifyAndReconnect);
});
it("limits what an https input may open to HTTPS on a render service", () => {
vi.stubEnv("PRODUCER_RESTRICT_PAGE_NETWORK", "true");
try {
expect(urlInputArgs(signed, { tool: "ffprobe", caBundles })).toEqual([
...verifyAndReconnect,
"-protocol_whitelist",
"https,tls,tcp",
]);
expect(urlInputArgs("/plan/compiled/bg.mp4", { caBundles: [] })).toEqual([]);
} finally {
it.each(["true", "1", " TRUE\n"])(
"limits what an https input may open to HTTPS on a render service (%j)",
(flag) => {
vi.stubEnv("PRODUCER_RESTRICT_PAGE_NETWORK", flag);
try {
expect(urlInputArgs(signed, { tool: "ffprobe", caBundles })).toEqual([
...verifyAndReconnect,
"-protocol_whitelist",
"https,tls,tcp",
"-format_whitelist",
expect.any(String),
]);
expect(urlInputArgs("/plan/compiled/bg.mp4", { caBundles: [] })).toEqual([]);
} finally {
vi.unstubAllEnvs();
}
},
);
it.skipIf(spawnSync(getFfprobeBinary(), ["-version"]).status !== 0)(
"on a render service lets ffprobe open a video but not a playlist or concat list named .mp4",
() => {
vi.stubEnv("PRODUCER_RESTRICT_PAGE_NETWORK", "true");
const args = urlInputArgs(signed, { caBundles });
vi.unstubAllEnvs();
}
});
const formats = args[args.indexOf("-format_whitelist") + 1]!;
const dir = mkdtempSync(join(tmpdir(), "hf-url-input-"));
try {
const video = join(dir, "clip.mp4");
const lavfi = ["-f", "lavfi", "-i", "testsrc2=size=32x32:rate=5:duration=1"];
spawnSync(getFfmpegBinary(), ["-v", "error", "-y", ...lavfi, "-c:v", "mpeg4", video]);
const playlist = join(dir, "playlist.mp4");
writeFileSync(playlist, "#EXTM3U\n#EXTINF:1,\nhttps://127.0.0.1:9/a.ts\n#EXT-X-ENDLIST\n");
const concat = join(dir, "concat.mp4");
writeFileSync(concat, "ffconcat version 1.0\nfile https://127.0.0.1:9/a.mp4\n");
const probe = (path: string) =>
spawnSync(getFfprobeBinary(), [
"-v",
"error",
"-format_whitelist",
formats,
"-show_format",
"--",
path,
]).status;
expect(probe(video)).toBe(0);
expect(probe(playlist)).not.toBe(0);
expect(probe(concat)).not.toBe(0);
} finally {
rmSync(dir, { recursive: true, force: true });
}
},
);
it("adds nothing for local paths and plain http", () => {
expect(urlInputArgs("/plan/compiled/bg.mp4", { caBundles: [] })).toEqual([]);
+7 -4
View File
@@ -12,7 +12,10 @@ const CA_BUNDLES = [
// Lambda's ffprobe 4.0 accepts these but not -reconnect_on_network_error; a stalled read fails after 30 s.
const RECONNECT_ARGS = ["-rw_timeout", "30000000", "-reconnect", "1", "-reconnect_delay_max", "2"];
/** ffmpeg and ffprobe skip TLS certificate checks unless told to; an https input must be verified, and on a render service whatever it names must be HTTPS too. */
const SELF_CONTAINED_FORMATS =
"mov,matroska,mxf,avi,mpeg,mpegts,mpegvideo,flv,asf,ogg,wav,mp3,aac,flac,aiff,gif,image2,png_pipe,jpeg_pipe,webp_pipe,bmp_pipe,tiff_pipe";
/** ffmpeg and ffprobe skip TLS certificate checks unless told to; an https input must be verified, and on a render service be a self-contained container that names only HTTPS. */
export function urlInputArgs(
input: string,
{
@@ -28,8 +31,8 @@ export function urlInputArgs(
);
}
const networkRetry = tool === "ffmpeg" ? ["-reconnect_on_network_error", "1"] : [];
const nestedOpensStayOnHttps = resolveRestrictPageNetwork()
? ["-protocol_whitelist", "https,tls,tcp"]
const renderServiceLimits = resolveRestrictPageNetwork()
? ["-protocol_whitelist", "https,tls,tcp", "-format_whitelist", SELF_CONTAINED_FORMATS]
: [];
return [
"-tls_verify",
@@ -38,7 +41,7 @@ export function urlInputArgs(
caFile,
...RECONNECT_ARGS,
...networkRetry,
...nestedOpensStayOnHttps,
...renderServiceLimits,
];
}
@@ -78,6 +78,7 @@ import {
withChunkCaptureCost,
} from "./chunkWeights.js";
import { runAudioStage } from "../render/stages/audioStage.js";
import { audioWorkDir } from "../render/shared.js";
import { runCompileStage } from "../render/stages/compileStage.js";
import {
appendVideoAudioFromProbe,
@@ -1874,7 +1875,11 @@ export async function buildPlanAudio(
});
try {
let stageStarted = Date.now();
await appendVideoAudioFromProbe(c);
await appendVideoAudioFromProbe({
...c,
downloadDir: audioWorkDir(c.workDir),
signal: c.abortSignal,
});
logPlanStage(c.log, "extract", stageStarted);
stageStarted = Date.now();
const mixed = await mixPlanAudio(c, c.compiledDir);
@@ -60,6 +60,10 @@ export interface CompositionMetadata {
* slightly different `end` / `mediaStart` / `volume` than the compiled
* HTML and we want to ignore sub-millisecond float noise.
*/
export function audioWorkDir(workDir: string): string {
return join(workDir, "audio-work");
}
export const BROWSER_MEDIA_EPSILON = 0.0001;
/**
@@ -29,7 +29,7 @@ import {
type AudioProcessingFailure,
type MixResult,
} from "@hyperframes/engine";
import type { CompositionMetadata } from "../shared.js";
import { audioWorkDir, type CompositionMetadata } from "../shared.js";
import type { ProducerLogger } from "../../../logger.js";
import { encoderFailureError } from "../encoderInterruption.js";
import { limitDeliveryPeaks } from "../audioDeliveryLimit.js";
@@ -202,7 +202,7 @@ async function mixAudioForDelivery(
audioResult = await processCompositionAudio(
audios,
projectDir,
join(workDir, "audio-work"),
audioWorkDir(workDir),
audioOutputPath,
duration,
abortSignal,
@@ -52,6 +52,10 @@ import {
resolveVideoExtractionWindow,
isHttpUrl,
assertPublicHttpsUrl,
downloadToTemp,
resolveRestrictPageNetwork,
isUrlNotPermittedError,
writeUrlDownloadTelemetry,
resolveProjectRelativeSrc,
runVideoExtractionWithRetry,
safeVideoExtractionSourceIdentity,
@@ -102,6 +106,7 @@ export interface ExtractVideosStageInput {
shownBoxes?: ReadonlyMap<string, ShownBox>;
skipFrameExtractionIds?: readonly string[];
urlByAbsentLocalPath?: ReadonlyMap<string, string>;
audioDownloadDir?: string;
onProgress?: ProgressCallback;
}
@@ -428,6 +433,7 @@ export async function runExtractVideosStage(
deferRangeExtraction,
shownBoxes,
urlByAbsentLocalPath,
audioDownloadDir,
skipFrameExtractionIds = [],
} = input;
@@ -530,7 +536,15 @@ export async function runExtractVideosStage(
}
if (skipFrameExtractionIds.length > 0) {
await appendVideoAudioFromProbe({ projectDir, compiledDir, composition, urlByAbsentLocalPath });
await appendVideoAudioFromProbe({
projectDir,
compiledDir,
composition,
urlByAbsentLocalPath,
downloadDir: audioDownloadDir,
signal: abortSignal,
log,
});
videoReadinessSkipIds = [...skipFrameExtractionIds];
} else if (composition.videos.length > 0) {
const totalVideos = composition.videos.length;
@@ -653,28 +667,60 @@ function isPublicHttpsUrl(url: string): boolean {
}
}
/**
* The audio-only form of the extract stage: which videos carry sound takes a probe per source, not their frames.
* Each video is moved to its extraction window first, as extraction does, so its sound lands where its picture does.
*/
export async function appendVideoAudioFromProbe(input: {
interface VideoAudioProbeInput {
projectDir: string;
compiledDir: string;
composition: CompositionMetadata;
urlByAbsentLocalPath?: ReadonlyMap<string, string>;
}): Promise<void> {
const { projectDir, compiledDir, composition, urlByAbsentLocalPath } = input;
/** Where a composition URL is downloaded before probing on a render service: the mixer's work folder, so the mix reuses it. */
downloadDir?: string;
signal?: AbortSignal;
log?: ProducerLogger;
}
function localProbeSource(src: string, input: VideoAudioProbeInput): string | null {
const path = resolveProjectRelativeSrc(src, input.projectDir, input.compiledDir);
const readFrom = input.urlByAbsentLocalPath?.get(path) ?? path;
return isHttpUrl(readFrom) || existsSync(readFrom) ? readFrom : null;
}
/** On a render service a composition URL is fetched under the download address rules and probed from that copy. */
async function remoteProbeSource(
video: CompositionMetadata["videos"][number],
input: VideoAudioProbeInput,
): Promise<string | null> {
if (!isPublicHttpsUrl(video.src)) return null;
if (!resolveRestrictPageNetwork()) return video.src;
if (!video.hasAudio || video.hidden) return null;
const downloadDir = input.downloadDir ?? join(input.compiledDir, REMOTE_MEDIA_SUBDIR);
try {
return await downloadToTemp(video.src, downloadDir, undefined, input.signal, undefined, {
onTelemetry: writeUrlDownloadTelemetry,
});
} catch (error) {
if (!isUrlNotPermittedError(error)) throw error;
input.log?.warn("Video sound skipped: its URL is outside the download address rules", {
videoId: video.id,
});
return null;
}
}
/**
* The audio-only form of the extract stage: which videos carry sound takes a probe per source, not their frames.
* Each video is moved to its extraction window first, as extraction does, so its sound lands where its picture does.
*/
export async function appendVideoAudioFromProbe(input: VideoAudioProbeInput): Promise<void> {
const { composition } = input;
const videos = composition.videos.filter(
(video) => !isVideoPastTimelineEnd(video, composition.duration),
);
const probed = await Promise.all(
videos.map(async (video) => {
if (isHttpUrl(video.src) && !isPublicHttpsUrl(video.src)) return null;
const path = isHttpUrl(video.src)
? video.src
: resolveProjectRelativeSrc(video.src, projectDir, compiledDir);
const readFrom = urlByAbsentLocalPath?.get(path) ?? path;
if (!isHttpUrl(readFrom) && !existsSync(readFrom)) return null;
const readFrom = isHttpUrl(video.src)
? await remoteProbeSource(video, input)
: localProbeSource(video.src, input);
if (readFrom === null) return null;
const metadata = await extractMediaMetadata(readFrom);
const window = await resolveFinalFrameExtractionWindow(
readFrom,
@@ -2,12 +2,14 @@ import { afterEach, beforeEach, describe, expect, it } from "bun:test";
import { spawnSync } from "node:child_process";
import { createServer } from "node:http";
import type { AddressInfo } from "node:net";
import { mkdirSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { getFfmpegBinary } from "@hyperframes/engine";
import { _setDownloadFetchForTests, getFfmpegBinary, resolveConfig } from "@hyperframes/engine";
import type { ProducerLogger } from "../../../logger.js";
import { createRenderJob } from "../../renderOrchestrator.js";
import { collectRenderMedia } from "../../renderMediaCollector.js";
import { appendVideoAudioFromProbe } from "./extractVideosStage.js";
import { appendVideoAudioFromProbe, runExtractVideosStage } from "./extractVideosStage.js";
const HAS_FFMPEG = spawnSync(getFfmpegBinary(), ["-version"]).status === 0;
@@ -17,7 +19,11 @@ describe.skipIf(!HAS_FFMPEG)("appendVideoAudioFromProbe", () => {
dir = mkdtempSync(join(tmpdir(), "hf-video-audio-probe-"));
mkdirSync(join(dir, "compiled"));
});
afterEach(() => rmSync(dir, { recursive: true, force: true }));
afterEach(() => {
rmSync(dir, { recursive: true, force: true });
_setDownloadFetchForTests();
delete process.env.PRODUCER_RESTRICT_PAGE_NETWORK;
});
const make = (name: string, withAudio: boolean) => {
const args = [
@@ -83,4 +89,142 @@ describe.skipIf(!HAS_FFMPEG)("appendVideoAudioFromProbe", () => {
await new Promise((resolve) => server.close(resolve));
}
});
const remoteSrc = "https://media.probe.example/talk.mp4";
const remoteComposition = (attrs = 'data-has-audio="true"') => {
const composition =
collectRenderMedia(`<div data-composition-id="root" data-start="0" data-duration="2">
<video id="r" src="${remoteSrc}" data-start="0" data-duration="2" ${attrs}></video>
</div>`);
composition.audios.length = 0;
return composition;
};
const serveTalk = (fetched: string[] = []) => {
make("talk.mp4", true);
const bytes = readFileSync(join(dir, "talk.mp4"));
_setDownloadFetchForTests(async (url) => {
fetched.push(url);
return new Response(bytes, {
status: 200,
headers: { "content-type": "video/mp4", "content-length": String(bytes.length) },
});
});
process.env.PRODUCER_RESTRICT_PAGE_NETWORK = "true";
return fetched;
};
const failDownloads = (error: Error | Response) => {
_setDownloadFetchForTests(async () => {
if (error instanceof Response) return error;
throw error;
});
process.env.PRODUCER_RESTRICT_PAGE_NETWORK = "true";
};
it("on a render service probes a composition URL from a copy the downloader fetched", async () => {
const fetched = serveTalk();
const composition = remoteComposition();
const downloadDir = join(dir, "audio-work");
await appendVideoAudioFromProbe({
projectDir: dir,
compiledDir: join(dir, "compiled"),
composition,
downloadDir,
});
expect(fetched).toEqual([remoteSrc]);
expect(readdirSync(downloadDir)).toHaveLength(1);
expect(composition.audios.map((audio) => audio.id)).toEqual(["r-audio"]);
expect(composition.audios[0]?.src).toBe(remoteSrc);
});
it("on a render service skips and logs a composition URL the address rules refuse", async () => {
failDownloads(
Object.assign(new Error("host resolves to a non-public address"), {
code: "HF_NON_PUBLIC_ADDRESS",
}),
);
const composition = remoteComposition();
const warnings: unknown[][] = [];
const log = { warn: (...args: unknown[]) => warnings.push(args) } as unknown as ProducerLogger;
await appendVideoAudioFromProbe({
projectDir: dir,
compiledDir: join(dir, "compiled"),
composition,
log,
});
expect(composition.audios).toEqual([]);
expect(warnings).toEqual([[expect.stringContaining("skipped"), { videoId: "r" }]]);
});
it("on a render service fails on a download error that is not an address refusal", async () => {
failDownloads(new Response("gone", { status: 404 }));
await expect(
appendVideoAudioFromProbe({
projectDir: dir,
compiledDir: join(dir, "compiled"),
composition: remoteComposition(),
}),
).rejects.toThrow(/HTTP 404/);
});
it("on a render service a cancelled render stops the download", async () => {
const fetched = serveTalk();
const controller = new AbortController();
controller.abort();
await expect(
appendVideoAudioFromProbe({
projectDir: dir,
compiledDir: join(dir, "compiled"),
composition: remoteComposition(),
signal: controller.signal,
}),
).rejects.toThrow();
expect(fetched).toEqual([]);
});
it.each([
["has no sound", ""],
["is muted", 'data-has-audio="true" muted'],
["is hidden", 'data-has-audio="true"'],
])("on a render service downloads nothing for a video that %s", async (name, attrs) => {
const fetched = serveTalk();
const composition = remoteComposition(attrs);
if (name === "is hidden") composition.videos[0]!.hidden = true;
await appendVideoAudioFromProbe({
projectDir: dir,
compiledDir: join(dir, "compiled"),
composition,
});
expect(fetched).toEqual([]);
expect(composition.audios).toEqual([]);
});
it("the extract stage downloads a passthrough video's URL into the audio work folder", async () => {
const fetched = serveTalk();
const composition = remoteComposition();
const audioDownloadDir = join(dir, "audio-work");
await runExtractVideosStage({
projectDir: dir,
compiledDir: join(dir, "compiled"),
job: createRenderJob({ fps: { num: 30, den: 1 }, quality: "standard", hdrMode: "force-sdr" }),
cfg: resolveConfig(),
composition,
skipFrameExtractionIds: ["r"],
audioDownloadDir,
abortSignal: undefined,
assertNotAborted: () => {},
});
expect(fetched).toEqual([remoteSrc]);
expect(readdirSync(audioDownloadDir)).toHaveLength(1);
expect(composition.audios.map((audio) => audio.id)).toEqual(["r-audio"]);
});
});
@@ -155,6 +155,7 @@ import {
type MemorySampler,
reportExtractProgress,
updateJobStatus,
audioWorkDir,
} from "./render/shared.js";
import { frameCacheOptions } from "./render/frameCacheBudget.js";
import { buildRenderErrorDetails } from "./render/cleanup.js";
@@ -3620,6 +3621,7 @@ async function executeRenderPipeline(input: {
log,
composition,
skipFrameExtractionIds: videoLayer ? [videoLayer.videoId] : [],
audioDownloadDir: audioWorkDir(workDir),
abortSignal: executionSignal,
assertNotAborted,
// Local staging can use links; distributed plan() alone requires real copies.