[flutter_tools] Call reassemble with DWDS 24.3.7 and update hot reload and restart analytics (#165006)

https://github.com/dart-lang/webdev/issues/2584

Reassemble was being called in DWDS in the injected client until
v24.3.7. Flutter tools should now instead be the one to call the service
extension. Now that it's in Flutter tools, we can also report how long
it took. Similarly, we should update analytics on various things like,
whether there was a reload rejection, how long the compile took, and
more.

Adds test to check that these analytics are being reported correctly.

## 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.
This commit is contained in:
Srujan Gaddam
2025-03-12 08:16:49 -07:00
committed by GitHub
parent eef31a1c2b
commit 0bdb4d68b5
10 changed files with 280 additions and 58 deletions

View File

@@ -260,6 +260,11 @@ class FakeWebDevice extends Fake implements Device {
return true;
}
@override
Future<String> get sdkNameAndVersion async {
return 'Flutter Tools';
}
@override
Future<LaunchResult> startApp(
ApplicationPackage? package, {

View File

@@ -75,6 +75,11 @@ const List<VmServiceExpectation> kAttachExpectations = <VmServiceExpectation>[
...kAttachIsolateExpectations,
];
const List<String> kDdcLibraryBundleFlags = <String>[
'--dartdevc-module-format=ddc',
'--dartdevc-canary',
];
void main() {
late FakeDebugConnection debugConnection;
late FakeChromeDevice chromeDevice;
@@ -725,13 +730,29 @@ name: my_app
flutterDevice,
logger: logger,
systemClock: SystemClock.fixed(DateTime(2001)),
debuggingOptions: DebuggingOptions.enabled(
const BuildInfo(
BuildMode.debug,
null,
trackWidgetCreation: true,
treeShakeIcons: false,
packageConfigPath: '.dart_tool/package_config.json',
// Hot reload only supported with these flags for now.
extraFrontEndOptions: kDdcLibraryBundleFlags,
),
),
);
fakeVmServiceHost = FakeVmServiceHost(
requests: <VmServiceExpectation>[
...kAttachExpectations,
const FakeVmServiceRequest(
method: kHotRestartServiceName,
jsonResponse: <String, Object>{'type': 'Success'},
method: kReloadSourcesServiceName,
args: <String, Object>{'isolateId': ''},
jsonResponse: <String, Object>{'type': 'ReloadReport', 'success': true},
),
const FakeVmServiceRequest(
method: 'ext.flutter.reassemble',
jsonResponse: <String, Object>{'type': 'ReloadReport', 'success': true},
),
const FakeVmServiceRequest(
method: 'streamListen',
@@ -769,7 +790,7 @@ name: my_app
final OperationResult result = await residentWebRunner.restart();
expect(logger.statusText, contains('Restarted application in'));
expect(logger.statusText, contains('Reloaded application in'));
expect(result.code, 0);
expect(webDevFS.mainUri.toString(), contains('entrypoint.dart'));
@@ -777,24 +798,26 @@ name: my_app
fakeAnalytics.sentEvents,
contains(
Event.hotRunnerInfo(
label: 'restart',
label: 'reload',
targetPlatform: 'web-javascript',
sdkName: '',
emulator: false,
fullRestart: true,
fullRestart: false,
overallTimeInMs: 0,
syncedBytes: 0,
invalidatedSourcesCount: 0,
transferTimeInMs: 0,
compileTimeInMs: 0,
findInvalidatedTimeInMs: 0,
scannedSourcesCount: 0,
reassembleTimeInMs: 0,
reloadVMTimeInMs: 0,
),
),
);
expect(
fakeAnalytics.sentEvents,
contains(
Event.timing(
workflow: 'hot',
variableName: 'web-incremental-restart',
elapsedMilliseconds: 0,
),
),
contains(Event.timing(workflow: 'hot', variableName: 'reload', elapsedMilliseconds: 0)),
);
},
overrides: <Type, Generator>{
@@ -807,20 +830,31 @@ name: my_app
);
testUsingContext(
'Can hot restart after attaching',
'Hot reload reject reports correct analytics',
() async {
final BufferLogger logger = BufferLogger.test();
final ResidentRunner residentWebRunner = setUpResidentRunner(
flutterDevice,
logger: logger,
systemClock: SystemClock.fixed(DateTime(2001)),
debuggingOptions: DebuggingOptions.enabled(
const BuildInfo(
BuildMode.debug,
null,
trackWidgetCreation: true,
treeShakeIcons: false,
packageConfigPath: '.dart_tool/package_config.json',
// Hot reload only supported with these flags for now.
extraFrontEndOptions: kDdcLibraryBundleFlags,
),
),
);
fakeVmServiceHost = FakeVmServiceHost(
requests: <VmServiceExpectation>[
...kAttachExpectations,
const FakeVmServiceRequest(
method: kHotRestartServiceName,
jsonResponse: <String, Object>{'type': 'Success'},
method: 'streamListen',
args: <String, Object>{'streamId': 'Isolate'},
),
],
);
@@ -848,39 +882,25 @@ name: my_app
final Completer<DebugConnectionInfo> connectionInfoCompleter =
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run(connectionInfoCompleter: connectionInfoCompleter));
await connectionInfoCompleter.future;
final OperationResult result = await residentWebRunner.restart(fullRestart: true);
final DebugConnectionInfo debugConnectionInfo = await connectionInfoCompleter.future;
// Ensure that generated entrypoint is generated correctly.
expect(webDevFS.mainUri, isNotNull);
final String entrypointContents = fileSystem.file(webDevFS.mainUri).readAsStringSync();
expect(entrypointContents, contains('// Flutter web bootstrap script'));
expect(entrypointContents, contains("import 'dart:ui_web' as ui_web;"));
expect(entrypointContents, contains('await ui_web.bootstrapEngine('));
expect(debugConnectionInfo, isNotNull);
expect(logger.statusText, contains('Restarted application in'));
expect(result.code, 0);
webDevFS.report = UpdateFSReport(hotReloadRejected: true);
final OperationResult result = await residentWebRunner.restart();
expect(result.code, 1);
expect(webDevFS.mainUri.toString(), contains('entrypoint.dart'));
expect(
fakeAnalytics.sentEvents,
contains(
Event.hotRunnerInfo(
label: 'restart',
label: 'reload-reject',
targetPlatform: 'web-javascript',
sdkName: '',
emulator: false,
fullRestart: true,
overallTimeInMs: 0,
),
),
);
expect(
fakeAnalytics.sentEvents,
contains(
Event.timing(
workflow: 'hot',
variableName: 'web-incremental-restart',
elapsedMilliseconds: 0,
fullRestart: false,
),
),
);
@@ -894,6 +914,120 @@ name: my_app
},
);
// Hot restart is available with and without the DDC library bundle format.
// Test one extra config where `fullRestart` is false without the DDC library
// bundle format - we should do a hot restart in this case because hot reload
// is not available.
for (final (List<String> flags, bool fullRestart) in <(List<String>, bool)>[
(kDdcLibraryBundleFlags, true),
(<String>[], true),
(<String>[], false),
]) {
testUsingContext(
'Can hot restart after attaching with flags: $flags fullRestart: $fullRestart',
() async {
final BufferLogger logger = BufferLogger.test();
final ResidentRunner residentWebRunner = setUpResidentRunner(
flutterDevice,
logger: logger,
systemClock: SystemClock.fixed(DateTime(2001)),
debuggingOptions: DebuggingOptions.enabled(
BuildInfo(
BuildMode.debug,
null,
trackWidgetCreation: true,
treeShakeIcons: false,
packageConfigPath: '.dart_tool/package_config.json',
extraFrontEndOptions: flags,
),
),
);
fakeVmServiceHost = FakeVmServiceHost(
requests: <VmServiceExpectation>[
...kAttachExpectations,
const FakeVmServiceRequest(
method: kHotRestartServiceName,
jsonResponse: <String, Object>{'type': 'Success'},
),
],
);
setupMocks();
final TestChromiumLauncher chromiumLauncher = TestChromiumLauncher();
final FakeProcess process = FakeProcess();
final Chromium chrome = Chromium(
1,
chromeConnection,
chromiumLauncher: chromiumLauncher,
process: process,
logger: logger,
);
chromiumLauncher.setInstance(chrome);
flutterDevice.device = GoogleChromeDevice(
fileSystem: fileSystem,
chromiumLauncher: chromiumLauncher,
logger: BufferLogger.test(),
platform: FakePlatform(),
processManager: FakeProcessManager.any(),
);
webDevFS.report = UpdateFSReport(success: true);
final Completer<DebugConnectionInfo> connectionInfoCompleter =
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run(connectionInfoCompleter: connectionInfoCompleter));
await connectionInfoCompleter.future;
final OperationResult result = await residentWebRunner.restart(fullRestart: fullRestart);
// Ensure that generated entrypoint is generated correctly.
expect(webDevFS.mainUri, isNotNull);
final String entrypointContents = fileSystem.file(webDevFS.mainUri).readAsStringSync();
expect(entrypointContents, contains('// Flutter web bootstrap script'));
expect(entrypointContents, contains("import 'dart:ui_web' as ui_web;"));
expect(entrypointContents, contains('await ui_web.bootstrapEngine('));
expect(logger.statusText, contains('Restarted application in'));
expect(result.code, 0);
expect(
fakeAnalytics.sentEvents,
contains(
Event.hotRunnerInfo(
label: 'restart',
targetPlatform: 'web-javascript',
sdkName: '',
emulator: false,
fullRestart: true,
overallTimeInMs: 0,
syncedBytes: 0,
invalidatedSourcesCount: 0,
transferTimeInMs: 0,
compileTimeInMs: 0,
findInvalidatedTimeInMs: 0,
scannedSourcesCount: 0,
),
),
);
expect(
fakeAnalytics.sentEvents,
contains(
Event.timing(
workflow: 'hot',
variableName: 'web-incremental-restart',
elapsedMilliseconds: 0,
),
),
);
},
overrides: <Type, Generator>{
Analytics: () => fakeAnalytics,
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
FeatureFlags: enableExplicitPackageDependencies,
Pub: FakePubWithPrimedDeps.new,
},
);
}
testUsingContext(
'Can hot restart after attaching with web-server device',
() async {
@@ -1130,7 +1264,8 @@ name: my_app
trackWidgetCreation: true,
treeShakeIcons: false,
packageConfigPath: '.dart_tool/package_config.json',
extraFrontEndOptions: <String>['--dartdevc-module-format=ddc', '--dartdevc-canary'],
// Hot reload only supported with these flags for now.
extraFrontEndOptions: kDdcLibraryBundleFlags,
),
),
);