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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
29d236f3fe
commit
dc1bfc99d2
@@ -0,0 +1,112 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshport_lab/features/lab_screen.dart';
|
||||
|
||||
void main() {
|
||||
const channel = MethodChannel('meshport/system_vpn');
|
||||
final binding = TestWidgetsFlutterBinding.ensureInitialized();
|
||||
// Profile storage: nothing stored, saves accepted.
|
||||
setUp(
|
||||
() => binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
(_) async => null,
|
||||
),
|
||||
);
|
||||
tearDown(
|
||||
() =>
|
||||
binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, null),
|
||||
);
|
||||
testWidgets(
|
||||
'form connect starts real native engine and can stop it',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(1400, 1600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(const MaterialApp(home: LabScreen()));
|
||||
final lab = tester.state(find.byType(LabScreen)) as dynamic;
|
||||
List<String> logs() => (lab.logs as List).cast<String>();
|
||||
Finder field(String label) => find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is TextField && widget.decoration?.labelText == label,
|
||||
);
|
||||
Future<void> waitForLog(String text) async {
|
||||
for (var i = 0; i < 60 && !logs().any((l) => l.contains(text)); i++) {
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 50)),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
expect(logs(), contains(contains(text)));
|
||||
}
|
||||
|
||||
await waitForLog('原生库已加载');
|
||||
// Startup restores profiles first; let it finish before overriding them.
|
||||
await waitForLog('穿透');
|
||||
// Mesh-only, in-app engine: no helper, VPN permission or proxy node.
|
||||
lab.runtimeMode = 'application';
|
||||
lab.proxyProfile.feature = 'mesh';
|
||||
lab.proxyProfile.entry = 'application';
|
||||
await tester.tap(find.text('组网').last);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('基础配置'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(field('网络名称'), 'ui-local-test');
|
||||
await tester.enterText(field('网络密钥'), 'test-only');
|
||||
await tester.enterText(field('虚拟 IPv4 / 前缀'), '10.79.0.11/24');
|
||||
await tester.tap(find.text('保存草稿'));
|
||||
await waitForLog('网络配置已保存到');
|
||||
for (var i = 0; i < 40 && find.text('保存中…').evaluate().isNotEmpty; i++) {
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 50)),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
await tester.pageBack();
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('概览').last);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('连接').last);
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
for (
|
||||
var i = 0;
|
||||
i < 40 && !logs().any((l) => l.contains('[启动组网引擎] 成功'));
|
||||
i++
|
||||
) {
|
||||
await tester.runAsync(() async {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||
});
|
||||
await tester.pump();
|
||||
}
|
||||
expect(logs(), contains(contains('[启动组网引擎] 成功')));
|
||||
for (
|
||||
var i = 0;
|
||||
i < 40 && find.text('引擎运行中 · 0 个节点').evaluate().isEmpty;
|
||||
i++
|
||||
) {
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 100)),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
expect(find.text('引擎运行中 · 0 个节点'), findsOneWidget);
|
||||
expect(find.textContaining('当前设备'), findsOneWidget);
|
||||
expect(find.textContaining('节点 ID'), findsOneWidget);
|
||||
await tester.tap(find.text('断开连接'));
|
||||
for (var i = 0; i < 40 && find.text('尚未连接').evaluate().isEmpty; i++) {
|
||||
await tester.runAsync(() async {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||
});
|
||||
await tester.pump();
|
||||
}
|
||||
expect(find.text('尚未连接'), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.runAsync(() async {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||
});
|
||||
},
|
||||
skip: Platform.environment['MESHPORT_LIBRARY'] == null,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user