Skip to content

test: cover the CLI argument parser#448

Merged
benvinegar merged 1 commit into
mainfrom
test/cli-parse-coverage
Jun 16, 2026
Merged

test: cover the CLI argument parser#448
benvinegar merged 1 commit into
mainfrom
test/cli-parse-coverage

Conversation

@benvinegar

Copy link
Copy Markdown
Member

What

Adds unit coverage for src/core/cli.ts, the CLI argument parser. It was pure, deterministic logic but sat at 82.4% line coverage — help-text branches, validation, and error paths were untested. This lifts it to 99.7% (the 3 remaining lines are unreachable defensive code: commander's help is always pre-intercepted).

30 new tests (53 → 83), all driving parseCli(...) directly — no daemons, binaries, or flakiness:

  • Help text for every command + session subcommand (diff, show, patch, pager, difftool, stash/stash show, daemon/daemon serve, skill/skill path, session and each of list/get/navigate/reload/comment plus the five comment subcommands).
  • Validation & errors: invalid layout mode, non-positive --hunk, commander unknown-option rethrow, ambiguous diff input, conflicting session selectors, unknown skill/daemon/stash/comment subcommands, comment-add target rules, and comment rm target-count rules for both selector styles.
  • session reload: missing nested command, no target, all three selector conflicts, and the three non-reloadable nested kinds (pager / nested session / stdin patch).
  • session comment apply stdin payload: the full validator surface — empty/invalid JSON, non-object root, missing comments array, non-object entry, missing filePath/summary, bad hunk selector, and the no-selector case.

Verification

  • bun run typecheck
  • bun run lint ✅ (0 warnings)
  • bun run format:check
  • Unit suite: 992 pass / 5 skip / 0 fail

Test-only; no user-visible change (empty changeset included).

🤖 Generated with Claude Code

The CLI parse layer in src/core/cli.ts is pure, deterministic logic but sat at
82% line coverage, with help-text branches, validation, and error paths
untested. Add tests driving parseCli directly across every command's --help
output, layout/positive-integer validation, unknown-command and
unsupported-subcommand errors, session selector and reload-target conflicts,
and the full `session comment apply` stdin-payload validators. Coverage rises
to ~99%; the remaining lines are defensive (commander help is always
pre-intercepted).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds 30 new unit tests for src/core/cli.ts, lifting line coverage from 82% to ~99% by exercising previously-untested help-text branches, validation error paths, and the full session comment apply stdin-payload validator. No production code is changed.

  • withStdin helper – a clean, try/finally-guarded utility that patches Bun.stdin.stream for the duration of an async callback, replacing the ad-hoc inline patching already present in earlier tests.
  • Four new describe blocks cover: per-command and per-session-subcommand help text, argument-validation errors, session reload invariants, and the complete session comment apply JSON payload validator.
  • All new assertion targets were cross-checked against the corresponding production paths in cli.ts and resolve correctly.

Confidence Score: 5/5

Test-only change with no production code modifications; safe to merge.

All new assertions were cross-checked against the production paths in cli.ts and resolve correctly. The withStdin helper properly guards stdin restoration in a try/finally, the applyWithPayload helper is scoped correctly, and each validation test targets the exact error message produced by the corresponding guard. No production behavior is altered.

No files require special attention.

Important Files Changed

Filename Overview
src/core/cli.test.ts Adds 30 new tests across 4 new describe blocks; uses a clean withStdin helper for stdin patching; all assertions correctly match the production logic in cli.ts
.changeset/cli-parse-coverage.md Empty frontmatter changeset (no version bump) appropriate for a test-only change

Reviews (1): Last reviewed commit: "test: cover the CLI argument parser" | Re-trigger Greptile

@benvinegar benvinegar merged commit aeb5c4f into main Jun 16, 2026
9 checks passed
@benvinegar benvinegar deleted the test/cli-parse-coverage branch June 16, 2026 18:08
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