Merge pull request #646 from ericszimmermann/ez_backup-restore

Backup and Restore functionality
This commit is contained in:
zjs81 authored and GitHub committed 2026-11-09 07:08:40 -07:00
commit 47f2293a5c
42 files changed
+7629 -251

No files matched your search

@@ -38,6 +38,26 @@ void main() {
});
});
group('private-key backup frames', () {
test('uses the firmware command codes and 64-byte identity payload', () {
final keyData = Uint8List.fromList(List.generate(64, (index) => index));
expect(buildExportPrivateKeyFrame(), [cmdExportPrivateKey]);
final frame = buildImportPrivateKeyFrame(keyData);
expect(frame.length, 65);
expect(frame.first, cmdImportPrivateKey);
expect(frame.sublist(1), keyData);
expect(respCodePrivateKey, 14);
expect(respCodeDisabled, 15);
});
test('rejects identity data with the wrong length', () {
expect(
() => buildImportPrivateKeyFrame(Uint8List(63)),
throwsArgumentError,
);
});
});
group('BufferWriter.writeCString', () {
test('NUL-terminates and truncates on a character boundary', () {
final writer = BufferWriter()..writeCString('#${'ё' * 20}', 32);
@@ -232,7 +232,7 @@ void main() {
await _connect();
// Nobody called "Ghost" has posted, so the reply keeps its mention.
const text = '@[Ghost] cheap radios for sale, message me today';
final cleanBefore = _filter.recentCleanCount;
const filterText = 'cheap radios for sale, message me today';
_connector.handleFrameForTest(
ReviewFrames.channelMessage(
channelIndex: 2,
@@ -241,16 +241,19 @@ void main() {
timestampSecs: _nowSecs(),
),
);
await _waitFor(() => _find(2, text) != null);
await _waitFor(
() => _find(2, text) != null && _filter.hasRecentCleanExample(filterText),
);
final message = _find(2, text)!;
expect(message.text, startsWith('@[Ghost]'));
expect(_filter.recentCleanCount, cleanBefore + 1);
final spamBefore = _filter.spamExampleCount;
await _connector.markChannelMessageSpam(_channelAt(2), message);
expect(_filter.spamExampleCount, spamBefore + 1);
// The clean example recorded on arrival is gone, not contradicted.
expect(_filter.recentCleanCount, cleanBefore);
// The clean example recorded on arrival is gone, not contradicted. Check
// this example directly: other queued messages can teach the filter while
// this async test is awaiting the retrain.
expect(_filter.hasRecentCleanExample(filterText), isFalse);
});
test('spam actions only touch the message in the chosen channel', () async {
@@ -51,6 +51,21 @@ void main() {
expect(queue.length, 0);
});
test('firmware-disabled private-key transfer fails its waiter', () async {
final queue = newQueue();
final pending = queue.track(
buildExportPrivateKeyFrame(),
waitForReply: true,
);
expect(queue.completeReply(frame([respCodeDisabled])), isTrue);
await expectLater(
pending!.completer!.future,
throwsA(isA<UnsupportedError>()),
);
expect(queue.length, 0);
});
test('untracked commands are not enrolled', () {
final queue = newQueue();
expect(queue.track(buildSyncNextMessageFrame()), isNull);
+5 -6
View File
@@ -208,14 +208,13 @@ void main() {
_connector.state == MeshCoreConnectionState.disconnected &&
_connector.isAutoReconnectScheduled,
);
await _waitFor(
() => !_connector.isAutoReconnectScheduled,
pollInterval: const Duration(milliseconds: 1),
);
// The timer firing proves an attempt started; wait for its failure to
// finish and the next backoff to become active.
final firstScheduledAttempt = _connector.reconnectAttemptsForTesting;
// Wait for the failed attempt to schedule its next backoff. The timer's
// inactive window can be shorter than a test poll interval, so observe
// the monotonic retry count instead of trying to catch that window.
await _waitFor(
() =>
_connector.reconnectAttemptsForTesting > firstScheduledAttempt &&
_connector.state == MeshCoreConnectionState.disconnected &&
_connector.isAutoReconnectScheduled,
);