Skip to content

fix(rspec): skip JSON parsing for non-JSON output#1510

Open
mcampbell wants to merge 1 commit intortk-ai:developfrom
mcampbell:fix/dont-parse-non-json-rpsec
Open

fix(rspec): skip JSON parsing for non-JSON output#1510
mcampbell wants to merge 1 commit intortk-ai:developfrom
mcampbell:fix/dont-parse-non-json-rpsec

Conversation

@mcampbell
Copy link
Copy Markdown

Summary

Fixes #1506 — RTK emits a false [rtk] rspec: JSON parse failed warning whenever rspec runs with its default text formatter (no --format json).

  • Add starts_with('{') guard in filter_rspec_output() so JSON parsing is only attempted on JSON-shaped output
  • Remove the now-unreachable eprintln!() warning
  • Add test test_filter_rspec_text_output_no_warning to document and lock in the fix

Root Cause

filter_rspec_output() unconditionally attempted serde_json::from_str on all rspec output. When rspec runs without --format json (the common case), output is plain text, which always fails the parse and emits:

[rtk] rspec: JSON parse failed (expected value at line 1 column 1), using text fallback

The fallback worked correctly, but the warning was noise.

Fix

// Only attempt JSON parsing if output looks like JSON (starts with '{')
if trimmed.starts_with('{') {
    if let Ok(rspec) = serde_json::from_str::<RspecOutput>(trimmed) {
        return build_rspec_summary(&rspec);
    }
    let stripped = strip_noise(output);
    if let Ok(rspec) = serde_json::from_str::<RspecOutput>(&stripped) {
        return build_rspec_summary(&rspec);
    }
    // fall through if JSON-shaped but unparseable
}
filter_rspec_text(&strip_noise(output))

Testing

  • All 29 rspec unit tests pass
  • New test verifies text output produces no warning and correct summary
  • cargo clippy --all-targets clean
  • cargo fmt --all -- --check clean

@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal labels Apr 25, 2026
@pszymkowiak
Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes a false warning emitted when rspec runs with its default text formatter by adding a starts_with('{') guard before attempting JSON parsing in filter_rspec_output(). This eliminates the noisy [rtk] rspec: JSON parse failed message for non-JSON output while preserving correct fallback behavior.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1506


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@mcampbell mcampbell changed the base branch from master to develop April 25, 2026 01:35
Don't attempt JSON parsing if rspec output doesn't start with '{'.
Eliminates false 'JSON parse failed' warnings on text-only output
while preserving JSON parsing for actual JSON output.

Fixes rtk-ai#1506
@mcampbell mcampbell force-pushed the fix/dont-parse-non-json-rpsec branch from e6a4f21 to f024b5f Compare April 25, 2026 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RTK is parsing rspec default output as json, when it is not.

2 participants