Skip to content

fix(cli): reject bad keyframes --shot --samples, --from and --to values as usage errors - #9057

Merged
jrusso1020 merged 3 commits into
heygen-com:mainfrom
Deanbarrow10:Deanbarrow10/keyframes-shot-numeric-flags
Nov 29, 2026
Merged

jrusso1020 merged 3 commits into
heygen-com:mainfrom
Deanbarrow10:Deanbarrow10/keyframes-shot-numeric-flags

Conversation

@Deanbarrow10

Copy link
Copy Markdown
Contributor

What

hyperframes keyframes --shot now rejects a bad --samples, --from or --to as a usage error (exit 2) instead of quietly swapping it for something else.

Why

All three flags went through the num() helper in keyframes.ts, which turns anything that isn't a number into null. captureMotionPathShot then clamped samples to 1 through 60. On main, with a small project that has one tween, every one of these printed "onion-skin screenshot saved" and exited 0.

  • --samples abc used the default of 9.
  • --samples 0 used 1, and --samples 500 used 60.
  • --from abc --to xyz were ignored, so the whole timeline was sampled.

Related work

Fixes #9056. Same pattern as #7672 (check) and #7909 (billing).

How

  • --samples uses the shared parsePositiveIntegerArg(value, "--samples", { max: 60 }) from utils/integerArg.ts. The max matches the clamp already in motionShot.ts, so every value that passes behaves exactly as before.
  • --from and --to go through a small shotSeconds check that accepts any finite number of 0 or more and throws CliUsageError otherwise. An empty string is rejected too, since Number("") is 0.
  • The flags are checked at the start of runOnionShot, so a bad value is reported before the animated element guard runs and before any browser opens. captureOnionShot now takes the parsed options instead of parsing them itself.
  • num() is still used for the parsed keyframe values, so nothing else changes.
  • The --samples help text and the docs/packages/cli.mdx table now say it takes 1 to 60.

Test plan

  • Unit tests added in keyframes.test.ts under keyframes --shot numeric flags. They cover abc, 0, -3, 2.5, 61 and "" for --samples, and abc, -1, xyz, "" and Infinity for --from and --to. Each must throw a usage_error with exit code 2. Another test runs the command with --samples abc on a project with no tweens and checks that it fails with the usage error and writes no PNG. Two more check that unset flags keep the defaults and valid values pass through.
  • Without the fix, the 12 new rejection tests fail. With it, all 54 tests in keyframes.test.ts pass (cd packages/cli && npx vitest run src/commands/keyframes.test.ts).
  • The pre-commit hooks passed: format, lint, fallow and typecheck.
  • Manual testing with the built CLI (node dist/cli.js keyframes <project> --shot out.png ...). --samples abc, --samples 0, --samples 500, --from abc --to xyz and --from -1 each print usage plus the error, exit 2, and write no PNG. With --json the output is {"ok":false,"error":{"code":"usage_error",...}}. --samples 12 --from 0.5 --to 1.5 still saves the screenshot and exits 0.
  • Documentation updated.
  • Comments follow CONTRIBUTING.md.

🤖 Generated with Claude Code

Deanbarrow10 and others added 2 commits November 28, 2026 20:14
…es as usage errors

Closes heygen-com#9056

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs heygen-com#9056

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mintlify

mintlify Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit abcfd4f.

Approve preview

Refs heygen-com#9056

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at abcfd4ff. Thanks for this, Dean. It's a clean, well-scoped fix, and the PR description made it easy to check.

What I checked

  • Behaviour. With the built CLI, --samples abc, --samples 0, --from -1 and --to Infinity each exit 2 and write no PNG. With --json, the output is {"ok":false,"error":{"code":"usage_error",…}}. --samples 12 --from 0.5 --to 1.5 goes on to the normal animated-element check and exits 0, as before.
  • The tests guard the fix. keyframes.test.ts passes locally (54/54). With the old num() parsing put back for the three flags, the 12 new rejection tests fail, so they would catch a regression.
  • Same behaviour for valid values. Reusing parsePositiveIntegerArg with max: 60 matches the existing Math.max(1, Math.min(60, …)) clamp in motionShot.ts, so every value that now passes renders exactly as before. Rejecting "" in shotSeconds is a good catch, since Number("") is 0.
  • Order. Parsing the flags at the top of runOnionShot means a bad value is reported before the animated-element check and before any browser starts. Passing the parsed options into captureOnionShot keeps a single parse.
  • The help text and the docs table both say 1 to 60. The commits are signed, CI is green, and the branch merges cleanly with current main.

Optional, not for this PR

--from 2 --to 1 (an inverted range) is still accepted. If that is worth a usage error too, it would make a nice small follow-up.

Need ✅ (silent fallbacks hid bad input) · Size ✅ · Reuse ✅ (the shared integer-flag helper) · Simpler ✅ · Structure ✅
Risk: low. Only invalid values change behaviour. Valid ones take the same path as before.

— Rames

@jrusso1020
jrusso1020 added this pull request to the merge queue Nov 29, 2026
Merged via the queue into heygen-com:main with commit 8482be0 Nov 29, 2026
77 checks passed
@miguel-heygen miguel-heygen mentioned this pull request Nov 29, 2026
5 of 6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli: keyframes --shot silently replaces bad --samples, --from and --to values

2 participants