Skip to content

fix(cli): reject unrecognized nonempty patch input - #1183

Merged
benvinegar merged 3 commits into
mainfrom
fix/1181-invalid-patch-input
Oct 13, 2026
Merged

benvinegar merged 3 commits into
mainfrom
fix/1181-invalid-patch-input

Conversation

@benvinegar

@benvinegar benvinegar commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #1181.

Reject nonempty explicit patch input when Pierre recognizes no file changes, instead of silently presenting a successful zero-file review. Print a useful diagnostic and return exit status 1.

Approach

  • Validate at the explicit patch loader after the existing parser runs. Do not create a second patch parser or change tolerant VCS parsing.
  • Preserve empty/whitespace input and supported mail-enveloped, traditional/unified, colorized, binary, empty-file, mode-only and rename-only patches.
  • Restore input flow after the startup terminal-color probe. Real-tmux validation exposed that idle stdin was left resumed: the diagnostic printed, but the process stayed alive instead of returning failure. Preserve input that was already flowing; pause previously idle input after replies or timeout.
  • No session/protocol or extension API changes.
  • Adds a patch Changeset. Independent of Empty reviews incorrectly report that no files match the current filter #1180 and sidebar PR fix(ui): keep the selected file visible in the sidebar during held navigation #1085.

Tests

  • New patch-loader rejection tests fail on untouched main; the preexisting malformed-input test now asserts the intentional rejection behavior.
  • Black-box CLI tests cover implicit/explicit stdin, file input, useful stderr, exit codes, empty input and valid mail-enveloped patches.
  • Theme-probe tests cover idle/paused/flowing input and timeout cleanup.
  • A real-PTY regression checks that the default-theme error path returns to the shell with status 1 without taking over the alternate screen.

Validation on Linux:

  • bun run typecheck, bun run lint, bun run format:check, bun run deps:check — passed on the final changes.
  • bun test packages/hunk/src/core/changeset/loaders.patch.test.ts packages/hunk/src/core/theme/detection.test.ts test/cli/patch-input.test.ts test/pty/invalid-patch-integration.test.ts — 28 passed.
  • bun run test — final rerun: 5,100 passed, 13 skipped, no failures.
  • bun run test:integration — 256 passed, 1 skipped, no failures. This full run started before the new invalid-patch PTY test was added; that test passed separately afterward.
  • After input-flow cleanup, reran bun test test/pty/terminal-theme-integration.test.ts test/pty/pager.test.ts test/pty/invalid-patch-integration.test.ts test/pty/watch-start-integration.test.ts — 18 passed, no failures, covering terminal probes, piped input, keyboard/mouse, startup watch and invalid-input exit.
  • bun run test:tty-smoke — final rerun: 11 passed, no failures.

CI follow-up

Added a separate test-only commit to address CI failures:

  • Website smoke checks now compare the rendered prerelease-label count with the published changelog source instead of assuming there are no prereleases. The previous assertion failed identically on untouched main (6aa52617, Website run). Stable Latest and release ordering/link assertions remain intact. All 103 browser smoke tests passed locally (1 skipped).
  • Real Git status fixtures receive a 30-second test budget; Windows CI exceeded the default five seconds and killed Git mid-fixture. No tests or platform checks are skipped.

No product behavior, generated release metadata or workflow gating changes are included in this follow-up. The identical test-only commit is also on #1182 so both independent PRs can pass CI.

Real terminal evidence

Source hunk patch bad.patch --no-extensions, where bad.patch contains only not a patch, in a real Linux tmux PTY at 120×32 with the default terminal theme:

hunk: No recognizable file changes in patch input (/tmp/…/bad.patch).

Provide a unified diff, or check the command producing the patch.
HUNK_EXIT:1
bash-5.3$

The excerpt is actual tmux screen text, not redirected CLI stdout. The new PTY test verifies the same failure/exit behavior. macOS and Windows not tested locally; non-PTY tests use portable process/path APIs. No installed binary or existing user window was changed.

Limits

This rejects entirely unrecognized nonempty input; it does not add exhaustive validation of every patch record or change partially recognized inputs. Plain-text hunk pager fallback remains unchanged.

This PR description was generated by Pi using gpt-6.1-sol

@vercel

vercel Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hunk-web Ready Ready Preview Oct 13, 2026 8:05pm UTC

Request Review

@benvinegar
benvinegar marked this pull request as ready for review October 13, 2026 18:17
@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Adds validation to reject malformed patch input.

The runtime changes have no established blocking defect, but the required environment-access rule must be satisfied before merging.

Findings

  1. P2 Required environment helper bypassed ▶
  2. P2 Exit tests can hang ▶
Fix with agent prompt
### Issue 1
test/cli/patch-input.test.ts:19
The new test reads `process.env` directly. The repository guide says, “Never access `process.env` directly,” and requires the approved environment helper instead. Use that helper to build the child environment before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 2
test/cli/patch-input.test.ts:15-20
`runTestPatch` uses `Bun.spawnSync` without a timeout. If the CLI stops exiting-the failure this PR addresses-the call blocks the test runner instead of reporting a failed test. Add a child-process timeout so this regression fails promptly rather than hanging the suite.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR rejects nonempty explicit patch input when the existing parser finds no files. It also pauses previously idle terminal input after the startup color probe.

  • Hunk rejects patch text that contains no recognizable file changes.
  • The terminal color probe leaves idle input paused when it finishes.

Reviews (1) · Last reviewed commit: "fix(cli): reject unrecognized nonempty p..." · Reviewed by Greptile

Comment thread test/cli/patch-input.test.ts
Comment thread test/cli/patch-input.test.ts

This branch was successfully deployed

1 active deployment
Preview — 87f1b9dc Deployed Oct 13, 2026 by vercel[bot]
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.

hunk patch silently accepts non-patch input as a successful empty review

1 participant