Files
MeshPort/apps/meshport_lab/test/telemetry_test.dart
T
shenleiandClaude Opus 5.5 dc1bfc99d2 Move mesh networking logic into the SDK and fix lifecycle bugs
SDK:
- Add build_config/migrate_config, mesh_cidrs, route_generation, health
  and start_bridged; expose abi_info (capability revision 2).
- Add wait_routes long-poll; stop wakes waiters, and context_free now
  stops the network immediately instead of waiting for waiters to time out.

Hosts:
- Dart: waitRoutes(), MeshProxySession route watcher, ABI capability check.
- Android: fix a deadlock where every VPN request waited on its own
  single-thread worker; requests are now async, status is served from a
  snapshot, and combined mode reports Partial when the mesh stops.
- macOS helper: mesh-only unified mode stops when the mesh is lost;
  installed_subnet_routes excludes the overlay.
- Lab: restore Partial sessions, write migrated profiles back, remove the
  unreachable TOML import dialog; native test now connects via the form.

Docs updated accordingly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 18:17:42 +09:00

168 lines
5.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshport_lab/features/network_telemetry.dart';
void main() {
testWidgets('Shows current device before any remote peer is discovered', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: NodeTelemetry(
status: {
'local_peer': {
'peer_id': 42,
'hostname': 'MeshPort-Lab',
'ipv4': '192.168.20.5/24',
'state': 'Running',
'udp_nat_type': 'Symmetric',
'version': 'test-core',
},
'peers': [],
'nodes': [],
},
),
),
),
);
expect(find.text('MeshPort-Lab · 当前设备'), findsOneWidget);
expect(find.textContaining('192.168.20.5/24'), findsOneWidget);
expect(find.textContaining('节点 ID 42'), findsOneWidget);
expect(find.text('运行中'), findsOneWidget);
expect(find.text('尚未发现其他节点。'), findsOneWidget);
expect(find.textContaining('中继'), findsNothing);
expect(find.textContaining('ms'), findsNothing);
});
testWidgets('Displays direct RTT and distinguishes relayed estimates', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: NodeTelemetry(
status: {
'peers': [
{
'peer_id': 1,
'direct': true,
'latency_ms': 23.4,
'rx_bytes': 2048,
'tx_bytes': 1024,
'rx_bytes_per_second': 1024.0,
'tx_bytes_per_second': 512.0,
},
],
'nodes': [
{
'peer_id': 1,
'hostname': 'game-server',
'ipv4': '10.77.0.2',
'path': 'direct',
'direct_available': true,
'latency_ms': 23.4,
'latency_source': 'link_rtt',
'metered': true,
'rx_bytes': 2048,
'tx_bytes': 1024,
'rx_bytes_per_second': 1024.0,
'tx_bytes_per_second': 512.0,
},
{
'peer_id': 2,
'hostname': 'relay-target',
'next_hop_peer_id': 1,
'path': 'relay',
'direct_available': false,
'latency_ms': 89,
'latency_source': 'route_estimate',
'metered': false,
},
],
},
),
),
),
);
expect(find.text('23.4 ms'), findsOneWidget);
expect(find.text('89.0 ms'), findsOneWidget);
expect(find.textContaining('链路 RTT'), findsOneWidget);
expect(find.textContaining('路由估算'), findsOneWidget);
expect(find.textContaining('1.0 KB/s'), findsOneWidget);
expect(find.textContaining('未单独计量'), findsOneWidget);
});
testWidgets('A direct connection can coexist with a relayed selected route', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: NodeTelemetry(
status: {
'peers': [
{'peer_id': 1, 'direct': true, 'latency_ms': 166.5},
],
'nodes': [
{
'peer_id': 1,
'hostname': 'DIG-US',
'next_hop_peer_id': 2,
'udp_nat_type': 'FullCone',
'version': '2.4.5',
'path': 'relay',
'direct_available': true,
'latency_ms': 108,
'latency_source': 'route_estimate',
'metered': true,
},
],
},
),
),
),
);
expect(find.textContaining('中继 · 有直连可用'), findsOneWidget);
expect(find.text('108.0 ms'), findsOneWidget);
expect(find.text('166.5 ms'), findsNothing);
expect(find.textContaining('FullCone'), findsOneWidget);
});
testWidgets('Punched Redmi AX6 uses measured RTT and direct label', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: NodeTelemetry(
status: {
'peers': [
{
'peer_id': 3157594741,
'direct': true,
'hole_punched': true,
'latency_ms': 7.497,
},
],
'nodes': [
{
'peer_id': 3157594741,
'hostname': 'Redmi_AX6',
'next_hop_peer_id': 3157594741,
'path': 'direct',
'direct_available': true,
'hole_punched': true,
'latency_ms': 7.497,
'latency_source': 'link_rtt',
'metered': true,
},
],
},
),
),
),
);
expect(find.text('7.5 ms'), findsOneWidget);
expect(find.textContaining('直连 · 打洞建立 · 链路 RTT'), findsOneWidget);
expect(find.textContaining('中继'), findsNothing);
});
}