refactor: add print_structured() shared helper, migrate CLI console output - #474
Merged
Conversation
…utput Rich console structured-output printing was hand-rolled 4 inconsistent ways across 9 CLI files: some bypassed Console entirely via typer.echo(json.dumps(...)), others routed through Console but printed a pre-serialized string, losing syntax highlighting. Adds print_structured(console, output, *, sort_keys=False) in the new operations_center.cli_output module, normalizing dict/BaseModel/dataclass payloads and always rendering via console.print_json(). Migrates all 15 in-scope call sites across audit, calibration, governance, run_show, worker_backend_probe, worker_backend_status, observer, run_memory, and artifact_index. Two call sites are deliberately left unmigrated (a truncated raw-content dump and a formatter-routed combined-output branch) since print_structured has no equivalent for their extra semantics. Adds tests/unit/test_cli_output.py (22 tests, 100% line/branch coverage) and updates existing CLI tests whose mocks no longer match the helper's type-dispatch. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
Consoleentirely viatyper.echo(json.dumps(...)), others routed throughConsolebut printed a pre-serialized string, losing syntax highlighting.print_structured(console, output, *, sort_keys=False)in the newoperations_center.cli_outputmodule, normalizingdict/BaseModel/dataclass payloads and always rendering viaconsole.print_json(...).audit,calibration,governance,run_show,worker_backend_probe,worker_backend_status,observer,run_memory, andartifact_index. Two call sites are deliberately left unmigrated — a truncated raw-content dump (artifact_index/cli.py get-artifact --print-content) and a formatter-routed combined-output branch (observer/cli.py query-flaky-tests) — sinceprint_structuredhas no equivalent for their extra semantics.Test plan
tests/unit/test_cli_output.py— 22 tests, 100% line/branch coverage on the new helperBaseModel/dataclass type-dispatchruff check .— 0 violations;ruff format --check— clean on all touched files🤖 Generated with Claude Code