Skip to content

refactor(mcp): reduce cognitive complexity of the test tool - #1758

Open
marcossevilla wants to merge 10 commits into
refactor/cc-packagesfrom
refactor/cc-mcp-server
Open

marcossevilla wants to merge 10 commits into
refactor/cc-packagesfrom
refactor/cc-mcp-server

Conversation

@marcossevilla

@marcossevilla marcossevilla commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Status

READY

Description

  • _parseTest builds its argument list in one expression from _flag and _option helpers, keeping the exact order of the original if-chain.
  • _runToolCommand hands its captured output buffer and its success and failure builders to a private _ToolRun, so the method only sets the working directory, runs the command and maps exceptions to failures. Stderr messages and StructuredToolError fields are unchanged.

timeout_seconds and paths are now read at the top of _parseTest. Well-formed input produces the same arguments, and badly typed input still throws a TypeError.

Found by the full cognitive complexity scan in #1755, which tests VeryGoodOpenSource/very_good_workflows#520. Every function in the touched files now scores 15 or under. Behavior, log output, exit codes and public APIs are unchanged, and no tests were needed because the existing ones already reach every new branch.

Function Before After
VeryGoodMCPServer._parseTest 21 2
VeryGoodMCPServer._runToolCommand 16 8

Part of a three-PR cleanup. Once all three merge, the full scan on #1755 passes:

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

🤖 Generated with Claude Code

Comment thread lib/src/mcp/mcp_server.dart Outdated
Comment thread lib/src/mcp/mcp_server.dart
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@marcossevilla
marcossevilla force-pushed the refactor/cc-mcp-server branch from 13ec12e to ab446c8 Compare October 1, 2026 13:41
@marcossevilla
marcossevilla changed the base branch from main to refactor/cc-packages October 1, 2026 13:41
@marcossevilla
marcossevilla added this pull request to stack #1759 October 1, 2026 13:41
@marcossevilla

Copy link
Copy Markdown
Member Author

@vgvbot /review-pr

@unicoderbot

unicoderbot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

I'll review the code and share my feedback shortly.

  • Preparing environment
    • Cloning repository
    • Setting up dev environment
  • Reviewing code
  • Posting review

Code review submitted.

@unicoderbot unicoderbot Bot left a comment

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.

The refactor cleanly reduces cognitive complexity in both _parseTest and _runToolCommand. The _flag/_option helpers preserve argument order and null/type handling, and the _ToolRun extraction keeps stderr messages and StructuredToolError fields intact.

However, there is a critical bug: the _ToolRun constructor is declared as new({...}) (line 615) with no class-name prefix. This is not valid Dart constructor syntax — a constructor must begin with the type identifier (e.g. _ToolRun({...}) or _ToolRun.new({...})). The call site at line 571 uses _ToolRun(toolName: ...) and expects an unnamed constructor, so this file will fail to compile. The description claims no new tests were added because existing tests already cover the branches, so this would surface the first time the test suite is run.

Comment thread lib/src/mcp/mcp_server.dart Outdated
@unicoderbot

unicoderbot Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Heads up — I'm auto-updating this PR by merging the latest refactor/cc-packages into this branch. No action needed; I'll comment again only if this update hits a conflict or an unexpected error.

@unicoderbot

unicoderbot Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Heads up — I'm auto-updating this PR by merging the latest refactor/cc-packages into this branch. No action needed; I'll comment again only if this update hits a conflict or an unexpected error.

@unicoderbot

unicoderbot Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Heads up — I'm auto-updating this PR by merging the latest refactor/cc-packages into this branch. No action needed; I'll comment again only if this update hits a conflict or an unexpected error.

@unicoderbot

unicoderbot Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Heads up — I'm auto-updating this PR by merging the latest refactor/cc-packages into this branch. No action needed; I'll comment again only if this update hits a conflict or an unexpected error.

unicoderbot Bot and others added 4 commits October 5, 2026 15:27
Address review feedback: ToolRun now lives in tool_run.dart together with
the CapturingStdout and sanitizeCommandOutput helpers it owns, avoiding a
circular import with mcp_server.dart. ToolRun.capture now returns the
command's exit code directly instead of being generic.
CapturingStdout and sanitizeCommandOutput now live in tool_run.dart, so
their tests move to the matching test file.
Only the optimization flag matched on false, so it is inlined as a
collection-if instead of widening _flag with a whenValue parameter.
Also points the _runToolCommand docs at ToolRun.capture rather than
duplicating the Logger-in-zone rationale.
unicoderbot[bot]
unicoderbot Bot previously approved these changes Oct 6, 2026

@unicoderbot unicoderbot Bot left a comment

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.

All my review comments have been resolved. Approving this PR. If another review is needed, just re-request it.

@unicoderbot

unicoderbot Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Heads up — I'm auto-updating this PR by merging the latest refactor/cc-packages into this branch. No action needed; I'll comment again only if this update hits a conflict or an unexpected error.

@unicoderbot

unicoderbot Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Heads up — I'm auto-updating this PR by merging the latest refactor/cc-packages into this branch. No action needed; I'll comment again only if this update hits a conflict or an unexpected error.

@unicoderbot unicoderbot Bot left a comment

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.

All my review comments have been resolved. Approving this PR. If another review is needed, just re-request it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant