From 8d11346efd36b3c11e16abdb1a72da4ad794c3e3 Mon Sep 17 00:00:00 2001 From: diffwireauto <330573775+diffwireauto@users.noreply.github.com> Date: Thu, 19 Nov 2026 03:13:57 -0500 Subject: [PATCH] test(#1157): a hidden Remote CLI switch keeps a stored grant on save Epic #1155, Gemini review finding (2026-11-19): the save path that leaves flag 0x10 alone when the switch is hidden was read, not tested. Two widget tests drive the dialog's Close through to the contact update frame: switch hidden on a radio without 0x07, the frame keeps 0x10; switch shown and turned off, the frame clears it. With the dialog changed to pass false when hidden, the first test fails. sendFrame finishes on real async work, so the save is driven with runAsync around advancing the 3 s contact re-read timeout. Agent: BrightForge (session 440fbe94) Co-Authored-By: Claude Opus 5.5 --- .../contact_settings_remote_cli_test.dart | 80 ++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/test/widgets/contact_settings_remote_cli_test.dart b/test/widgets/contact_settings_remote_cli_test.dart index 20f44f94..728a43ae 100644 --- a/test/widgets/contact_settings_remote_cli_test.dart +++ b/test/widgets/contact_settings_remote_cli_test.dart @@ -41,18 +41,32 @@ Uint8List advert(List tags) => Uint8List.fromList([ for (final t in tags) ...[t, 0x00], ]); -final contact = Contact( +Contact makeContact({int flags = 0}) => Contact( publicKey: Uint8List.fromList(List.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 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 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.delayed(const Duration(milliseconds: 50)), + ); + await tester.pump(const Duration(seconds: 4)); + } + await tester.runAsync( + () => Future.delayed(const Duration(milliseconds: 50)), + ); + await tester.pumpAndSettle(); + } + + bool wrote(Uint8List frame) => sent.any( + (f) => + f.length == frame.length && + Iterable.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); + }); }