resolveServiceOverrides function
Future<Map<String, dynamic> >
resolveServiceOverrides({
- required TestAppPatcher patcher,
- required Set<
int> usedPorts, - int preferredOffset = 0,
Resolves configured service endpoints for an individual CLI worker.
Port selection is kept here so serial and sharded execution share the same collision rules and the CLI remains responsible only for orchestration.
Implementation
Future<Map<String, dynamic>> resolveServiceOverrides({
required TestAppPatcher patcher,
required Set<int> usedPorts,
int preferredOffset = 0,
}) async {
final testsDir = patcher.testsDirPath;
if (testsDir == null) return const {};
final configFile = File(p.join(testsDir, 'config.yaml'));
if (!configFile.existsSync()) return const {};
final config = EnsembleTestParser.parseConfigString(
configFile.readAsStringSync(),
sourcePath: configFile.path,
);
if (config.services.isEmpty) return const {};
final overrides = <String, dynamic>{};
for (final service in config.services) {
final resolvedUrl = await _allocateServiceUrl(
service.url,
usedPorts: usedPorts,
preferredOffset: preferredOffset,
);
if (resolvedUrl == null) continue;
final uri = Uri.parse(resolvedUrl);
overrides[service.name] = {
'url': resolvedUrl,
// Flutter's isolated test workers run from a generated workspace. Start
// local fixtures from the app root so relative script paths and project
// files resolve the same way in serial and sharded runs.
if (service.workingDirectory == null || service.workingDirectory!.isEmpty)
'workingDirectory': patcher.appDir,
'environment': {'PORT': '${uri.port}'},
};
}
return overrides;
}