-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathdockerRunArgs.test.ts
More file actions
293 lines (268 loc) · 9 KB
/
Copy pathdockerRunArgs.test.ts
File metadata and controls
293 lines (268 loc) · 9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import { describe, expect, it } from "vitest";
import { buildDockerRunArgs, type DockerRenderOptions } from "./dockerRunArgs.js";
const BASE: DockerRenderOptions = {
fps: { num: 30, den: 1 },
quality: "standard",
format: "mp4",
gpu: false,
browserGpu: false,
hdrMode: "auto",
crf: undefined,
videoBitrate: undefined,
quiet: false,
};
const FIXED_INPUT = {
imageTag: "hyperframes-renderer:0.0.0-test",
projectDir: "/abs/proj",
outputDir: "/abs/out",
outputFilename: "out.mp4",
};
describe("buildDockerRunArgs", () => {
it("matches snapshot for the default render", () => {
expect(buildDockerRunArgs({ ...FIXED_INPUT, options: BASE })).toMatchInlineSnapshot(`
[
"run",
"--rm",
"--platform",
"linux/amd64",
"--shm-size=2g",
"-v",
"/abs/proj:/project:ro",
"-v",
"/abs/out:/output",
"hyperframes-renderer:0.0.0-test",
"/project",
"--output",
"/output/out.mp4",
"--fps",
"30",
"--quality",
"standard",
"--format",
"mp4",
"--no-browser-gpu",
]
`);
});
it("omits --workers when auto sizing should happen inside the container", () => {
const args = buildDockerRunArgs({ ...FIXED_INPUT, options: BASE });
expect(args).not.toContain("--workers");
});
it("matches snapshot when every renderer flag is enabled", () => {
expect(
buildDockerRunArgs({
...FIXED_INPUT,
options: {
...BASE,
gpu: true,
hdrMode: "force-hdr",
crf: 18,
videoBitrate: undefined,
quiet: true,
},
}),
).toMatchInlineSnapshot(`
[
"run",
"--rm",
"--platform",
"linux/amd64",
"--shm-size=2g",
"--gpus",
"all",
"-v",
"/abs/proj:/project:ro",
"-v",
"/abs/out:/output",
"hyperframes-renderer:0.0.0-test",
"/project",
"--output",
"/output/out.mp4",
"--fps",
"30",
"--quality",
"standard",
"--format",
"mp4",
"--crf",
"18",
"--quiet",
"--gpu",
"--no-browser-gpu",
"--hdr",
]
`);
});
// Regression for the original PR feedback: --hdr was silently dropped from
// the docker arg array. Keep this assertion explicit (in addition to the
// snapshot above) so the failure message points directly at the flag.
it("forwards --hdr to the container when hdrMode is force-hdr", () => {
const args = buildDockerRunArgs({
...FIXED_INPUT,
options: { ...BASE, hdrMode: "force-hdr" },
});
expect(args).toContain("--hdr");
expect(args).not.toContain("--sdr");
});
it("forwards --sdr to the container when hdrMode is force-sdr", () => {
const args = buildDockerRunArgs({
...FIXED_INPUT,
options: { ...BASE, hdrMode: "force-sdr" },
});
expect(args).toContain("--sdr");
expect(args).not.toContain("--hdr");
});
it("omits --hdr and --sdr when hdrMode is auto", () => {
const args = buildDockerRunArgs({ ...FIXED_INPUT, options: BASE });
expect(args).not.toContain("--hdr");
expect(args).not.toContain("--sdr");
});
it("requests host GPU passthrough only when gpu is enabled", () => {
const off = buildDockerRunArgs({ ...FIXED_INPUT, options: BASE });
expect(off).not.toContain("--gpus");
expect(off).not.toContain("--gpu");
const on = buildDockerRunArgs({
...FIXED_INPUT,
options: { ...BASE, gpu: true },
});
// `--gpus all` is a docker run flag (host passthrough); `--gpu` is the
// hyperframes CLI flag forwarded into the container — both must be set.
expect(on).toContain("--gpus");
expect(on).toContain("all");
expect(on).toContain("--gpu");
});
it("forces software browser capture inside Docker", () => {
const args = buildDockerRunArgs({ ...FIXED_INPUT, options: BASE });
expect(args).toContain("--no-browser-gpu");
});
it("forwards every renderer-shaped option (regression tripwire for silent drops)", () => {
const args = buildDockerRunArgs({
...FIXED_INPUT,
options: {
fps: { num: 60, den: 1 },
quality: "high",
format: "webm",
workers: 8,
gpu: true,
browserGpu: false,
hdrMode: "force-hdr",
crf: 16,
videoBitrate: undefined,
quiet: true,
entryFile: "compositions/intro.html",
},
});
// Each value must reach the container exactly once. If a future option
// is added but only wired through to renderLocal, this test forces the
// author to update buildDockerRunArgs (and add a check here) too.
expect(args).toContain("60");
expect(args).toContain("high");
expect(args).toContain("webm");
expect(args).toContain("8");
expect(args).toContain("--crf");
expect(args).toContain("16");
expect(args).toContain("--quiet");
expect(args).toContain("--gpu");
expect(args).toContain("--no-browser-gpu");
expect(args).toContain("--hdr");
expect(args).toContain("--composition");
expect(args).toContain("compositions/intro.html");
});
it("forwards --format png-sequence to the container", () => {
const args = buildDockerRunArgs({
...FIXED_INPUT,
outputFilename: "frames",
options: { ...BASE, format: "png-sequence" },
});
const formatIdx = args.indexOf("--format");
expect(formatIdx).toBeGreaterThanOrEqual(0);
expect(args[formatIdx + 1]).toBe("png-sequence");
});
it("forwards --video-bitrate to the container when set", () => {
const args = buildDockerRunArgs({
...FIXED_INPUT,
options: { ...BASE, videoBitrate: "10M" },
});
expect(args).toContain("--video-bitrate");
expect(args).toContain("10M");
expect(args).not.toContain("--crf");
});
it("forwards --variables JSON to the container when set", () => {
const args = buildDockerRunArgs({
...FIXED_INPUT,
options: { ...BASE, variables: { title: "Hello", n: 3 } },
});
const idx = args.indexOf("--variables");
expect(idx).toBeGreaterThan(-1);
expect(args[idx + 1]).toBe('{"title":"Hello","n":3}');
});
it("omits --variables when none provided", () => {
const args = buildDockerRunArgs({ ...FIXED_INPUT, options: BASE });
expect(args).not.toContain("--variables");
});
it("omits --variables when payload is empty", () => {
const args = buildDockerRunArgs({
...FIXED_INPUT,
options: { ...BASE, variables: {} },
});
expect(args).not.toContain("--variables");
});
it("forwards --composition to the container when entryFile is set", () => {
const args = buildDockerRunArgs({
...FIXED_INPUT,
options: { ...BASE, entryFile: "compositions/intro.html" },
});
const idx = args.indexOf("--composition");
expect(idx).toBeGreaterThan(-1);
expect(args[idx + 1]).toBe("compositions/intro.html");
});
it("omits --composition when entryFile is not set", () => {
const args = buildDockerRunArgs({ ...FIXED_INPUT, options: BASE });
expect(args).not.toContain("--composition");
});
it("forwards rational --fps verbatim (NTSC 30000/1001)", () => {
// Regression for the fps fraction-syntax feature: the rational form must
// survive the host → container hop as a single `30000/1001` argument so
// the in-container CLI re-parses it as exact NTSC, not 29.97 decimal.
const args = buildDockerRunArgs({
...FIXED_INPUT,
options: { ...BASE, fps: { num: 30000, den: 1001 } },
});
const fpsIdx = args.indexOf("--fps");
expect(fpsIdx).toBeGreaterThanOrEqual(0);
expect(args[fpsIdx + 1]).toBe("30000/1001");
});
it("forwards integer --fps as a bare integer string", () => {
const args = buildDockerRunArgs({
...FIXED_INPUT,
options: { ...BASE, fps: { num: 60, den: 1 } },
});
const fpsIdx = args.indexOf("--fps");
expect(fpsIdx).toBeGreaterThanOrEqual(0);
expect(args[fpsIdx + 1]).toBe("60");
});
it("forwards --resolution to the container when outputResolution is set", () => {
const args = buildDockerRunArgs({
...FIXED_INPUT,
options: { ...BASE, outputResolution: "landscape-4k" },
});
const idx = args.indexOf("--resolution");
expect(idx).toBeGreaterThan(-1);
expect(args[idx + 1]).toBe("landscape-4k");
});
it("omits --resolution when outputResolution is not set", () => {
const args = buildDockerRunArgs({ ...FIXED_INPUT, options: BASE });
expect(args).not.toContain("--resolution");
});
it("forwards --no-page-side-compositing when pageSideCompositing is false", () => {
const args = buildDockerRunArgs({
...FIXED_INPUT,
options: { ...BASE, pageSideCompositing: false },
});
expect(args).toContain("--no-page-side-compositing");
});
it("omits --no-page-side-compositing when pageSideCompositing is not explicitly false", () => {
const args = buildDockerRunArgs({ ...FIXED_INPUT, options: BASE });
expect(args).not.toContain("--no-page-side-compositing");
});
});