Skip to content

fix(cli): make every command's text output match its --json data - #6616

Merged
josephfarina merged 1 commit into
mainfrom
fix/cli-text-json-parity
Sep 28, 2026
Merged

josephfarina merged 1 commit into
mainfrom
fix/cli-text-json-parity

Conversation

@josephfarina

@josephfarina josephfarina commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

User impact

Every caller of the CLI sees the same facts in text as in --json. Three commands had divergences that reached stdout:

  • upgrade --list printed (undefined) on 24 of 65 rows and showed PR numbers the JSON does not carry, while the version field that decides whether a codemod applies never appeared.
  • theme targets drew a hand-padded character table (INV23 violation) and omitted the className field.
  • docs list omitted the package field.

Problem and solution fit

Each command wrote its own text renderer, and nothing checked that the text was a projection of the JSON. INV4 says human output is produced only by the formatters; INV5 says text field names mirror JSON keys. This PR fixes the divergences it can reach without conflicting with open PRs, and adds a manifest-driven guard test that fails when any new command ships without a parity case.

Expected behavior and authority

  • docs/architecture/cli-surface.md INV4, INV5, INV12
  • docs/specs/AST-042-cli-command-admission/spec.md FR1, FR3

Smallest restoration

Command Direction Fix
upgrade --list text to JSON Render each codemod from the JSON result via records() (name, title, version, optional) instead of API logger; no more (undefined) rows
theme targets text to JSON Replace formatTargetsTable with records() inline layout; show className
docs list JSON to text Add package field to records()

Deferred (open PRs would conflict)

Command Divergence Blocked by
template --list id missing, isReady folded into name as WIP suffix #6265 already adds id to the list fields and edits the same lines; the WIP marker folded into name remains a divergence
component detail themeData passed to formatFull, findRelatedBlocks, --blocks fields #6507 edits the adjacent theme-resolution lines
component --props type union in formatProps code block deeper refactor of the formatProps markdown renderer

Divergences the sweep fixed

Command Divergence Merged PR
build (no query) playbook text vs {playbook: true} #6566
component detail findRelatedBlocks, resolveTheme #6574
hook detail findRelatedBlocks #6537
doctor label renamed to check (INV5); id missing #6516
search kind, score, reason omitted #6527
discover entry fields missing #6521

Evidence

Mutation proofs

  1. Record key (text to JSON): inserted record({hardcodedFact}) — test fails with Text record keys not in JSON: hardcodedFact
  2. Detail data (text to JSON): reverted hook findRelatedBlocks — test fails with Text record keys not in JSON: dirName
  3. Text block (build-playbook class): inserted text("A fact the JSON does not have.") — test fails with [text] A fact the JSON does not have.
  4. Missing field (JSON to text): removed package from docs records — test fails with JSON fields not in text: package

Scope

  • One defect family is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal context.

Testing

pnpm exec vitest run packages/cli/clients/cli/commands/text-json-parity.test.mjs  # 98 passed
pnpm -F @astryxdesign/cli typecheck:strict
pnpm check:repo
pnpm -F @astryxdesign/cli readme:check

Rebased onto current main. The stale doc-route inventory failure on the prior head is gone; focused checks pass (129/129), and the full CLI suite passes (5,232 passed, 2 expected failures). Strict typecheck and repository checks pass; required CI and exact-head review passed at this head. Nonrequired visual checks may still be running. The docs-list projection overlaps draft #6626 and the lint allowlist in #6617 must drop its fixed build-theme entry once both changes are together.

@vercel

vercel Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Sep 28, 2026 8:24pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 24, 2026
@josephfarina
josephfarina force-pushed the fix/cli-text-json-parity branch from c8c4534 to 7ee0646 Compare September 24, 2026 22:09
@astracat-bot

astracat-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Sep 28, 2026, 8:25 PM UTC

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Previews ready: Storybook and Sandbox were built with this PR's docsite. CI evidence will be added when available.

View Storybook for this PR · View Sandbox for this PR

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes — the direction is right and most of it lands, but two regressions introduced by this change need fixing first.

What works: upgrade --list now renders name, title, version, and optional from the JSON result (no more (undefined) rows), docs shows package, and theme targets uses the shared formatter instead of a hand-drawn table.

1. theme targets loses information in text mode. The new field list drops states and deprecatedFor, which --json still returns and the old text showed. Measured on the current data, 52 of 295 targets have supported states and 24 are deprecated with a canonical replacement — neither appears in the new text output, so a reader choosing theme overrides from text can pick a deprecated key or miss legal states with no signal anything was omitted. The new parity test passes this only because it allowlists exactly those two fields. Please include states and deprecatedFor in the rendered fields (inline rendering already skips empty values), update the subtitle field list, and remove those allowlist entries so the guard actually proves parity here.

2. upgrade --list failures are silent in text mode. Silencing the logger for --list also suppresses handled errors: astryx upgrade --list --registry exits 1 and prints nothing in text mode, while --json prints the invalid-argument error. Please render the handled error in text mode (or don't silence the logger on the error path) and cover that failure combination in the parity test.

Finally, the changeset's claim that the guard fails whenever a command's text and JSON differ overstates what the skipped/allowlisted cases enforce — please narrow that wording or the skips to match.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes — this revision fixes most of the earlier feedback, and one issue remains.

What now works: theme targets includes states and deprecatedFor again (verified against --json: 52 of 295 targets have states and 24 are deprecated with a replacement; both now appear in text, and the parity test no longer allowlists them), upgrade --list renders name, title, version, and optional with no (undefined) rows, docs shows package, and the changeset wording now matches what the guard test actually enforces.

Remaining: upgrade --list failures are still silent in text mode. The new catch-block line re-enables the logger, but the error was already logged — and suppressed — inside the API while the logger was silent for --list, and the logger does not replay suppressed lines. The catch then sets the exit code without printing the error, so astryx upgrade --list --registry still exits 1 and prints nothing about why, while --json prints the ERR_INVALID_ARGUMENT envelope. Please emit the handled error in text mode in the catch (for example, log e.message after re-enabling the logger), and add a parity-test case for this failing combination so the guard covers it.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes — this revision fixes the remaining silent failure, and one over-correction from that fix needs scoping.

What now works: upgrade --list --registry in text mode now exits 1 and prints its error once, matching the --json envelope; upgrade --list renders name, title, version, and optional with no (undefined) rows; docs shows package; and theme targets includes states and deprecatedFor again, verified against --json.

Remaining: non-list upgrade failures print the error twice. The catch block now replays e.message unconditionally, but for non-list calls the logger was never silent, so the API already printed the error before throwing. Measured examples: bare upgrade (missing --from), upgrade --from notsemver, and upgrade --registry --from 1.0.0 each show the identical message twice on stderr, while --json shows it once. Please scope the replay to the case where the logger was actually silent (the --list path; --json is handled separately), update the catch comment that still says human mode already saw the error, and add a regression check asserting the stderr message occurs once for both the --list --registry failure and a non-list failure — the parity guard currently reads stdout only and has no upgrade failure case, which is how this escaped it.

PUBLIC DELTA RECEIPT: afada75126e9c96cd1f4b06fa4ce438d13fe26af7f310960d50e644164f30f66

[Automated review]

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes — the behaviour is now right, and two small guard issues remain before approval.

What now works: upgrade --list renders name, title, version, and optional with no (undefined) rows; docs shows package; theme targets includes className, states, and deprecatedFor again, verified against --json; upgrade --list --registry in text mode exits 1 and prints its error exactly once, and non-list failures (for example bare upgrade or an invalid --from) also print exactly once — no silent failures and no duplicated errors.

1. No test covers the upgrade failure paths this change fixes. The parity guard's only upgrade case is the --list success path, and it checks stdout and exit status only, although the harness also returns stderr. The two failure regressions that already happened here (silent list failures, then duplicated non-list errors) both passed the existing suites, and they still would. Please add a regression case asserting the handled error occurs exactly once on stderr with exit 1 in text mode for both upgrade --list --registry and a non-list failure, and update the catch comment that still says human mode already saw the error line — that is not true for --list.

2. Running the parity suite leaves a file behind. The theme template case runs with the repository root as its working directory, so a suite run writes an untracked theme.template.ts there, which can be committed by accident. Please give that case a temp working directory, like the other writing cases, or clean the file up afterwards.

PUBLIC DELTA RECEIPT: "107a258a6cef4273a3c33dbbd1759eda82b471447a9aaeade5257d297ba02946"

[Automated review]

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving — the text output now matches --json, and every issue raised on earlier revisions is fixed at this revision.

Verified: upgrade --list renders name, title, version, and optional with no (undefined) rows; docs shows package; theme targets uses the shared formatter and includes className, states, and deprecatedFor; upgrade --list --registry in text mode exits 1 and prints its error exactly once, as do non-list failures such as bare upgrade or an invalid --from; the parity suite passes (98 tests), now including upgrade failure-path cases, and a suite run leaves the working tree clean.

Non-blocking note: the non-list failure case asserts the error is not duplicated rather than asserting it occurs exactly once on stderr (the --list failure case does assert exactly once). Behaviour was measured directly as exactly once, so this does not hold approval, but tightening that assertion would make the guard stronger.

PUBLIC DELTA RECEIPT: f00c6cc834eab7ed099861fc7cad38f11ece38d8d3cfec6649be160cf5e9d61f

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving — the text output now matches --json, and every issue raised on earlier revisions is fixed at this revision.

Verified: upgrade --list renders name, title, version, and optional with no (undefined) rows; docs shows package; theme targets uses the shared formatter and includes className, states, and deprecatedFor (shown as deprecated; use …); arrow-bearing titles render in plain ASCII; upgrade --list --registry in text mode exits 1 and prints its error exactly once, as do non-list failures such as bare upgrade or an invalid --from; the parity suite passes (98 tests, with the full CLI client suite also passing), now including upgrade failure-path cases, and a suite run leaves the working tree clean.

Non-blocking note: the non-list failure case asserts the error is not duplicated rather than asserting it occurs exactly once on stderr (the --list failure case does assert exactly once). Behaviour was measured directly as exactly once, so this does not hold approval, but tightening that assertion would make the guard stronger.

PUBLIC DELTA RECEIPT: 8fa34074578ca6bffa4d8a56b019b39c5602487f52f6396fd5fffabb3524fb19

[Automated review]

github-actions Bot added a commit that referenced this pull request Sep 25, 2026
@josephfarina
josephfarina force-pushed the fix/cli-text-json-parity branch from 8095ee0 to cc37ca7 Compare September 28, 2026 19:43
Fixes:
- build-theme targets: replace character-drawn formatTargetsTable with
  records() inline layout (INV23); show className field
- docs list: add package field to text projection
- upgrade --list: render from JSON result via records() instead of API
  logger (was printing undefined, showing PR numbers, missing version)

Deferred (open PRs would conflict):
- template: id, isReady fields (#6265)
- component: themeData, findRelatedBlocks, --blocks fields (#6507)
- component --props: type union in formatProps code block

Guard test (text-json-parity.test.mjs):
- manifest-driven: fails on a new JSON-capable command with no case
- checks text->JSON (record keys, text blocks, list items)
- checks JSON->text (leaf fields by label or per-key value presence)
- per-command allowlist with stale-entry check
@josephfarina
josephfarina force-pushed the fix/cli-text-json-parity branch from cc37ca7 to eb26a5f Compare September 28, 2026 20:17
@josephfarina
josephfarina merged commit b1da7d2 into main Sep 28, 2026
37 checks passed
@github-actions
github-actions Bot deleted the fix/cli-text-json-parity branch September 29, 2026 06:24

This branch was successfully deployed

1 active deployment
Preview — eb26a5f6 Deployed Sep 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant