From b7a2a6a5245fa0e0c985ee7deb3ea006ebc4442d Mon Sep 17 00:00:00 2001 From: Qiu Yuzhou Date: Sun, 4 Oct 2026 00:30:43 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=B8=BA=20Agent=20=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E6=B5=8B=E8=AF=95=E5=A4=8D=E7=94=A8=E5=B0=8F?= =?UTF-8?q?=E8=A7=84=E5=88=99=E5=A4=B9=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ProxyControlWorkflowIntegrationTests.swift | 33 +------------------ ...eControllerTests+AgentAndSystemProxy.swift | 4 +++ .../Tests/ProxyRuntimeControllerTests.swift | 7 +++- .../Tests/ProxyRuntimeFixture.swift | 31 +++++++++++++++++ 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/ShadowsocksX-NG2/Tests/ProxyControlWorkflowIntegrationTests.swift b/ShadowsocksX-NG2/Tests/ProxyControlWorkflowIntegrationTests.swift index a8accfb7..735718f7 100644 --- a/ShadowsocksX-NG2/Tests/ProxyControlWorkflowIntegrationTests.swift +++ b/ShadowsocksX-NG2/Tests/ProxyControlWorkflowIntegrationTests.swift @@ -74,7 +74,7 @@ final class ProxyControlWorkflowIntegrationTests: XCTestCase { settingsStore: settingsStore ?? InMemoryProxySettingsStore(), appBundle: AppArtifact.bundle, // Keep real ACL compilation; corpus coverage belongs to the packaged-rule tests. - ruleSnapshots: BuiltinRuleSnapshots(loader: Self.controlFlowRuleSnapshot), + ruleSnapshots: BuiltinRuleSnapshots(loader: ProxyRuntimeFixture.controlFlowRuleSnapshot), settingsRestore: RestoredProxySettings( settings: settings ?? ProxySettings(listen: ActivationFixture.listen), unreadableError: nil), @@ -306,34 +306,3 @@ final class ProxyControlWorkflowIntegrationTests: XCTestCase { } } - -extension ProxyControlWorkflowIntegrationTests { - fileprivate nonisolated static func controlFlowRuleSnapshot(_ source: RulesSource) throws - -> RuleSnapshot - { - switch source { - case .geolocationCN: - return rulesFixture( - source, - rules: [ - ProxyRule(action: .direct, match: .domainExact("direct.example")), - ProxyRule(action: .direct, match: .domainSuffix("internal.example")), - ]) - case .chinaIPv4: - return rulesFixture( - source, - rules: [ - ProxyRule(action: .direct, match: .ipv4CIDR("1.0.0.0/24")) - ]) - case .gfwlist: - return rulesFixture( - source, - rules: [ - ProxyRule(action: .proxy, match: .domainSuffix("proxy.example")), - ProxyRule(action: .direct, match: .domainExact("safe.proxy.example")), - ]) - case .custom, .fixed: - throw RuleSnapshotError.missing - } - } -} diff --git a/ShadowsocksX-NG2/Tests/ProxyRuntimeControllerTests+AgentAndSystemProxy.swift b/ShadowsocksX-NG2/Tests/ProxyRuntimeControllerTests+AgentAndSystemProxy.swift index a191d04b..a26486c1 100644 --- a/ShadowsocksX-NG2/Tests/ProxyRuntimeControllerTests+AgentAndSystemProxy.swift +++ b/ShadowsocksX-NG2/Tests/ProxyRuntimeControllerTests+AgentAndSystemProxy.swift @@ -6,6 +6,10 @@ import XCTest /// Agent 开关与系统代理开关的拆分语义(issue #60):与既有开关用例同文件 /// 追加(Xcode 测试扫描限制),扩展持有独立用例组。 final class ProxyRuntimeAgentAndSystemProxyTests: ProxyRuntimeControllerTests { + override func makeDefaultRuleSnapshots() -> BuiltinRuleSnapshots { + BuiltinRuleSnapshots(loader: ProxyRuntimeFixture.controlFlowRuleSnapshot) + } + func testEnableWithoutActiveTargetDeploysEmptyServerListening() async throws { _ = try makeSeededCatalog() let controller = makeController( diff --git a/ShadowsocksX-NG2/Tests/ProxyRuntimeControllerTests.swift b/ShadowsocksX-NG2/Tests/ProxyRuntimeControllerTests.swift index 6ff08012..ebc18210 100644 --- a/ShadowsocksX-NG2/Tests/ProxyRuntimeControllerTests.swift +++ b/ShadowsocksX-NG2/Tests/ProxyRuntimeControllerTests.swift @@ -102,6 +102,11 @@ class ProxyRuntimeControllerTests: XCTestCase { return (catalog, server) } + /// Subclasses can choose small rule inputs without changing packaged-data suites. + func makeDefaultRuleSnapshots() -> BuiltinRuleSnapshots { + BuiltinRuleSnapshots(bundle: AppArtifact.bundle) + } + func makeController( probe: EndpointProbing, agentStatus: LaunchAgentStatus = .notRegistered, @@ -153,7 +158,7 @@ class ProxyRuntimeControllerTests: XCTestCase { customRuleStore: customRuleStore ?? CustomRuleStore(fileURL: runtime.directory.appendingPathComponent("custom-rules.json")), appBundle: AppArtifact.bundle, - ruleSnapshots: ruleSnapshots, + ruleSnapshots: ruleSnapshots ?? makeDefaultRuleSnapshots(), settingsRestore: restored, agent: agent, probe: probe, diff --git a/ShadowsocksX-NG2/Tests/ProxyRuntimeFixture.swift b/ShadowsocksX-NG2/Tests/ProxyRuntimeFixture.swift index 965102d6..6aaecefb 100644 --- a/ShadowsocksX-NG2/Tests/ProxyRuntimeFixture.swift +++ b/ShadowsocksX-NG2/Tests/ProxyRuntimeFixture.swift @@ -333,3 +333,34 @@ final class InMemoryProxySettingsStore: ProxySettingsStoring { saved = settings } } + +extension ProxyRuntimeFixture { + static func controlFlowRuleSnapshot(_ source: RulesSource) throws + -> RuleSnapshot + { + switch source { + case .geolocationCN: + return rulesFixture( + source, + rules: [ + ProxyRule(action: .direct, match: .domainExact("direct.example")), + ProxyRule(action: .direct, match: .domainSuffix("internal.example")), + ]) + case .chinaIPv4: + return rulesFixture( + source, + rules: [ + ProxyRule(action: .direct, match: .ipv4CIDR("1.0.0.0/24")) + ]) + case .gfwlist: + return rulesFixture( + source, + rules: [ + ProxyRule(action: .proxy, match: .domainSuffix("proxy.example")), + ProxyRule(action: .direct, match: .domainExact("safe.proxy.example")), + ]) + case .custom, .fixed: + throw RuleSnapshotError.missing + } + } +}