Skip to content

cmdio: allow --output json for raw bodies that are JSON - #7661

Open
anshul0713 wants to merge 2 commits into
mainfrom
anshul0713/cmdio-json-reader
Open

anshul0713 wants to merge 2 commits into
mainfrom
anshul0713/cmdio-json-reader

Conversation

@anshul0713

Copy link
Copy Markdown
Contributor

Changes

--output json now works for commands that return a raw response body, when that body is a JSON document. The body is passed through, indented like other JSON output, with numbers kept exact. Bodies that aren't JSON still fail with the same json output not supported error.

This affects commands whose generated code renders an io.Reader, for example:

  • serving-endpoints get-open-api (always JSON)
  • serving-endpoints http-request (JSON when the external API returns JSON)
  • fs cat of a JSON file

serving-endpoints export-metrics (Prometheus text) and fs cat of a text file keep failing as before.

Why

Agents and scripts pass --output json by habit. In agent trials of shell-only Model Serving usage, serving-endpoints get-open-api NAME -o json failed with json output not supported even though the response is an OpenAPI JSON document. The agents then had to retry without the flag. The text renderer already copies the body unchanged; only the JSON path refused.

Backward compatibility

  • Text output is unchanged: the text path still picks the raw copy first.
  • Under --output json, a JSON body now renders where it used to error. A non-JSON body gets the same error as before.
  • No request, flag or exit-code changes for any command.

Tests

  • libs/cmdio render tests: JSON body under --output json (indented), the same body under text output (unchanged), and an integer above 2^53 (kept exact). The existing non-JSON case still expects the error.
  • go test ./acceptance -run TestAccept/cmd passes, apart from cmd/api/*, which fail on main too in my environment (the user agent picks up a local meta-harness value).
  • Checked against a staging workspace: serving-endpoints get-open-api databricks-gpt-5-4 -o json returns the schema, and serving-endpoints export-metrics NAME -o json still errors.
  • ./task lint passes.

This pull request and its description were written by Isaac.

Commands that return a raw response body (serving-endpoints get-open-api,
http-request, fs cat) failed with "json output not supported" under
--output json, even when the body is a JSON document. Agents and scripts
pass --output json by habit, so this broke them for no reason. Pass a
body that is valid JSON through, indented like other JSON output. Bodies
that aren't JSON still fail with the same error.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Anshul Gupta <anshul.gupta@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Anshul Gupta <anshul.gupta@databricks.com>
@eng-dev-ecosystem-bot

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 65bb00c

Run: 43822317794

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 270 15 3:45
💚​ aws-windows-latest-4core-16gb 1 272 13 3:04
💚​ azure linux-2core-8gb 1 269 15 3:31
💚​ azure-windows-latest-4core-16gb 1 271 13 3:18
💚​ gcp linux-2core-8gb 1 270 15 3:33
💚​ gcp-windows-latest-4core-16gb 1 272 13 3:57
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 3 slowest tests (at least 2 minutes):
duration env testname
3:51 gcp-windows-latest-4core-16gb TestAccept
3:13 azure-windows-latest-4core-16gb TestAccept
2:59 aws-windows-latest-4core-16gb TestAccept

This branch has not been deployed

No deployments
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.

2 participants