Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions src/parser/cli/tests/cli_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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.

Future-proofing observation, not a blocker: brace counting matches { and } anywhere on the line, including inside string literals. The current diagnostic messages do not contain braces ("all 6 instructions have valid program_id_index" etc.), but a future diagnostic that interpolates braces in its message would skew depth. If you ever generalize this beyond the current Diagnostic block, consider walking lines until the matching }, at the same indent rather than counting braces. For the current shape it is fine.

depth -= line.matches('}').count() as i32;
if depth == 0 {
continue;
}
continue;
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.

Style nit: the two continue; statements at the end of the if depth > 0 block are redundant — both arms continue regardless of whether depth just dropped to zero. Collapses to one continue; after the depth check.

}
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);
Expand Down
26 changes: 0 additions & 26 deletions src/parser/cli/tests/fixtures/solana-text.display.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading