Repository navigation
test(contracts): pin CLI plain/help/completions contracts (#1060) - #1084
Conversation
Adds 3 new contract-marked test files under tests/unit/cli/ covering the human-facing CLI surface that #1080 (machine surface) did not pin: - test_plain_output_contract.py: --plain output is ASCII-only (no ANSI CSI sequences, no Rich box-drawing), empty-archive messages are stable human prose (not JSON-shaped), deterministic across consecutive invocations, and --plain does not collapse stderr into stdout. - test_help_contract.py: every command path from iter_command_paths() responds to --help (exit 0, Usage section, non-empty description, no traceback). Root --help exposes Usage/Options/Commands. --version matches 'polylogue, version <semver>+<sha>[-dirty]' per CONTRIBUTING.md. --help stays on stdout. - test_completions_contract.py: bash/zsh/fish each produce non-empty shell-script output mentioning 'polylogue' with shell-specific syntax markers. Unknown shell exits non-zero without traceback; missing --shell errors land on stderr. CLI bug fixed in the same change: polylogue/cli/commands/status.py constructed urllib.request.Request *outside* the try/except OSError, so a malformed --daemon-url (e.g. "not-a-url") raised an unhandled ValueError instead of falling back to the direct archive read path. Moved Request() inside the try block and broadened the catch to (OSError, ValueError). Surfaced by test_json_envelope_contract.py::TestStatusJsonContract:: test_status_json_no_traceback_on_bad_url, which was failing on master. Ref #1060 Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ 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: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a40fe6b334
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if line in ("Options:", "Commands:"): | ||
| continue | ||
| substantive.append(line) |
There was a problem hiding this comment.
Exclude option rows when asserting help descriptions
This contract says it should fail when help only contains boilerplate, but the filter currently counts option lines (for example the default --help row) as “substantive.” That means commands with no real description will still pass, so the new contract does not actually protect against missing docstrings/help text drift as intended.
Useful? React with 👍 / 👎.
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Adds 3 contract-marked test files (
tests/unit/cli/test_plain_output_contract.py,test_help_contract.py,test_completions_contract.py) pinning thehuman-facing CLI surface that #1080 (machine surface) did not cover:
plain rendering,
--helpstructure across every command path, shellcompletions, version identity, and stdout/stderr discipline. Also fixes
one pre-existing CLI bug surfaced by the new coverage.
Problem
After #1080 pinned the machine surface (
--format jsonenvelopes), thehuman-facing CLI surface still had no contract coverage. Help-text drift
would have landed silently: a command losing its docstring, a regression
to ANSI leakage in
--plainoutput, a renamed shell, or a broken--versionshape would not have failed any test.Concretely, this branch caught a real bug:
polylogue status --daemon-url not-a-url --format jsonraised an unhandledValueErrorfromurllib.request.Request._parsebecauseRequest(...)was constructedoutside the
try/except OSErrorblock inpolylogue/cli/commands/status.py.The failing test
TestStatusJsonContract::test_status_json_no_traceback_on_bad_urlfrom#1080 was already red on master at fc3c43f (
devtools verify --quickexit 1 on the inherited baseline). Fixing it is part of this branch.
Solution
Three new files under
tests/unit/cli/, all using@pytest.mark.contract,record_contract_evidence, andworkspace_envfor isolation. Patterns follow
test_json_envelope_contract.py(the#1080 template).
test_plain_output_contract.py(10 tests, 8 evidence streams):asserts no ANSI CSI sequences, raw ESC bytes, box-drawing, or block
characters in
--plain list/stats/config/statusstdout or stderr;empty-archive messages are human prose (not JSON-shaped) containing
No conversations; consecutive invocations produce byte-identicaloutput;
--plaindoes not collapse Click usage errors into stdout.test_help_contract.py(109 tests, 53 evidence streams):enumerates the full Click command tree via
iter_command_paths(cli)and parametrizes over all 52 paths. Each gets two checks (
--helpexits 0 with no traceback + has a substantive description line). Root
--helpexposesUsage:/Options:/Commands:.-haliases--help.--versionmatchespolylogue, version <semver>+<sha>[-dirty]perCONTRIBUTING.md.Help output stays on stdout.
test_completions_contract.py(9 tests, 4 evidence streams):bash/zsh/fisheach produce non-empty shell-syntax outputmentioning
polylogue, with shell-specific markers (compgenforbash,
compdeffor zsh,complete -cfor fish). Unknown shell exitsnon-zero with no traceback. Missing
--shellerrors land on stderr,not stdout.
Stdout/stderr discipline (Scope §4 in the issue) is covered as classes
within these three files rather than as a separate file — Click 8.3+
exposes
result.stdout/result.stderrseparately, so assertions livewhere the surface they test lives.
CLI bug fixed:
polylogue/cli/commands/status.py— movedRequest(...)inside thetryblock and broadened the catch fromOSErrorto(OSError, ValueError)so malformed daemon URLs fall backto the direct archive path instead of crashing.
Verification
Ref #1060
🤖 Generated with Claude Code