fix(cli): render every field variant instead of "Field: Unknown" - #462
Open
shahan-khatchadourian-anchorage wants to merge 1 commit into
Open
fix(cli): render every field variant instead of "Field: Unknown"#462shahan-khatchadourian-anchorage wants to merge 1 commit into
shahan-khatchadourian-anchorage wants to merge 1 commit into
Conversation
`format_field` handles `TextV2`, `PreviewLayout`, `AmountV2` and `AddressV2`. Every other `SignablePayloadField` variant -- seven of the eleven in a default build, eight of twelve with the `diagnostics` feature -- fell through to a catch-all that printed `Field: Unknown`, and `common_label` mirrored the same gap by returning "Unknown" for them, so the label was lost too. `Number` is the variant this hides in practice, and it is not rare: `visualsign-solana` emits it for jupiter_swap's slippage and platform fee, compute_budget's four limits, and system's account space. Those sit inside a `PreviewLayout`'s expanded list, so the nested render path hid them too. A user triaging a swap saw every routing detail except the slippage they were agreeing to. The catch-all now reads `label()` and `fallback_text()`, which are exhaustive over the enum, so this closes the whole class rather than the one variant -- including any variant added later. Display only. The wire payload was always correct: `Number`'s custom `Serialize` impl maps it to `amount_v2`, recovering the unit from `fallback_text`, so backends and wallets were unaffected. It still matters, because the CLI is the tool reached for to triage a production payload. `output.rs` had no test module, which is why this went unnoticed. Add one covering `Number` at the top level and nested inside a `PreviewLayout`, plus an assertion that no variant renders as "Unknown". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot started reviewing on behalf of
shahan-khatchadourian-anchorage
August 7, 2026 03:11
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the CLI human-readable renderer to display all SignablePayloadField variants using the enum’s label() / fallback_text() accessors, avoiding the previous fallback output (Field: Unknown) for unhandled variants and adding regression tests for Number fields (including nested rendering via PreviewLayout).
Changes:
- Replaces the
format_fieldcatch-all branch to printfield.label(): field.fallback_text()for any remaining variants. - Removes
common_label()(previously returned"Unknown"for most variants). - Adds unit tests covering
Numberrendering at top-level and nested in aPreviewLayout.
Suppressed comments (2)
src/parser/cli-core/src/output.rs:285
- Same as above: checking for the substring "Unknown" is overly broad; assert that the old placeholder
Field: Unknownline is absent instead.
let out = render(fields);
assert!(!out.contains("Unknown"), "{out}");
for expected in ["Note: hello", "Total: 1.5 ETH", "Count: 7 items"] {
src/parser/cli-core/src/output.rs:301
- Same as above: assert the specific old placeholder (
Field: Unknown) rather than banning the word "Unknown" entirely.
let out = render(vec![layout.signable_payload_field]);
assert!(out.contains("Slippage: 50 bps"), "{out}");
assert!(!out.contains("Unknown"), "{out}");
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+141
to
+143
| // Every remaining variant renders from the accessors, which are | ||
| // exhaustive over the enum. A variant added later prints its | ||
| // label and value rather than silently reading as "Unknown". |
Comment on lines
+263
to
+265
| assert!(out.contains("Amount: 1000000 raw token units"), "{out}"); | ||
| assert!(!out.contains("Unknown"), "{out}"); | ||
| } |
Comment on lines
+267
to
+271
| /// Every variant must render its label and value. The catch-all arm reads | ||
| /// from `label()`/`fallback_text()`, which are exhaustive over the enum, | ||
| /// so a variant added later cannot silently print as "Unknown". | ||
| #[test] | ||
| fn no_field_variant_renders_as_unknown() { |
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.
format_fieldhandlesTextV2,PreviewLayout,AmountV2andAddressV2. Every otherSignablePayloadFieldvariant — seven of the eleven in a default build, eight of twelve with thediagnosticsfeature — fell through to a catch-all printingField: Unknown, andcommon_labelmirrored the gap by returning"Unknown", losing the label too.What this hides today
Numberis the variant that matters in practice, and it is not rare.visualsign-solanaemits it for:jupiter_swap— slippage and platform feecompute_budget— all four limitssystem— account spaceAll already on main. Those sit inside a
PreviewLayout's expanded list, and the nested render path goes through the same catch-all, so it hid them too. Someone triaging a swap saw every routing detail except the slippage they were agreeing to.The fix
The catch-all reads
label()andfallback_text(), which are exhaustive over the enum. This closes the class rather than the one variant, including any variant added later.common_labelhad exactly one caller and is removed.Display only — the wire payload was always correct.
Number's customSerializemaps it toamount_v2, recovering the unit fromfallback_text, so backends and wallets were unaffected. It still matters because the CLI is the tool reached for to triage a production payload.Testing
output.rshad no test module at all, which is why this went unnoticed — the Jupiter tests assert on decoded values, never on rendered output. This adds one coveringNumberat the top level,Numbernested inside aPreviewLayout(the path the Solana fields actually take), and an assertion that no variant renders asUnknown. All three were verified to fail without the fix.Coordination
#439 modifies the same match block, adding a
Diagnosticarm above the catch-all plus its ownmod testsat the end of this file. When that stack rebases onto a main containing this PR, expect:_arm — keep this PR's accessor version, keep feat(near): report refused token metadata as a diagnostic #439'sDiagnosticarm above itdiagnostic_testsso the two modules coexist; without that rename, keeping both hunks isE0428Field: Unknowntells the reader nothing") needs rewording, since diagnostics no longer print that way🤖 Generated with Claude Code