devtools icon indicating copy to clipboard operation
devtools copied to clipboard

DevTools extensions don't load for a test ran with `flutter test` or `dart test`

Open kenzieschmoll opened this issue 1 year ago • 7 comments

  • When running flutter test test/app_that_uses_foo_test.dart --start-paused , the package:foo DevTools extension does not load
  • When running flutter run test/app_that_uses_foo_test.dart --start-paused -d flutter-tester, the package:foo DevTools extension does load.

In the flutter test case, rootLibraryForMainIsolate is returning file:///var/folders/gf/14ctmb656m3100h5z857669800fv4z/T/flutter_tools.9i1YVt/flutter_test_listener.ASUv35/listener.dart, whereas in the flutter run case it returns the expected path to the test file.

Since we have DevTools extensions intended for test files (e.g. Patrol), we should fix this and cherry pick to stable.

CC @bkonyi @DanTup for any ideas you have on how we can get the proper root lib or isolate for the flutter test case.

kenzieschmoll avatar Feb 08 '24 00:02 kenzieschmoll

What is odd is that the Flutter sidebar DevTools menu properly detects the foo extension even though DevTools itself cannot: Screenshot 2024-02-07 at 4 20 01 PM

We get the app root directly from VS code in the sidebar case: https://github.com/flutter/devtools/blob/master/packages/devtools_app/lib/src/standalone_ui/vs_code/debug_sessions.dart/#L166

Whereas in DevTools itself, we try to get the URI from the isolate: https://github.com/flutter/devtools/blob/master/packages/devtools_app/lib/src/extensions/extension_service.dart#L185

@DanTup how are you passing the proper URI for the debug session, and is this something we can get on the DevTools side too from the VM service?

kenzieschmoll avatar Feb 08 '24 00:02 kenzieschmoll

@DanTup how are you passing the proper URI for the debug session, and is this something we can get on the DevTools side too from the VM service?

VS Code knows where the root of the project is because when we start a debugging session we need to work out where the project root is to know if it's a Dart/Flutter project. So against the debug session information, we keep track of this (and we include it when we tell the sidebar a debug session started).

I guess we could pass this info along to DevTools somehow, but I'm not sure what the best way would be (because it's tied to a specific debug session). We could perhaps provide the running debug sessions to DTD and include this, or we could perhaps include it when we tell the DevTools server about the VM Services:

https://github.com/Dart-Code/Dart-Code/blob/95dfe4e8ca027ec9ce19565ed3d59009d0654ffb/src/extension/sdk/dev_tools/manager.ts#L463

(We currently call vm.register for each debug session.. I think it's currently only used to let DevTools server register the launchDevTools service to allow us to launch DevTools in Chrome without doing the Chrome search in Dart-Code)

DanTup avatar Feb 08 '24 10:02 DanTup

We could also perhaps include it on the querystring if we're launching DevTools I think?

DanTup avatar Feb 08 '24 10:02 DanTup

The one problem with having the IDEs pass in a value somehow is that this also needs to work in the command line case where a user is running a test with dart test or flutter test.

kenzieschmoll avatar Feb 08 '24 17:02 kenzieschmoll

The right thing is probably to have both dart test and flutter test explicitly mark the main isolate as a system isolate so that DevTools will ignore it by default.

bkonyi avatar Feb 08 '24 18:02 bkonyi

The right thing is probably to have both dart test and flutter test explicitly mark the main isolate as a system isolate so that DevTools will ignore it by default.

When I printed out all the isolates DevTools was aware of, there was only one available.

kenzieschmoll avatar Feb 08 '24 18:02 kenzieschmoll

The right thing is probably to have both dart test and flutter test explicitly mark the main isolate as a system isolate so that DevTools will ignore it by default.

When I printed out all the isolates DevTools was aware of, there was only one available.

Which one? The listener.dart isolate? Was it paused at start? If it was marked as a system isolate it wouldn't pause at start and the isolate it spawns would, which is probably the behavior we would want anyway.

bkonyi avatar Feb 08 '24 18:02 bkonyi