mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-12 15:20:13 +00:00
fix(producer): preserve render request config contracts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { DEFAULT_CONFIG } from "@hyperframes/engine";
|
||||
import { DEFAULT_CONFIG, resolveConfig } from "@hyperframes/engine";
|
||||
import {
|
||||
createRenderRequest,
|
||||
distributedConfigFromRequest,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
renderRequestFromDistributedConfig,
|
||||
serializeRenderRequest,
|
||||
} from "./renderRequest.js";
|
||||
import { InvalidConfigError } from "./services/distributed/renderConfigValidation.js";
|
||||
|
||||
const originalForceScreenshot = process.env.PRODUCER_FORCE_SCREENSHOT;
|
||||
|
||||
@@ -203,6 +204,52 @@ describe("RenderRequest", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("accepts fractional coresPerWorker snapshots from the canonical resolver", () => {
|
||||
const engineConfig = resolveConfig({ coresPerWorker: 0.5 });
|
||||
const value = createRenderRequest({
|
||||
projectDir: "/project",
|
||||
outputPath: "/output/video.mp4",
|
||||
engineConfig,
|
||||
options: {
|
||||
fps: { num: 30, den: 1 },
|
||||
quality: "standard",
|
||||
format: "mp4",
|
||||
distributed: { width: 1920, height: 1080, cfr: true },
|
||||
},
|
||||
});
|
||||
|
||||
expect(value.options.engineConfig.coresPerWorker).toBe(0.5);
|
||||
expect(parseRenderRequest(serializeRenderRequest(value))).toEqual(value);
|
||||
|
||||
const distributed = distributedConfigFromRequest(value);
|
||||
(distributed as { engineConfig: unknown }).engineConfig = engineConfig;
|
||||
expect(
|
||||
renderRequestFromDistributedConfig({
|
||||
projectDir: value.projectDir,
|
||||
outputPath: value.outputPath,
|
||||
config: distributed,
|
||||
}).options.engineConfig.coresPerWorker,
|
||||
).toBe(0.5);
|
||||
});
|
||||
|
||||
it("preserves the distributed InvalidConfigError contract for engine snapshots", () => {
|
||||
const value = request();
|
||||
const distributed = distributedConfigFromRequest(value);
|
||||
(distributed as { engineConfig: unknown }).engineConfig = {};
|
||||
|
||||
try {
|
||||
renderRequestFromDistributedConfig({
|
||||
projectDir: value.projectDir,
|
||||
outputPath: value.outputPath,
|
||||
config: distributed,
|
||||
});
|
||||
throw new Error("expected distributed validation to fail");
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(InvalidConfigError);
|
||||
expect((error as InvalidConfigError).field).toBe("config.engineConfig");
|
||||
}
|
||||
});
|
||||
|
||||
it("validates the reverse distributed adapter at the wire boundary", () => {
|
||||
const distributed = distributedConfigFromRequest(request());
|
||||
distributed.width = 1921;
|
||||
|
||||
@@ -208,7 +208,14 @@ export function validateDistributedRenderConfig(
|
||||
validateVariablesPayload(config.variables);
|
||||
}
|
||||
if (config.engineConfig !== undefined) {
|
||||
validateEngineConfigSnapshot(config.engineConfig);
|
||||
try {
|
||||
validateEngineConfigSnapshot(config.engineConfig);
|
||||
} catch (error) {
|
||||
throw new InvalidConfigError(
|
||||
"config.engineConfig",
|
||||
error instanceof Error ? error.message : "must be a valid engine config snapshot",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
|
||||
Reference in New Issue
Block a user