Skip to content

[tool] Move changed file detection to base command class #8730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

stuartmorgan-g
Copy link
Contributor

Consolidates the code to find all changed file paths into the PackageLoopingCommand class that is the base of almost all of the repo tooling commands. This in a preparatory PR for a future change to allow each command to define a list of files or file patterns that definitively don't affect that test, so that CI can be smarter about what tests to run (e.g., not running expensive integration tests for README changes).

A side effect of this change is that tests of almost all commands now need a mock GitDir instance. This would add a lot of copy/pasted boilerplate to the test setup, and there is already too much of that, so instead this refactors common test setup:

  • Creating a memory file system
  • Populating it with a packages directory
  • Creating a RecordingProcessRunner to mock out process calls
  • Creating a mock GitDir that forwards to a RecordingProcessRunner

into a helper method (using records and destructuring to easily return multiple values). While some tests don't need all of these steps, those that don't can easily ignore parts of it, and it will make it much easier to update tests in the future if they need them, and it makes the setup much more consistent which makes it easier to reason about test setup in general.

Prep for flutter/flutter#136394

Pre-launch Checklist

Consolidates the code to find all changed file paths into the
`PackageLoopingCommand` class that is the base of almost all of the repo
tooling commands. This in a preparatory PR for a future change to allow
each command to define a list of files or file patterns that
definitively *don't* affect that test, so that CI can be smarter about
what tests to run (e.g., not running expensive integration tests for
README changes).

A side effect of this change is that tests of almost all commands now
need a mock `GitDir` instance. This would add a lot of copy/pasted
boilerplate to the test setup, and there is already too much of that, so
instead this refactors common test setup:
- Creating a memory file system
- Populating it with a packages directory
- Creating a RecordingProcessRunner to mock out process calls
- Creating a mock GitDir that forwards to a RecordingProcessRunner

into a helper method (using records and destructuring to easily return
multiple values). While some tests don't need all of these steps, those
that don't can easily ignore parts of it, and it will make it much
easier to update tests in the future if they need them, and it makes the
setup much more consistent which makes it easier to reason about test
setup in general.

Prep for flutter/flutter#136394
Copy link
Contributor Author

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

You'll want to read the test/util.dart and test/mocks.dart changes before all the rest of the test changes since those are the foundation all the test changes are built on.

/// Get a list of all the pubspec.yaml file that is changed.
Future<List<String>> getChangedPubSpecs() async {
return (await getChangedFiles()).where(_isPubspec).toList();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code was only used in one place (and isn't really related to git so it's not clear why it was in this class), so I inlined it where it was used so that I could use the cached changed files list instead of recomputing it here.

final List<String> changedFiles = await finder.getChangedPubSpecs();

expect(changedFiles, equals(<String>['file1/pubspec.yaml']));
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the test for the now-inlined code. The existing command-level tests cover the functionality in that context.

late MockPlatform mockPlatform;
late Directory packagesDir;
late Directory thirdPartyPackagesDir;

SamplePackageCommand configureCommand({bool includeSubpackages = false}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I extracted a helper like this in a couple of tests. Some of our unit tests have the unfortunate pattern of setting up a usual command in setUp, but then in a few specific tests creating a custom command instance that overrides more things, ignoring the one in setUp, and using the local one.

I didn't want to try to fix all of those in this PR since this is already quite large, but when I hit those cases I did pull out a helper so that changes like "add gitDir: gitDir because now the command needs that mocked out" can at least be made in only one place in the file instead of having to look at why a subset of a command's tests are failing and then updating them with exactly the same change.

/// otherwise [fileSystem] must be provided and it will be created an arbitrary
/// location in that filesystem.
Directory createPackagesDirectory(
{Directory? parentDir, FileSystem? fileSystem}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We no longer needed the parentDir version, so I was able to simplify this method quite a bit.

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

Much cleaner than before. I like it.

Comment on lines +499 to +504
({
Directory packagesDir,
RecordingProcessRunner processRunner,
RecordingProcessRunner gitProcessRunner,
GitDir gitDir,
}) configureBaseCommandMocks({
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 25, 2025
@auto-submit auto-submit bot merged commit 8c287e9 into flutter:main Mar 25, 2025
83 checks passed
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Apr 2, 2025
flutter/packages@125c117...07496eb

2025-04-02 alexander.irion@siemens.com [multicast_dns]
MDnsClient::listen supports onError callback (flutter/packages#8888)
2025-04-02 15619084+vashworth@users.noreply.github.com Upgrade tests to
use Xcode 16 and iOS 18 (flutter/packages#8968)
2025-04-01 engine-flutter-autoroll@skia.org Manual roll Flutter from
1d954f4 to 05b5e79 (225 revisions) (flutter/packages#8960)
2025-04-01 kevmoo@users.noreply.github.com Drop deprecated HTML head
meta tags (flutter/packages#8970)
2025-04-01 stuartmorgan@google.com Adjust PR checklist formatter
discussion (flutter/packages#8924)
2025-04-01 stuartmorgan@google.com Update CODEOWNERS username
(flutter/packages#8933)
2025-04-01 69054810+M97Chahboun@users.noreply.github.com
[flutter_markdown] Added sizedImageBuilder to Markdown widget
(flutter/packages#6739)
2025-04-01 stuartmorgan@google.com [google_maps_flutter] Skip impl copy
of iOS tests (flutter/packages#8975)
2025-04-01 stuartmorgan@google.com [google_maps_flutter] Skip more
hanging iOS tests (flutter/packages#8967)
2025-04-01 stanleycocoa@gmail.com [url_launcher] When not fully loaded,
clicking close causes the callback to not be triggered correctly.
(flutter/packages#8582)
2025-04-01 robert.odrowaz@leancode.pl [camera_avfoundation] Test utils
and mocks swift migration - part 2 (flutter/packages#8892)
2025-03-31 15619084+vashworth@users.noreply.github.com [webview_flutter]
Skip flaky legacy tests on iOS (flutter/packages#8911)
2025-03-31 davidmartos96@gmail.com [camera_android] Don't override
default fps range when not recording (flutter/packages#8891)
2025-03-31 filiph@users.noreply.github.com [google_maps_flutter] Fix
typo and remove duplicitous CHANGELOG entry (flutter/packages#8754)
2025-03-31 kevmoo@users.noreply.github.com [extension_gsi] Support the
latest version of googleapis_auth (flutter/packages#8931)
2025-03-31 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump com.android.tools.build:gradle from 8.0.0 to 8.9.1 in
/packages/pigeon/platform_tests/test_plugin/android
(flutter/packages#8955)
2025-03-31 linxunfeng@yeah.net [webview_flutter_wkwebview] Fixes crash
when sending undefined message via javascript channel
(flutter/packages#8776)
2025-03-31 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump com.android.tools.build:gradle from 8.0.0 to 8.9.1 in
/packages/pigeon/platform_tests/alternate_language_test_plugin/android
(flutter/packages#8946)
2025-03-31 10687576+bparrishMines@users.noreply.github.com
[interactive_media_ads] Fixes `AdEventType`s not triggering on iOS in
release mode (flutter/packages#8918)
2025-03-31 stuartmorgan@google.com [google_maps_flutter] Skip test that
hangs iOS CI (flutter/packages#8958)
2025-03-28 engine-flutter-autoroll@skia.org Manual roll Flutter from
b16430b to 1d954f4 (114 revisions) (flutter/packages#8922)
2025-03-28 robert.odrowaz@leancode.pl [camera_avfoundation] Test utils
and mocks swift migration - part 3 (flutter/packages#8912)
2025-03-27 jacksongardner@google.com Use a more deterministic way of
waiting for ad widgets to be ready. (flutter/packages#8920)
2025-03-27 robert.odrowaz@leancode.pl [camera_avfoundation] Test utils
and mocks swift migration - part 1 (flutter/packages#8890)
2025-03-27 tarrinneal@gmail.com [pigeon] correct usage of extended
generics in generator methods (flutter/packages#8910)
2025-03-27 34892635+fa0311@users.noreply.github.com [video_player] Fix
layout issue caused by `Transform.rotate` not affecting space
calculation. (flutter/packages#8685)
2025-03-27 43759233+kenzieschmoll@users.noreply.github.com
[shared_preferences] Fix a late initialized error with the example app
(flutter/packages#8540)
2025-03-26 stuartmorgan@google.com [various] Disable sandbox in Chrome
dart tests (flutter/packages#8909)
2025-03-25 stuartmorgan@google.com [tool] Move changed file detection to
base command class (flutter/packages#8730)
2025-03-25 34327253+lenzpaul@users.noreply.github.com [Camera] Add lens
type information (iOS) (flutter/packages#8723)
2025-03-25 tarrinneal@gmail.com [pigeon] kotlin equality methods
(flutter/packages#8887)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

---------

Co-authored-by: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com>
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Apr 3, 2025
flutter/packages@125c117...07496eb

2025-04-02 alexander.irion@siemens.com [multicast_dns]
MDnsClient::listen supports onError callback (flutter/packages#8888)
2025-04-02 15619084+vashworth@users.noreply.github.com Upgrade tests to
use Xcode 16 and iOS 18 (flutter/packages#8968)
2025-04-01 engine-flutter-autoroll@skia.org Manual roll Flutter from
1d954f4 to 05b5e79 (225 revisions) (flutter/packages#8960)
2025-04-01 kevmoo@users.noreply.github.com Drop deprecated HTML head
meta tags (flutter/packages#8970)
2025-04-01 stuartmorgan@google.com Adjust PR checklist formatter
discussion (flutter/packages#8924)
2025-04-01 stuartmorgan@google.com Update CODEOWNERS username
(flutter/packages#8933)
2025-04-01 69054810+M97Chahboun@users.noreply.github.com
[flutter_markdown] Added sizedImageBuilder to Markdown widget
(flutter/packages#6739)
2025-04-01 stuartmorgan@google.com [google_maps_flutter] Skip impl copy
of iOS tests (flutter/packages#8975)
2025-04-01 stuartmorgan@google.com [google_maps_flutter] Skip more
hanging iOS tests (flutter/packages#8967)
2025-04-01 stanleycocoa@gmail.com [url_launcher] When not fully loaded,
clicking close causes the callback to not be triggered correctly.
(flutter/packages#8582)
2025-04-01 robert.odrowaz@leancode.pl [camera_avfoundation] Test utils
and mocks swift migration - part 2 (flutter/packages#8892)
2025-03-31 15619084+vashworth@users.noreply.github.com [webview_flutter]
Skip flaky legacy tests on iOS (flutter/packages#8911)
2025-03-31 davidmartos96@gmail.com [camera_android] Don't override
default fps range when not recording (flutter/packages#8891)
2025-03-31 filiph@users.noreply.github.com [google_maps_flutter] Fix
typo and remove duplicitous CHANGELOG entry (flutter/packages#8754)
2025-03-31 kevmoo@users.noreply.github.com [extension_gsi] Support the
latest version of googleapis_auth (flutter/packages#8931)
2025-03-31 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump com.android.tools.build:gradle from 8.0.0 to 8.9.1 in
/packages/pigeon/platform_tests/test_plugin/android
(flutter/packages#8955)
2025-03-31 linxunfeng@yeah.net [webview_flutter_wkwebview] Fixes crash
when sending undefined message via javascript channel
(flutter/packages#8776)
2025-03-31 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump com.android.tools.build:gradle from 8.0.0 to 8.9.1 in
/packages/pigeon/platform_tests/alternate_language_test_plugin/android
(flutter/packages#8946)
2025-03-31 10687576+bparrishMines@users.noreply.github.com
[interactive_media_ads] Fixes `AdEventType`s not triggering on iOS in
release mode (flutter/packages#8918)
2025-03-31 stuartmorgan@google.com [google_maps_flutter] Skip test that
hangs iOS CI (flutter/packages#8958)
2025-03-28 engine-flutter-autoroll@skia.org Manual roll Flutter from
b16430b to 1d954f4 (114 revisions) (flutter/packages#8922)
2025-03-28 robert.odrowaz@leancode.pl [camera_avfoundation] Test utils
and mocks swift migration - part 3 (flutter/packages#8912)
2025-03-27 jacksongardner@google.com Use a more deterministic way of
waiting for ad widgets to be ready. (flutter/packages#8920)
2025-03-27 robert.odrowaz@leancode.pl [camera_avfoundation] Test utils
and mocks swift migration - part 1 (flutter/packages#8890)
2025-03-27 tarrinneal@gmail.com [pigeon] correct usage of extended
generics in generator methods (flutter/packages#8910)
2025-03-27 34892635+fa0311@users.noreply.github.com [video_player] Fix
layout issue caused by `Transform.rotate` not affecting space
calculation. (flutter/packages#8685)
2025-03-27 43759233+kenzieschmoll@users.noreply.github.com
[shared_preferences] Fix a late initialized error with the example app
(flutter/packages#8540)
2025-03-26 stuartmorgan@google.com [various] Disable sandbox in Chrome
dart tests (flutter/packages#8909)
2025-03-25 stuartmorgan@google.com [tool] Move changed file detection to
base command class (flutter/packages#8730)
2025-03-25 34327253+lenzpaul@users.noreply.github.com [Camera] Add lens
type information (iOS) (flutter/packages#8723)
2025-03-25 tarrinneal@gmail.com [pigeon] kotlin equality methods
(flutter/packages#8887)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

---------

Co-authored-by: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com>
androidseb pushed a commit to androidseb/packages that referenced this pull request Jun 8, 2025
Consolidates the code to find all changed file paths into the `PackageLoopingCommand` class that is the base of almost all of the repo tooling commands. This in a preparatory PR for a future change to allow each command to define a list of files or file patterns that definitively *don't* affect that test, so that CI can be smarter about what tests to run (e.g., not running expensive integration tests for README changes).

A side effect of this change is that tests of almost all commands now need a mock `GitDir` instance. This would add a lot of copy/pasted boilerplate to the test setup, and there is already too much of that, so instead this refactors common test setup:
- Creating a memory file system
- Populating it with a packages directory
- Creating a RecordingProcessRunner to mock out process calls
- Creating a mock GitDir that forwards to a RecordingProcessRunner

into a helper method (using records and destructuring to easily return multiple values). While some tests don't need all of these steps, those that don't can easily ignore parts of it, and it will make it much easier to update tests in the future if they need them, and it makes the setup much more consistent which makes it easier to reason about test setup in general.

Prep for flutter/flutter#136394
zhangyuang pushed a commit to zhangyuang/flutter-fork that referenced this pull request Jun 9, 2025
…er#166457)

flutter/packages@125c117...07496eb

2025-04-02 alexander.irion@siemens.com [multicast_dns]
MDnsClient::listen supports onError callback (flutter/packages#8888)
2025-04-02 15619084+vashworth@users.noreply.github.com Upgrade tests to
use Xcode 16 and iOS 18 (flutter/packages#8968)
2025-04-01 engine-flutter-autoroll@skia.org Manual roll Flutter from
1d954f4 to 05b5e79 (225 revisions) (flutter/packages#8960)
2025-04-01 kevmoo@users.noreply.github.com Drop deprecated HTML head
meta tags (flutter/packages#8970)
2025-04-01 stuartmorgan@google.com Adjust PR checklist formatter
discussion (flutter/packages#8924)
2025-04-01 stuartmorgan@google.com Update CODEOWNERS username
(flutter/packages#8933)
2025-04-01 69054810+M97Chahboun@users.noreply.github.com
[flutter_markdown] Added sizedImageBuilder to Markdown widget
(flutter/packages#6739)
2025-04-01 stuartmorgan@google.com [google_maps_flutter] Skip impl copy
of iOS tests (flutter/packages#8975)
2025-04-01 stuartmorgan@google.com [google_maps_flutter] Skip more
hanging iOS tests (flutter/packages#8967)
2025-04-01 stanleycocoa@gmail.com [url_launcher] When not fully loaded,
clicking close causes the callback to not be triggered correctly.
(flutter/packages#8582)
2025-04-01 robert.odrowaz@leancode.pl [camera_avfoundation] Test utils
and mocks swift migration - part 2 (flutter/packages#8892)
2025-03-31 15619084+vashworth@users.noreply.github.com [webview_flutter]
Skip flaky legacy tests on iOS (flutter/packages#8911)
2025-03-31 davidmartos96@gmail.com [camera_android] Don't override
default fps range when not recording (flutter/packages#8891)
2025-03-31 filiph@users.noreply.github.com [google_maps_flutter] Fix
typo and remove duplicitous CHANGELOG entry (flutter/packages#8754)
2025-03-31 kevmoo@users.noreply.github.com [extension_gsi] Support the
latest version of googleapis_auth (flutter/packages#8931)
2025-03-31 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump com.android.tools.build:gradle from 8.0.0 to 8.9.1 in
/packages/pigeon/platform_tests/test_plugin/android
(flutter/packages#8955)
2025-03-31 linxunfeng@yeah.net [webview_flutter_wkwebview] Fixes crash
when sending undefined message via javascript channel
(flutter/packages#8776)
2025-03-31 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump com.android.tools.build:gradle from 8.0.0 to 8.9.1 in
/packages/pigeon/platform_tests/alternate_language_test_plugin/android
(flutter/packages#8946)
2025-03-31 10687576+bparrishMines@users.noreply.github.com
[interactive_media_ads] Fixes `AdEventType`s not triggering on iOS in
release mode (flutter/packages#8918)
2025-03-31 stuartmorgan@google.com [google_maps_flutter] Skip test that
hangs iOS CI (flutter/packages#8958)
2025-03-28 engine-flutter-autoroll@skia.org Manual roll Flutter from
b16430b to 1d954f4 (114 revisions) (flutter/packages#8922)
2025-03-28 robert.odrowaz@leancode.pl [camera_avfoundation] Test utils
and mocks swift migration - part 3 (flutter/packages#8912)
2025-03-27 jacksongardner@google.com Use a more deterministic way of
waiting for ad widgets to be ready. (flutter/packages#8920)
2025-03-27 robert.odrowaz@leancode.pl [camera_avfoundation] Test utils
and mocks swift migration - part 1 (flutter/packages#8890)
2025-03-27 tarrinneal@gmail.com [pigeon] correct usage of extended
generics in generator methods (flutter/packages#8910)
2025-03-27 34892635+fa0311@users.noreply.github.com [video_player] Fix
layout issue caused by `Transform.rotate` not affecting space
calculation. (flutter/packages#8685)
2025-03-27 43759233+kenzieschmoll@users.noreply.github.com
[shared_preferences] Fix a late initialized error with the example app
(flutter/packages#8540)
2025-03-26 stuartmorgan@google.com [various] Disable sandbox in Chrome
dart tests (flutter/packages#8909)
2025-03-25 stuartmorgan@google.com [tool] Move changed file detection to
base command class (flutter/packages#8730)
2025-03-25 34327253+lenzpaul@users.noreply.github.com [Camera] Add lens
type information (iOS) (flutter/packages#8723)
2025-03-25 tarrinneal@gmail.com [pigeon] kotlin equality methods
(flutter/packages#8887)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

---------

Co-authored-by: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com>
FMorschel pushed a commit to FMorschel/packages that referenced this pull request Jun 9, 2025
Consolidates the code to find all changed file paths into the `PackageLoopingCommand` class that is the base of almost all of the repo tooling commands. This in a preparatory PR for a future change to allow each command to define a list of files or file patterns that definitively *don't* affect that test, so that CI can be smarter about what tests to run (e.g., not running expensive integration tests for README changes).

A side effect of this change is that tests of almost all commands now need a mock `GitDir` instance. This would add a lot of copy/pasted boilerplate to the test setup, and there is already too much of that, so instead this refactors common test setup:
- Creating a memory file system
- Populating it with a packages directory
- Creating a RecordingProcessRunner to mock out process calls
- Creating a mock GitDir that forwards to a RecordingProcessRunner

into a helper method (using records and destructuring to easily return multiple values). While some tests don't need all of these steps, those that don't can easily ignore parts of it, and it will make it much easier to update tests in the future if they need them, and it makes the setup much more consistent which makes it easier to reason about test setup in general.

Prep for flutter/flutter#136394
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants