buildFlutterTestArgs function

List<String> buildFlutterTestArgs(
  1. List<String> arguments, {
  2. required String suiteEncryptionKey,
  3. required String? reportMode,
  4. required String? reportFile,
  5. required int? timeoutSeconds,
  6. required bool verbose,
  7. List<String> shardPaths = const [],
  8. List<String> shardIds = const [],
  9. int? workerIndex,
  10. String? progressFile,
  11. String? appLogPath,
  12. String? appLogDisplayPath,
  13. String? artifactRoot,
  14. Map<String, dynamic>? serviceOverrides,
  15. String artifactDisplayRoot = 'build/ensemble_test_runner',
  16. String testEntryRelativePath = TestAppPatcher.testEntryRelativePath,
  17. FlutterDevice? physicalDevice,
  18. bool hostOwnsServices = false,
  19. String? testsAssetPrefix,
  20. bool useRuntimeWorkerConfig = false,
})

Builds the complete, deterministic command line passed to flutter test.

Keeping command construction separate from process orchestration makes the worker boundary explicit and lets callers validate it without launching a Flutter process.

Implementation

List<String> buildFlutterTestArgs(
  List<String> arguments, {
  required String suiteEncryptionKey,
  required String? reportMode,
  required String? reportFile,
  required int? timeoutSeconds,
  required bool verbose,
  List<String> shardPaths = const [],
  List<String> shardIds = const [],
  int? workerIndex,
  String? progressFile,
  String? appLogPath,
  String? appLogDisplayPath,
  String? artifactRoot,
  Map<String, dynamic>? serviceOverrides,
  String artifactDisplayRoot = 'build/ensemble_test_runner',
  String testEntryRelativePath = TestAppPatcher.testEntryRelativePath,
  FlutterDevice? physicalDevice,
  bool hostOwnsServices = false,
  String? testsAssetPrefix,
  bool useRuntimeWorkerConfig = false,
}) {
  final planBatchFile = planBatchFileFromArguments(arguments);
  final runtimeWorkerConfig = useRuntimeWorkerConfig && physicalDevice == null;
  return [
    'test',
    testEntryRelativePath,
    '--no-pub',
    if (physicalDevice != null) ...['-d', physicalDevice.id],
    if (hostOwnsServices) '--dart-define=ensembleTestHostOwnsServices=true',
    if (testsAssetPrefix != null)
      '--dart-define=ensembleTestTestsAssetPrefix=${testsAssetPrefix.endsWith('/') ? testsAssetPrefix : '$testsAssetPrefix/'}',
    if (physicalDevice != null)
      '--dart-define=ensembleTestExecutionMode=integration',
    if (arguments.contains('--reset-device-storage'))
      '--dart-define=ensembleTestResetDeviceStorage=true',
    if (arguments.contains('--allow-device-storage-mutation'))
      '--dart-define=ensembleTestAllowDeviceStorageMutation=true',
    if (physicalDevice != null && !physicalDevice.isVirtual)
      '--dart-define=ensembleTestDeviceIsPhysical=true',
    if (!runtimeWorkerConfig)
      '--dart-define=ensembleTestEncryptionKey=$suiteEncryptionKey',
    if (physicalDevice != null) ...[
      '--dart-define=ensembleTestPhysicalDeviceId=${physicalDevice.id}',
      '--dart-define=ensembleTestPhysicalPlatform=${physicalDevice.platform}',
      '--dart-define=ensembleTestPhysicalDeviceName=${physicalDevice.name}',
    ],
    if (!runtimeWorkerConfig && reportMode != null)
      '--dart-define=ensembleTestReport=$reportMode',
    '--dart-define=ensembleTestEmitJsonReport=true',
    if (!runtimeWorkerConfig && reportFile != null)
      '--dart-define=ensembleTestReportFile=$reportFile',
    if (!runtimeWorkerConfig && timeoutSeconds != null)
      '--dart-define=ensembleTestTimeoutSeconds=$timeoutSeconds',
    if (!runtimeWorkerConfig && workerIndex != null) ...[
      '--dart-define=ensembleTestWorkerIndex=$workerIndex',
      '--dart-define=ensembleTestWorkerSuffix=worker${workerIndex + 1}',
    ],
    if (!runtimeWorkerConfig && progressFile != null)
      '--dart-define=ensembleTestProgressFile=$progressFile',
    if (!runtimeWorkerConfig && appLogPath != null)
      '--dart-define=ensembleTestAppLogFile=$appLogPath',
    if (!runtimeWorkerConfig && appLogDisplayPath != null)
      '--dart-define=ensembleTestAppLogDisplayFile=$appLogDisplayPath',
    if (!runtimeWorkerConfig && artifactRoot != null)
      '--dart-define=ensembleTestArtifactRoot=$artifactRoot',
    if (!runtimeWorkerConfig &&
        serviceOverrides != null &&
        serviceOverrides.isNotEmpty)
      '--dart-define=ensembleTestServiceOverrides=${json.encode(serviceOverrides)}',
    if (!runtimeWorkerConfig)
      '--dart-define=ensembleTestArtifactDisplayRoot=$artifactDisplayRoot',
    if (!runtimeWorkerConfig) ..._inputDartDefines(arguments),
    if (!runtimeWorkerConfig) ..._selectionDartDefines(arguments),
    if (!runtimeWorkerConfig && shardPaths.isNotEmpty)
      '--dart-define=ensembleTestShardPath=${shardPaths.join(',')}',
    if (!runtimeWorkerConfig && shardIds.isNotEmpty)
      '--dart-define=ensembleTestShardId=${shardIds.join(',')}',
    if (!runtimeWorkerConfig && planBatchFile != null)
      '--dart-define=ensembleTestPlanBatchFile=$planBatchFile',
    '--reporter',
    verbose ? 'expanded' : 'silent',
    ...flutterTestArguments(arguments),
  ];
}