Skip to content

[tool] Migrate DaemonCommand and DebugAdapterCommand to modular dependency injection - #190793

Merged
auto-submit[bot] merged 18 commits into
flutter:masterfrom
bkonyi:di/24-daemon-and-dap
Sep 9, 2026
Merged

auto-submit[bot] merged 18 commits into
flutter:masterfrom
bkonyi:di/24-daemon-and-dap

Conversation

@bkonyi

@bkonyi bkonyi commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part 24 of the modular dependency injection migration.

  • Migrates DaemonCommand and DebugAdapterCommand (DAP) to modular constructor dependency injection:
    • DaemonCommand({required super.toolContext, required AndroidContext androidContext, AndroidWorkflow? androidWorkflow, DeviceManager? deviceManager, this.hidden = false})
    • DebugAdapterCommand({required super.toolContext, bool verboseHelp = false})
  • Injects AndroidContext into DaemonCommand instead of individual platform dependencies.
  • Wires DAP adapters to use injected context objects; ensures DAP vmServiceInfoFile tests execute against real disk via LocalFileSystem for file watching support.
  • Migrates unit tests in test/commands.shard/hermetic/daemon_test.dart and debug_adapter_test.dart to hermetic testWithoutContext.

Part of #188471

@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. a: desktop Running on desktop team-android Owned by Android platform team team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-windows Owned by the Windows platform team team-linux Owned by the Linux platform team labels Aug 8, 2026
@bkonyi
bkonyi force-pushed the di/24-daemon-and-dap branch 8 times, most recently from 117122d to fae00c4 Compare August 12, 2026 18:40
@bkonyi
bkonyi force-pushed the di/24-daemon-and-dap branch from fae00c4 to a87a721 Compare September 2, 2026 13:25
@bkonyi
bkonyi marked this pull request as ready for review September 2, 2026 13:25
@bkonyi bkonyi added the CICD Run CI/CD label Sep 2, 2026
@github-actions github-actions Bot removed a: desktop Running on desktop team-android Owned by Android platform team team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-windows Owned by the Windows platform team team-linux Owned by the Linux platform team labels Sep 2, 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 refactors DaemonCommand, DebugAdapterCommand, and related domain classes to explicitly inject dependencies via ToolContext and constructor parameters, reducing reliance on global variables. The review feedback suggests replacing LocalFileSystem with MemoryFileSystem in flutter_adapter_test.dart to ensure the tests remain hermetic and do not leak resources.

Comment thread packages/flutter_tools/test/general.shard/dap/flutter_adapter_test.dart Outdated
@bkonyi

bkonyi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@bkonyi

bkonyi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 refactors DaemonCommand and DebugAdapterCommand to inject dependencies via ToolContext and constructors rather than relying on global variables. The review identified a compilation error in executable.dart due to an incorrect import, missing critical dependencies in Daemon.createMachineDaemon within run.dart, and formatting violations in daemon_test.dart where lines exceed standard length limits.

Comment thread packages/flutter_tools/lib/executable.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/run.dart
Comment thread packages/flutter_tools/test/commands.shard/hermetic/daemon_test.dart Outdated
Comment thread packages/flutter_tools/test/commands.shard/hermetic/daemon_test.dart Outdated
@bkonyi

bkonyi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 refactors the DaemonCommand, Daemon, and DebugAdapterCommand classes to remove direct references to global variables and instead inject dependencies such as FileSystem, Logger, Platform, ProcessManager, AnsiTerminal, Stdio, and FeatureFlags via constructors and ToolContext. Related commands, adapters, and unit tests are updated to support this dependency injection, and a new test file is added for DebugAdapterCommand. I have no feedback to provide.

@bkonyi

bkonyi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 refactors the daemon and debug adapter commands, servers, and domains to use dependency injection instead of relying on the global globals object. Dependencies such as FileSystem, Logger, Platform, ProcessManager, Stdio, and FeatureFlags are now explicitly passed through constructors. Corresponding tests have been updated to supply these dependencies, and a new test file has been added to verify DebugAdapterCommand properties and behavior. There are no review comments, so I have no feedback to provide.

@bkonyi

bkonyi commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 refactors DaemonCommand, DebugAdapterCommand, Daemon, and its associated domains to use explicit dependency injection instead of relying on global variables, updating the corresponding tests to pass these dependencies. Feedback on these changes suggests making fileSystem a required parameter in the Daemon constructor to prevent non-hermetic fallbacks and broken shutdown hooks, and wrapping the temporary directory cleanup in tests with try-catch blocks to avoid flaky failures on Windows.

Comment on lines +283 to +299
FileSystem? fileSystem,
FileTransfer fileTransfer = const FileTransfer(),
}) {
Java? java,
this.logToStdout = false,
Logger? logger,
this.notifyingLogger,
OutputPreferences? outputPreferences,
Platform? platform,
ProcessManager? processManager,
Stdio? stdio,
SystemClock? systemClock,
AnsiTerminal? terminal,
}) : _stdio = stdio,
_logger = logger ?? BufferLogger.test(),
_fs =
fileSystem ??
LocalFileSystem(LocalSignals.instance, Signals.defaultExitSignals, ShutdownHooks()) {

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

Simplify and Refactor Dependency Injection

Defaulting to LocalFileSystem in the Daemon constructor introduces two issues:

  1. Non-hermetic fallback: It can cause tests to accidentally touch the real disk if they omit the fileSystem parameter.
  2. Broken Shutdown Hooks: Instantiating ShutdownHooks() directly via ShutdownHooks() creates a new instance that is not registered with the main process exit signals. Consequently, any cleanup hooks registered by LocalFileSystem (such as deleting temporary directories) will never be executed, leading to resource leaks.

Since all production and test instantiations of Daemon in this PR have already been updated to pass a FileSystem, we can make fileSystem a required parameter. This simplifies the constructor, removes the fragile fallback, and ensures hermeticity.

    required FileSystem fileSystem,
    FileTransfer fileTransfer = const FileTransfer(),
    Java? java,
    this.logToStdout = false,
    Logger? logger,
    this.notifyingLogger,
    OutputPreferences? outputPreferences,
    Platform? platform,
    ProcessManager? processManager,
    Stdio? stdio,
    SystemClock? systemClock,
    AnsiTerminal? terminal,
  }) : _stdio = stdio,
       _logger = logger ?? BufferLogger.test(),
       _fs = fileSystem {
References
  1. Suggest simplification and refactoring to enhance readability and maintainability. (link)

final Directory tempDir = fs.systemTempDirectory.createTempSync(
'dap_flutter_attach_vmServiceInfoFile',
);
addTearDown(() => tempDir.deleteSync(recursive: true));

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

On Windows, tempDir.deleteSync(recursive: true) can fail with a FileSystemException (such as Access Denied or Sharing Violation) if the file watcher or any other process still holds an active handle on the directory or its contents.

To prevent flaky test failures, wrap the deletion in a try-catch block to silently ignore transient deletion failures during teardown.

Suggested change
addTearDown(() => tempDir.deleteSync(recursive: true));
addTearDown(() {
try {
tempDir.deleteSync(recursive: true);
} catch (_) {
// Ignore transient deletion failures on Windows.
}
});

final Directory tempDir = fs.systemTempDirectory.createTempSync(
'dap_flutter_attach_vmServiceInfoFile',
);
addTearDown(() => tempDir.deleteSync(recursive: true));

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

On Windows, tempDir.deleteSync(recursive: true) can fail with a FileSystemException (such as Access Denied or Sharing Violation) if the file watcher or any other process still holds an active handle on the directory or its contents.

To prevent flaky test failures, wrap the deletion in a try-catch block to silently ignore transient deletion failures during teardown.

Suggested change
addTearDown(() => tempDir.deleteSync(recursive: true));
addTearDown(() {
try {
tempDir.deleteSync(recursive: true);
} catch (_) {
// Ignore transient deletion failures on Windows.
}
});

@bkonyi
bkonyi requested a review from chingjun September 8, 2026 23:45
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 9, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Sep 9, 2026
Merged via the queue into flutter:master with commit 4f4467b Sep 9, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 9, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Sep 9, 2026
flutter/flutter@b444e78...63b9518

2026-09-09 [email protected] Roll Packages from 9af9c60 to 36e088a (24 revisions) (flutter/flutter#192485)
2026-09-09 [email protected] Re-add Xcode and OpenJDK dependencies to macOS wasm local_engine builders (flutter/flutter#192238)
2026-09-09 [email protected] Roll Dart SDK from 77094991d1c1 to 4be1b711b4ba (5 revisions) (flutter/flutter#192453)
2026-09-09 [email protected] [material] Use super parameters in more places (flutter/flutter#192149)
2026-09-09 [email protected] [cupertino] Use super parameters in more places (flutter/flutter#192148)
2026-09-09 [email protected] [flutter_tools] Gracefully handle EROFS and write-protected file system errors (flutter/flutter#192431)
2026-09-09 [email protected] [tool] Migrate BuildIOSCommand and BuildIOSArchiveCommand to modular dependency injection (flutter/flutter#192250)
2026-09-09 [email protected] Replace more enum instances comparison to use `equality ==` instead of `identical` and update related tests (flutter/flutter#192229)
2026-09-09 [email protected] [web] Support local screenshot and golden testing in felt test (flutter/flutter#191318)
2026-09-09 [email protected] [tool] Migrate DaemonCommand and DebugAdapterCommand to modular dependency injection (flutter/flutter#190793)
2026-09-09 [email protected] [web] Support local golden testing in flutter test (flutter/flutter#191386)
2026-09-09 [email protected] [flutter_tools] Ignore widget previews outside lib/ during LSP code generation (flutter/flutter#192326)
2026-09-09 [email protected] [flutter_tools] Read package_config.json asynchronously in loadPackageConfigWithLogging (flutter/flutter#192443)
2026-09-08 [email protected] Add precacheTestImage to flutter_test and unskip web image tests (flutter/flutter#191435)
2026-09-08 [email protected] et: Fix compile_commands.json post-processing (flutter/flutter#192395)
2026-09-08 [email protected] Refactor createDebuggingOptions and option registrations to OptionDescriptor (flutter/flutter#192307)
2026-09-08 [email protected] [flutter_tools] Fix test separation between `VersionFreshnessValidator` and `FlutterVersion.checkFlutterVersionFreshness` (flutter/flutter#191593)
2026-09-08 [email protected] [tool] Migrate EmulatorsCommand to modular dependency injection (flutter/flutter#190769)
2026-09-08 [email protected] [tool] Migrate Desktop build subcommands and toolchain to modular dependency injection (flutter/flutter#190781)
2026-09-08 [email protected] [tool] Migrate Tooling and Analysis commands to modular dependency injection (flutter/flutter#190788)
2026-09-08 [email protected] Skip KGP version validation for AGP built-in Kotlin (flutter/flutter#192206)

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
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
…r#12814)

flutter/flutter@b444e78...63b9518

2026-09-09 [email protected] Roll Packages from 9af9c60 to 36e088a (24 revisions) (flutter/flutter#192485)
2026-09-09 [email protected] Re-add Xcode and OpenJDK dependencies to macOS wasm local_engine builders (flutter/flutter#192238)
2026-09-09 [email protected] Roll Dart SDK from 77094991d1c1 to 4be1b711b4ba (5 revisions) (flutter/flutter#192453)
2026-09-09 [email protected] [material] Use super parameters in more places (flutter/flutter#192149)
2026-09-09 [email protected] [cupertino] Use super parameters in more places (flutter/flutter#192148)
2026-09-09 [email protected] [flutter_tools] Gracefully handle EROFS and write-protected file system errors (flutter/flutter#192431)
2026-09-09 [email protected] [tool] Migrate BuildIOSCommand and BuildIOSArchiveCommand to modular dependency injection (flutter/flutter#192250)
2026-09-09 [email protected] Replace more enum instances comparison to use `equality ==` instead of `identical` and update related tests (flutter/flutter#192229)
2026-09-09 [email protected] [web] Support local screenshot and golden testing in felt test (flutter/flutter#191318)
2026-09-09 [email protected] [tool] Migrate DaemonCommand and DebugAdapterCommand to modular dependency injection (flutter/flutter#190793)
2026-09-09 [email protected] [web] Support local golden testing in flutter test (flutter/flutter#191386)
2026-09-09 [email protected] [flutter_tools] Ignore widget previews outside lib/ during LSP code generation (flutter/flutter#192326)
2026-09-09 [email protected] [flutter_tools] Read package_config.json asynchronously in loadPackageConfigWithLogging (flutter/flutter#192443)
2026-09-08 [email protected] Add precacheTestImage to flutter_test and unskip web image tests (flutter/flutter#191435)
2026-09-08 [email protected] et: Fix compile_commands.json post-processing (flutter/flutter#192395)
2026-09-08 [email protected] Refactor createDebuggingOptions and option registrations to OptionDescriptor (flutter/flutter#192307)
2026-09-08 [email protected] [flutter_tools] Fix test separation between `VersionFreshnessValidator` and `FlutterVersion.checkFlutterVersionFreshness` (flutter/flutter#191593)
2026-09-08 [email protected] [tool] Migrate EmulatorsCommand to modular dependency injection (flutter/flutter#190769)
2026-09-08 [email protected] [tool] Migrate Desktop build subcommands and toolchain to modular dependency injection (flutter/flutter#190781)
2026-09-08 [email protected] [tool] Migrate Tooling and Analysis commands to modular dependency injection (flutter/flutter#190788)
2026-09-08 [email protected] Skip KGP version validation for AGP built-in Kotlin (flutter/flutter#192206)

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
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
…r#12814)

flutter/flutter@b444e78...63b9518

2026-09-09 [email protected] Roll Packages from 9af9c60 to 36e088a (24 revisions) (flutter/flutter#192485)
2026-09-09 [email protected] Re-add Xcode and OpenJDK dependencies to macOS wasm local_engine builders (flutter/flutter#192238)
2026-09-09 [email protected] Roll Dart SDK from 77094991d1c1 to 4be1b711b4ba (5 revisions) (flutter/flutter#192453)
2026-09-09 [email protected] [material] Use super parameters in more places (flutter/flutter#192149)
2026-09-09 [email protected] [cupertino] Use super parameters in more places (flutter/flutter#192148)
2026-09-09 [email protected] [flutter_tools] Gracefully handle EROFS and write-protected file system errors (flutter/flutter#192431)
2026-09-09 [email protected] [tool] Migrate BuildIOSCommand and BuildIOSArchiveCommand to modular dependency injection (flutter/flutter#192250)
2026-09-09 [email protected] Replace more enum instances comparison to use `equality ==` instead of `identical` and update related tests (flutter/flutter#192229)
2026-09-09 [email protected] [web] Support local screenshot and golden testing in felt test (flutter/flutter#191318)
2026-09-09 [email protected] [tool] Migrate DaemonCommand and DebugAdapterCommand to modular dependency injection (flutter/flutter#190793)
2026-09-09 [email protected] [web] Support local golden testing in flutter test (flutter/flutter#191386)
2026-09-09 [email protected] [flutter_tools] Ignore widget previews outside lib/ during LSP code generation (flutter/flutter#192326)
2026-09-09 [email protected] [flutter_tools] Read package_config.json asynchronously in loadPackageConfigWithLogging (flutter/flutter#192443)
2026-09-08 [email protected] Add precacheTestImage to flutter_test and unskip web image tests (flutter/flutter#191435)
2026-09-08 [email protected] et: Fix compile_commands.json post-processing (flutter/flutter#192395)
2026-09-08 [email protected] Refactor createDebuggingOptions and option registrations to OptionDescriptor (flutter/flutter#192307)
2026-09-08 [email protected] [flutter_tools] Fix test separation between `VersionFreshnessValidator` and `FlutterVersion.checkFlutterVersionFreshness` (flutter/flutter#191593)
2026-09-08 [email protected] [tool] Migrate EmulatorsCommand to modular dependency injection (flutter/flutter#190769)
2026-09-08 [email protected] [tool] Migrate Desktop build subcommands and toolchain to modular dependency injection (flutter/flutter#190781)
2026-09-08 [email protected] [tool] Migrate Tooling and Analysis commands to modular dependency injection (flutter/flutter#190788)
2026-09-08 [email protected] Skip KGP version validation for AGP built-in Kotlin (flutter/flutter#192206)

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

CICD Run CI/CD 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