Add guards for stale help examples and JSON output purity#197
Merged
Conversation
…commands Add two overarching meta-tests that close gaps the per-command suite left: - test_json_stdout_purity: walks the live Typer tree and asserts every leaf command keeps the "errors → stderr, data → stdout" contract under --json. Triggered by an unknown flag (a uniform, pre-network parse error, safe even for interactive commands), it pins stdout empty + a pure-JSON error envelope on stderr, plus the human-mode split. Nothing previously swept this. - test_help_example_flags: parses each command's --help "Examples" epilog and validates every flag/subcommand against the live tree, catching stale copy after a rename (e.g. login --api-key → --with-api-key). docs_consistency_gate covers REFERENCE/README refs but not the in-help examples users copy-paste. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A8VXBitwFzqz5VsLCyepiY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two new test suites that enforce repo-wide invariants across all leaf commands:
--helpexamples reference only flags and subcommands that actually exist, catching silent rot from renames (e.g.,--api-key→--with-api-key) or removed subcommands.assembly … --json | next-tool.Key Changes
tests/test_help_example_flags.py— New test module that:Examplesepilog from every leaf command's--helpoutput$ assembly …command lines and splits pipelines into per-assemblysegmentstests/test_json_stdout_purity.py— New test module that:exit_code == 2(standard Click usage error)stdout == ""(no data leaked during error)--jsonmode (machine-readable error envelope) and human mode (error on stderr, not stdout)Implementation Details
assemblytoken is glued to shell syntax (e.g.,$(assembly …) rather than mis-parsing, since those same commands appear unglued elsewhere in the examples.leaf_command_items()andleaf_command_argvs()helpers (fromtests/_cli_tree) to automatically cover every leaf command without manual enumeration.These guards close gaps left by existing checks:
test_help_examples_coverageproves examples exist but not that they're valid;docs_consistency_gate.pykeeps REFERENCE.md/README in sync but doesn't check in---helpexamples.https://claude.ai/code/session_01A8VXBitwFzqz5VsLCyepiY