Skip to content

fix(cli): render every field variant instead of "Field: Unknown" - #462

Open
shahan-khatchadourian-anchorage wants to merge 1 commit into
mainfrom
cli/render-all-field-variants
Open

fix(cli): render every field variant instead of "Field: Unknown"#462
shahan-khatchadourian-anchorage wants to merge 1 commit into
mainfrom
cli/render-all-field-variants

Conversation

@shahan-khatchadourian-anchorage

Copy link
Copy Markdown
Contributor

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 printing Field: Unknown, and common_label mirrored the gap by returning "Unknown", losing the label too.

What this hides today

Number is the variant that matters in practice, and it is not rare. visualsign-solana emits it for:

  • jupiter_swap — slippage and platform fee
  • compute_budget — all four limits
  • system — account space

All 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() and fallback_text(), which are exhaustive over the enum. This closes the class rather than the one variant, including any variant added later. common_label had exactly one caller and is removed.

Display only — the wire payload was always correct. Number's custom Serialize 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.

Testing

output.rs had 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 covering Number at the top level, Number nested inside a PreviewLayout (the path the Solana fields actually take), and an assertion that no variant renders as Unknown. All three were verified to fail without the fix.

Coordination

#439 modifies the same match block, adding a Diagnostic arm above the catch-all plus its own mod tests at the end of this file. When that stack rebases onto a main containing this PR, expect:

🤖 Generated with Claude Code

`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 AI 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.

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_field catch-all branch to print field.label(): field.fallback_text() for any remaining variants.
  • Removes common_label() (previously returned "Unknown" for most variants).
  • Adds unit tests covering Number rendering at top-level and nested in a PreviewLayout.
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: Unknown line 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() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants