Skip to content

test(contracts): pin CLI plain/help/completions contracts (#1060) - #1084

Merged
Sinity merged 1 commit into
masterfrom
feature/test/cli-plain-help-contracts
May 16, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/test/cli-plain-help-contracts

Conversation

@Sinity

@Sinity Sinity commented May 16, 2026

Copy link
Copy Markdown
Owner

Summary

Adds 3 contract-marked test files (tests/unit/cli/test_plain_output_contract.py,
test_help_contract.py, test_completions_contract.py) pinning the
human-facing CLI surface that #1080 (machine surface) did not cover:
plain rendering, --help structure across every command path, shell
completions, 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 json envelopes), the
human-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 --plain output, a renamed shell, or a broken
--version shape would not have failed any test.

Concretely, this branch caught a real bug: polylogue status --daemon-url not-a-url --format json raised an unhandled ValueError from
urllib.request.Request._parse because Request(...) was constructed
outside the try/except OSError block in polylogue/cli/commands/status.py.
The failing test
TestStatusJsonContract::test_status_json_no_traceback_on_bad_url from
#1080 was already red on master at fc3c43f (devtools verify --quick
exit 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, and workspace_env
for 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/status stdout or stderr;
    empty-archive messages are human prose (not JSON-shaped) containing
    No conversations; consecutive invocations produce byte-identical
    output; --plain does 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 (--help
    exits 0 with no traceback + has a substantive description line). Root
    --help exposes Usage:/Options:/Commands:. -h aliases
    --help. --version matches
    polylogue, version <semver>+<sha>[-dirty] per CONTRIBUTING.md.
    Help output stays on stdout.
  • test_completions_contract.py (9 tests, 4 evidence streams):
    bash/zsh/fish each produce non-empty shell-syntax output
    mentioning polylogue, with shell-specific markers (compgen for
    bash, compdef for zsh, complete -c for fish). Unknown shell exits
    non-zero with no traceback. Missing --shell errors 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.stderr separately, so assertions live
where the surface they test lives.

CLI bug fixed: polylogue/cli/commands/status.py — moved
Request(...) inside the try block and broadened the catch from
OSError to (OSError, ValueError) so malformed daemon URLs fall back
to the direct archive path instead of crashing.

Verification

nix develop -c pytest tests/unit/cli/test_plain_output_contract.py \
  tests/unit/cli/test_help_contract.py \
  tests/unit/cli/test_completions_contract.py \
  tests/unit/cli/test_json_envelope_contract.py -p no:randomly
# 172 passed in 12.36s

nix develop -c pytest tests/unit/cli -p no:randomly
# 1062 passed, 1 xfailed in 36.49s

nix develop -c devtools verify --quick
# total_duration_s 35.82, exit_code 0
# (status.py fix was required to bring this from red to green)

ls .cache/verification/evidence/ | grep -cE 'cli\.(plain|help|completions)'
# 68 new evidence artifacts

Ref #1060

🤖 Generated with Claude Code

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]>
@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 41 minutes and 7 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 19435ff3-4c64-4842-a545-6c54bcce6a8a

📥 Commits

Reviewing files that changed from the base of the PR and between fc3c43f and a40fe6b.

📒 Files selected for processing (4)
  • polylogue/cli/commands/status.py
  • tests/unit/cli/test_completions_contract.py
  • tests/unit/cli/test_help_contract.py
  • tests/unit/cli/test_plain_output_contract.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/test/cli-plain-help-contracts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread polylogue/cli/commands/status.py Resolved
Comment on lines +129 to +131
if line in ("Options:", "Commands:"):
continue
substantive.append(line)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 61.F057 / P2: fixed-already at the checked revision: Malformed JSON from the custom HTTP endpoint is converted into OperationFailedError at polylogue/cli/commands/status.py:151. The command handles that as unavailable with a nonzero exit rather than silently substituting direct archive health.

Only the rows listed above are dispositioned. Held findings remain open.

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.

1 participant