-
Notifications
You must be signed in to change notification settings - Fork 13
fix(parser_cli): keep text display fixture diagnostics-agnostic #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
prasanna-anchorage
merged 1 commit into
main
from
shahankhatch/fix-stagex-cli-text-diagnostics
May 15, 2026
+39
−28
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style nit: the two |
||
| } | ||
| 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); | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
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 skewdepth. 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.