Skip to content

[flutter_tools] Delete AppContext and legacy test context shims - #197412

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
bkonyi:di/34-delete-app-context
Nov 27, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:masterfrom
bkonyi:di/34-delete-app-context

Conversation

@bkonyi

@bkonyi bkonyi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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 #47161

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
@bkonyi
bkonyi requested review from a team as code owners November 25, 2026 21:47
@bkonyi bkonyi added the CICD Run CI/CD label Nov 25, 2026
@bkonyi
bkonyi requested a review from a team as a code owner November 25, 2026 21:47
@bkonyi
bkonyi requested review from chingjun and reidbaker and removed request for a team November 25, 2026 21:47
@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. a: desktop Running on desktop team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-windows Owned by the Windows platform team labels Nov 25, 2026

@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 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.

Comment on lines +117 to +127
return TestFlutterCommandRunner._(
analytics: analytics ?? const NoOpAnalytics(),
androidContext: androidContext ?? FakeAndroidContext(gradleUtils: gradleUtils),
applicationPackageFactory:
applicationPackageFactory ??
FlutterApplicationPackageFactory(
androidSdkBuilder: () => null,
plistParserBuilder: () => resolvedPlistParser,
templatePathProvider: resolvedTemplatePathProvider,
toolContext: resolvedToolContext,
),

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

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.

Suggested change
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
  1. Suggest simplification and refactoring: Assess whether the code can be made simpler or refactored to enhance readability and maintainability. (link)

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 27, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 27, 2026
Merged via the queue into flutter:master with commit 32d72fd Nov 27, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 27, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 27, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop CICD Run CI/CD team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-windows Owned by the Windows platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants