|
| 1 | +import { afterEach, describe, expect, it } from "vitest"; |
| 2 | +import { DEFAULT_CONFIG } from "@hyperframes/engine"; |
| 3 | +import { |
| 4 | + createRenderRequest, |
| 5 | + distributedConfigFromRequest, |
| 6 | + parseRenderRequest, |
| 7 | + renderConfigFromRequest, |
| 8 | + renderRequestFromDistributedConfig, |
| 9 | + serializeRenderRequest, |
| 10 | +} from "./renderRequest.js"; |
| 11 | + |
| 12 | +const originalForceScreenshot = process.env.PRODUCER_FORCE_SCREENSHOT; |
| 13 | + |
| 14 | +afterEach(() => { |
| 15 | + if (originalForceScreenshot === undefined) delete process.env.PRODUCER_FORCE_SCREENSHOT; |
| 16 | + else process.env.PRODUCER_FORCE_SCREENSHOT = originalForceScreenshot; |
| 17 | +}); |
| 18 | + |
| 19 | +function request() { |
| 20 | + return createRenderRequest({ |
| 21 | + projectDir: "/project", |
| 22 | + outputPath: "/output/video.mp4", |
| 23 | + engineConfig: { ...DEFAULT_CONFIG, protocolTimeout: 123_456 }, |
| 24 | + options: { |
| 25 | + fps: { num: 30, den: 1 }, |
| 26 | + quality: "high", |
| 27 | + format: "mp4", |
| 28 | + workers: 3, |
| 29 | + useGpu: true, |
| 30 | + strictness: "best-effort", |
| 31 | + entryFile: "compositions/main.html", |
| 32 | + crf: 18, |
| 33 | + videoFrameFormat: "png", |
| 34 | + hdrMode: "force-sdr", |
| 35 | + variables: { title: "Hello", nested: { count: 2 } }, |
| 36 | + outputResolution: "landscape-4k", |
| 37 | + distributed: { |
| 38 | + width: 1920, |
| 39 | + height: 1080, |
| 40 | + codec: "h264", |
| 41 | + chunkSize: 120, |
| 42 | + maxParallelChunks: 8, |
| 43 | + cfr: true, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }); |
| 47 | +} |
| 48 | + |
| 49 | +describe("RenderRequest", () => { |
| 50 | + it("round-trips through JSON without dropping nested options", () => { |
| 51 | + const value = request(); |
| 52 | + expect(parseRenderRequest(serializeRenderRequest(value))).toEqual(value); |
| 53 | + }); |
| 54 | + |
| 55 | + it("adapts the same request to local and distributed execution", () => { |
| 56 | + const value = request(); |
| 57 | + const local = renderConfigFromRequest(value); |
| 58 | + const distributed = distributedConfigFromRequest(value); |
| 59 | + |
| 60 | + expect(local).toMatchObject({ |
| 61 | + fps: { num: 30, den: 1 }, |
| 62 | + quality: "high", |
| 63 | + format: "mp4", |
| 64 | + variables: value.options.variables, |
| 65 | + producerConfig: { protocolTimeout: 123_456 }, |
| 66 | + }); |
| 67 | + expect(distributed).toMatchObject({ |
| 68 | + fps: 30, |
| 69 | + width: 1920, |
| 70 | + height: 1080, |
| 71 | + format: "mp4", |
| 72 | + chunkSize: 120, |
| 73 | + variables: value.options.variables, |
| 74 | + producerConfig: { protocolTimeout: 123_456 }, |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + it("round-trips distributed adapter fields back into the shared request", () => { |
| 79 | + const value = request(); |
| 80 | + const distributed = distributedConfigFromRequest(value); |
| 81 | + const reconstructed = renderRequestFromDistributedConfig({ |
| 82 | + projectDir: value.projectDir, |
| 83 | + outputPath: value.outputPath, |
| 84 | + config: distributed, |
| 85 | + }); |
| 86 | + |
| 87 | + expect(reconstructed.options).toMatchObject({ |
| 88 | + fps: value.options.fps, |
| 89 | + quality: value.options.quality, |
| 90 | + format: value.options.format, |
| 91 | + entryFile: value.options.entryFile, |
| 92 | + variables: value.options.variables, |
| 93 | + distributed: value.options.distributed, |
| 94 | + }); |
| 95 | + }); |
| 96 | + |
| 97 | + it("snapshots environment-derived engine options once at the boundary", () => { |
| 98 | + process.env.PRODUCER_FORCE_SCREENSHOT = "true"; |
| 99 | + const value = createRenderRequest({ |
| 100 | + projectDir: "/project", |
| 101 | + outputPath: "/output/video.mp4", |
| 102 | + options: { fps: { num: 30, den: 1 }, quality: "standard", format: "mp4" }, |
| 103 | + }); |
| 104 | + process.env.PRODUCER_FORCE_SCREENSHOT = "false"; |
| 105 | + |
| 106 | + expect(value.options.engineConfig.forceScreenshot).toBe(true); |
| 107 | + expect(renderConfigFromRequest(value).producerConfig?.forceScreenshot).toBe(true); |
| 108 | + }); |
| 109 | + |
| 110 | + it("rejects unsupported distributed fps before an adapter launch", () => { |
| 111 | + const value = request(); |
| 112 | + value.options.fps = { num: 30_000, den: 1_001 }; |
| 113 | + expect(() => distributedConfigFromRequest(value)).toThrow("does not support fps"); |
| 114 | + }); |
| 115 | +}); |
0 commit comments