test(cli): add direct unit coverage for args helpers#859
test(cli): add direct unit coverage for args helpers#859muddlebee merged 1 commit intoTracer-Cloud:mainfrom
Conversation
Greptile SummaryThis PR adds a focused unit test module ( Confidence Score: 5/5Safe 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
Sequence DiagramsequenceDiagram
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)
Reviews (1): Last reviewed commit: "test(cli): add direct unit coverage for ..." | Re-trigger Greptile |
|
@imjohnzakkam thank you for your contribution. |
Fixes #834
Describe the changes you have made in this PR -
Added direct unit tests for
app/cli/args.pyintests/cli/test_args.py.The new coverage verifies
write_jsonwhen 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) -
Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
Explain your implementation approach:
I added a focused unit test module for
parse_argsandwrite_jsoninstead 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_jsonoutput 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
Verification
python -m pytest tests/cli/test_args.pyruff check tests/cli/test_args.pyOutput summary:
6 passedAll checks passed!