refactor(test): reduce cognitive complexity of the test runners - #1756
Open
marcossevilla wants to merge 1 commit into
Open
marcossevilla wants to merge 1 commit into
marcossevilla wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Member
Author
|
@vgvbot /review-pr |
Contributor
Contributor
There was a problem hiding this comment.
Approve. This is a clean, careful refactor that significantly reduces cognitive complexity across the test runners while preserving behavior, log output, exit codes, and public APIs.
Verified correctness
CoverageMetrics.fromLcovRecords— the_add+_uncoveredLinesWithdecomposition preserves per-file accumulation (via[...?uncoveredLines[file], ...newLines]) and still filters by exclude globs the same way._TestEventReporterswitch — I confirmedTestEventinvery_good_test_runner 0.4.0isabstract class TestEvent(not sealed), with subtypesStartTestEvent,AllSuitesTestEvent,DebugTestEvent,ExitTestEventnot matched in the newswitch. In Dart, a non-exhaustiveswitchstatement (not expression) over a non-sealed type simply falls through on no-match — matching the original if-chain's silent ignore of those types.ExitTestEventcontinues to be handled explicitly in_testCommand._checkCoverage— the simplifiedif (uncoveredLines != null)is sound becauseuncoveredLinesis assigned non-null only whenoptions.showUncovered && coverageMetrics.uncoveredLines.isNotEmpty._reportDone—success = event.success ?? false; if (success) return;is equivalent to the originalif (event.success != true)(continues on null/false, returns on true)._writeLcovordering change for Dart+all— assert runs before enhance now;_convertDartCoverageToLcovcreates the file beforehand, so the invariant holds. The PR description already calls this out._enhanceLcovWithUntestedFiles—.map((r) => r.file).nonNulls.toSet()is equivalent towhere((r) => r.file != null).map((r) => r.file!).toSet(); the_untestedFileRecordLF/LH/DA/SF format and the (pre-existing) prefix-based line filter ('part'still matchingpartition) are preserved verbatim._runTests/_validateTargetextractions in both commands are mechanical and preserve exit-code semantics.
Observations (no action required)
_runTestsinDartTestCommand/TestCommandtakesrecursiveeven though it's only forwarded toTestCLIRunner.test— fine, keeps the extraction honest.- The near-identical
_validateTargetduplication betweenTestCommandandDartTestCommandis already called out in the PR description as a follow-up.
No correctness, security, or lifecycle issues found. The reasoning that existing tests already reach every new branch is believable given the refactor is purely structural, but CI should confirm.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Status
READY
Description
TestCLIRunner.testmoves its per-package body into_testPackage. Coverage settings are grouped in a private_CoverageOptionsvalue and handled by_reportCoverage,_writeLcov,_convertDartCoverageToLcovand_checkCoverage._testCommandhands each test event to a private_TestEventReporterthat switches on the event type and keeps the tallies and failure list._enhanceLcovWithUntestedFilesbuilds each record through_untestedFileRecordand_isCoverableLine.CoverageMetrics.fromLcovRecordsfilters excluded records and folds the rest through small helpers.TestCommand.runandDartTestCommand.runmove their target checks into_validateTargetand their runner call into a helper, and the forwarded argument lists become private getters on the options classes.One ordering change: for dart runs with
collectCoverageFrom: all, thelcov.infoexistence assert now runs before the untested-files enhancement. The file already exists at that point, and asserts are off in release builds.A follow-up could share the near-identical
_validateTargetbetweenTestCommandandDartTestCommand.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.
TestCLIRunner.test_testCommandTestCLIRunner._enhanceLcovWithUntestedFilesTestCommand.runCoverageMetrics.fromLcovRecordsDartTestCommand.runPart of a three-PR cleanup. Once all three merge, the full scan on #1755 passes:
Type of Change
🤖 Generated with Claude Code