test(cli): parse Click JSON output robustly in tests#731
Conversation
Add a shared test helper for CliRunner output that can tolerate prefixed stderr log lines before the JSON body, and add a subprocess regression proving real CLI execution still keeps scan JSON on stdout and finding logs on stderr. Co-authored-by: Codex <noreply@openai.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdded a resilient JSON parsing helper to extract JSON objects from Click CLI output that may contain interleaved logs; refactored tests to use it and added unit and subprocess tests to validate parsing and log/JSON separation. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Rename the tar fixture path local so CI's broader tests/assets/generators/generate_jinja2_test_assets.py:308:1: error: Library
stubs not installed for "yaml" [import-untyped]
import yaml
^
modelaudit/utils/sources/dvc.py:16:1: error: Library stubs not installed for
"yaml" [import-untyped]
import yaml
^
modelaudit/auth/config.py:9:1: error: Library stubs not installed for "yaml"
[import-untyped]
import yaml
^
modelaudit/auth/config.py:9:1: note: Hint: "python3 -m pip install types-PyYAML"
modelaudit/progress/hooks.py:136:1: error: Library stubs not installed for
"requests" [import-untyped]
import requests
^
modelaudit/utils/sources/jfrog.py:13:1: error: Library stubs not installed for
"requests" [import-untyped]
import requests
^
modelaudit/utils/helpers/retry.py:172:1: error: Library stubs not installed for
"requests" [import-untyped]
import requests
^
modelaudit/utils/sources/pytorch_hub.py:8:1: error: Library stubs not installed
for "requests" [import-untyped]
import requests
^
modelaudit/auth/client.py:7:1: error: Library stubs not installed for
"requests" [import-untyped]
import requests
^
modelaudit/auth/client.py:7:1: note: Hint: "python3 -m pip install types-requests"
modelaudit/auth/client.py:7:1: note: (or run "mypy --install-types" to install all missing stub packages)
modelaudit/auth/client.py:7:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
modelaudit/telemetry.py:24:1: error: Library stubs not installed for "yaml"
[import-untyped]
import yaml
^
modelaudit/integrations/license_checker.py:7:1: error: Library stubs not
installed for "requests" [import-untyped]
import requests
^
modelaudit/scanners/oci_layer_scanner.py:18:1: error: Library stubs not
installed for "yaml" [import-untyped]
import yaml
^
modelaudit/scanners/nemo_scanner.py:16:1: error: Library stubs not installed
for "yaml" [import-untyped]
import yaml
^
modelaudit/scanners/manifest_scanner.py:29:1: error: Library stubs not
installed for "yaml" [import-untyped]
import yaml
^
modelaudit/scanners/jinja2_template_scanner.py:52:1: error: Library stubs not
installed for "yaml" [import-untyped]
import yaml
^
tests/test_auth_config.py:7:1: error: Library stubs not installed for "yaml"
[import-untyped]
import yaml
^
tests/integrations/test_jfrog.py:9:1: error: Library stubs not installed for
"requests" [import-untyped]
import requests
^
tests/scanners/test_nemo_scanner.py:9:1: error: Library stubs not installed for
"yaml" [import-untyped]
import yaml
^
tests/scanners/test_jinja2_template_scanner.py:301:1: error: Library stubs not
installed for "yaml" [import-untyped]
import yaml # noqa: F401
^
modelaudit/cli.py:2547:1: error: Library stubs not installed for "yaml"
[import-untyped]
import yaml
^
Found 19 errors in 19 files (checked 392 source files)
does not see an incompatible reassignment when parsing JSON output.
Co-authored-by: Codex <noreply@openai.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/test_cli.py`:
- Around line 183-204: The test
test_scan_json_subprocess_separates_logs_from_stdout_for_findings reuses the
name payload for both the temporary file (payload variable created for the tar)
and the parsed JSON result (payload = json.loads(...)), which is confusing;
rename one of them (e.g., rename the file variable to payload_file or the parsed
result to result_json or parsed_payload) and update all subsequent references
(the tar.add call and the json.loads assignment plus the issue assertions and
any uses of payload) to use the new name so there is no shadowing or ambiguity.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 819de9ed-5c38-4800-af4e-ce4bbc14d8aa
📒 Files selected for processing (1)
tests/test_cli.py
Co-authored-by: Codex <noreply@openai.com>
|
Addressed the CodeRabbit variable-shadowing feedback in |
Summary
CliRunneroutput even when Click prepends merged stderr log lines before the JSON bodyValidation
uv run pytest tests/test_cli_output.py tests/test_cli.py tests/test_nested_pickle_integration.py -quv run ruff check tests/cli_output.py tests/test_cli_output.py tests/test_cli.py tests/test_nested_pickle_integration.py tests/conftest.pyuv run mypy modelaudit/Summary by CodeRabbit