Skip to content

refactor: replace fragile io.StringIO output suppression with validate_all_detailed - #23

Merged
shenxianpeng merged 1 commit into
mainfrom
chore/refactor-mcp-output-suppression
Jul 29, 2026
Merged

refactor: replace fragile io.StringIO output suppression with validate_all_detailed#23
shenxianpeng merged 1 commit into
mainfrom
chore/refactor-mcp-output-suppression

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Jul 29, 2026

Copy link
Copy Markdown
Member

Summary

_run_checks() was using io.StringIO + redirect_stdout / redirect_stderr to suppress terminal output while calling ValidationEngine.validate_all(). This approach was fragile and reconstructed check dicts manually from rule templates instead of using actual failure details.

Changes

Before After
io.StringIO + redirect_stdout/stderr ValidationEngine.validate_all_detailed()
One ValidationEngine per rule Single engine for all filtered rules
Dict built from rule.error / rule.suggest CheckOutcome from _last_failure (real failure details)
Manual dict construction CheckOutcome.to_dict()

Files changed: src/commit_check_mcp/server.py — 9 insertions, 19 deletions.

Benefits

  • Removes fragile io.StringIO / redirect_stdout / redirect_stderr pattern
  • Uses validate_all_detailed() which internally sets _suppress_output on each validator
  • CheckOutcome carries the actual value / error / suggest from validation, not rule templates
  • Cleaner code, fewer imports

Verification

  • All 67 tests pass
  • Import cleaned up (io, redirect_stdout, redirect_stderr, unused ValidationResult removed)

Summary by CodeRabbit

  • Bug Fixes
    • Improved commit validation result handling for more consistent and accurate per-check outcomes.
    • Reduced reliance on captured console output when reporting validation results.

…e_all_detailed

_run_checks() was using io.StringIO + redirect_stdout/redirect_stderr to
suppress terminal output while running ValidationEngine.validate_all().
This approach was fragile and manually reconstructed check dicts from
rule templates rather than actual failure details.

Switch to ValidationEngine.validate_all_detailed() which:
- Internally sets _suppress_output on each validator
- Returns structured CheckOutcome objects with real failure details
- Provides to_dict() for direct serialization
- Runs all rules through a single engine call instead of one per rule
@github-actions github-actions Bot added the chore label Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 58efaa2b-38ac-4e79-9e57-517eace0983d

📥 Commits

Reviewing files that changed from the base of the PR and between 09a166e and 2b9ae41.

📒 Files selected for processing (1)
  • src/commit_check_mcp/server.py

📝 Walkthrough

Walkthrough

The commit-check MCP server now runs filtered checks through ValidationEngine.validate_all_detailed() and serializes CheckOutcome objects, replacing per-rule execution, output redirection, and manual ValidationResult mapping.

Changes

Detailed validation flow

Layer / File(s) Summary
Use structured validation outcomes
src/commit_check_mcp/server.py
Updates imports and changes _run_checks to collect detailed outcomes from one validation pass and convert them with to_dict().

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the refactor from output suppression to validate_all_detailed, which matches the main code change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/refactor-mcp-output-suppression

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (09a166e) to head (2b9ae41).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #23   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          209       203    -6     
=========================================
- Hits           209       203    -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shenxianpeng
shenxianpeng merged commit c4be16d into main Jul 29, 2026
7 checks passed
@shenxianpeng
shenxianpeng deleted the chore/refactor-mcp-output-suppression branch July 29, 2026 20:46
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