Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/cli/src/commands/layout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
vi.mock("../utils/project.js", () => resolveProjectMock());
vi.mock("@hyperframes/core/compiler", () => bundleToSingleHtmlFailureMock());

import { createInspectCommand } from "./layout.js";
import { createInspectCommand, parseLayoutTolerance } from "./layout.js";

afterEach(() => {
vi.restoreAllMocks();
Expand Down Expand Up @@ -49,3 +49,14 @@ describe("layout command deprecation (U5)", () => {
expect(parsed._meta.deprecated).toBe(true);
});
});

describe("parseLayoutTolerance", () => {
it("preserves an explicit zero tolerance", () => {
expect(parseLayoutTolerance("0")).toBe(0);
});

it("clamps negative tolerance and defaults invalid input", () => {
expect(parseLayoutTolerance("-1")).toBe(0);
expect(parseLayoutTolerance("invalid")).toBe(2);
});
});
7 changes: 6 additions & 1 deletion packages/cli/src/commands/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const INSPECT_SCHEMA_VERSION = 1;
const MOTION_FPS = 20;
const MOTION_MAX_SAMPLES = 300;

export function parseLayoutTolerance(value: string): number {
const parsed = Number.parseFloat(value);
return Math.max(0, Number.isFinite(parsed) ? parsed : 2);
}

export const examples: Example[] = [
["Inspect visual layout across the current composition", "hyperframes layout"],
["Inspect a specific project", "hyperframes layout ./my-video"],
Expand Down Expand Up @@ -486,7 +491,7 @@ export function createInspectCommand(commandName: "inspect" | "layout") {
printDeprecationNotice(commandName);
const project = resolveProject(args.dir);
const samples = Math.max(1, parseInt(args.samples as string, 10) || 9);
const tolerance = Math.max(0, parseFloat(args.tolerance as string) || 2);
const tolerance = parseLayoutTolerance(args.tolerance as string);
const timeout = Math.max(500, parseInt(args.timeout as string, 10) || 5000);
const maxIssues = Math.max(1, parseInt(args["max-issues"] as string, 10) || 80);
const at = parseAt(args.at);
Expand Down