Sitelet https://github.com/flutter/flutter/pull/188471
Skip to content

[tool] Migrate flutter_tools commands to modular dependency injection - #188471

Closed
bkonyi wants to merge 17 commits into
flutter:masterfrom
bkonyi:remove-globals-dependency-injection
Closed

bkonyi wants to merge 17 commits into
flutter:masterfrom
bkonyi:remove-globals-dependency-injection

Conversation

@bkonyi

@bkonyi bkonyi commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR implements the first major phase of migrating the flutter_tools package away from Zone-based dependency injection (globals.dart and context.get) toward an explicit, Layered Dependency Injection (DI) architecture using standard constructor injection.

This refactoring is a critical, non-negotiable technical prerequisite for the Flutter team's long-term roadmap to decouple target platform support (Android, iOS, Web) out of the core runner and load them dynamically as isolated extensions via the Generic Extension Protocol (GEP).

To facilitate extremely clean and easy code reviews, this PR is structured as a sequence of 17 atomic, build-clean, and test-green commits. Each commit introduces a single infrastructure component or migrates a single command, allowing the history to be easily split into smaller, sequential PRs.

Across this migration, 50+ files were modified, all verified by 100% clean static analysis and green test suites!


Architectural Highlights

We organize the tool's 33+ core dependencies into three cohesive layers, orchestrating their creation topologically at startup:

  1. HostEnvironment (Layer 1): Stateless OS wrappers (FileSystem, Logger, Platform, ProcessManager, Stdio, Signals) held in ToolContext.
  2. ToolConfiguration (Layer 2): Stateful configurations (Cache, Config, Artifacts, FeatureFlags, ShutdownHooks) held in ToolContext.
  3. WorkflowServices (Layer 3): Heavy domain services (DeviceManager, Doctor, EmulatorManager, BuildSystem). Design Rule: Injected directly via constructors only where needed (completely removed from the monolithic ToolContext).

Platform-Specific Isolation (AndroidContext & AppleContext)

Platform-specific dependencies (e.g., Xcode or AndroidSdk) are separated into dedicated sub-contexts that are nullable at the runner level (e.g., AppleContext is null on Linux), enforcing strict compile-time platform boundaries and enabling targeted mocking in tests.


Why Explicit DI is Mandatory for Tool Extensibility

As detailed in the official Flutter Tool Extensibility Design, platform support will eventually run as dynamically-loaded extensions:

  1. The Isolate Barrier (Compile-Time Block): GEP extensions run in separate Dart Isolates. Isolates do not share memory, and extension packages cannot import globals.dart (compile-time block). Platform-specific code must be 100% free of globals to compile and run. Explicit DI is the only architecture that can cross the isolate barrier.
  2. Trivial "Lift-and-Shift" Migration: Because our refactoring already groups platform utilities into dedicated containers (AndroidContext, AppleContext), migrating Android or Apple support to external GEP extension packages later becomes a simple, low-friction directory move.
  3. Dynamic Registration: Decoupled core managers (like DeviceManager or DiagnosticsManager) can cleanly accept, register, and delegate to dynamically-loaded, extension-backed components (like custom Device or DoctorValidator instances) during bootstrapping, without mutating fragile global variables.

14 Migrated Commands

We have refactored the constructors and internal logic of 14 core commands to require ToolContext (for Layer 1 & 2) and their specific Layer 3 dependencies directly via their constructors (resolving them via non-nullable instance getters instead of globals.xxx):

  1. CleanCommand (Core + direct BuildSystem injection)
  2. ChannelCommand (Core)
  3. ConfigCommand (Core)
  4. ScreenshotCommand (Core + direct DeviceManager injection)
  5. SymbolizeCommand (Core)
  6. DoctorCommand (Core + direct Doctor injection)
  7. DevicesCommand (Core + direct DeviceManager and Doctor injection)
  8. EmulatorsCommand (Core + direct EmulatorManager and Doctor injection)
  9. DowngradeCommand (Core)
  10. InstallCommand (Core + direct DeviceManager injection)
  11. LogsCommand (Core + direct DeviceManager injection)
  12. DebugAdapterCommand (Core)
  13. UpgradeCommand (Core)
  14. ShellCompletionCommand (Core)

Testing & Quality Assurance

  • 100% Hermetic Tests: We replace testUsingContext with standard, hermetic unit tests (testWithoutContext).
  • Compiler-Enforced Mocks: If a new dependency is added to a command in the future, the test fails to compile immediately, forcing the developer to provide a mock. This prevents silent runtime fallbacks to local host environments.
  • Central Test Regressions Resolved: Resolved pre-existing test regressions (such as the args_test.dart crash) by implementing a robust FakeToolDependencies to handle command generation checks.
  • Zero-Lint Guarantee: Cleaned up all files to pass dart format and dart analyze --fatal-infos with zero issues.

Verification Results

  • Static Analysis: dart analyze --fatal-infos -> 100% Clean (No issues found!)
  • Core DI Bootstrapping Tests (dependency_injection_test.dart) -> PASSED
  • Migrated Command Tests (clean_test.dart, devices_test.dart, emulators_test.dart, etc.) -> PASSED

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 24, 2026
@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. team-android Owned by Android platform team team-ios Owned by iOS platform team and removed CICD Run CI/CD labels Jun 24, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Jun 24, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 24, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Jun 24, 2026
@bkonyi
bkonyi force-pushed the remove-globals-dependency-injection branch from 90b4976 to 4d89801 Compare June 24, 2026 16:05
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 24, 2026
bkonyi added 17 commits June 25, 2026 15:38
…unner

Introduce explicit dependency injection containers to replace Zone-based lookup.

- Created `ToolContext`, `AppleContext`, and `AndroidContext` to hold modular dependencies.
- Implemented `ToolDependencies.bootstrap` to topologically instantiate all 36+ dependencies in the correct order.
- Resolved circular dependencies (e.g. `ProcessManager` -> `Analytics` -> `FlutterVersion`) using a lazy closure.
- Wired the bootstrapper into `runner.dart` to initialize dependencies at startup.
- Updated `FlutterCommandRunner` and `executable.dart` to accept and propagate the new contexts.
- Added `dependency_injection_test.dart` to verify bootstrapping and override propagation.

This is a backward-compatible change preparing for incremental command migration.
Refactor `CleanCommand` to receive its dependencies via explicit modular contexts.

- Updated `CleanCommand` constructor to require `ToolContext` and `AppleContext`.
- Refactored all internal logic in `CleanCommand` to resolve dependencies via injected contexts instead of `globals`.
- Updated `FlutterCommand` base class to accept optional `ToolContext` and expose fallback getters to maintain 100% backward compatibility.
- Resolved a covariance violation in `custom_devices.dart` by making `CustomDevicesCommandBase.fileSystem` non-nullable.
- Wired contexts into `CleanCommand` registration inside `executable.dart`.
- Refactored `clean_test.dart` to use localized mock/fake contexts, verifying hermetic execution.

This establishes a clean, verified template for migrating the remaining commands in Phase 3.
Refactor `ChannelCommand` to receive its dependencies via explicit modular contexts.

- Updated `ChannelCommand` constructor to require `ToolContext`.
- Refactored all internal logic in `ChannelCommand` to resolve dependencies via injected contexts instead of `globals`.
- Refactored `ChannelCommand.upgradeChannel` and `_checkout` static methods to explicitly accept their dependencies as arguments, preventing global state leakage.
- Added `FlutterVersion flutterVersion` to `ToolContext` and wired it into `ToolDependencies.bootstrap`.
- Updated `UpgradeCommand` callsites to pass explicit dependencies to `ChannelCommand.upgradeChannel`.
- Resolved covariance and `annotate_overrides` warnings in `build.dart`, `build_ios_framework.dart`, and `widget_preview.dart` due to new getters on the base class.
- Refactored `channel_test.dart` to use `FakeToolContext` and added a new test explicitly verifying that the command resolves its dependencies from the injected context rather than the Zone.

This continues our incremental command migration in Phase 3.
Refactor `ConfigCommand` to receive its dependencies via explicit modular contexts.

- Updated `ConfigCommand` constructor to require `ToolContext` and `AndroidContext`.
- Refactored all internal logic in `ConfigCommand` to resolve dependencies via injected contexts instead of `globals`.
- Added `config` and `terminal` (typed as `Terminal` to prevent covariant conflicts) getters to the `FlutterCommand` base class with safe global fallbacks.
- Wired contexts into `ConfigCommand` registration inside `executable.dart`.
- Refactored `config_test.dart` to use `FakeToolContext` and `FakeAndroidContext` and added two new DI validation tests explicitly verifying that the command resolves its dependencies from the injected contexts rather than the Zone.

This continues our incremental command migration in Phase 3.
Refactor `ScreenshotCommand` to receive its dependencies via explicit modular contexts.

- Updated `ScreenshotCommand` constructor to require `ToolContext`.
- Refactored all internal logic in `ScreenshotCommand` to resolve dependencies via injected contexts instead of `globals`.
- Added `fileSystemUtils` getter to the `FlutterCommand` base class with safe global fallbacks.
- Resolved a Dart flow-analysis type promotion warning by introducing a non-nullable local copy of `outputFile` to ensure clean promotion in closures.
- Wired contexts into `ScreenshotCommand` registration inside `executable.dart`.
- Refactored `screenshot_command_test.dart` to use `FakeToolContext` and added a new DI validation test group.

This continues our incremental command migration in Phase 3.
Refactor `SymbolizeCommand` to receive its dependencies via explicit modular contexts.

- Updated `SymbolizeCommand` constructor to require `ToolContext`.
- Refactored all internal logic in `SymbolizeCommand` to resolve dependencies via injected contexts instead of `globals`.
- Added `stdio` getter to the `FlutterCommand` base class with safe global fallbacks.
- Wired contexts into `SymbolizeCommand` registration inside `executable.dart`.
- Refactored `symbolize_test.dart` to use `FakeToolContext` and added a new DI validation test.

This continues our incremental command migration in Phase 3.
Refactor `DoctorCommand` and expand the DI container to support the `Doctor` service.

- Added `Doctor doctor` to the modular `ToolContext` container.
- Topologically bootstrapped `Doctor` inside `ToolDependencies.bootstrap` using the already-constructed logger and clock.
- Exposed a `doctor` getter on the `FlutterCommand` base class with safe global fallbacks to preserve backward compatibility.
- Refactored `DoctorCommand` constructor to require `ToolContext` and updated all internal code to use the inherited `doctor` getter instead of `globals.doctor`.
- Wired contexts into `DoctorCommand` registration inside `executable.dart`.
- Refactored `doctor_test.dart` to use `FakeToolContext` and added 3 new DI validation tests.
- Updated `dependency_injection_test.dart` to assert `doctor` bootstrapping.

This expands our explicit DI container and continues Phase 3 command migration.
Expand explicit dependency injection container to topologically bootstrap the entire device discovery infrastructure.

- Added `OperatingSystemUtils os`, `Artifacts artifacts`, `WindowsWorkflow windowsWorkflow`, `MacOSWorkflow macOSWorkflow`, and `DeviceManager deviceManager` to the core `ToolContext`.
- Added `AndroidWorkflow androidWorkflow` to `AndroidContext`.
- Added `IOSWorkflow iosWorkflow` and `IOSSimulatorUtils iosSimulatorUtils` to `AppleContext`.
- Topologically bootstrapped and wired all of these in `ToolDependencies.bootstrap(...)`.
- Updated `FlutterDeviceManager` constructor to accept nullable platform-specific dependencies, allowing robust platform-agnostic instantiation and registration.
- Exposed `os`, `artifacts`, and `deviceManager` getters on `FlutterCommand` base class with safe global fallbacks.
- Updated `dependency_injection_test.dart` to assert correct bootstrapping across different platforms and verify override propagation.

This is a major architectural milestone that enables explicit injection of the entire device discovery infrastructure at startup.
Refactor `DevicesCommand` to receive its dependencies via explicit modular contexts.

- Updated `DevicesCommand` constructor to require `ToolContext` as a named parameter.
- Refactored all internal logic in `DevicesCommand` to resolve `doctor`, `deviceManager`, `platform`, and `logger` from the inherited getters instead of `globals.xxx`.
- Completely removed `globals.dart` import from `devices.dart`.
- Wired contexts into `DevicesCommand` registration inside `executable.dart`.
- Refactored `runner_test.dart` to inject `toolContext` into its `DevicesCommand` instantiation, preventing compilation errors in other shards.
- Refactored `permeable/devices_test.dart` and `hermetic/devices_test.dart` to use `FakeToolContext` and `createDevicesCommand` helper (updating all 27 instantiations!).
- Added a highly robust, combined structural and behavioral DI validation test case in `hermetic/devices_test.dart` to verify explicit injection.

This continues our Phase 3 command migration, leveraging our explicitly bootstrapped `DeviceManager`.
Refactor `EmulatorsCommand` and expand the DI container to support the `EmulatorManager` service.

- Added `EmulatorManager emulatorManager` to the modular `ToolContext` container.
- Topologically bootstrapped `EmulatorManager` inside `ToolDependencies.bootstrap` using Android and core dependencies (`java`, `androidSdk`, `processManager`, `logger`, `fs`, `androidWorkflow`).
- Supported optional `EmulatorManager? emulatorManager` override in the bootstrapper for hermetic testing.
- Exposed `emulatorManager` getter on the `FlutterCommand` base class with safe Zone-based fallbacks.
- Refactored `EmulatorsCommand` constructor to require `ToolContext`, and refactored all internal code to use inherited getters instead of `globals.xxx`.
- Explicitly prefixed all `emulatorManager` references in `EmulatorsCommand` with `this.emulatorManager` to bypass Dart's lexical scope shadowing from `emulator.dart`.
- Wired contexts into `EmulatorsCommand` registration inside `executable.dart`.
- Wrote a brand-new, comprehensive hermetic unit test suite (`emulators_test.dart`) from scratch with 15 tests covering listing, launching, and creation behaviors.
- Updated `dependency_injection_test.dart` to assert correct bootstrapping and override propagation.

This expands our explicit DI container and continues Phase 3 command migration.
…vice

Refactor `DowngradeCommand` and expand the DI container to support the `PersistentToolState` service.

- Added `PersistentToolState persistentToolState` to the modular `ToolContext` container.
- Topologically bootstrapped `PersistentToolState` inside `ToolDependencies.bootstrap` using the container's file system and logger.
- Supported optional `PersistentToolState? persistentToolState` override in the bootstrapper for hermetic testing.
- Exposed `persistentToolState` getter on the `FlutterCommand` base class with safe global fallbacks.
- Refactored `DowngradeCommand` constructor to require `ToolContext`, and completely removed all other optional parameters (`persistentToolState`, `logger`, `flutterVersion`, `terminal`, `stdio`, `fileSystem`).
- Completely removed all private nullable fields and lazy-initialization blocks in `runCommand`, replacing them with direct, non-nullable inherited base class getters.
- Wired contexts into `DowngradeCommand` registration inside `executable.dart` (removing legacy overrides).
- Refactored `downgrade_test.dart` to use `FakeToolContext` and `setUpCommand` helper, and added a mathematically rigorous DI validation test.
- Solved the environment-specific Android SDK lookup failure in `downgrade_test.dart` by explicitly setting `command.applicationPackages = FakeApplicationPackageFactory();` in the setup.
- Updated `dependency_injection_test.dart` to assert correct bootstrapping and override propagation for `PersistentToolState` (implementing `isRunningOnBot` on `FakePersistentToolState` to prevent bootstrapping crash).

This expands our explicit DI container and continues Phase 3 command migration.
Refactor `InstallCommand` to receive its dependencies via explicit modular contexts.

- Updated `InstallCommand` constructor to require `ToolContext` as a named parameter.
- Refactored all internal logic in `InstallCommand` to resolve `fileSystem` and `logger` from inherited getters instead of `globals.xxx`.
- Decoupled the top-level helper function `installApp` by passing `Logger logger` explicitly and eliminating its internal `globals.xxx` logging dependencies.
- Completely removed `globals.dart` import from `install.dart`.
- Wired contexts into `InstallCommand` registration inside `executable.dart`.
- Refactored `install_test.dart` to use `FakeToolContext` and `createInstallCommand` helper (updating all 6 instantiations!).
- Added a dedicated DI validation test case in `install_test.dart` to verify explicit injection.

This continues our Phase 3 command migration.
Refactor `LogsCommand` to receive its dependencies via explicit modular contexts.

- Updated `LogsCommand` constructor to require `ToolContext` as a named parameter.
- Refactored all internal logic in `LogsCommand` to resolve `logger` from inherited getter instead of `globals.printStatus`.
- Completely removed `globals.dart` import from `logs.dart`.
- Wired contexts into `LogsCommand` registration inside `executable.dart`.
- Refactored `logs_test.dart` to use `FakeToolContext` and `createLogsCommand` helper (updating both instantiations!).
- Added a dedicated DI validation test case in `logs_test.dart` to verify explicit injection.

This continues our Phase 3 command migration.
Refactor `DebugAdapterCommand` to receive its dependencies via explicit modular contexts and resolve a pre-existing test regression.

- Updated `DebugAdapterCommand` constructor to require `ToolContext` as a named parameter.
- Refactored all internal logic in `DebugAdapterCommand` to resolve `stdio`, `fileSystem`, `platform`, and `logger` from inherited getters instead of `globals.xxx`.
- Completely removed `globals.dart` import from `debug_adapter.dart`.
- Wired contexts into `DebugAdapterCommand` registration inside `executable.dart`.
- Patched `FakeToolContext` in `args_test.dart` to delegate `flutterVersion` to `globals.flutterVersion` (mocked by `TestBed`), resolving a pre-existing crash where `ConfigCommand` reads `flutterVersion.channel` in its constructor during command generation checks.
- Wrote a brand-new, comprehensive hermetic unit test suite (`debug_adapter_test.dart`) from scratch with 2 tests covering startup/shutdown (clean exit on closed stdin) and deep DI validation.

This continues our Phase 3 command migration and improves general test health.
Refactor `UpgradeCommand` and `UpgradeCommandRunner` to receive their dependencies via explicit modular contexts, and decouple associated top-level helpers.

- Updated `UpgradeCommand` constructor to require `ToolContext` as a named parameter.
- Refactored `UpgradeCommandRunner` constructor to require `ToolContext` and resolve all dependencies (platform, git, flutterVersion, fs, logger, persistentToolState, processUtils) from the injected context instead of `globals.xxx`.
- Removed the mutable `SystemClock clock` field from `UpgradeCommandRunner`, resolving it instead via the injected context's `systemClock` to improve test isolation.
- Decoupled the top-level `precacheArtifacts` helper function by passing `ToolContext` explicitly and eliminating all its internal `globals.xxx` dependencies.
- Updated `ChannelCommand` to store the context and propagate it to the updated `precacheArtifacts` call.
- Completely removed `globals.dart` import from `upgrade.dart`.
- Wired contexts into `UpgradeCommand` registration inside `executable.dart`.
- Refactored `hermetic/upgrade_test.dart` to use a strict `FakeToolContext` and added a dedicated DI validation test case.
- Refactored `permeable/upgrade_test.dart` by implementing a `ZoneDelegatingToolContext` universal adapter, ensuring all 24 legacy Zone-based tests continue to pass perfectly with zero regressions.

This continues our Phase 3 command migration and achieves clean DI for one of our most complex SDK commands.
Refactor `ShellCompletionCommand` to receive its dependencies via explicit modular contexts, and purge globals from its unit tests.

- Updated `ShellCompletionCommand` constructor to require `ToolContext` as a named parameter.
- Refactored all internal logic in `ShellCompletionCommand` to resolve `stdio` and `fileSystem` from inherited getters instead of `globals.xxx`.
- Completely removed `globals.dart` import from `shell_completion.dart`.
- Wired contexts into `ShellCompletionCommand` registration inside `executable.dart`.
- Refactored `shell_completion_test.dart` to use `FakeToolContext` and a local `fileSystem` variable, completely purging `globals` from the test file.
- Replaced all 5 instantiations of `ShellCompletionCommand` in tests with the helper.
- Added a dedicated DI validation test case in `shell_completion_test.dart` using strict throwing mocks to prove perfect DI isolation.

This continues our Phase 3 command migration and achieves clean DI for our shell integration tools.
…roidSdk

By default, AndroidSdk.locateAndroidSdk constructed a new OperatingSystemUtils instance internally when resolving the SDK. This bypassed the FakeOperatingSystemUtils override provided by testUsingContext in hermetic tests, causing actual process execution (which -a aapt) that failed under FakeProcessManager when no matching commands were expected.

This change:
1. Adds an optional operatingSystemUtils parameter to AndroidSdk.locateAndroidSdk.
2. Uses the passed operatingSystemUtils or falls back to globals.os if no overrides are passed, ensuring that tests honoring the zone overrides will use the fake implementation.
3. Updates ToolDependencies.bootstrap to pass its constructed finalOS to locateAndroidSdk.
4. Fixes dependency_injection_test.dart by adding whichAll stub to FakeOperatingSystemUtils and passing mock Android SDK/Studio in overrides tests.
@bkonyi
bkonyi force-pushed the remove-globals-dependency-injection branch from 4d89801 to 8e84c76 Compare June 25, 2026 17:04
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 25, 2026
pull Bot pushed a commit to Mu-L/flutter that referenced this pull request Sep 18, 2026
## Summary
Part 23a of the modular dependency injection migration.
* Migrates `DevFS` and `DevFSContent` to modular dependency injection,
removing ambient `devFSConfig` and `HttpClientFactory` context lookups.
* Injects explicit `Config?` and `DevFSConfig?` parameters into `DevFS`
and `DevFSFileContent`.
Fork diff:
bkonyi/flutter@master...di/23a-devfs
Part of flutter#188471
pull Bot pushed a commit to fucheng-guo-sun/flutter that referenced this pull request Sep 25, 2026
…tter#192924)

## Description

This pull request migrates `CoverageCollector` in `flutter_tools` to
modular dependency injection using `ToolContext`.

This is Layer 21b in the modular dependency injection migration for the
testing subsystem (stacked on Layer 21a
[flutter#192923](flutter#192923)).

### Fork Compare Link
* Compare:
bkonyi/flutter@master...di/21b-coverage-collector

Part of [flutter#188471](flutter#188471).

## Tests
* `test/general.shard/coverage_collector_test.dart`
bkonyi added a commit to bkonyi/flutter that referenced this pull request Sep 28, 2026
…utterDevice.create (flutter#192830)

## Summary

Part 22a of the modular dependency injection migration.

* Migrates `FlutterDevice` and `FlutterDevice.create` to accept a
required `ToolContext` and destructure its dependencies (`artifacts`,
`config`, `fs`, `logger`, `platform`, `processManager`,
`shutdownHooks`):
  ```dart
  static Future<FlutterDevice> create(
    Device device, {
    required BuildInfo buildInfo,
    required String? target,
    required ToolContext toolContext,
    ResidentCompilerFactory? residentCompilerFactory,
    TargetModel? targetModelOverride,
    String? userIdentifier,
  })
  ```
* Requires non-nullable `ToolContext` on `AttachCommand`,
`DriveCommand`, `FlutterDriverFactory`, `WebDriverService`, and
`Daemon`, eliminating duplicate individual service constructor
parameters (`fileSystem`, `logger`, `platform`, `processInfo`,
`signals`, `stdio`, `terminal`, `outputPreferences`, `processUtils`) and
`toolContext!` null-assertions.
* Updates `FakeFlutterDevice` test doubles in `hot_shared.dart` and
`resident_runner_helpers.dart`, and unit tests across
`attach_test.dart`, `drive_test.dart`, `web_driver_service_test.dart`,
`resident_runner_test.dart`, `cold_test.dart`, and `hot_test.dart`.

Fork diff:
master...di/22a-flutter-device

Part of flutter#188471
DanTup pushed a commit to DanTup/flutter that referenced this pull request Sep 28, 2026
…tter#192924)

## Description

This pull request migrates `CoverageCollector` in `flutter_tools` to
modular dependency injection using `ToolContext`.

This is Layer 21b in the modular dependency injection migration for the
testing subsystem (stacked on Layer 21a
[flutter#192923](flutter#192923)).

### Fork Compare Link
* Compare:
bkonyi/flutter@master...di/21b-coverage-collector

Part of [flutter#188471](flutter#188471).

## Tests
* `test/general.shard/coverage_collector_test.dart`
DanTup pushed a commit to DanTup/flutter that referenced this pull request Sep 28, 2026
…tter#192924)

## Description

This pull request migrates `CoverageCollector` in `flutter_tools` to
modular dependency injection using `ToolContext`.

This is Layer 21b in the modular dependency injection migration for the
testing subsystem (stacked on Layer 21a
[flutter#192923](flutter#192923)).

### Fork Compare Link
* Compare:
bkonyi/flutter@master...di/21b-coverage-collector

Part of [flutter#188471](flutter#188471).

## Tests
* `test/general.shard/coverage_collector_test.dart`
flutter-zl pushed a commit to flutter-zl/flutter that referenced this pull request Sep 29, 2026
…ncy injection (flutter#190783)

## Summary

Part 17 of the modular dependency injection migration.

> [!NOTE]
> Stacked on [flutter#192462](flutter#192462)
(`di/17a-build-bundle-command`), which migrated `BuildBundleCommand` to
modular DI.

* Migrates Web build subcommand and toolchain components to modular
constructor dependency injection:
- `BuildWebCommand({required BuildSystem buildSystem, required
FeatureFlags featureFlags, required ToolContext toolContext, required
super.verboseHelp, BuildTargets buildTargets = const BuildTargetsImpl(),
WebBuilder? webBuilder})`
* Passes `ToolContext` directly to subcommands, eliminating
`context.get` fallbacks in `BuildCommand` and `WebBuilder`.
* Injects `FileSystem` into `defaultDepfilePath` and
`getAssetBuildDirectory`.
* Migrates unit tests in
`test/commands.shard/hermetic/build_web_test.dart` to hermetic
`testWithoutContext`.

Part of flutter#188471
pull Bot pushed a commit to TheRakeshPurohit/flutter that referenced this pull request Sep 30, 2026
…injection (flutter#190789)

## Description

This pull request migrates `TestCommand`, `FlutterTestRunner`,
`FlutterPlatform`, `FlutterWebPlatform`, and `TestGoldenComparator` to
modular dependency injection using `ToolContext`.

This is Layer 21c in the modular dependency injection migration for the
testing subsystem (Layer 21a
[flutter#192923](flutter#192923) and Layer 21b
[flutter#192924](flutter#192924) have merged
into `master`).

### Fork Compare Link
* Compare:
bkonyi/flutter@master...di/21-testing-subsystem

Part of [flutter#188471](flutter#188471).

## Tests
* `test/commands.shard/hermetic/test_test.dart`
* `test/general.shard/flutter_platform_test.dart`
* `test/commands.shard/hermetic/flutter_web_platform_test.dart`
* `test/general.shard/test/test_golden_comparator_test.dart`
* `test/integration.shard/test_golden_comparator_test.dart`
palmoni5 pushed a commit to palmoni5/flutter that referenced this pull request Oct 1, 2026
…193524)

## Summary

Migrates `DeviceManager` (`FlutterDeviceManager`) initialization out of
`context_runner.dart` and into `ToolDependencies.bootstrap` in
`tool_dependencies.dart`, exposing `deviceManager` on
`ToolDependencies`.

* Bootstraps `AndroidWorkflow`, `MacOSWorkflow`, `WindowsWorkflow`, and
`FlutterDeviceManager` in `ToolDependencies.bootstrap`.
* Removes the `DeviceManager` fallback from `context_runner.dart` and
binds `DeviceManager: () => toolDeps.deviceManager` in `runner.dart`
after bootstrapping so unmigrated callers accessing
`globals.deviceManager` resolve the bootstrapped instance.
* Wires `toolDependencies.deviceManager` into `DaemonCommand` and
`DevicesCommand` in `executable.dart`.
* Adds unit test coverage in
`packages/flutter_tools/test/general.shard/context/dependency_injection_test.dart`.

Part of flutter#188471

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant in-code documentation (doc comments with
`///`).
- [x] If this PR introduces a new feature or capability, I created and
linked a website documentation issue or PR in [flutter/website] (or
verified none is needed).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[flutter/website]: https://github.com/flutter/website
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
biggs0125 pushed a commit to biggs0125/flutter that referenced this pull request Oct 1, 2026
…or DI (flutter#193542)

Migrates `DaemonCommand`, `DaemonServer`, `Daemon`, `DaemonDomain`,
`AppDomain`, `DeviceDomain`, `EmulatorDomain`, and `ProxyDomain` to
explicit constructor dependency injection via `ToolContext`,
`AndroidContext`, `Analytics`, `FeatureFlags`, and `DeviceManager`, and
makes `DelegatingToolContext` `const` in `test/src/fakes.dart`.

Note: in `--listen-on-tcp-port` mode, per-connection domain errors now
route through `NotifyingLogger` to connected clients rather than the
server's stderr (`DaemonServer.logger` continues to log general
server-level errors).

Fork diff:
bkonyi/flutter@master...di/22b-1-daemon

Part of flutter#188471

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
frank-weindel pushed a commit to frank-weindel/flutter that referenced this pull request Oct 3, 2026
…iverService to constructor DI (flutter#193543)

Migrates `DriveCommand`, `FlutterDriverFactory`, and `WebDriverService`
to explicit constructor dependency injection via `ToolContext`,
`Analytics`, `BuildSystem`, and `BuildTargets`.

Fork diff:
bkonyi/flutter@master...di/22b-2-drive-and-web-driver

Part of flutter#188471

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
ZhuJHua pushed a commit to ZhuJHua/flutter that referenced this pull request Oct 6, 2026
…un() (flutter#193714)

Restores `await subscription.asFuture<void>();` before `await
subscription.cancel();` in `DaemonServer.run()`, which was inadvertently
removed in flutter#192830. Without
awaiting the subscription future, `flutter daemon --listen-on-tcp-port`
immediately cancels the `ServerSocket` listener and exits right after
binding.

Part of flutter#188471

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD team-android Owned by Android platform team team-ios Owned by iOS 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.

1 participant