test(cli): cover the diagnose command's exit codes, loading paths and flags - #270
test(cli): cover the diagnose command's exit codes, loading paths and flags#270Nitjsefnie wants to merge 3 commits into
Conversation
Add offline unit tests for the oaeval diagnose CLI command using typer.testing.CliRunner. Mock DiagnosisAnalyzer to avoid model calls or API keys. Coverage: - argument parsing and help output - missing/invalid report paths (exit code 2) - empty and unsupported report payloads (exit code 0) - PipelineResult wrapper unpacking - terminal and JSON output formats - global --json flag wiring - --threshold and --max-recs option propagation - --verbose detailed failure output Co-Authored-By: Kimi K2.7 Code <noreply@kimi.com>
There was a problem hiding this comment.
🟡 Not ready to approve
The new tests include a likely failing help assertion and a context-reset fixture that can leak global CLI state across modules, making the suite order-dependent.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
Adds a new unit-test module to increase coverage of the oaeval diagnose CLI command, focusing on exit-code behavior, report-loading shapes, output modes, and option wiring to the DiagnosisAnalyzer.
Changes:
- Added
tests/unit/test_cli/test_diagnose.pywith 13 unit tests usingtyper.testing.CliRunner. - Introduced a
DiagnosisAnalyzermonkeypatch fixture to keep tests fully offline while validating flag/arg wiring and output.
File summaries
| File | Description |
|---|---|
| tests/unit/test_cli/test_diagnose.py | Adds CLI-layer tests for diagnose covering validation paths, report-loading variants, output formats, and analyzer option wiring. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 3
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
…port Review follow-up on two of the three Copilot findings. The autouse `_reset_cli_context` fixture reset the module-level CLI context before each test but not after it. `openagent_eval.cli.context` keeps that state in a module-level global, so the `--json` invocation in `test_diagnose_global_json_flag_triggers_json_output` left `json_output=True` behind for whatever module ran next -- and test_main.py, test_run.py and test_synth.py, which collect after this module, never reset it themselves. Reset on both sides, matching the fixture already used in tests/unit/test_cli/test_audit.py. `set_context` was imported but never used (ruff F401). Removed. The third finding -- that the help assertion should use the uppercase metavar `REPORT_PATH` -- does not apply here. Typer overrides Click's `Argument.make_metavar` (typer/core.py) and renders the parameter name verbatim, so `oaeval diagnose --help` prints `report_path` in lowercase and never prints `REPORT_PATH`. The assertion is left as is. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Two of the three land; the first does not, and I checked it against the rendered output before changing anything. Metavar case — leaving it as-is. Typer is not Click on this point. Context fixture — fixed ( Unused import — fixed in the same commit; One thing worth knowing while I was in there: the lint job cannot fail the build — |
|
The 3.11 red here is unrelated to this change — |
There was a problem hiding this comment.
🟡 Not ready to approve
One of the new help-output assertions is likely brittle (argument metavar casing) and may fail across Click/Typer help rendering.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
Suppressed comments (1)
tests/unit/test_cli/test_diagnose.py:103
- Typer/Click help output typically renders argument metavars uppercased (e.g.,
REPORT_PATH), so asserting on the Python parameter namereport_pathis likely to be brittle and may fail across Click/Typer versions.
assert result.exit_code == 0
output = strip_ansi(result.output)
assert "report_path" in output
for flag in ("--output", "--threshold", "--max-recs", "--verbose"):
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
|
Followed up on the lint-gate note: it turned out to be deliberate rather than an oversight — the MyPy step's own comment about |
Description
Closes #104. Adds
tests/unit/test_cli/test_diagnose.py— 13 tests for thediagnoseCLI, following the existingtyper.testing.CliRunnerpatterns in this repo.DiagnosisAnalyzeris mocked throughout, so the suite runs fully offline with no model call and no API key.Coverage is aimed at behaviour rather than line count — the exit codes, the input-validation paths, and the flags that must actually reach the analyzer:
.jsonfile · malformed JSONPipelineResultwrapper with aresultskey is unpacked and handed to the analyzer--output jsonemits a serialisableDiagnosisReport· the global--jsonflag forces JSON when--outputis omitted--thresholdand--max-recsarrive at theDiagnosisAnalyzerconstructor ·--verboserenders detailed failuresType of Change
Related Issues
Closes #104
How Has This Been Tested?
uv run pytest) — CI's own command,uv run pytest tests/unit -v --tb=shortBefore: 1015 passed, 4 skipped. After: 1028 passed, 4 skipped — the +13 are these tests, and nothing pre-existing changed.
No production code was touched; the commit is that one test file. (
uv sync --all-extrasmodifieduv.locklocally while setting up to run your suite — deliberately left unstaged.)One courtesy note: @bityodha commented "assigne to me" on #104 back on 2026-07-14. I checked before starting — there is no assignee, no
claimedlabel, and no PR referencing the issue — so I read it as never having got started rather than as work in progress. Happy to close this if they are in fact mid-way through.Generated by Claude Opus 5 (brief, review), Kimi K2.7 Code (implementation)