diff --git a/packages/producer/src/services/distributed/planV2.test.ts b/packages/producer/src/services/distributed/planV2.test.ts index 9c1be46b88..87ca9d13b6 100644 --- a/packages/producer/src/services/distributed/planV2.test.ts +++ b/packages/producer/src/services/distributed/planV2.test.ts @@ -450,20 +450,43 @@ describe("Plan v2 manifest", () => { ); }); - it("keeps a deferred source the page itself loads in every chunk", () => { + it("ships each compiled/ video source only to the chunks that show it", () => { const root = tempPath("hf-plan-v2-deferred-compiled-source-"); const v1 = createV1Plan(root, { video: true, videoStart: 1 / 30, deferredSource: "compiled/hero.mp4", }); + // A second clip shown in both chunks, also shipped from compiled/. + const videosPath = join(v1, "meta", "videos.json"); + const videos = JSON.parse(readFileSync(videosPath, "utf-8")) as PlanVideosJson; + const hero = videos.extracted[0]!; + videos.videos.push({ ...videos.videos[0]!, id: "long", src: "long.mp4", start: 0 }); + videos.extracted.push({ + ...hero, + videoId: "long", + deferredRange: { ...hero.deferredRange!, sourcePath: "compiled/long.mp4" }, + }); + writeFileSync(videosPath, JSON.stringify(videos)); + writeFileSync(join(v1, "compiled", "long.mp4"), "long source video"); + refreshV1PlanHash(v1); const manifest = readPlanV2Manifest(createPlanV2FromV1(v1, join(root, "v2")).planDir); + const chunksOf = (path: string) => + manifest.artifacts.find((artifact) => artifact.path === path)?.chunks; expect(manifest.limitations.videoDependencyMode).toBe("source-extract"); - for (const chunkIndex of [0, 1]) { - const artifacts = listPlanV2ArtifactsForTarget(manifest, { role: "chunk", chunkIndex }); - expect(artifacts.some((artifact) => artifact.path === "compiled/hero.mp4")).toBe(true); - } + expect(chunksOf("compiled/hero.mp4")).toEqual([1]); + expect(chunksOf("compiled/long.mp4")).toEqual([0, 1]); + expect(chunksOf("compiled/index.html")).toBe("all"); + expect(chunksOf("compiled/asset.txt")).toBe("all"); + + const chunk0Dir = join(root, "chunk-0"); + materializePlanV2Target(join(root, "v2"), { role: "chunk", chunkIndex: 0 }, chunk0Dir); + expect(existsSync(join(chunk0Dir, "compiled", "hero.mp4"))).toBe(false); + expect(existsSync(join(chunk0Dir, "compiled", "long.mp4"))).toBe(true); + expect(validatePlanV2MaterializedTarget(chunk0Dir, { role: "chunk", chunkIndex: 0 })).not.toBe( + null, + ); }); it("rejects a deferred video source outside the plan directory", () => { diff --git a/packages/producer/src/services/distributed/planV2.ts b/packages/producer/src/services/distributed/planV2.ts index 02183f9bda..690982c758 100644 --- a/packages/producer/src/services/distributed/planV2.ts +++ b/packages/producer/src/services/distributed/planV2.ts @@ -288,8 +288,18 @@ function artifactTargets( if (path === "plan.json" || path === "meta/chunks.json" || path === "meta/encoder.json") { return { chunks: "all", assembler: true }; } - // Each chunk's page loads every