Skip to content

feat: add prepare image cli - #58

Merged
edhor1608 merged 1 commit into
mainfrom
codex/v1-prepare-image-cli
May 14, 2026
Merged

edhor1608 merged 1 commit into
mainfrom
codex/v1-prepare-image-cli

Conversation

@edhor1608

@edhor1608 edhor1608 commented May 14, 2026 •

Copy link
Copy Markdown
Owner

Note

Add prepare-image CLI to export images as JPEG with white background compositing

  • Adds a prepare-image CLI (src/cli/prepare_image.ts) accepting <input>, --out, --border-px, and --help flags; exits nonzero on invalid usage or processing errors.
  • Adds prepareImage domain function (src/domain/prepare_image.ts) that uses ffprobe to detect source dimensions (respecting rotation metadata), computes layout, then runs ffmpeg to composite the source onto a white background canvas and exports a single-frame JPEG with metadata stripped.
  • Adds computePrepareImageLayout (src/domain/prepare_image_layout.ts) to deterministically select landscape (3:2) or portrait (3:4) output targets, avoid upscaling, and compute render size, offsets, and optional centered cover crop.
  • Adds resolvePrepareImageOutputPath (src/domain/output_path.ts) to normalize the output to .jpg, create parent directories, reject directory paths, and auto-suffix (-1, -2, …) to avoid overwriting existing files.
  • Default border is 165px when --border-px is omitted.

Macroscope summarized 9e86a92.

Summary by CodeRabbit

  • New Features

    • Added a prepare-image CLI to produce white-background prepared images with optional border sizing and prints the output path.
  • Documentation

    • Added a plan describing CLI usage, validation, processing approach, and key implementation decisions.
  • Tests

    • Added integration tests covering --help output and end-to-end image export and dimension verification.
  • Chores

    • Registered the new CLI entry and updated test scripts to include its integration tests.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 14, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3cffd71a-2aa7-4ee0-9b72-568d42ce3813

📥 Commits

Reviewing files that changed from the base of the PR and between 7d1afd5 and f5e6a40.

📒 Files selected for processing (7)
  • docs/plans/v1-prepare-image-cli.md
  • package.json
  • src/cli/prepare_image.ts
  • src/domain/prepare_image.ts
  • tests/helpers/cli.ts
  • tests/integration/cli.integration.test.ts
  • tests/integration/prepare_image.integration.test.ts

📝 Walkthrough

Walkthrough

This PR introduces a new prepare-image CLI command and wiring in package.json and test helpers. It adds a domain prepareImage function that uses ffprobe to read source dimensions/rotation, computes a layout, and runs ffmpeg with a single filter graph to crop/scale, composite transparent input over a white background, and emit a JPEG. The CLI entrypoint parses positional input plus --out and optional --border-px, calls prepareImage, and prints the output path. Integration tests verify --help and a PNG→JPEG conversion asserting exit code, stdout, file existence, and output dimensions.

Possibly related PRs

  • edhor1608/passepartout#54: Related integration test/helper changes for consistent --help behavior and CLI test matrix inclusion.
  • edhor1608/passepartout#6: Previously added CLI plumbing changes (command union/dispatch) that overlap test helper wiring patterns.

Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Docstring Coverage ❌ Error Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add prepare image cli' clearly and directly describes the main change: introducing a new CLI entrypoint for preparing images.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/v1-prepare-image-cli
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch codex/v1-prepare-image-cli

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Comment @coderabbitai help to get the list of available commands and usage tips.

edhor1608 commented May 14, 2026 •

Copy link
Copy Markdown
Owner Author

coderabbitai[bot]
coderabbitai Bot previously requested changes May 14, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/integration/prepare_image.integration.test.ts`:
- Around line 19-36: The test "exports a PNG as a JPEG and prints the actual
output path" runs FFmpeg/FFprobe and needs an explicit 30s timeout; update the
test to use a 30_000 ms timeout by passing 30000 as the third argument to the
test(...) call (or call jest.setTimeout(30000) at the top of the file) so that
the async test using runPrepareImageCli and inspectMedia has a 30-second limit
instead of the default 5s.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 48e400f8-5c82-4867-9842-4d336ed4b783

📥 Commits

Reviewing files that changed from the base of the PR and between 5c28c6b and 7d1afd5.

📒 Files selected for processing (7)
  • docs/plans/v1-prepare-image-cli.md
  • package.json
  • src/cli/prepare_image.ts
  • src/domain/prepare_image.ts
  • tests/helpers/cli.ts
  • tests/integration/cli.integration.test.ts
  • tests/integration/prepare_image.integration.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: check
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc)

**/*.{js,ts,jsx,tsx}: Prioritize using plain JavaScript/TypeScript instead of libraries for fundamental algorithms (e.g., use Array methods instead of lodash)
Use functional programming patterns and immutable data structures in JavaScript/TypeScript code

Files:

  • tests/integration/cli.integration.test.ts
  • src/cli/prepare_image.ts
  • tests/integration/prepare_image.integration.test.ts
  • tests/helpers/cli.ts
  • src/domain/prepare_image.ts
tests/**/*.test.{ts,tsx,js}

📄 CodeRabbit inference engine (AGENTS.md)

Use explicit 30 second timeout for ffmpeg-heavy tests instead of relying on Bun's default 5 second per-test timeout

Files:

  • tests/integration/cli.integration.test.ts
  • tests/integration/prepare_image.integration.test.ts
src/cli/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Organize code into src/cli for command entry points and argument parsing

Files:

  • src/cli/prepare_image.ts
src/domain/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Place deterministic policy, analysis, export, report, benchmark, and validation logic in src/domain

Files:

  • src/domain/prepare_image.ts
🔇 Additional comments (16)
src/domain/prepare_image.ts (8)

1-23: LGTM!


24-61: LGTM!


63-91: LGTM!


109-115: LGTM!


117-124: LGTM!


126-142: LGTM!


144-154: LGTM!


93-107: ⚡ Quick win

No action needed. The buildPrepareImageFilter function is safe from FFmpeg filter injection because all PrepareImageLayout properties are strictly typed as number. TypeScript ensures that non-numeric values cannot reach the filter string construction, making injection impossible. No additional sanitization is required.

			> Likely an incorrect or invalid review comment.
src/cli/prepare_image.ts (4)

1-14: LGTM!


50-66: LGTM!


68-80: LGTM!


24-41: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Fix the argument parsing loop to avoid skipping arguments.

There's a bug in the argument parsing loop. On lines 29 and 36, you increment index and then continue, but the for loop at line 24 will increment index again at the end of the iteration. This causes the parser to skip the next argument after --out or --border-px.

For example, if the args are ["input.png", "--out", "output.jpg", "--border-px", "10"], after processing --out, index is incremented from 1 to 2 (line 29), then the loop increments it to 3, skipping "--border-px".

🐛 Proposed fix to remove manual index increments
   if (flag === "--out") {
     outputPath = readFlagValue(args, index, "--out");
-    index += 1;
     continue;
   }

   if (flag === "--border-px") {
     const value = readFlagValue(args, index, "--border-px");
     borderPx = parseBorderPx(value);
-    index += 1;
     continue;
   }

The for loop's increment expression already handles advancing to the next argument.

			> Likely an incorrect or invalid review comment.
tests/helpers/cli.ts (1)

23-24: LGTM!

Also applies to: 39-39, 110-112

tests/integration/cli.integration.test.ts (1)

28-28: LGTM!

package.json (1)

16-16: LGTM!

Also applies to: 26-26

docs/plans/v1-prepare-image-cli.md (1)

1-21: LGTM!

Comment thread tests/integration/prepare_image.integration.test.ts
@edhor1608

Copy link
Copy Markdown
Owner Author

@coderabbitai review\n\nAll active review threads have been addressed or replied to and resolved. Please re-review the current stack state.

@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown

@edhor1608 Thanks for the update! I'll kick off a fresh review of the current stack state now.

✅ Actions performed

Full review triggered.

@edhor1608
edhor1608 marked this pull request as ready for review May 14, 2026 20:54
@edhor1608
edhor1608 force-pushed the codex/v1-prepare-image-layout branch 2 times, most recently from 1ae3a8c to b00efbf Compare May 14, 2026 20:56
@edhor1608
edhor1608 force-pushed the codex/v1-prepare-image-cli branch 2 times, most recently from b1e6ea8 to 9e86a92 Compare May 14, 2026 20:59
@edhor1608
edhor1608 dismissed coderabbitai[bot]’s stale review May 14, 2026 21:00

Dismissed after addressed review thread was resolved and fresh CodeRabbit status passed.

edhor1608 commented May 14, 2026 •

Copy link
Copy Markdown
Owner Author

Merge activity

  • May 14, 9:04 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 14, 9:05 PM UTC: Graphite rebased this pull request as part of a merge.
  • May 14, 9:06 PM UTC: @edhor1608 merged this pull request with Graphite.

@edhor1608
edhor1608 changed the base branch from codex/v1-prepare-image-layout to graphite-base/58 May 14, 2026 21:04
@edhor1608
edhor1608 changed the base branch from graphite-base/58 to main May 14, 2026 21:04
@edhor1608
edhor1608 force-pushed the codex/v1-prepare-image-cli branch from 9e86a92 to f5e6a40 Compare May 14, 2026 21:05
@edhor1608
edhor1608 merged commit dfd531e into main May 14, 2026
2 of 3 checks passed
@edhor1608
edhor1608 deleted the codex/v1-prepare-image-cli branch May 15, 2026 18:54
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.

1 participant