From 1656bb891d25d40c33b55b234ce38a85cb1c8da0 Mon Sep 17 00:00:00 2001 From: Shahan Khatchadourian Date: Thu, 14 May 2026 14:52:07 -0400 Subject: [PATCH] fix(parser_cli): keep text display fixture diagnostics-agnostic The stagex parser_cli build runs `cargo test --no-default-features --features solana`, which disables the default `diagnostics` feature. The post-#228 `solana-text.display.expected` had the new `Diagnostic { ... }` blocks baked in, so the actual binary output (no diagnostics emitted) diverged from the fixture and the test failed inside the container. Restore the same separation the JSON path already enforces: the display fixture covers only display fields, the diagnostics fixture covers only diagnostics. Strip `Diagnostic { ... }` blocks from the text Debug dump before comparing, gated on the `diagnostics` feature. Tested both `cargo test -p parser_cli` (default features) and `cargo test -p parser_cli --no-default-features --features solana` (stagex config); both pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/parser/cli/tests/cli_test.rs | 41 ++++++++++++++++++- .../fixtures/solana-text.display.expected | 26 ------------ 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/parser/cli/tests/cli_test.rs b/src/parser/cli/tests/cli_test.rs index 5f9f1bcce..5c6f63fab 100644 --- a/src/parser/cli/tests/cli_test.rs +++ b/src/parser/cli/tests/cli_test.rs @@ -203,18 +203,55 @@ fn test_cli_with_fixtures() { } } Err(_) => { - // Non-JSON output (text/human): plain string comparison + // Non-JSON output (text/human): strip diagnostic blocks from the + // actual Debug-formatted payload so the display fixture stays + // diagnostics-agnostic, matching how the JSON branch filters them above. + #[cfg_attr(not(feature = "diagnostics"), allow(unused_mut))] + let mut actual_display = actual_output.trim().to_string(); + #[cfg(feature = "diagnostics")] + { + actual_display = strip_debug_diagnostic_blocks(&actual_display); + } assert_strings_match( test_name, "display", expected_display.trim(), - actual_output.trim(), + &actual_display, ); } } } } +/// Remove `Diagnostic { ... },` blocks from a Rust `{:#?}` payload dump. +/// The blocks live inside the `fields:` array at 8-space indent, so balanced-brace +/// counting from each ` Diagnostic {` line drops the whole entry. +#[cfg(feature = "diagnostics")] +fn strip_debug_diagnostic_blocks(input: &str) -> String { + let mut out = String::with_capacity(input.len()); + let mut depth: i32 = 0; + for line in input.lines() { + if depth == 0 && line == " Diagnostic {" { + depth = 1; + continue; + } + if depth > 0 { + depth += line.matches('{').count() as i32; + depth -= line.matches('}').count() as i32; + if depth == 0 { + continue; + } + continue; + } + out.push_str(line); + out.push('\n'); + } + if !input.ends_with('\n') && out.ends_with('\n') { + out.pop(); + } + out +} + fn assert_strings_match(test_name: &str, fixture_type: &str, expected: &str, actual: &str) { if expected != actual { let diff = TextDiff::from_lines(expected, actual); diff --git a/src/parser/cli/tests/fixtures/solana-text.display.expected b/src/parser/cli/tests/fixtures/solana-text.display.expected index 35e7a7dd4..571707ddf 100644 --- a/src/parser/cli/tests/fixtures/solana-text.display.expected +++ b/src/parser/cli/tests/fixtures/solana-text.display.expected @@ -737,32 +737,6 @@ SignablePayload { ), }, }, - Diagnostic { - common: SignablePayloadFieldCommon { - fallback_text: "ok: all 6 instructions have valid program_id_index", - label: "transaction::oob_program_id", - }, - diagnostic: SignablePayloadFieldDiagnostic { - rule: "transaction::oob_program_id", - domain: "transaction", - level: "ok", - message: "all 6 instructions have valid program_id_index", - instruction_index: None, - }, - }, - Diagnostic { - common: SignablePayloadFieldCommon { - fallback_text: "ok: all 6 instructions have valid account indices", - label: "transaction::oob_account_index", - }, - diagnostic: SignablePayloadFieldDiagnostic { - rule: "transaction::oob_account_index", - domain: "transaction", - level: "ok", - message: "all 6 instructions have valid account indices", - instruction_index: None, - }, - }, ], payload_type: "SolanaTx", subtitle: None,