build static method
Implementation
static Future<CliCompiledPlanBatch> build({
required String appDirectory,
required String testsDirectory,
required List<String> arguments,
required EnsembleTestConfig config,
Map<String, String>? assetContents,
Map<String, dynamic>? decodedDocuments,
ExecutionPlan Function(EnsembleTestCase test)? compile,
}) async {
// Sharding applies --device before deriving expanded IDs. The parent CLI
// does not narrow widget-mode config before calling this builder, so do
// the same filtering here or the worker IDs (for example, a scenario ID
// without a device suffix) will not match the compiled definitions.
final selectedConfig = applyDeviceFilter(
config,
CliTestSelection.valueSet(arguments, '--device'),
);
// The shard planner has already enumerated and read the complete suite.
// Treat that snapshot as authoritative so the plan handoff does not repeat
// the same recursive filesystem walk (or reopen the source files).
final paths = assetContents == null
? Directory(testsDirectory)
.listSync(recursive: true)
.whereType<File>()
.where((file) => file.path.endsWith('.test.yaml'))
.map((file) =>
p.relative(file.path, from: appDirectory).replaceAll('\\', '/'))
.toList()
: assetContents.keys.toList();
paths.sort();
final assets = assetContents ??
{
for (final path in paths)
path: File(p.join(appDirectory, path)).readAsStringSync(),
};
final selection = EnsembleTestSelection(
ids: CliTestSelection.valueSet(arguments, '--id'),
features: CliTestSelection.valueSet(arguments, '--feature'),
profiles: CliTestSelection.valueSet(arguments, '--profile'),
tags: CliTestSelection.valueSet(arguments, '--tag'),
paths: CliTestSelection.valueSet(arguments, '--path'),
);
final plan = await EnsembleTestExecutionPlanner.buildFromAssets(
assetContents: assets,
config: selectedConfig,
selection: selection,
inputs: inputValuesFromArguments(arguments),
decodedDocuments: decodedDocuments,
assetLoader: (assetPath) async {
final file = File(p.join(appDirectory, assetPath));
if (!file.existsSync()) {
throw AssetLoadException(
assetPath,
FileSystemException(
'Test asset not found',
file.path,
));
}
return file.readAsString();
},
);
final definitions = <String, EnsembleTestDefinition>{
for (final definition in plan.ordered) definition.testCase.id: definition,
};
final compileTest =
compile ?? (test) => CompiledPlanCompiler().compile(test);
final compiled = <String, ExecutionPlan>{};
for (final definition in plan.ordered) {
try {
compiled[definition.testCase.id] = compileTest(definition.testCase);
} on Object {
// Keep invalid plans on the worker's normal case-level error path.
// Successfully compiled plans are still handed off without a second
// compilation in each worker process.
}
}
return CliCompiledPlanBatch._(
definitionsById: Map.unmodifiable(definitions),
plansById: Map.unmodifiable(compiled),
config: selectedConfig,
);
}