Merge upstream/dev (86 commits) into tth
build / ci-image (push) Successful in 10s
build / build (push) Failing after 4m27s

Upstream redesigned the chat composer (bubble, round +/send button,
ChatComposerQuote for the reply preview); our terminal theme had tweaked
the old layout. Took upstream's structure and re-applied the terminal
look to the new widgets: compact panel padding, square bubble, square
button, square and one-line-low reply quote. The terminal reply padding
in channel_chat_screen now lives in ChatComposerQuote, so DMs get it too.

Also fixed for the merge:
- mesh_ui: AvatarCircle uses upstream's avatarInitials() (nullable); the
  terminal glyph falls back to the person icon like upstream does;
- chat_screen: upstream split maxMessageRetries into direct/flood limits,
  the terminal line now shows the bubble's maxSendAttempts;
- test/screens/copy_messages_test.dart: the 1x1 PNG had a bad IDAT CRC.
  Its async decode failure leaked into the next test; upstream's real
  flutter_langdetect hides that by timing, our stub (instant init) does
  not, so the DM test failed ~3 of 5 runs. Replaced with a valid PNG.

Checked in the CI image (Flutter 3.47.9): flutter analyze lib test clean;
flutter test all green except settings_reveal_test "hides Image Messages
sub-options", which fails the same way on plain upstream/dev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-11-23 12:43:57 +01:00
commit 63907cb17d
210 files changed
+47623 -4900

No files matched your search

@@ -0,0 +1,15 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/services/background_service.dart';
void main() {
test('the foreground service does not stop when the app goes to the '
'background', () {
// flutter_foreground_task's stopWithTask option stops the service on the
// first activity pause, not on task removal. Swipe-away is handled by
// android:stopWithTask in the manifest instead.
final options = BackgroundService.taskOptions;
expect(options.stopWithTask, isNull);
expect(options.toJson().containsKey('stopWithTask'), isFalse);
expect(options.allowAutoRestart, isFalse);
});
}
+26
View File
@@ -132,6 +132,32 @@ void main() {
},
);
test('keeps contact added times out of app settings', () async {
SharedPreferences.setMockInitialValues({
'app_settings': jsonEncode({'theme_mode': 'dark'}),
'contact_added_at_0011223344': jsonEncode({'aa': 1}),
});
PrefsManager.reset();
await PrefsManager.initialize();
addTearDown(PrefsManager.reset);
final connector = MeshCoreConnector();
addTearDown(connector.dispose);
final json = await const BackupService().createBackup(
items: {BackupItem.appSettings},
connector: connector,
settings: AppSettings(),
password: '',
);
final payload = jsonDecode(json) as Map<String, dynamic>;
final section =
(payload['sections'] as Map<String, dynamic>)['appSettings']
as Map<String, dynamic>;
final preferences = section['preferences'] as Map<String, dynamic>;
expect(preferences, contains('app_settings'));
expect(preferences, isNot(contains('contact_added_at_0011223344')));
});
test('backs up a sensitive key without unrelated app settings', () async {
SharedPreferences.setMockInitialValues({
'app_settings': jsonEncode({
@@ -0,0 +1,35 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/models/image_codec_support.dart';
import 'package:meshcore_open/services/app_settings_service.dart';
import 'package:meshcore_open/services/image_codec_backend.dart';
import 'package:meshcore_open/services/image_codec_service.dart';
import 'package:meshcore_open/services/image_codec_settings_store.dart';
import 'package:meshcore_open/widgets/image_send_codec_binding.dart';
/// Runs in both build modes; each half skips in the other (`scripts/onnx.sh`).
void main() {
ImageCodecService newService() {
final service = ImageCodecService(
AppSettingsService(),
settingsStore: InMemoryImageCodecSettingsStore(
const ImageCodecPreferences(enabled: true),
),
);
addTearDown(service.dispose);
return service;
}
test('ONNX-free build reports the image codec unavailable', () {
final service = newService();
expect(createImageCodecBackend(), isNull);
expect(service.availability, ImageCodecAvailability.unavailable);
expect(service.unavailableReason, contains('without ONNX Runtime'));
expect(service.canRunInference, isFalse);
}, skip: imageCodecRuntimeAvailable ? 'ONNX Runtime is compiled in' : false);
test('ONNX build has a codec backend', () {
final service = newService();
expect(createImageCodecBackend(), isA<OnnxImageCodecBackend>());
expect(service.unavailableReason, isNull);
}, skip: imageCodecRuntimeAvailable ? false : 'built without ONNX Runtime');
}
@@ -0,0 +1,286 @@
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:meshcore_open/models/contact.dart';
import 'package:meshcore_open/models/message.dart';
import 'package:meshcore_open/models/path_selection.dart';
import 'package:meshcore_open/services/app_settings_service.dart';
import 'package:meshcore_open/services/message_retry_service.dart';
import 'package:meshcore_open/storage/prefs_manager.dart';
Contact _contact({int pathLength = 1, List<int> path = const [0x11]}) =>
Contact(
publicKey: Uint8List.fromList(List<int>.generate(32, (i) => i + 1)),
name: 'Test',
type: 1,
pathLength: pathLength,
path: Uint8List.fromList(path),
lastSeen: DateTime.now(),
);
void main() {
setUp(() async {
SharedPreferences.setMockInitialValues({});
await PrefsManager.initialize();
});
test('rotation sends direct attempts, then flood, then stops', () async {
final settings = AppSettingsService();
await settings.loadSettings();
await settings.updateSettings(
settings.settings.copyWith(
autoRouteRotationEnabled: true,
directRetries: 1,
floodRetries: 1,
),
);
final service = MessageRetryService(
sentWatchdogGrace: const Duration(milliseconds: 5),
);
addTearDown(service.dispose);
final sends = <int>[];
final thresholds = <int>[];
service.initialize(
RetryServiceConfig(
sendMessage: (_, _, attempt, _) async {
sends.add(attempt);
},
addMessage: (_, _) {},
updateMessage: (_) {},
calculateTimeout: (_, _, {String? contactKey, int? deviceTimeoutMs}) =>
15,
appSettingsService: settings,
selectRetryPath: (_, attemptIndex, directRetries, _) {
thresholds.add(directRetries);
if (attemptIndex >= directRetries) {
return const PathSelection(
pathBytes: [],
hopCount: -1,
useFlood: true,
);
}
return const PathSelection(
pathBytes: [0x22],
hopCount: 1,
useFlood: false,
);
},
),
);
await service.sendMessageWithRetry(contact: _contact(), text: 'hello');
await pumpEventQueue();
await Future<void>.delayed(const Duration(milliseconds: 1400));
expect(sends, [0, 1]);
expect(thresholds, [1, 1]);
});
test('rotation off keeps retrying a direct path without flooding', () async {
final settings = AppSettingsService();
await settings.loadSettings();
await settings.updateSettings(
settings.settings.copyWith(
autoRouteRotationEnabled: false,
directRetries: 2,
floodRetries: 5,
),
);
final service = MessageRetryService(
sentWatchdogGrace: const Duration(milliseconds: 5),
);
addTearDown(service.dispose);
final sends = <int>[];
var picked = false;
service.initialize(
RetryServiceConfig(
sendMessage: (_, _, attempt, _) async {
sends.add(attempt);
},
addMessage: (_, _) {},
updateMessage: (_) {},
calculateTimeout: (_, _, {String? contactKey, int? deviceTimeoutMs}) =>
15,
appSettingsService: settings,
selectRetryPath: (_, _, _, _) {
picked = true;
return const PathSelection(
pathBytes: [],
hopCount: -1,
useFlood: true,
);
},
),
);
await service.sendMessageWithRetry(contact: _contact(), text: 'hello');
await pumpEventQueue();
await Future<void>.delayed(const Duration(milliseconds: 1400));
expect(sends, [0, 1]);
expect(picked, isFalse);
});
test('a flood path without rotation stops after the flood budget', () async {
final settings = AppSettingsService();
await settings.loadSettings();
await settings.updateSettings(
settings.settings.copyWith(
autoRouteRotationEnabled: false,
directRetries: 4,
floodRetries: 1,
),
);
final service = MessageRetryService(
sentWatchdogGrace: const Duration(milliseconds: 5),
);
addTearDown(service.dispose);
final latest = <Message>[];
final sends = <int>[];
service.initialize(
RetryServiceConfig(
sendMessage: (_, _, attempt, _) async {
sends.add(attempt);
},
addMessage: (_, message) => latest.add(message),
updateMessage: (message) => latest.add(message),
calculateTimeout: (_, _, {String? contactKey, int? deviceTimeoutMs}) =>
15,
appSettingsService: settings,
),
);
await service.sendMessageWithRetry(
contact: _contact(pathLength: -1, path: const []),
text: 'hello',
);
await pumpEventQueue();
await Future<void>.delayed(const Duration(milliseconds: 200));
expect(sends, [0]);
expect(latest.last.status, MessageStatus.failed);
});
test(
'flood-only rotation floods saved direct contact even if selector returns null',
() async {
final settings = AppSettingsService();
await settings.loadSettings();
await settings.updateSettings(
settings.settings.copyWith(
autoRouteRotationEnabled: true,
directRetries: 0,
floodRetries: 1,
),
);
final service = MessageRetryService(
sentWatchdogGrace: const Duration(milliseconds: 5),
);
addTearDown(service.dispose);
final latest = <Message>[];
final sends = <int>[];
var clearedCount = 0;
var setPathCount = 0;
service.initialize(
RetryServiceConfig(
sendMessage: (_, _, attempt, _) async {
sends.add(attempt);
},
addMessage: (_, message) => latest.add(message),
updateMessage: (message) => latest.add(message),
clearContactPath: (_) async {
clearedCount++;
},
setContactPath: (_, _, _) async {
setPathCount++;
},
calculateTimeout:
(_, _, {String? contactKey, int? deviceTimeoutMs}) => 15,
appSettingsService: settings,
selectRetryPath: (_, _, _, _) => null,
),
);
await service.sendMessageWithRetry(
contact: _contact(pathLength: 1, path: const [0x11]),
text: 'hello',
);
await pumpEventQueue();
await Future<void>.delayed(const Duration(milliseconds: 200));
expect(sends, [0]);
expect(clearedCount, 1);
expect(setPathCount, 0);
expect(latest.last.pathLength, -1);
expect(latest.last.pathBytes, isEmpty);
expect(latest.last.status, MessageStatus.failed);
},
);
test(
'rotation with direct attempts > 0 tries direct paths before flooding',
() async {
final settings = AppSettingsService();
await settings.loadSettings();
await settings.updateSettings(
settings.settings.copyWith(
autoRouteRotationEnabled: true,
directRetries: 2,
floodRetries: 1,
),
);
final service = MessageRetryService(
sentWatchdogGrace: const Duration(milliseconds: 5),
);
addTearDown(service.dispose);
final actions = <String>[];
final sends = <int>[];
service.initialize(
RetryServiceConfig(
sendMessage: (_, _, attempt, _) async {
sends.add(attempt);
},
addMessage: (_, _) {},
updateMessage: (_) {},
clearContactPath: (_) async => actions.add('flood'),
setContactPath: (_, bytes, _) async =>
actions.add('direct:${bytes.join(',')}'),
calculateTimeout:
(_, _, {String? contactKey, int? deviceTimeoutMs}) => 15,
appSettingsService: settings,
selectRetryPath: (_, attemptIndex, directRetries, _) {
if (attemptIndex >= directRetries) return null;
return attemptIndex == 0
? const PathSelection(
pathBytes: [0x22],
hopCount: 1,
useFlood: false,
)
: const PathSelection(
pathBytes: [0x33],
hopCount: 1,
useFlood: false,
);
},
),
);
await service.sendMessageWithRetry(
contact: _contact(pathLength: 1, path: const [0x11]),
text: 'hello',
);
await pumpEventQueue();
await Future<void>.delayed(const Duration(milliseconds: 3500));
expect(sends, [0, 1, 2]);
expect(actions, ['direct:34', 'direct:51', 'flood']);
},
);
}
+10 -2
View File
@@ -56,7 +56,12 @@ void main() {
);
test('missing RESP_CODE_SENT times out and retries', () async {
await service.sendMessageWithRetry(contact: _contact(), text: 'hello');
// A direct path uses the direct budget (default 4). A flood path would
// stop after the default single flood attempt.
await service.sendMessageWithRetry(
contact: _contact(pathLength: 1, path: const [0x11]),
text: 'hello',
);
await pumpEventQueue();
expect(sends.map((s) => s.attempt), [0]);
@@ -80,7 +85,10 @@ void main() {
});
test('late ACK for an attempt whose SENT was lost still delivers', () async {
await service.sendMessageWithRetry(contact: _contact(), text: 'hello');
await service.sendMessageWithRetry(
contact: _contact(pathLength: 1, path: const [0x11]),
text: 'hello',
);
await pumpEventQueue();
// Let the watchdog fire; the retry is now waiting on its backoff.
@@ -0,0 +1,194 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/services/notification_service.dart';
class _NoopNotificationsPlatform extends FlutterLocalNotificationsPlatform {}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
const channel = MethodChannel('dexterous.com/flutter/local_notifications');
final service = NotificationService();
setUp(() {
service.resetForTest();
debugDefaultTargetPlatformOverride = null;
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null);
FlutterLocalNotificationsPlatform.instance = _NoopNotificationsPlatform();
debugDefaultTargetPlatformOverride = null;
service.resetForTest();
});
group('NotificationService.hasNotificationPermission', () {
test('queries Android areNotificationsEnabled and updates cache', () async {
debugDefaultTargetPlatformOverride = TargetPlatform.android;
AndroidFlutterLocalNotificationsPlugin.registerWith();
bool? androidEnabled = true;
var checkCalls = 0;
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) async {
if (call.method == 'initialize') return true;
if (call.method == 'areNotificationsEnabled') {
checkCalls++;
return androidEnabled;
}
return null;
});
expect(await service.hasNotificationPermission(), isTrue);
expect(service.canNotifyCacheForTest, isTrue);
expect(checkCalls, 1);
// Subsequent ensureCanNotify uses the cached grant without re-querying.
expect(await service.ensureCanNotifyForTest(), isTrue);
expect(checkCalls, 1);
// Revoking OS permission invalidates the cached true on the next live check.
androidEnabled = false;
expect(await service.hasNotificationPermission(), isFalse);
expect(service.canNotifyCacheForTest, isNull);
expect(checkCalls, 2);
// _ensureCanNotify now re-queries and returns false instead of stale true.
expect(await service.ensureCanNotifyForTest(), isFalse);
expect(checkCalls, 3);
// Null response from channel is treated as false.
androidEnabled = null;
expect(await service.hasNotificationPermission(), isFalse);
expect(service.canNotifyCacheForTest, isNull);
});
test(
'queries iOS checkPermissions and invalidates cache when revoked',
() async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
IOSFlutterLocalNotificationsPlugin.registerWith();
Map<String, Object?>? permissionsResponse = {
'isEnabled': true,
'isAlertEnabled': true,
'isBadgeEnabled': true,
'isSoundEnabled': true,
'isProvisionalEnabled': false,
'isCriticalEnabled': false,
'isProvidesAppNotificationSettingsEnabled': false,
'isCarPlayEnabled': false,
};
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) async {
if (call.method == 'initialize') return true;
if (call.method == 'checkPermissions') return permissionsResponse;
return null;
});
expect(await service.hasNotificationPermission(), isTrue);
expect(service.canNotifyCacheForTest, isTrue);
expect(await service.ensureCanNotifyForTest(), isTrue);
// Provisional permission also counts as granted.
permissionsResponse = {
'isEnabled': false,
'isAlertEnabled': false,
'isBadgeEnabled': false,
'isSoundEnabled': false,
'isProvisionalEnabled': true,
};
expect(await service.hasNotificationPermission(), isTrue);
expect(service.canNotifyCacheForTest, isTrue);
// Denied in iOS Settings clears the cached grant.
permissionsResponse = {
'isEnabled': false,
'isAlertEnabled': false,
'isBadgeEnabled': false,
'isSoundEnabled': false,
'isProvisionalEnabled': false,
};
expect(await service.hasNotificationPermission(), isFalse);
expect(service.canNotifyCacheForTest, isNull);
expect(await service.ensureCanNotifyForTest(), isFalse);
permissionsResponse = null;
expect(await service.hasNotificationPermission(), isFalse);
},
);
test('queries macOS checkPermissions and updates cache', () async {
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
MacOSFlutterLocalNotificationsPlugin.registerWith();
Map<String, Object?>? permissionsResponse = {
'isEnabled': true,
'isAlertEnabled': true,
'isBadgeEnabled': true,
'isSoundEnabled': true,
};
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) async {
if (call.method == 'initialize') return true;
if (call.method == 'checkPermissions') return permissionsResponse;
return null;
});
expect(await service.hasNotificationPermission(), isTrue);
expect(service.canNotifyCacheForTest, isTrue);
permissionsResponse = {
'isEnabled': false,
'isAlertEnabled': false,
'isBadgeEnabled': false,
'isSoundEnabled': false,
};
expect(await service.hasNotificationPermission(), isFalse);
expect(service.canNotifyCacheForTest, isNull);
});
test(
'returns true on desktop platforms without an OS permission gate',
() async {
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
FlutterLocalNotificationsPlatform.instance =
_NoopNotificationsPlatform();
expect(await service.hasNotificationPermission(), isTrue);
expect(service.canNotifyCacheForTest, isTrue);
},
);
test('requestPermissions updates and clears canNotify cache', () async {
debugDefaultTargetPlatformOverride = TargetPlatform.android;
AndroidFlutterLocalNotificationsPlugin.registerWith();
var grantResult = true;
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) async {
if (call.method == 'initialize') return true;
if (call.method == 'requestNotificationsPermission') {
return grantResult;
}
if (call.method == 'areNotificationsEnabled') {
return grantResult;
}
return null;
});
expect(await service.requestPermissions(), isTrue);
expect(service.canNotifyCacheForTest, isTrue);
grantResult = false;
expect(await service.requestPermissions(), isFalse);
expect(service.canNotifyCacheForTest, isNull);
expect(await service.ensureCanNotifyForTest(), isFalse);
});
});
}
+19 -12
View File
@@ -121,7 +121,7 @@ void main() {
final pick = svc.selectPathForAttempt(
pubKey,
attemptIndex: attemptIndex,
maxRetries: 5,
directRetries: 4,
recentSelections: recent,
);
final key = pick.useFlood
@@ -139,7 +139,7 @@ void main() {
final selection = svc.selectPathForAttempt(
pubKey,
attemptIndex: 0,
maxRetries: 5,
directRetries: 4,
);
expect(selection.useFlood, isTrue);
});
@@ -150,7 +150,7 @@ void main() {
final selection = svc.selectPathForAttempt(
pubKey,
attemptIndex: 0,
maxRetries: 0,
directRetries: 0,
);
expect(selection.useFlood, isTrue);
});
@@ -163,7 +163,7 @@ void main() {
final selection = svc.selectPathForAttempt(
pubKey,
attemptIndex: i,
maxRetries: 5,
directRetries: 4,
);
expect(
selection.useFlood,
@@ -274,7 +274,7 @@ void main() {
final pick = svc.selectPathForAttempt(
pubKey,
attemptIndex: 0,
maxRetries: 5,
directRetries: 4,
);
expect(pick.useFlood, isFalse);
expect(pick.hopCount, 0);
@@ -299,21 +299,28 @@ void main() {
expect(resolved.pathBytes, isEmpty);
});
test('final attempt is always flood regardless of known paths', () async {
test('attempts at and after directRetries flood', () async {
final pubKey = _hex('ef01');
await _seed(svc, pubKey, pathBytes: [0x01], hopCount: 1);
for (final retries in [1, 2, 5, 10]) {
final lastAttempt = svc.selectPathForAttempt(
for (final direct in [0, 1, 4, 9]) {
final flooded = svc.selectPathForAttempt(
pubKey,
attemptIndex: retries - 1,
maxRetries: retries,
attemptIndex: direct,
directRetries: direct,
);
expect(
lastAttempt.useFlood,
flooded.useFlood,
isTrue,
reason: 'maxRetries=$retries: last attempt must be flood',
reason: 'directRetries=$direct: that attempt floods',
);
if (direct == 0) continue;
final routed = svc.selectPathForAttempt(
pubKey,
attemptIndex: direct - 1,
directRetries: direct,
);
expect(routed.useFlood, isFalse);
}
});
});
@@ -0,0 +1,81 @@
import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:meshcore_open/services/storage_service.dart';
import 'package:meshcore_open/storage/prefs_manager.dart';
void main() {
setUp(() async {
SharedPreferences.setMockInitialValues({});
PrefsManager.reset();
await PrefsManager.initialize();
});
test('a saved on or off overrides the global clock-sync default', () async {
SharedPreferences.setMockInitialValues({
'repeater_auto_clock_sync_after_login': jsonEncode({
'on-node': true,
'off-node': false,
}),
});
PrefsManager.reset();
await PrefsManager.initialize();
final storage = StorageService();
expect(
await storage.repeaterClockSyncAfterLogin(
'on-node',
globalDefault: false,
),
isTrue,
);
expect(
await storage.repeaterClockSyncAfterLogin(
'off-node',
globalDefault: true,
),
isFalse,
);
expect(
await storage.repeaterClockSyncAfterLogin(
'new-node',
globalDefault: true,
),
isTrue,
);
expect(
await storage.repeaterClockSyncAfterLogin(
'new-node',
globalDefault: false,
),
isFalse,
);
});
test('choosing default removes the per-repeater override', () async {
final storage = StorageService();
await storage.setRepeaterClockSyncOverride(
'node',
RepeaterClockSyncOverride.on,
);
expect(
await storage.getRepeaterClockSyncOverride('node'),
RepeaterClockSyncOverride.on,
);
await storage.setRepeaterClockSyncOverride(
'node',
RepeaterClockSyncOverride.followDefault,
);
expect(
await storage.getRepeaterClockSyncOverride('node'),
RepeaterClockSyncOverride.followDefault,
);
expect(
PrefsManager.instance.containsKey('repeater_auto_clock_sync_after_login'),
isFalse,
);
});
}
+1 -1
View File
@@ -205,7 +205,7 @@ void main() {
final pick = svc.selectPathForAttempt(
contact,
attemptIndex: attempt,
maxRetries: maxRetries,
directRetries: maxRetries - 1,
recentSelections: used,
context: context,
);