feat(client): P5 连接页实时速度 + 连接错误冒泡 UI(#6 6E,并入 #4)
ci-pangolin / Lint — shellcheck (push) Has been cancelled
ci-pangolin / OpenAPI Sync Check (push) Has been cancelled
ci-pangolin / Redline Scan — 脱敏 (UI 文案) (push) Has been cancelled
ci-pangolin / Flutter — analyze + test (push) Has been cancelled

- vpnStatsProvider:暴露内核 statsStream(上/下行瞬时速率);连接页速度行
  下/上行改用实时数据(B/s→Mb/s),不再硬编码 86.4/12.1;延迟用实测节点 ping。
- ConnectionState 加 error 字段;_connect 失败不再静默回 off,而是按语言
  冒泡 ConnectApiException 文案;节点未就绪(无 uuid)给出提示并删除旧 1.2s
  mock 连接路径。
- 连接页 caption 下/桌面 pill 上方显示错误文案(红)。
- 重写 connection_controller_test 适配(无网络:未就绪→off+error)。

flutter analyze 0 error;114 tests passed。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-19 00:09:31 +08:00
parent f20eddad55
commit ce5155d4ca
3 changed files with 78 additions and 39 deletions
@@ -1,7 +1,7 @@
// connection_controller_test.dart — 连接状态机:严格三态、禁乐观显示
// connection_controller_test.dart — 连接状态机:严格三态、错误冒泡
//
// ConnectionController 通过 Riverpod ProviderContainer 测试。
// 使用演示节点uuid 为空)→ 走 mock 分支(1.2s Timer 进入 on
// 节点 uuid 为空(未就绪)→ _connect 不走网络,直接回 off 并给出错误提示
// 覆盖 tokenStoreProvider 避免 FlutterSecureStorage 平台依赖。
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -33,18 +33,13 @@ class _NullTokenStore implements TokenStore {
// ── 辅助 ──────────────────────────────────────────────────────────
/// 演示节点uuid 为空 → _connect 走 1.2s mock 分支)
const _demoNode = Node(
code: 'HK',
nameZh: '香港',
nameEn: 'Hong Kong',
ping: 18,
);
/// 未就绪节点(uuid 为空)→ _connect 不走网络,直接回 off+错误
const _notReadyNode = Node(code: 'HK', nameZh: '香港', nameEn: 'Hong Kong', ping: 18);
ProviderContainer makeContainer() => ProviderContainer(
overrides: [
tokenStoreProvider.overrideWithValue(const _NullTokenStore()),
effectiveNodeProvider.overrideWithValue(_demoNode),
effectiveNodeProvider.overrideWithValue(_notReadyNode),
vpnBridgeProvider.overrideWithValue(VpnBridgeMock()),
],
);
@@ -56,20 +51,13 @@ void main() {
expect(c.read(connectionProvider).phase, VpnPhase.off);
});
test('toggle → off 态立即切为 connecting', () {
test('节点未就绪时 toggle → off 并冒泡错误(不再静默)', () {
final c = makeContainer();
addTearDown(c.dispose);
c.read(connectionProvider.notifier).toggle();
expect(c.read(connectionProvider).phase, VpnPhase.connecting);
});
test('connecting 时再次 toggle 被忽略(禁止乐观回退)', () {
final c = makeContainer();
addTearDown(c.dispose);
c.read(connectionProvider.notifier).toggle();
expect(c.read(connectionProvider).phase, VpnPhase.connecting);
c.read(connectionProvider.notifier).toggle(); // connecting 中点 → 无效
expect(c.read(connectionProvider).phase, VpnPhase.connecting);
final s = c.read(connectionProvider);
expect(s.phase, VpnPhase.off);
expect(s.error, isNotNull);
});
test('off 态 onNodeChanged 不触发连接', () {