Skip to content

test(cli): add direct unit coverage for args helpers#859

Merged
muddlebee merged 1 commit intoTracer-Cloud:mainfrom
imjohnzakkam:issue/834-cli-args-unit-tests
Apr 28, 2026
Merged

test(cli): add direct unit coverage for args helpers#859
muddlebee merged 1 commit intoTracer-Cloud:mainfrom
imjohnzakkam:issue/834-cli-args-unit-tests

Conversation

@imjohnzakkam
Copy link
Copy Markdown
Contributor

Fixes #834

Describe the changes you have made in this PR -

Added direct unit tests for app/cli/args.py in tests/cli/test_args.py.

The new coverage verifies write_json when writing to stdout and to a file, and it adds parser-level checks for the mutually exclusive input flags without going through end-to-end CLI execution.

Screenshots of the UI changes (If any) -

  • None

Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • Yes, I used AI assistance (continue below)

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:
I added a focused unit test module for parse_args and write_json instead of exercising the full CLI entrypoint. This keeps the tests aligned with the issue's request to validate parser behavior directly.

For edge cases, I covered both write_json output paths and multiple invalid combinations of the mutually exclusive input flags. The parser assertions check that these conflicts still fail with argparse's standard exit code and surface the conflicting flag in stderr, which helps guard against regressions in the CLI contract.


Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • My code follows the project's style guidelines and conventions

Verification

  • python -m pytest tests/cli/test_args.py
  • ruff check tests/cli/test_args.py

Output summary:

  • 6 passed
  • All checks passed!

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 24, 2026

Greptile Summary

This PR adds a focused unit test module (tests/cli/test_args.py) covering write_json (stdout and file paths) and parse_args (mutually exclusive input flag rejection and a valid combination), closing issue #834. The implementation is straightforward and the tests accurately reflect the behavior of app/cli/args.py.

Confidence Score: 5/5

Safe to merge — tests are correct, assertions match source behavior, and no logic or security issues were found.

All findings are P2 or lower. The test assertions correctly reflect the source implementation, argparse stderr capture via capsys is valid, and the parametrized cases cover the right error conditions. No blocking issues.

No files require special attention.

Important Files Changed

Filename Overview
tests/cli/test_args.py New test file covering write_json stdout/file paths and parse_args mutually-exclusive group rejection plus a valid args combination; logic is correct and assertions align with the source implementation.

Sequence Diagram

sequenceDiagram
    participant T as Test (test_args.py)
    participant PA as parse_args()
    participant WJ as write_json()
    participant AP as argparse.ArgumentParser

    T->>WJ: write_json(payload, None)
    WJ-->>T: prints to stdout (capsys captures)

    T->>WJ: write_json(payload, "result.json")
    WJ-->>T: writes file via Path.write_text()

    T->>PA: parse_args(["--input", "...", "--input-json", "..."])
    PA->>AP: parser.parse_args(argv)
    AP-->>T: SystemExit(2) + stderr message

    T->>PA: parse_args(["--input", "...", "--output", "...", "--evaluate"])
    PA->>AP: parser.parse_args(argv)
    AP-->>T: argparse.Namespace (valid)
Loading

Reviews (1): Last reviewed commit: "test(cli): add direct unit coverage for ..." | Re-trigger Greptile

@muddlebee muddlebee merged commit 50c340a into Tracer-Cloud:main Apr 28, 2026
6 of 7 checks passed
@muddlebee
Copy link
Copy Markdown
Collaborator

@imjohnzakkam thank you for your contribution.

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.

Add direct unit tests for app/cli/args.py

2 participants