@ -41,18 +41,32 @@ Uint8List advert(List<int> tags) => Uint8List.fromList([
for ( final t in tags ) . . . [ t , 0x00 ] ,
] ) ;
final contact = Contact (
Contact makeContact ( { int flags = 0 } ) = > Contact (
publicKey: Uint8List . fromList ( List < int > . generate ( 32 , ( i ) = > i ) ) ,
receivedName: ' Peer ' ,
type: advTypeChat ,
flags: flags ,
pathLength: 0 ,
path: Uint8List ( 0 ) ,
lastSeen: DateTime . fromMillisecondsSinceEpoch ( 0 ) ,
) ;
/ / / The contact - update frame the dialog ' s Close writes, for [flags].
Uint8List updateFrame ( Contact c , int flags ) = > buildUpdateContactPathFrame (
c . publicKey ,
c . path ,
c . pathLength ,
hashWidth: c . pathHashWidth ,
type: c . type ,
flags: flags ,
name: c . receivedName ,
) ;
void main ( ) {
late OffbandDatabase db ;
late MeshCoreConnector connector ;
late List < Uint8List > sent ;
late Contact contact ;
setUp ( ( ) async {
SharedPreferences . setMockInitialValues ( { } ) ;
@ -61,10 +75,38 @@ void main() {
db = OffbandDatabase ( NativeDatabase . memory ( ) ) ;
BlobStore . overrideForTest ( BlobStore ( db ) ) ;
connector = MeshCoreConnector ( ) ;
connector . sendFrameOverrideForTest = ( _ ) { } ;
sent = [ ] ;
connector . sendFrameOverrideForTest = sent . add ;
connector . setConnectedForTest ( ) ;
contact = makeContact ( ) ;
} ) ;
/ / / Tap Close , then let the connector ' s 3 s contact re-read time out so it
/ / / falls back to [ contact ] and writes the update frame .
Future < void > closeAndSave ( WidgetTester tester ) async {
sent . clear ( ) ;
await tester . tap ( find . text ( ' Close ' ) ) ;
await tester . pump ( ) ;
/ / sendFrame completes on real async work the fake clock does not run , so
/ / let real time pass on both sides of advancing the fake 3 s timeout .
for ( var i = 0 ; i < 2 ; i + + ) {
await tester . runAsync (
( ) = > Future < void > . delayed ( const Duration ( milliseconds: 50 ) ) ,
) ;
await tester . pump ( const Duration ( seconds: 4 ) ) ;
}
await tester . runAsync (
( ) = > Future < void > . delayed ( const Duration ( milliseconds: 50 ) ) ,
) ;
await tester . pumpAndSettle ( ) ;
}
bool wrote ( Uint8List frame ) = > sent . any (
( f ) = >
f . length = = frame . length & &
Iterable < int > . generate ( f . length ) . every ( ( i ) = > f [ i ] = = frame [ i ] ) ,
) ;
tearDown ( ( ) async {
BlobStore . clearTestOverride ( ) ;
await db . close ( ) ;
@ -142,4 +184,38 @@ void main() {
await openDialog ( tester ) ;
expect ( find . text ( ' Remote CLI ' ) , findsNothing ) ;
} ) ;
/ / Gemini review of Epic # 1155 : a grant the user cannot see must survive a
/ / save . Hiding the switch must never clear flag 0x10 .
testWidgets ( ' switch hidden: saving keeps a stored grant ' , ( tester ) async {
contact = makeContact ( flags: contactFlagRemoteCliAllowed ) ;
connector . handleFrameForTest (
deviceInfo ( length: 85 , verCode: 22 , version: ' 1.4.0-1.17.0 ' ) ,
) ;
await openDialog ( tester ) ;
expect ( find . text ( ' Remote CLI ' ) , findsNothing ) ;
await closeAndSave ( tester ) ;
expect ( wrote ( updateFrame ( contact , contactFlagRemoteCliAllowed ) ) , isTrue ) ;
expect ( wrote ( updateFrame ( contact , 0 ) ) , isFalse ) ;
} ) ;
testWidgets ( ' switch shown and turned off: saving clears the grant ' , (
tester ,
) async {
/ / The twin that proves the check above can see a cleared flag .
contact = makeContact ( flags: contactFlagRemoteCliAllowed ) ;
connector . handleFrameForTest (
deviceInfo ( length: 82 , verCode: 14 , version: ' v1.18.0 ' ) ,
) ;
await openDialog ( tester ) ;
await tester . tap ( find . text ( ' Remote CLI ' ) ) ;
await tester . pump ( ) ;
await closeAndSave ( tester ) ;
expect ( wrote ( updateFrame ( contact , 0 ) ) , isTrue ) ;
expect ( wrote ( updateFrame ( contact , contactFlagRemoteCliAllowed ) ) , isFalse ) ;
} ) ;
}