ensureHostFixturesSupported function
void
ensureHostFixturesSupported(
- EnsembleTestContext context, {
- ApplicationTestServices? services,
- bool requireResolved = false,
Rejects YAML mocks/fixtures that cannot attach to the application under test.
Effective fixtures come from suite config.yaml and the individual test
(already merged into EnsembleTestContext.testCase by the planner). A host
must either expose ApiMockingTestService / StorageTestService or have the
Ensemble API overlay installed on the real HTTP provider — otherwise we fail
closed before steps run.
When requireResolved is false (pre-launch), Ensemble overlay attachment is
checked immediately; pure-Flutter hosts may defer until launch returns
services. When requireResolved is true (post-launch), unresolved fixtures
always throw.
Implementation
void ensureHostFixturesSupported(
EnsembleTestContext context, {
ApplicationTestServices? services,
bool requireResolved = false,
}) {
final apiMocks = effectiveHostApiMocks(context);
final suiteDeclaresMocks = suiteDeclaresApiMocks(context.config);
final needsApiMocking = apiMocks.isNotEmpty || suiteDeclaresMocks;
final needsStorage = hostDeclaresStorageFixtures(context);
if (suiteDeclaresMocks && apiMocks.isEmpty) {
throw EnsembleTestFailure(
'Suite config declares API mocks but none were resolved onto the test. '
'Check suite mocks / profiles composition.',
);
}
if (needsApiMocking) {
final api = services?.api;
if (api is ApiMockingTestService) {
api.applyMocks(TestMocks(apis: apiMocks));
} else if (api != null) {
throw const UnsupportedApplicationCapability('apiMocking');
} else if (ensembleApiOverlayAttached(context)) {
// Ensemble HTTP provider owns the overlay installed by applyInPlaceSetup.
for (final entry in apiMocks.entries) {
context.apiOverlay.setMock(entry.key, entry.value);
}
} else if (requireResolved || Ensemble().getConfig() != null) {
// Ensemble was initialized but the overlay never attached, or we are
// past launch with no host ApiMockingTestService.
throw const UnsupportedApplicationCapability('apiMocking');
}
// else: pure Flutter pre-launch — wait for services after launch.
}
if (needsStorage) {
if (services?.storage != null) {
// Host-owned storage fixtures are applied by the driver's storage service
// during prepare/launch; presence of the capability is enough here.
return;
}
if (Ensemble().getConfig() != null) {
// applyInPlaceSetup already ran applyTestBootstrap when config exists.
return;
}
if (requireResolved) {
throw const UnsupportedApplicationCapability('storage');
}
}
}