Skip to content

Write HTML. Render video. Built for agents.

fix(fallow): resolve audit findings for portrait --resolution PR

Via7e58d050f892
diff --git a/.fallowrc.jsonc b/.fallowrc.jsonc
index d0ccbb4ab4..14efceac63 100644
--- a/.fallowrc.jsonc
+++ b/.fallowrc.jsonc
@@ -743,6 +743,18 @@
// work on this same branch (commits 444639d75, b57b31beb, 6f2e9848c,
// eba8a0fa2), unrelated to the Grade group (Plan 5) currently landing.
"packages/studio/src/components/editor/propertyPanelSections.tsx",
+ // Portrait --resolution alias fix (via/resolution-portrait-fix):
+ // server.ts `render` (cyclo 10 / CRAP 31.6) and distributed/plan.ts
+ // `plan` (cyclo 33 / CRAP 36.7) are both pre-existing complexity —
+ // the PR only threads `outputResolutionAspectAgnostic` through the
+ // parseRenderOverrides/RenderInput/DistributedRenderConfig shape and
+ // adds one field spread inside `plan`. Neither function body gained
+ // branches, but the line-shift fingerprint re-flags the inherited
+ // complexity. The new re-target logic itself is extracted into
+ // `adaptAspectAgnosticResolution` in compileStage.ts to keep that
+ // stage's runCompileStage under the cyclo/cognitive thresholds.
+ "packages/producer/src/server.ts",
+ "packages/producer/src/services/distributed/plan.ts",
],
},
}
diff --git a/packages/producer/src/services/render/stages/compileStage.ts b/packages/producer/src/services/render/stages/compileStage.ts
index 5b21886a3e..cf3f13995e 100644
--- a/packages/producer/src/services/render/stages/compileStage.ts
+++ b/packages/producer/src/services/render/stages/compileStage.ts
@@ -37,7 +37,7 @@
import { join } from "node:path";
import type { EngineConfig } from "@hyperframes/engine";
-import { suggestMatchingPreset } from "@hyperframes/core";
+import { suggestMatchingPreset, type CanvasResolution } from "@hyperframes/core";
import type { CompiledComposition } from "../../htmlCompiler.js";
import { compileForRender } from "../../htmlCompiler.js";
import type { ProducerLogger } from "../../../logger.js";
@@ -110,6 +110,41 @@ export interface CompileStageResult {
deCompileGate?: string;
}
+/**
+ * Aspect-agnostic aliases (`--resolution 1080p` / `hd` / `4k` / `uhd`) all
+ * normalize to a landscape preset up-front (see `normalizeResolutionFlag`),
+ * which was historically fine because 16:9 was the only shipped orientation.
+ * Once portrait + square presets landed, that early normalization started
+ * rejecting portrait/square compositions with a cryptic "aspect ratio does
+ * not match" from `resolveDeviceScaleFactor` — a common enough hit that a
+ * field report (CLI 0.7.59) surfaced it. When the flag was aspect-agnostic,
+ * re-target the preset to the sibling that matches the composition's
+ * orientation while preserving the tier (HD vs 4K). Explicit
+ * orientation-bearing presets stay strict — a `--resolution portrait` on a
+ * landscape composition still errors, honoring the user's stated intent.
+ *
+ * Extracted so `runCompileStage` keeps its complexity envelope tight; the
+ * two-branch shape lives here.
+ */
+function adaptAspectAgnosticResolution(
+ requested: CanvasResolution | undefined,
+ aspectAgnostic: boolean | undefined,
+ width: number,
+ height: number,
+ log: ProducerLogger,
+): CanvasResolution | undefined {
+ if (!requested || !aspectAgnostic) return requested;
+ const flipped = suggestMatchingPreset(width, height, requested);
+ if (!flipped || flipped === requested) return requested;
+ log.info("Adapted aspect-agnostic --resolution to composition orientation", {
+ compositionWidth: width,
+ compositionHeight: height,
+ requestedResolution: requested,
+ effectiveResolution: flipped,
+ });
+ return flipped;
+}
+
export async function runCompileStage(input: CompileStageInput): Promise<CompileStageResult> {
const {
projectDir,
@@ -274,31 +309,13 @@ export async function runCompileStage(input: CompileStageInput): Promise<Compile
height: compiled.height,
};
const { width, height } = composition;
- // Aspect-agnostic aliases (`--resolution 1080p` / `hd` / `4k` / `uhd`) all
- // normalize to a landscape preset up-front (see `normalizeResolutionFlag`),
- // which was historically fine because 16:9 was the only shipped orientation.
- // Once portrait + square presets landed, that early normalization started
- // rejecting portrait/square compositions with a cryptic "aspect ratio does
- // not match" from `resolveDeviceScaleFactor` — a common enough hit that a
- // field report (CLI 0.7.59) surfaced it. When the flag was aspect-agnostic,
- // re-target the preset to the sibling that matches the composition's
- // orientation while preserving the tier (HD vs 4K). Explicit
- // orientation-bearing presets stay strict — a `--resolution portrait` on a
- // landscape composition still errors, honoring the user's stated intent.
- const requestedResolution = job.config.outputResolution;
- let effectiveResolution = requestedResolution;
- if (requestedResolution && job.config.outputResolutionAspectAgnostic) {
- const flipped = suggestMatchingPreset(width, height, requestedResolution);
- if (flipped && flipped !== requestedResolution) {
- log.info("Adapted aspect-agnostic --resolution to composition orientation", {
- compositionWidth: width,
- compositionHeight: height,
- requestedResolution,
- effectiveResolution: flipped,
- });
- effectiveResolution = flipped;
- }
- }
+ const effectiveResolution = adaptAspectAgnosticResolution(
+ job.config.outputResolution,
+ job.config.outputResolutionAspectAgnostic,
+ width,
+ height,
+ log,
+ );
const deviceScaleFactor = resolveDeviceScaleFactor({
compositionWidth: width,
compositionHeight: height,