import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:sm_mobile/core/app_controller.dart'; import 'package:sm_mobile/core/failure.dart'; import 'package:sm_mobile/services/legal.dart'; import 'support.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); test( 'license consent binds exact build, license and displayed guidance', () async { final store = MemoryStore(); final legal = Legal(store); expect(await legal.load(), false); await expectLater( legal.accept(guidanceDisplayed: false), throwsA(isA()), ); await legal.accept(guidanceDisplayed: true); expect(await Legal(store).load(), true); final record = jsonDecode(store.values['consent']!); record['identity'] = 'different-build-same-version'; store.values['consent'] = jsonEncode(record); expect(await Legal(store).load(), false); }, ); test('Vault cannot initialize before explicit license acceptance', () async { final c = AppController(MemoryStore()); await c.initialize(); await expectLater( c.openVault('valid master password', create: true), throwsA(isA()), ); expect(await c.vault.exists(), false); c.dispose(); }); test( 'background cancels Vault initialization and invalidates pending work', () async { final c = AppController(MemoryStore()); await c.initialize(); await c.acceptLicense(); final opening = c.openVault( 'valid background master password', create: true, ); c.didChangeAppLifecycleState(AppLifecycleState.paused); await expectLater(opening, throwsA(isA())); expect(c.vault.unlocked, false); expect(c.ssh.connected, false); c.dispose(); }, ); }