mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
Follow-ups to the mobile diagnostic reporting work in
docs/mobile-diagnostic-reporting.md.
## Changes
- **Install ID repair:** if the install ID file holds something that
isn't text, the app now replaces it with a new ID, as it already does
for an empty file. Before, every report went out without an install ID.
A read that fails (for example, no file descriptor free) still keeps the
file, so a passing error never replaces a good ID.
- **Clock-window refusals are not reported as errors:** the spec treats
relay refusals for a timestamp outside the relay's clock window as
expected (counting them is still pending). The app only recognized one
of the relay's wordings ("timestamp too far from server time"), so
refusals for canvas events, relay-admin commands, leave requests and
observer frames were reported as invalid requests. The five wordings are
matched from the start of the reason, so unrelated `invalid:` reasons
that mention a timestamp, such as the feedback timestamp overflow or one
that echoes a value, are still reported.
- **Diagnostics card:** rows get subtitles, and the divider indent
matches the neighbouring Settings cards.
- **Comments:** explain why push stop gates its current-identity request
on the community key, and correct a test comment about who drops a
repeated error object.
## Validation
New tests cover:
- member attribution on relay sessions, including a missing key and an
answer that arrives after the member changed;
- push stop reports while signed out;
- reporter wiring for hosted admission and the self-hosted probe;
- frames the socket can't decode;
- a table of relay refusal reasons, each either reported or not, for
both `OK` and `CLOSED`;
- an install ID file whose reads fail keeps its ID.
Full-app run on an iPhone 17 Pro simulator at 61b04f6: startup, channel
list, sending and reacting, Settings, the Diagnostics card and Send test
report, and install ID repair (a file that isn't valid UTF-8 and an
empty file each got a new ID that stayed the same on the next launch).
Not covered: a relay clock-window refusal, which the live relay would
not produce.
## Diagnostics card
| Before | After |
| --- | --- |
| 
| 
|
---------
Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
71 lines
2.2 KiB
Dart
71 lines
2.2 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:buzz/shared/diagnostics/diagnostic_reporter.dart';
|
|
import 'package:buzz/shared/relay/relay_socket.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
// A frame the app cannot decode is reported, once, and the socket keeps
|
|
// reading. A frame it can decode is not reported, whatever it says.
|
|
void main() {
|
|
for (final (name, frame, reported) in <(String, Object, bool)>[
|
|
('not json', 'not json', true),
|
|
('a truncated frame', '["EVENT","sub",{"id":"ab', true),
|
|
('an empty frame', '', true),
|
|
('an object where an array belongs', '{"error":"nope"}', true),
|
|
('a JSON string', '"hello"', true),
|
|
('a binary frame', utf8.encode('["NOTICE","binary"]'), false),
|
|
('an empty array', '[]', false),
|
|
('a frame of a type the app ignores', '["NOTICE","hello"]', false),
|
|
]) {
|
|
test(
|
|
'$name is ${reported ? '' : 'not '}reported and reading goes on',
|
|
() async {
|
|
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
|
|
addTearDown(() => server.close(force: true));
|
|
server.listen((request) async {
|
|
final ws = await WebSocketTransformer.upgrade(request);
|
|
ws
|
|
..add(frame)
|
|
..add('["NOTICE","still here"]');
|
|
});
|
|
|
|
final reporter = _RecordingDiagnostics();
|
|
final received = Completer<void>();
|
|
final socket = RelaySocket(
|
|
wsUrl: 'ws://127.0.0.1:${server.port}',
|
|
nsec: null,
|
|
onMessage: (message) {
|
|
if (message.last == 'still here' && !received.isCompleted) {
|
|
received.complete();
|
|
}
|
|
},
|
|
onConnected: () {},
|
|
onDisconnected: (_) {},
|
|
)..diagnostics = reporter;
|
|
addTearDown(socket.dispose);
|
|
unawaited(socket.connect());
|
|
|
|
await received.future;
|
|
expect(reporter.operations, [
|
|
if (reported) DiagnosticOperation.relayFrame,
|
|
]);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _RecordingDiagnostics extends NoopDiagnosticReporter {
|
|
final operations = <DiagnosticOperation>[];
|
|
|
|
@override
|
|
void reportError(
|
|
Object error,
|
|
StackTrace? stackTrace, {
|
|
required DiagnosticOperation operation,
|
|
}) {
|
|
operations.add(operation);
|
|
}
|
|
}
|