feat(routing): 域名级系统锁冲突提示 + 重置默认按钮 + 客户端 follow-up 清理
承接 FT-A(GET /v1/me/routing 含只读 system_locked_domains)。 - RoutingProfile 加只读 systemLockedDomains(fromJson 读/toJson 不输出); routing_screen 冲突检测扩展到域名类规则(domain/domain_suffix/domain_keyword 命中锁定域名 → systemLocked),ip_cidr 私网启发式保留。 - RoutingProfile.defaults() + RoutingProfileNotifier.resetToDefault()(复用 _persist:乐观更新/失败回滚/存成功后自动重连,保留只读 systemLockedDomains 不丢)+ routing_screen 加「重置默认」按钮与二次确认弹层(新增 3 个 l10n 键)。 - RoutingRule.copyWith 用哨兵支持 note 显式清空为 null;RoutingRule/Builtin/ RoutingProfile 加值相等 operator==/hashCode。 - T8 smartRouteSub 清理:grep 全仓发现 design/prototype/i18n/alias.json → gen_proto_i18n.mjs(CI 漂移闸)仍有活引用,按计划口径不删,详见 .superpowers/sdd/task-FTB-report.md。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -36,4 +36,67 @@ void main() {
|
||||
expect(p.builtin.lanDirect, isTrue);
|
||||
expect(p.builtin.privateViaTunnel, isTrue);
|
||||
});
|
||||
|
||||
test('systemLockedDomains:fromJson 读取,默认空,toJson 不输出(只读字段)', () {
|
||||
final withLocks = RoutingProfile.fromJson({
|
||||
'mode': 'rule',
|
||||
'rules': [],
|
||||
'final': 'proxy',
|
||||
'system_locked_domains': ['git.yanmeiai.com', 'admin.yanmeiai.com'],
|
||||
});
|
||||
expect(withLocks.systemLockedDomains, ['git.yanmeiai.com', 'admin.yanmeiai.com']);
|
||||
expect(withLocks.toJson().containsKey('system_locked_domains'), isFalse);
|
||||
|
||||
final withoutLocks = RoutingProfile.fromJson({'mode': 'rule', 'rules': [], 'final': 'proxy'});
|
||||
expect(withoutLocks.systemLockedDomains, isEmpty);
|
||||
});
|
||||
|
||||
test('RoutingProfile.defaults() 对齐服务端 routing.Default()', () {
|
||||
final d = RoutingProfile.defaults();
|
||||
expect(d.mode, 'rule');
|
||||
expect(d.builtin.chinaDirect, isTrue);
|
||||
expect(d.builtin.lanDirect, isTrue);
|
||||
expect(d.builtin.privateViaTunnel, isTrue);
|
||||
expect(d.rules, isEmpty);
|
||||
expect(d.finalAction, 'proxy');
|
||||
});
|
||||
|
||||
test('RoutingRule.copyWith 用哨兵让 note 可清空为 null', () {
|
||||
const r = RoutingRule(type: 'domain', value: 'a.com', action: 'proxy', note: 'ci');
|
||||
final cleared = r.copyWith(note: null);
|
||||
expect(cleared.note, isNull, reason: '显式传 null 应清空 note,而不是被 ?? 吞掉');
|
||||
|
||||
final unchanged = r.copyWith(value: 'b.com');
|
||||
expect(unchanged.note, 'ci', reason: '不传 note 时应保留原值');
|
||||
});
|
||||
|
||||
test('RoutingRule / Builtin / RoutingProfile 值相等(operator==)', () {
|
||||
const r1 = RoutingRule(type: 'domain', value: 'a.com', action: 'proxy', note: 'x');
|
||||
const r2 = RoutingRule(type: 'domain', value: 'a.com', action: 'proxy', note: 'x');
|
||||
const r3 = RoutingRule(type: 'domain', value: 'a.com', action: 'direct', note: 'x');
|
||||
expect(r1, r2);
|
||||
expect(r1.hashCode, r2.hashCode);
|
||||
expect(r1 == r3, isFalse);
|
||||
|
||||
const b1 = Builtin(chinaDirect: true, lanDirect: false, privateViaTunnel: true);
|
||||
const b2 = Builtin(chinaDirect: true, lanDirect: false, privateViaTunnel: true);
|
||||
const b3 = Builtin();
|
||||
expect(b1, b2);
|
||||
expect(b1.hashCode, b2.hashCode);
|
||||
expect(b1 == b3, isFalse);
|
||||
|
||||
const p1 = RoutingProfile(mode: 'rule', rules: [r1], finalAction: 'proxy');
|
||||
const p2 = RoutingProfile(mode: 'rule', rules: [r2], finalAction: 'proxy');
|
||||
final p3 = RoutingProfile.fromJson({
|
||||
'mode': 'rule',
|
||||
'rules': [
|
||||
{'type': 'domain', 'value': 'a.com', 'action': 'proxy', 'note': 'x', 'enabled': true}
|
||||
],
|
||||
'final': 'proxy',
|
||||
'system_locked_domains': ['git.yanmeiai.com'],
|
||||
});
|
||||
expect(p1, p2);
|
||||
expect(p1.hashCode, p2.hashCode);
|
||||
expect(p1 == p3, isFalse, reason: 'systemLockedDomains 不同应视为不相等');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -115,6 +115,36 @@ void main() {
|
||||
expect(api.saved, hasLength(3));
|
||||
});
|
||||
|
||||
test('resetToDefault() 还原出厂档案,保留 systemLockedDomains,并落盘', () async {
|
||||
final api = _FakeAccountApi()
|
||||
..initial = RoutingProfile.fromJson({
|
||||
'mode': 'global',
|
||||
'builtin': {'china_direct': false, 'lan_direct': true, 'private_via_tunnel': true},
|
||||
'rules': [
|
||||
{'type': 'domain', 'value': 'a.com', 'action': 'reject'},
|
||||
],
|
||||
'final': 'direct',
|
||||
'system_locked_domains': ['git.yanmeiai.com'],
|
||||
});
|
||||
final c = _makeContainer(api);
|
||||
addTearDown(c.dispose);
|
||||
await _waitLoggedIn(c);
|
||||
await c.read(routingProfileProvider.future);
|
||||
|
||||
await c.read(routingProfileProvider.notifier).resetToDefault();
|
||||
|
||||
final state = c.read(routingProfileProvider).value!;
|
||||
expect(state.mode, 'rule');
|
||||
expect(state.builtin.chinaDirect, isTrue);
|
||||
expect(state.rules, isEmpty);
|
||||
expect(state.finalAction, 'proxy');
|
||||
expect(state.systemLockedDomains, ['git.yanmeiai.com'],
|
||||
reason: '只读字段随重置保留,不因重置默认档案而丢失');
|
||||
|
||||
expect(api.saved, hasLength(1));
|
||||
expect(api.saved.single.mode, 'rule');
|
||||
});
|
||||
|
||||
test('保存失败:回退到变更前 state 且 rethrow,不静默吞', () async {
|
||||
final api = _FakeAccountApi();
|
||||
final c = _makeContainer(api);
|
||||
|
||||
@@ -103,11 +103,101 @@ void main() {
|
||||
|
||||
expect(find.text(StringsZh().routingRuleShadowed), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a domain rule matching a system-locked domain is flagged forced', (tester) async {
|
||||
final profile = RoutingProfile.fromJson({
|
||||
'mode': 'rule',
|
||||
'builtin': {'china_direct': true, 'lan_direct': true, 'private_via_tunnel': true},
|
||||
'rules': [
|
||||
{'type': 'domain_suffix', 'value': 'git.yanmeiai.com', 'action': 'direct'},
|
||||
],
|
||||
'final': 'proxy',
|
||||
'system_locked_domains': ['git.yanmeiai.com'],
|
||||
});
|
||||
|
||||
await tester.pumpWidget(ProviderScope(
|
||||
overrides: [
|
||||
appTextProvider.overrideWithValue(StringsZh()),
|
||||
routingProfileProvider.overrideWith(() => _FakeRoutingNotifier(profile)),
|
||||
],
|
||||
child: MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: PangolinTheme.light,
|
||||
home: const RoutingScreen(),
|
||||
),
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(StringsZh().routingForcedRow), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('reset button opens confirm dialog and resets on confirm', (tester) async {
|
||||
final profile = RoutingProfile.fromJson({
|
||||
'mode': 'rule',
|
||||
'builtin': {'china_direct': true, 'lan_direct': true, 'private_via_tunnel': true},
|
||||
'rules': [
|
||||
{'type': 'domain_suffix', 'value': 'x.com', 'action': 'direct'},
|
||||
],
|
||||
'final': 'proxy',
|
||||
});
|
||||
|
||||
final notifier = _FakeRoutingNotifier(profile);
|
||||
await tester.pumpWidget(ProviderScope(
|
||||
overrides: [
|
||||
appTextProvider.overrideWithValue(StringsZh()),
|
||||
routingProfileProvider.overrideWith(() => notifier),
|
||||
],
|
||||
child: MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: PangolinTheme.light,
|
||||
home: const RoutingScreen(),
|
||||
),
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('x.com'), findsOneWidget);
|
||||
|
||||
// 重置按钮在 FINAL 区之后,滚到可见再点(屏内不止一个 Scrollable,取外层 ListView)。
|
||||
await tester.scrollUntilVisible(
|
||||
find.text(StringsZh().routingReset),
|
||||
200,
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(StringsZh().routingReset));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 确认弹层出现,取消不触发重置。
|
||||
expect(find.text(StringsZh().routingResetConfirmBody), findsOneWidget);
|
||||
await tester.tap(find.text(StringsZh().devCancel));
|
||||
await tester.pumpAndSettle();
|
||||
expect(notifier.resetCalled, isFalse);
|
||||
expect(find.text('x.com'), findsOneWidget);
|
||||
|
||||
// 再次点击并确认 → 触发重置。
|
||||
await tester.tap(find.text(StringsZh().routingReset));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(StringsZh().routingResetConfirmAction));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(notifier.resetCalled, isTrue);
|
||||
expect(find.text('x.com'), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
class _FakeRoutingNotifier extends RoutingProfileNotifier {
|
||||
_FakeRoutingNotifier(this._v);
|
||||
final RoutingProfile _v;
|
||||
bool resetCalled = false;
|
||||
|
||||
@override
|
||||
Future<RoutingProfile> build() async => _v;
|
||||
|
||||
/// 绕过真实 _persist(需要 accountApiProvider/网络),只验证「确认后触发重置」的
|
||||
/// UI 交互链路;真正的 _persist 复用行为由 routing_provider_test.dart 覆盖。
|
||||
@override
|
||||
Future<void> resetToDefault() async {
|
||||
resetCalled = true;
|
||||
state = AsyncData(RoutingProfile.defaults().copyWith(systemLockedDomains: _v.systemLockedDomains));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user