Repository navigation
[flutter_tools] Delete AppContext and legacy test context shims - #197412
Conversation
Deletes the Zone-based `AppContext` (`lib/src/base/context.dart`) and the legacy test context harnesses (`test/src/context.dart`, `test/src/context_runner.dart`, `test/src/testbed.dart`, and `DelegatingToolContext`) now that all production code and tests use explicit dependency injection via `ToolContext` and `ToolDependencies`. - Removes the remaining `context.run` wrappers in `lib/runner.dart` and `lib/src/runner/flutter_command_runner.dart` and the dead `ContextDependencyCycleException` catch in `lib/src/base/error_handling_io.dart`. - Moves reusable test fakes (`FakeDeviceManager`, `TestDeviceDiscoverySupportFilter`, `FakeAndroidLicenseValidator`, `NoopIOSSimulatorUtils`, `FakeXcodeProjectInterpreter`, `NoopCrashReporter`, `LocalFileSystemBlockingSetCurrentDirectory`, `FakeSignals`) from `test/src/context.dart` into `test/src/fakes.dart` and updates test imports. - Migrates the remaining `testUsingContext` tests in `dependency_injection_test.dart` to plain `test` and deletes `context_test.dart`, `context_runner_test.dart`, and `testbed_test.dart`. - Updates `forbidden_imports_test.dart`, `dev/bots/analyze.dart`, `README.md`, and `AGENTS.md`. Part of flutter#47161
There was a problem hiding this comment.
Code Review
This pull request completely removes the legacy zone-based dependency injection mechanism (AppContext), testUsingContext, and TestBed from flutter_tools and its tests, transitioning fully to explicit dependency injection. Feedback on the changes suggests propagating the AndroidSdk from the resolved AndroidContext in TestFlutterCommandRunner instead of hardcoding it to null to ensure configured fakes remain accessible.
| return TestFlutterCommandRunner._( | ||
| analytics: analytics ?? const NoOpAnalytics(), | ||
| androidContext: androidContext ?? FakeAndroidContext(gradleUtils: gradleUtils), | ||
| applicationPackageFactory: | ||
| applicationPackageFactory ?? | ||
| FlutterApplicationPackageFactory( | ||
| androidSdkBuilder: () => null, | ||
| plistParserBuilder: () => resolvedPlistParser, | ||
| templatePathProvider: resolvedTemplatePathProvider, | ||
| toolContext: resolvedToolContext, | ||
| ), |
There was a problem hiding this comment.
Instead of hardcoding androidSdkBuilder to return null, we can propagate the AndroidSdk from the resolved AndroidContext. This ensures that tests using the default applicationPackageFactory can still access the configured/fake AndroidSdk if one is provided.
| return TestFlutterCommandRunner._( | |
| analytics: analytics ?? const NoOpAnalytics(), | |
| androidContext: androidContext ?? FakeAndroidContext(gradleUtils: gradleUtils), | |
| applicationPackageFactory: | |
| applicationPackageFactory ?? | |
| FlutterApplicationPackageFactory( | |
| androidSdkBuilder: () => null, | |
| plistParserBuilder: () => resolvedPlistParser, | |
| templatePathProvider: resolvedTemplatePathProvider, | |
| toolContext: resolvedToolContext, | |
| ), | |
| final AndroidContext resolvedAndroidContext =\n androidContext ?? FakeAndroidContext(gradleUtils: gradleUtils);\n return TestFlutterCommandRunner._(\n analytics: analytics ?? const NoOpAnalytics(),\n androidContext: resolvedAndroidContext,\n applicationPackageFactory:\n applicationPackageFactory ??\n FlutterApplicationPackageFactory(\n androidSdkBuilder: () => resolvedAndroidContext.androidSdk,\n plistParserBuilder: () => resolvedPlistParser,\n templatePathProvider: resolvedTemplatePathProvider,\n toolContext: resolvedToolContext,\n ), |
References
- Suggest simplification and refactoring: Assess whether the code can be made simpler or refactored to enhance readability and maintainability. (link)
flutter/flutter@82ec424...43150a8 2026-11-27 [email protected] Windows: fix for popup descendent of popup closing the whole tree when the 2nd popup gains focus (flutter/flutter#196911) 2026-11-27 [email protected] Roll Skia from d693d85a4b77 to fe34f20b9689 (1 revision) (flutter/flutter#197491) 2026-11-27 [email protected] Roll Dart SDK from 691817e0ec3b to 5c3e102fc422 (1 revision) (flutter/flutter#197489) 2026-11-27 [email protected] Roll Fuchsia Linux SDK from 0bgCrr76CM4IqPO0v... to cBAjguERWwvY6tFtz... (flutter/flutter#197488) 2026-11-27 [email protected] [flutter_tools] Delete AppContext and legacy test context shims (flutter/flutter#197412) 2026-11-26 [email protected] Revert: [tool][engine] Enable experimental VM service by default (flutter/flutter#197481) 2026-11-26 [email protected] iOS: Remove engine includes from the platform views controller headers (flutter/flutter#197429) 2026-11-26 [email protected] [tool][engine] Enable experimental VM service by default (flutter/flutter#190100) 2026-11-26 [email protected] Add trust gate flags for "flutter analyze" (flutter/flutter#196415) 2026-11-26 [email protected] Roll Dart SDK from 7fcaf46b0308 to 691817e0ec3b (1 revision) (flutter/flutter#197475) 2026-11-26 [email protected] [Windows] Fix MASM flags in Windows GN `tool("asm")` (flutter/flutter#197464) 2026-11-26 [email protected] Roll Skia from cef5963c1bb2 to d693d85a4b77 (2 revisions) (flutter/flutter#197469) 2026-11-26 [email protected] Roll Packages from 105a874 to da586f5 (3 revisions) (flutter/flutter#197471) If this roll has caused a breakage, revert this CL and set the roller to dry run mode using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: 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
Deletes the Zone-based
AppContext(lib/src/base/context.dart) and the legacy test context harnesses (test/src/context.dart,test/src/context_runner.dart,test/src/testbed.dart, andDelegatingToolContext) now that all production code and tests use explicit dependency injection viaToolContextandToolDependencies.context.runwrappers inlib/runner.dartandlib/src/runner/flutter_command_runner.dartand the deadContextDependencyCycleExceptioncatch inlib/src/base/error_handling_io.dart.FakeDeviceManager,TestDeviceDiscoverySupportFilter,FakeAndroidLicenseValidator,NoopIOSSimulatorUtils,FakeXcodeProjectInterpreter,NoopCrashReporter,LocalFileSystemBlockingSetCurrentDirectory,FakeSignals) fromtest/src/context.dartintotest/src/fakes.dartand updates test imports.testUsingContexttests independency_injection_test.dartto plaintestand deletescontext_test.dart,context_runner_test.dart, andtestbed_test.dart.forbidden_imports_test.dart,dev/bots/analyze.dart,README.md, andAGENTS.md.Part of #47161