Repository: flutter
Issue: `--experimental-faster-testing` doesn't sanitize paths
Labels: a: tests,tool,has reproducible steps,P3,team-tool,triaged-tool,found in release: 3.27,found in release: 3.28

### Steps to reproduce

1. Create a Flutter project *with some tests*
2. Place it on a path that uses hyphens (for example, in a Git repository with a hyphenated name)
3. Run `flutter test --experimental-faster-testing`

### Expected results

Tests compile and run correctly.

### Actual results

Files generated with the `--experimental-faster-testing` flag include invalid library names – those are based on the test files' paths. Paths can include characters that are invalid identifier characters, like hyphens.

### Code sample

Example project for reference: https://github.com/PiotrRogulski/experimental-testing-app


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

(None)

</details>


### Logs

<details open><summary>Logs</summary>

```console

$ flutter test --experimental-faster-testing --verbose
[   +2 ms] Could not interpret results of "git describe": 3.28.0-2.0.pre.38596
[  +14 ms] executing: sysctl hw.optional.arm64
[   +3 ms] Exit code 0 from: sysctl hw.optional.arm64
[        ] hw.optional.arm64: 1
[  +26 ms] executing: sw_vers -productName
[  +10 ms] Exit code 0 from: sw_vers -productName
[        ] macOS
[        ] executing: sw_vers -productVersion
[  +10 ms] Exit code 0 from: sw_vers -productVersion
[        ] 15.3
[        ] executing: sw_vers -buildVersion
[  +10 ms] Exit code 0 from: sw_vers -buildVersion
[        ] 24D5034f
[        ] executing: uname -m
[   +3 ms] Exit code 0 from: uname -m
[        ] arm64
[  +15 ms] Found 2 files which will be executed as Widget Tests.
[   +2 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'LegacyCanvasKitRemover' is not required, skipping update.
[   +1 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +20 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'LegacyCanvasKitRemover' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[  +32 ms] Skipping pub get: version match.
[  +84 ms] No packages with native assets. Skipping native assets compilation.
[        ] Writing native assets json to file:///Users/piotrrogulski/repos/experimental-testing-app/build/native_assets/macos/native_assets.json.
[   +1 ms] Writing /Users/piotrrogulski/repos/experimental-testing-app/build/native_assets/macos/native_assets.json done.
[  +66 ms] Stopping scan for flutter_test_config.dart; found project root at /Users/piotrrogulski/repos/experimental-testing-app
[        ] Stopping scan for flutter_test_config.dart; found project root at /Users/piotrrogulski/repos/experimental-testing-app
[        ] Compiling file:///Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/child_test_isolate_spawner.dart
[   +3 ms] /Users/piotrrogulski/fvm/versions/master/bin/cache/dart-sdk/bin/dartaotruntime /Users/piotrrogulski/fvm/versions/master/bin/cache/dart-sdk/bin/snapshots/frontend_server_aot.dart.snapshot --sdk-root /Users/piotrrogulski/fvm/versions/master/bin/cache/artifacts/engine/common/flutter_patched_sdk/ --incremental --no-print-incremental-dependencies --target=flutter --experimental-emit-debug-metadata --output-dill /Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/child_test_isolate_spawner.dill --packages /Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/.dart_tool/package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --verbosity=error
[   +7 ms] <- compile file:///Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/child_test_isolate_spawner.dart
[ +621 ms] build/isolate_spawning_tester/child_test_isolate_spawner.dart:10:84: Error: Expected ';' after this.
[   +1 ms] import '/Users/piotrrogulski/repos/experimental-testing-app/test/two_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_two_test;
[        ]                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:10:123: Error: Expected a declaration, but got '-'.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/two_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_two_test;
[        ]                                                                                           ^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:10:124: Error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
[        ] Try adding the name of the type of the variable or the keyword 'var'.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/two_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_two_test;
[        ]                                                                                           ^^^^^^^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:10:124: Error: Expected ';' after this.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/two_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_two_test;
[        ]                                                                                           ^^^^^^^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:10:131: Error: Expected a declaration, but got '-'.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/two_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_two_test;
[        ]                                                                                           ^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:10:132: Error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
[        ] Try adding the name of the type of the variable or the keyword 'var'.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/two_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_two_test;
[        ]                                                                                           ^^^^^^^^^^^^^^^^^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:11:1: Error: Directives must appear before any declarations.
[        ] Try moving the directive before any declarations.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/one_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_one_test;
[        ] ^^^^^^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:11:84: Error: Expected ';' after this.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/one_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_one_test;
[        ]                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:11:123: Error: Expected a declaration, but got '-'.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/one_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_one_test;
[        ]                                                                                           ^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:11:124: Error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
[        ] Try adding the name of the type of the variable or the keyword 'var'.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/one_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_one_test;
[        ]                                                                                           ^^^^^^^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:11:124: Error: Expected ';' after this.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/one_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_one_test;
[        ]                                                                                           ^^^^^^^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:11:131: Error: Expected a declaration, but got '-'.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/one_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_one_test;
[        ]                                                                                           ^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:11:132: Error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
[        ] Try adding the name of the type of the variable or the keyword 'var'.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/one_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_one_test;
[        ]                                                                                           ^^^^^^^^^^^^^^^^^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:11:124: Error: 'testing' is already declared in this scope.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/one_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_one_test;
[        ]                                                                                           ^^^^^^^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:10:124: Context: Previous declaration of 'testing'.
[        ] import '/Users/piotrrogulski/repos/experimental-testing-app/test/two_test.dart' as _Users_piotrrogulski_repos_experimental-testing-app_test_two_test;
[        ]                                                                                           ^^^^^^^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:50:152: Error: Can't use 'testing' because it is declared more than once.
[        ]       createChannelAndConnect('/Users/piotrrogulski/repos/experimental-testing-app/test/two_test.dart', route, _Users_piotrrogulski_repos_experimental-testing-app_test_two_test.main);
[        ]                                                                                           ^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:50:112: Error: A prefix can't be used as an expression.
[        ]       createChannelAndConnect('/Users/piotrrogulski/repos/experimental-testing-app/test/two_test.dart', route, _Users_piotrrogulski_repos_experimental-testing-app_test_two_test.main);
[        ]                                                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:52:152: Error: Can't use 'testing' because it is declared more than once.
[        ]       createChannelAndConnect('/Users/piotrrogulski/repos/experimental-testing-app/test/one_test.dart', route, _Users_piotrrogulski_repos_experimental-testing-app_test_one_test.main);
[        ]                                                                                           ^
[        ] build/isolate_spawning_tester/child_test_isolate_spawner.dart:52:112: Error: A prefix can't be used as an expression.
[        ]       createChannelAndConnect('/Users/piotrrogulski/repos/experimental-testing-app/test/one_test.dart', route, _Users_piotrrogulski_repos_experimental-testing-app_test_one_test.main);
[        ]                                                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[  +27 ms] <- accept
[        ] Compiling file:///Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/child_test_isolate_spawner.dart took 663ms
[        ] Compiling file:///Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/root_test_isolate_spawner.dart
[        ] /Users/piotrrogulski/fvm/versions/master/bin/cache/dart-sdk/bin/dartaotruntime /Users/piotrrogulski/fvm/versions/master/bin/cache/dart-sdk/bin/snapshots/frontend_server_aot.dart.snapshot --sdk-root /Users/piotrrogulski/fvm/versions/master/bin/cache/artifacts/engine/common/flutter_patched_sdk/ --incremental --no-print-incremental-dependencies --target=flutter --experimental-emit-debug-metadata --output-dill /Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/root_test_isolate_spawner.dill --packages /Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/.dart_tool/package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --verbosity=error
[   +5 ms] <- compile file:///Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/root_test_isolate_spawner.dart
[ +466 ms] <- accept
[        ] Compiling file:///Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/root_test_isolate_spawner.dart took 473ms
[   +1 ms] Using this directory for fonts configuration: /var/folders/cx/x_9fdh5j2mb0_wnjtg4d7pz40000gn/T/flutter_tools.ga59ss/flutter_test_fonts.WIaLuH
[        ] Starting flutter_tester process with command=[/Users/piotrrogulski/fvm/versions/master/bin/cache/artifacts/engine/darwin-x64/flutter_tester, --disable-vm-service, --enable-checked-mode, --verify-entry-points, --enable-software-rendering, --skia-deterministic-rendering, --enable-dart-profiling, --non-interactive, --use-test-fonts, --disable-asset-fonts, --packages=/Users/piotrrogulski/repos/experimental-testing-app/.dart_tool/package_config.json, --flutter-assets-dir=/Users/piotrrogulski/repos/experimental-testing-app/build/unit_test_assets, /Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/root_test_isolate_spawner.dill], environment={FLUTTER_TEST: true, FONTCONFIG_FILE: /var/folders/cx/x_9fdh5j2mb0_wnjtg4d7pz40000gn/T/flutter_tools.ga59ss/flutter_test_fonts.WIaLuH/fonts.conf, APP_NAME: experimental_testing_app, UNIT_TEST_ASSETS: /Users/piotrrogulski/repos/experimental-testing-app/build/unit_test_assets}
[   +6 ms] Started flutter_tester process at pid 3606

00:00 +0: loading /Users/piotrrogulski/repos/experimental-testing-app/test/two_test.dart                                                                                                               [ERROR:flutter/shell/testing/tester_main.cc(674)] Unhandled exception
Exception: 'file:///Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/child_test_isolate_spawner.dart': error: build/isolate_spawning_tester/child_test_isolate_spawner.dart:50:112: Error: A prefix can't be used as an expression.
      createChannelAndConnect('/Users/piotrrogulski/repos/experimental-testing-app/test/two_test.dart', route, _Users_piotrrogulski_repos_experimental-testing-app_test_two_test.main);
                                                                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Stack trace: #0      main (file:///Users/piotrrogulski/repos/experimental-testing-app/build/isolate_spawning_tester/root_test_isolate_spawner.dart:85:55)
#1      _runMain.<anonymous closure> (dart:ui/hooks.dart:305:23)
#2      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:315:19)
#3      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:194:12)

[ +468 ms] flutter_tester process at pid 3606 exited with code=1
[        ] Runtime for phase TestRunner: Wall-clock: 0:00:01.625387; combined: 0:00:01.625407.
[        ] Runtime for phase Compile: Wall-clock: 0:00:01.136856; combined: 0:00:01.136894.
[        ] Runtime for phase Run: Wall-clock: 0:00:00.474527; combined: 0:00:00.474532.
[        ] Runtime for phase CoverageTotal: Wall-clock: 0:00:00.000000; combined: 0:00:00.000000.
[        ] Runtime for phase CoverageCollect: Wall-clock: 0:00:00.000000; combined: 0:00:00.000000.
[        ] Runtime for phase CoverageParseJson: Wall-clock: 0:00:00.000000; combined: 0:00:00.000000.
[        ] Runtime for phase CoverageAddHitmap: Wall-clock: 0:00:00.000000; combined: 0:00:00.000000.
[        ] Runtime for phase CoverageDataCollect: Wall-clock: 0:00:00.000000; combined: 0:00:00.000000.
[        ] Runtime for phase WatcherFinishedTest: Wall-clock: 0:00:00.000000; combined: 0:00:00.000000.
[   +4 ms] "flutter test" took 1,884ms.
[   +2 ms] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:34:3)
           #1      TestCommand.runCommand (package:flutter_tools/src/commands/test.dart:715:7)
           <asynchronous suspension>
           #2      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1558:27)
           <asynchronous suspension>
           #3      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:154:19)
           <asynchronous suspension>
           #4      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
           <asynchronous suspension>
           #5      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:496:9)
           <asynchronous suspension>
           #6      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:154:19)
           <asynchronous suspension>
           #7      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:431:5)
           <asynchronous suspension>
           #8      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:98:11)
           <asynchronous suspension>
           #9      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:154:19)
           <asynchronous suspension>
           #10     main (package:flutter_tools/executable.dart:99:3)
           <asynchronous suspension>


[        ] Running 2 shutdown hooks
[   +1 ms] Shutdown hooks complete
[        ] exiting with code 1


```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel master, 3.28.0-2.0.pre.38596, on macOS 15.3 24D5034f darwin-arm64, locale en-US)
    • Flutter version 3.28.0-2.0.pre.38596 on channel master at /Users/piotrrogulski/fvm/versions/master
    • Upstream repository git@github.com:flutter/flutter.git
    • Framework revision dbf9e32879 (7 hours ago), 2025-01-02 18:23:10 -0800
    • Engine revision dbf9e32879
    • Dart version 3.7.0 (build 3.7.0-267.0.dev)
    • DevTools version 2.41.0

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/piotrrogulski/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /Users/piotrrogulski/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode-16.2.0.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2.2)
    • Android Studio at /Users/piotrrogulski/Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)

[✓] VS Code (version 1.95.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.56.0

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 15.3 24D5034f darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 15.3 24D5034f darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 131.0.6778.205

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>