Repository navigation
fix(cli): --json emits raw, byte-exact JSON — no Rich value mutation (#69) - #70
Merged
Merged
Conversation
…69) Rich's JSON renderable soft-wrapped long string values at the console width, inserting literal newlines into the data: every machine consumer of --json got corrupted values, and a value that wrapped mid-string came out as invalid JSON. Bit the post-Railway-incident secret rotation — a vault-stored DB URI came back with a newline mid-hostname. print_json now writes plain json.dumps to stdout on the machine path (never the display renderable). The highlighted rendering is reserved for interactive TTYs — display-only wrapping there — and CAMPUS_CLI_AGENT=1 forces the raw form for agent tools that allocate a pty. The old pretty=False branch had the same wrap/markup hazard; the raw path now bypasses Rich entirely.
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
Closes #69.
print_jsonrouted every--jsonoutput through Rich's display-orientedJSONrenderable, which soft-wraps long string values at the console width by inserting literal\ncharacters into the values. Piped/consumed output was corrupted — and a value that wrapped mid-string came out as invalid JSON (raw newline inside a string literal). This bit the post-Railway-incident secret rotation: a vault-stored DB URI round-tripped with an embedded newline mid-hostname.The fix
print_jsonwrites plainjson.dumps(data, indent=2)straight to stdout on the machine path — byte-exact values, always spec-valid, no Rich renderable, no terminal-width dependence.CAMPUS_CLI_AGENT=1→ raw even on a TTY, for agent tools that allocate a pty (issue proposal 3);pretty=True/Falsestill overrides.pretty=Falsebranch (console.print(json.dumps(...))) had the same wrap hazard (plus Rich markup interpretation of[…]in output) — the raw path now bypasses Rich entirely.auth status --jsonalready did the right thing (typer.echo(json.dumps(...))); this makes every other--jsoncommand match that contract. All ~30print_jsoncall sites (vault get/list, client list/get/rotate, grants, user, audit keys/traces) are covered without changes.Tests
tests/unit/test_output.py: byte-exact long-value round-trip, spec-valid raw JSON, pretty routing on a forced TTY,CAMPUS_CLI_AGENTforcing raw on a TTY (and ignoring falsy values).TestAuditJsonShapesgains the console-width round-trip regression (audit keys list --jsonwith a 110-char value) — verified to fail against the old code.ruff checkclean.Docs
README gains a short "Machine-readable output" section documenting the guarantee and the
CAMPUS_CLI_AGENT=1opt-out.