Flutter testing and the reference app
Test against the AppCore contract fixture server, run the staging smoke test, and use examples/flutter-reference.
On this page
Contract fixture server
sdk/flutter/tool/fixture_server.dart is a local HTTP server that returns contract-shaped responses for the consumer
API. It validates every request body and every response body against packages/contracts/schemas, using a
pure-Dart JSON Schema validator (tool/contract_schemas.dart). It also records a violation for any request without
x-request-id and any effect (non-GET) without Idempotency-Key.
It is not a backend. Its data is fixed: user usr_1, product prod_premium, entitlement premium_lessons,
balance ai_credits. The OTP code is always 123456. It lives in tool/, not lib/, so it is not part of the
package's public API.
Run it for an app in debug
cd sdk/flutter
dart run tool/fixture_server.dart --port 8787It listens on 127.0.0.1 only. Point a debug build at http://127.0.0.1:8787 (iOS Simulator) or
http://10.0.2.2:8787 (Android emulator). AppCoreManifest.validate allows plain http only for these hosts, and
only in debug. It cannot reach a physical device.
The standalone server always serves app_id gotomama and environment_id staging. Your manifest must use those
values while you point at it, or AppCore.init throws APP_ENVIRONMENT_MISMATCH. Contract violations are printed
to stderr as CONTRACT VIOLATION: ....
Change scenarios (standalone server, debug only)
curl -X POST localhost:8787/__fixture/scenario -d '{"verify_mode":"pending"}' # ok | pending | conflict
curl -X POST localhost:8787/__fixture/scenario -d '{"restore_job_status":"awaiting_manual"}'
curl -X POST localhost:8787/__fixture/scenario -d '{"fail_path":"/v1/commerce/purchases/verify","fail_status":503,"fail_count":4}'
curl -X POST localhost:8787/__fixture/scenario -d '{"revoke_sessions":true}' # next call gets 401
curl -X POST localhost:8787/__fixture/scenario -d '{"premium":true}'Use it from Dart tests
The SDK's own tests start one server per test and fail on any violation. test/support/harness.dart has the
pattern:
import 'package:appcore_sdk/appcore_sdk.dart';
import 'package:flutter_test/flutter_test.dart';
import '../tool/fixture_server.dart'; // path relative to sdk/flutter/test
void main() {
late FixtureServer fx;
setUp(() async => fx = await FixtureServer.start()); // random port
tearDown(() async {
final violations = List.of(fx.violations);
await fx.close();
expect(violations, isEmpty);
});
test('signs in with OTP', () async {
final core = await AppCore.init(
manifest: AppCoreManifest(apiBaseUrl: fx.baseUrl, appId: 'gotomama', environmentId: 'staging'),
secureStorage: MemorySecureStore(),
appVersion: '1.0.0',
releaseMode: false,
sleep: (_) async {}, // skip retry backoff
);
final ch = await core.auth.requestOtp(method: 'email_otp', destination: 'user@example.com');
await core.auth.verifyOtp(challengeId: ch.challengeId, code: '123456');
expect(core.session.isSignedIn, isTrue);
});
}Set fx.scenario fields to cover failure paths: authMethods, purchaseProviders, channels,
minimumSdkVersion, sessionAppId (issues a session for another app), rotateOnNext, verifyMode,
restoreJobStatus, failNext (path prefix → list of statuses), configValues, malformedConfig.
fx.requests records every request, and fx.analyticsBatches records every event batch. For purchases, use a fake
StoreBridge; FakeStore in harness.dart shows one.
To use this from your own app's tests, vendor tool/fixture_server.dart, tool/contract_schemas.dart and
tool/fixtures/, and point ContractSchemas.load(schemaDir) (FixtureServer.start(schemaDir: ...)) at a copy of
packages/contracts/schemas.
Warning
Not yet enabled: fixture coverage for account linking (/v1/auth/methods*, /contact-challenges*,
/social-link-proof), /v1/catalog/plans, /v1/commerce/subscriptions and /v1/finance/documents. These return
404 NOT_FOUND from the fixture server. The fixture server also does not check social-login nonces.
Run the SDK suite
cd sdk/flutter
flutter test # 70 passed, 3 skipped (WS10 status, 2026-11-30)
dart analyzeStaging smoke test
APPCORE_STAGING_URL=https://<your-api-host> APPCORE_APP_ID=<your-app-id> \
flutter test test/staging_smoke_test.dartIt checks that /v1/config/public matches PublicCapabilities and that AppCore.init succeeds, that a forged
bearer gets a canonical 401 Problem, and that a manifest for the wrong app is rejected at init. Without
APPCORE_STAGING_URL the three tests are skipped. In the last recorded run, only the forged-bearer check passed.
The other two failed because staging public config had not been published yet (503 FEATURE_UNAVAILABLE).
Reference app (examples/flutter-reference)
A complete consumer app on the SDK: login (email and WhatsApp OTP, Apple, Google), an entitlement-gated screen, a
paywall with restore, inbox, and settings (permission card, preferences, analytics consent, export, subscription,
sign out, sign out everywhere, delete account). One codebase builds two apps, chosen at build time with
--dart-define=APP=gotomama|quprep. It depends on the SDK by path.
| Path | What to copy |
|---|---|
lib/adapters/secure_store.dart | PlatformSecureStore (SecureStore) |
lib/adapters/iap_store.dart | IapStoreBridge (StoreBridge, StoreKit 2 / Play Billing) |
lib/adapters/fcm_push.dart | FcmPushBridge (PushBridge) |
lib/adapters/social.dart | GoogleSignInBridge, AppleSignInBridge (SocialSignInBridge) |
lib/adapters/local_notifications.dart | LocalNotificationsAdapter (LocalNotificationsBridge) |
lib/adapters/fixture_store.dart | FixtureStoreBridge: a simulated store for fixture mode |
lib/app_config.dart | Build-time manifest per flavor; fixture mode refuses to start in release |
lib/screens/home.dart | Startup wiring: attach the store, attach push, refresh entitlements, fetch config, flush on pause |
Run it in fixture mode:
cd sdk/flutter && dart run tool/fixture_server.dart --port 8787
cd examples/flutter-reference && flutter run -d <simulator> --dart-define=FIXTURE=true --dart-define=APP=gotomamaFixture mode shows a labelled banner. On the Plans tab you pick the store outcome (purchased, pending, cancelled, error).
Warning
Not yet enabled: running the reference app against real providers. Its iOS and Android projects do not yet contain Firebase files, capabilities or URL schemes. Only an iOS Simulator fixture-mode run is in progress (WS10). No Android build has been run.
Manual device checklist
From sdk/flutter/INTEGRATION.md. None of this has been run yet. Record the device, OS, app and provider versions
when you do.
- Native Sign in with Apple (iOS) and Google (Android, iOS)
- Email OTP and WhatsApp OTP with real delivery
- Push: foreground, background and terminated tap; denied permission
- StoreKit sandbox: purchase, restore, Ask to Buy
- Play license tester: purchase, pending, cancel
- Purchase on one device, access on a second device
- Sign-out and account switch clear the inbox and reminders