Skip to content

Improve help text, refactor command registration, and fix test assertions#6

Merged
ryan-williams merged 5 commits intomainfrom
rw/create
Nov 9, 2025
Merged

Improve help text, refactor command registration, and fix test assertions#6
ryan-williams merged 5 commits intomainfrom
rw/create

Conversation

@ryan-williams
Copy link
Copy Markdown
Member

@ryan-williams ryan-williams commented Nov 8, 2025

This PR includes three improvements to the ghpr codebase:

1. Better Help Text and Validation

  • Draft flag validation - Added error when using -d without -y, since draft mode is incompatible with web editor
  • Clearer help text - Updated create command and flag descriptions to clearly explain the three modes:
    • Default (no -y): Interactive web editor (waits for user)
    • -y once: Create via API then view result
    • -yy twice: Create silently
  • Auto gist push - create now automatically pushes to gist remote after finalizing PR/Issue

2. Decorator Syntax Refactoring

Converted all 10 command register() functions from deeply nested function calls to clean vertical decorator stacks:

# Before
cli.command()(
    flag('-g', '--gist')(
        flag('-n', '--dry-run')(
            command
        )
    )
)

# After
@cli.command()
@flag('-n', '--dry-run')
@flag('-g', '--gist')
def command_cmd(dry_run, gist):
    command(gist, dry_run)

This makes the code much more readable and maintainable. Net result: -32 lines of code!

3. Comprehensive Test Assertion Improvements

Fixed all test assertions across the test suite to use precise equality checks instead of fragile substring matching:

  • test_import.py - Used regex to extract exact command names from CLI help, fixed shell integration checks
  • test_create.py - Changed to exact tuple comparisons for gh command arguments, added missing mocks for push() call
  • test_files.py - Replaced all substring checks with full content equality, fixed newline handling
  • test_gist.py - Replaced substring checks with exact equality, fixed gist footer formatting expectations

Impact: Fixed 51+ problematic assertions that used assert x in y patterns. All 92 tests now pass with precise, maintainable assertions that clearly document expected values

- Add validation error when using -d without -y (draft incompatible with web editor)
- Update command help text to clarify web editor vs API modes
- Update -d flag help to note it requires -y
- Update -y flag help to explain the three modes clearly
- Add automatic gist push after PR/Issue finalization
Convert all register() functions from nested function calls to clean
vertical decorator stacks for better readability.

Affected commands: create, shell-integration, pull, clone, diff, push,
ingest-attachments, upload, open, show
After creating a PR/Issue and updating the local file with link-reference
format, push the changes back to GitHub so the PR body includes:
- Link-reference definition ([owner/repo#N]: url)
- Gist footer (if gist remote exists)

This ensures GitHub, local, and gist are all in sync after creation.
The test was doing naive substring matching which incorrectly found 'comment'
in command descriptions like 'Clone a PR or Issue description and comments...'

Now uses regex to extract exact command names from the Commands: section,
preventing false positives from substring matches in help text.

Also added docstring to clone_cmd wrapper for better documentation.
- Replace substring matching (assert x in y) with exact equality checks
- Replace partial list checks with full list/tuple comparisons
- Update test expectations to match exact command arguments
- Fix test mocking to include new push() call in _finalize_created_item
- Use precise regex matching for shell integration output

This makes tests more robust and prevents false positives from
substring matches in help text or command descriptions.
@ryan-williams ryan-williams changed the title Improve help text and refactor command registration Improve help text, refactor command registration, and fix test assertions Nov 9, 2025
@ryan-williams ryan-williams merged commit 803d918 into main Nov 9, 2025
6 checks passed
@ryan-williams ryan-williams deleted the rw/create branch November 9, 2025 01:13
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