Skip to content

[material_ui, cupertino_ui, go_router] Command to test dart fixes - #12390

Open
justinmc wants to merge 12 commits into
flutter:mainfrom
justinmc:test-dart-fixes
Open

[material_ui, cupertino_ui, go_router] Command to test dart fixes#12390
justinmc wants to merge 12 commits into
flutter:mainfrom
justinmc:test-dart-fixes

Conversation

@justinmc

@justinmc justinmc commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

This PR creates a new repo-level CI command to run the dart fix tests in relevant packages. Before this PR, go_router had its own script to run its dart fix tests, and material_ui and cupertino_ui had dart fix tests that were not being run. After this PR, all of the above are run via the new command.

Part of flutter/flutter#182568

@justinmc justinmc self-assigned this Aug 6, 2026
@github-actions github-actions Bot added p: go_router triage-framework Should be looked at in framework triage labels Aug 7, 2026
@justinmc justinmc added the CICD Run CI/CD label Aug 7, 2026
@justinmc
justinmc requested a review from stuartmorgan-g August 7, 2026 19:52
@justinmc
justinmc marked this pull request as ready for review August 7, 2026 19:52

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request replaces the standalone tool/run_tests.dart script with a new test-dart-fixes command in the repository tooling, implemented in TestDartFixes. This command automates running Dart fix tests for packages containing a test_fixes directory. Feedback on the implementation highlights opportunities to improve testability by using the package's file system and the configured processRunner instead of hardcoded LocalFileSystem and Process.start calls. Additionally, minor typos in string interpolation within error messages were identified.

Comment thread script/tool/lib/src/test_dart_fixes.dart Outdated
Comment on lines +131 to +140
static Future<int> _runProcess(
String command,
List<String> arguments, {
String? workingDirectory,
}) async {
final Process process = await _streamOutput(
Process.start(command, arguments, workingDirectory: workingDirectory),
);
return process.exitCode;
}

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.

high

Calling Process.start directly from dart:io bypasses the processRunner passed to the constructor, which prevents mocking process execution in unit tests. Consider making these helper methods non-static and using processRunner to run the processes.

try {
testDirectory = await _createTestDirectory(package);
} catch (error) {
return PackageResult.fail(['Failed to create temporary test directory: $error}']);

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.

medium

There is a typo in the string interpolation: $error} has an extra closing brace. It should be $error.

Suggested change
return PackageResult.fail(['Failed to create temporary test directory: $error}']);
return PackageResult.fail(['Failed to create temporary test directory: $error']);

}
result = PackageResult.success();
} catch (error) {
result = PackageResult.fail(['Dart fix tests failed: $error}']);

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.

medium

There is a typo in the string interpolation: $error} has an extra closing brace. It should be $error.

Suggested change
result = PackageResult.fail(['Dart fix tests failed: $error}']);
result = PackageResult.fail(['Dart fix tests failed: $error']);

@justinmc

justinmc commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Questions for @stuartmorgan-g in code review:

  • There are only 3 packages that support this, so it leaves a bunch of spam in the terminal saying "skipped x package". Is that ok or is there a way I should be avoiding that?
  • I deleted go_router's script that did this previously, but is there anything else that I should clean up there?

@stuartmorgan-g stuartmorgan-g left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two main high-level things

  • This command needs to be added to the CI so it's actually running. How long does it take to run? If it's fast we could just add it to https://github.com/flutter/packages/blob/main/.ci/targets/dart_unit_tests.yaml. If it's not, we'll need to think about where we can add it without causing issues.
  • We unit test all of the repo tooling, so this needs corresponding tests in script/tool's test directory. See other commands for the common patterns of DI, faking process output/exit codes, etc., and let me know if you have any questions.

There are only 3 packages that support this, so it leaves a bunch of spam in the terminal saying "skipped x package". Is that ok or is there a way I should be avoiding that?

That's a feature :)

(For context, when I started working on this repo, I discovered that we had a significant number of tests that people thought we were running but weren't because of various mistakes that were silently ignored, and it was extremely hard to figure that out because the CI output was just a sea of results for the things that did run. As a result, the tool is now designed for auditability, so that it's very easy to look at a run log and see exactly what did and did not run, to make sure that matches expectations.)

I deleted go_router's script that did this previously, but is there anything else that I should clean up there?

I don't think so; removing run_tests.dart will cause the package to be skipped by the custom-tests command (in the same way that removing test_fixes would cause a package to be skipped by this new command).

'This command requires "flutter" to be in your path.';

@override
PackageLoopingType get packageLoopingType => PackageLoopingType.includeAllSubpackages;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could sub-packages ever have their own dart fixes? If not we only need to look at top-level packages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible but doesn't happen in any of our packages. I'll set it to .topLevelOnly.

return PackageResult.fail(['Failed to create temporary test directory: $error']);
}

late final PackageResult result;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually need the late keyword? I would expect it to work without it (with better safety).

/// Run the dart fix tests for the package in the given temporary directory.
///
/// Resolves with the status code of the command.
Future<int> _runDartFixTests(RepositoryPackage package, Directory testDirectory) async {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package is never used.

final int pubGetStatusCode = await _runProcess('dart', <String>[
'pub',
'get',
], workingDirectory: testDirectory);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have runPubGet to abstract this, in pub_utils.dart. You just need to construct a RepositoryPackage from the test directory.

], workingDirectory: testDirectory);
}

Future<int> _runProcess(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods should be removed in favor of the command taking a ProcessRunner, and using processRunner.runAndStream. See dart_test_command.dart for an example (or almost any other command).

@justinmc

Copy link
Copy Markdown
Contributor Author

How long does it take to run?

About 40 seconds. Most of the time is from running flutter pub get three times in series. I've added it to dart_unit_tests.yaml preemptively, but let me know if that's too long and we should put it somewhere else.

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

Labels

CICD Run CI/CD p: go_router triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants