mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-10-29 05:33:45 +00:00
test(rules): align fixtures with preset ownership
Select presets explicitly so document stores, runtime preparation, and browsing assertions use the intended rule sources.
This commit is contained in:
@@ -84,7 +84,8 @@ extension ProxyRuntimeControllerModeTests {
|
||||
let controller = makeController(
|
||||
probe: ProxyRuntimeFixture.FakeProbe.reachable(),
|
||||
settings: ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, preferredMode: .global, agentEnabled: true),
|
||||
listen: ActivationFixture.listen, preferredMode: .global,
|
||||
rulePreset: .chinaDirect, agentEnabled: true),
|
||||
proxyMode: .global,
|
||||
ruleSnapshots: loader)
|
||||
try await controller.activate(seeded.server)
|
||||
|
||||
@@ -43,7 +43,8 @@ final class BuiltinRuleCatalogTests: XCTestCase {
|
||||
_ = try await snapshots.load(.chinaIPv4)
|
||||
XCTFail("The first runtime source request should fail")
|
||||
} catch {}
|
||||
let workflow = RulesWorkflow(loadCustom: { [] }, builtinSnapshots: snapshots)
|
||||
let workflow = RulesWorkflow(
|
||||
preset: .chinaDirect, loadCustom: { [] }, builtinSnapshots: snapshots)
|
||||
await workflow.refresh()
|
||||
XCTAssertFalse(workflow.snapshot.isComplete)
|
||||
XCTAssertEqual(loader.count(.chinaIPv4), 1)
|
||||
|
||||
@@ -34,7 +34,8 @@ extension ProxyRuntimeControllerTests {
|
||||
probe: probe,
|
||||
listeningStore: InMemoryProxyListeningStore(),
|
||||
settings: settings
|
||||
?? ProxyRuntimeSettings(listen: ActivationFixture.listen, agentEnabled: true),
|
||||
?? ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, rulePreset: .chinaDirect, agentEnabled: true),
|
||||
proxyMode: proxyMode,
|
||||
launchHealthTimeoutSeconds: launchHealthTimeoutSeconds,
|
||||
launchHealthRetryDelay: launchHealthRetryDelay,
|
||||
@@ -200,6 +201,7 @@ final class CustomRuleControllerTests: ProxyRuntimeControllerTests {
|
||||
let settings = ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen,
|
||||
preferredMode: .global,
|
||||
rulePreset: .chinaDirect,
|
||||
agentEnabled: true)
|
||||
let controller = makeControllerWithCustomRules(
|
||||
store: store, settings: settings, proxyMode: .global)
|
||||
|
||||
@@ -27,7 +27,8 @@ final class CustomRuleDeletionControllerTests: ProxyRuntimeControllerTests {
|
||||
try store.saveDocument(original)
|
||||
let controller = makeDeletionController(
|
||||
store: store,
|
||||
settings: ProxyRuntimeSettings(listen: ActivationFixture.listen, agentEnabled: false))
|
||||
settings: ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, rulePreset: .chinaDirect, agentEnabled: false))
|
||||
let workflow = deletionWorkflow(controller)
|
||||
await workflow.refresh()
|
||||
workflow.select(Set(workflow.snapshot.rows.map(\.id)))
|
||||
@@ -160,7 +161,8 @@ final class CustomRuleDeletionControllerTests: ProxyRuntimeControllerTests {
|
||||
try store.saveDocument(original)
|
||||
let controller = makeDeletionController(
|
||||
store: store,
|
||||
settings: ProxyRuntimeSettings(listen: ActivationFixture.listen, agentEnabled: false))
|
||||
settings: ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, rulePreset: .chinaDirect, agentEnabled: false))
|
||||
let workflow = deletionWorkflow(controller)
|
||||
await workflow.refresh()
|
||||
workflow.select(Set(workflow.snapshot.rows.map(\.id)))
|
||||
@@ -191,6 +193,7 @@ final class CustomRuleDeletionControllerTests: ProxyRuntimeControllerTests {
|
||||
|
||||
private func deletionWorkflow(_ controller: ProxyRuntimeController) -> RulesWorkflow {
|
||||
RulesWorkflow(
|
||||
preset: controller.rulePreset,
|
||||
loadDocument: { try controller.ruleDocuments.load() },
|
||||
commitDocument: { await controller.commitRuleDocument($0) },
|
||||
builtinSnapshots: controller.ruleSnapshots)
|
||||
|
||||
@@ -13,7 +13,8 @@ final class CustomRuleEditingControllerTests: ProxyRuntimeControllerTests {
|
||||
let (store, _) = try makeCustomRuleStore()
|
||||
let controller = makeControllerWithCustomRules(
|
||||
store: store,
|
||||
settings: ProxyRuntimeSettings(listen: ActivationFixture.listen, agentEnabled: false))
|
||||
settings: ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, rulePreset: .chinaDirect, agentEnabled: false))
|
||||
let workflow = editingWorkflow(controller)
|
||||
await workflow.refresh()
|
||||
var draft = try XCTUnwrap(workflow.makeCustomRuleDraft())
|
||||
@@ -103,6 +104,7 @@ final class CustomRuleEditingControllerTests: ProxyRuntimeControllerTests {
|
||||
|
||||
private func editingWorkflow(_ controller: ProxyRuntimeController) -> RulesWorkflow {
|
||||
RulesWorkflow(
|
||||
preset: controller.rulePreset,
|
||||
loadDocument: { try controller.ruleDocuments.load() },
|
||||
commitDocument: { await controller.commitRuleDocument($0) },
|
||||
builtinSnapshots: controller.ruleSnapshots)
|
||||
|
||||
@@ -38,7 +38,8 @@ final class RuleEnablementControllerTests: ProxyRuntimeControllerTests {
|
||||
let controller = makeRuleEnablementController(
|
||||
store: store,
|
||||
settings: ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, preferredMode: .rule, agentEnabled: true),
|
||||
listen: ActivationFixture.listen, preferredMode: .rule,
|
||||
rulePreset: .chinaDirect, agentEnabled: true),
|
||||
proxyMode: .rule, ruleApplicationDelay: { try await applicationGate.wait() })
|
||||
try await controller.activate(seeded.server)
|
||||
let before = agent.registerCount
|
||||
@@ -75,7 +76,8 @@ final class RuleEnablementControllerTests: ProxyRuntimeControllerTests {
|
||||
let controller = makeRuleEnablementController(
|
||||
store: store,
|
||||
settings: ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, preferredMode: .rule, agentEnabled: true),
|
||||
listen: ActivationFixture.listen, preferredMode: .rule,
|
||||
rulePreset: .chinaDirect, agentEnabled: true),
|
||||
proxyMode: .rule, launchHealthTimeoutSeconds: 0.3,
|
||||
launchHealthRetryDelay: { try await healthGate.wait() })
|
||||
try await controller.activate(seeded.server)
|
||||
@@ -123,7 +125,8 @@ final class RuleEnablementControllerTests: ProxyRuntimeControllerTests {
|
||||
let controller = makeRuleEnablementController(
|
||||
store: store,
|
||||
settings: ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, preferredMode: .global, agentEnabled: true),
|
||||
listen: ActivationFixture.listen, preferredMode: .global,
|
||||
rulePreset: .chinaDirect, agentEnabled: true),
|
||||
proxyMode: .global, ruleSnapshots: BuiltinRuleSnapshots(loader: { await loader.load($0) }))
|
||||
try await controller.activate(seeded.server)
|
||||
let runtimeStore = RuntimeFileStore(fileURL: runtime.contract)
|
||||
@@ -163,7 +166,8 @@ final class RuleEnablementControllerTests: ProxyRuntimeControllerTests {
|
||||
let controller = makeRuleEnablementController(
|
||||
store: store,
|
||||
settings: ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, preferredMode: .global, agentEnabled: true),
|
||||
listen: ActivationFixture.listen, preferredMode: .global,
|
||||
rulePreset: .chinaDirect, agentEnabled: true),
|
||||
proxyMode: .global, ruleSnapshots: BuiltinRuleSnapshots(loader: { await loader.load($0) }))
|
||||
try await controller.activate(seeded.server)
|
||||
let modeSwitch = Task { await controller.setProxyMode(.rule) }
|
||||
@@ -189,7 +193,8 @@ final class RuleEnablementControllerTests: ProxyRuntimeControllerTests {
|
||||
defer { loader.resume() }
|
||||
let snapshots = BuiltinRuleSnapshots(loader: { await loader.load($0) })
|
||||
let settings = ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, preferredMode: .global, agentEnabled: true)
|
||||
listen: ActivationFixture.listen, preferredMode: .global,
|
||||
rulePreset: .chinaDirect, agentEnabled: true)
|
||||
let controller = makeRuleEnablementController(
|
||||
store: store, settings: settings, proxyMode: .global, ruleSnapshots: snapshots)
|
||||
try await controller.activate(seeded.server)
|
||||
@@ -236,7 +241,8 @@ final class RuleEnablementControllerTests: ProxyRuntimeControllerTests {
|
||||
let controller = makeRuleEnablementController(
|
||||
store: store,
|
||||
settings: ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, preferredMode: .global, agentEnabled: true),
|
||||
listen: ActivationFixture.listen, preferredMode: .global,
|
||||
rulePreset: .chinaDirect, agentEnabled: true),
|
||||
proxyMode: .global, ruleSnapshots: BuiltinRuleSnapshots(loader: { await loader.load($0) }))
|
||||
try await controller.activate(seeded.server)
|
||||
let old = Task { await controller.setProxyMode(.rule) }
|
||||
@@ -363,7 +369,8 @@ extension RuleEnablementControllerTests {
|
||||
let (store, _) = try makeCustomRuleStore()
|
||||
let controller = makeRuleEnablementController(
|
||||
store: store,
|
||||
settings: ProxyRuntimeSettings(listen: ActivationFixture.listen, agentEnabled: false))
|
||||
settings: ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, rulePreset: .chinaDirect, agentEnabled: false))
|
||||
let identity = ProxyRule(action: .proxy, match: try RuleMatch(domainExact: "saved.example"))
|
||||
let outcome = await controller.updateRuleDocument(
|
||||
CustomRuleDocument(rules: [], disabledIdentities: [identity]))
|
||||
@@ -375,7 +382,8 @@ extension RuleEnablementControllerTests {
|
||||
try broken.write(to: store.fileURL)
|
||||
let newSession = makeRuleEnablementController(
|
||||
store: store,
|
||||
settings: ProxyRuntimeSettings(listen: ActivationFixture.listen, agentEnabled: false))
|
||||
settings: ProxyRuntimeSettings(
|
||||
listen: ActivationFixture.listen, rulePreset: .chinaDirect, agentEnabled: false))
|
||||
let rejected = await newSession.updateRuleDocument(CustomRuleDocument(rules: []))
|
||||
XCTAssertEqual(rejected, .persistenceFailed)
|
||||
XCTAssertEqual(try Data(contentsOf: store.fileURL), broken)
|
||||
|
||||
@@ -59,6 +59,7 @@ final class RuleEnablementWorkflowTests: XCTestCase {
|
||||
let started = expectation(description: "analysis paused")
|
||||
let gate = RulesAnalysisGate(started: started)
|
||||
let workflow = RulesWorkflow(
|
||||
preset: .chinaDirect,
|
||||
loadDocument: { try session.load() },
|
||||
commitDocument: { document in
|
||||
do {
|
||||
@@ -107,6 +108,7 @@ final class RuleEnablementWorkflowTests: XCTestCase {
|
||||
let reads = RulesReadCounts()
|
||||
let rule = CustomRule(action: .proxy, match: try RuleMatch(domainExact: "saved.example"))
|
||||
let workflow = RulesWorkflow(
|
||||
preset: .chinaDirect,
|
||||
loadDocument: {
|
||||
reads.recordDocument()
|
||||
return CustomRuleDocument(rules: [rule])
|
||||
|
||||
@@ -82,6 +82,7 @@ final class RulesWorkflowTests: XCTestCase {
|
||||
attribution: "author"),
|
||||
rules: [ProxyRule(action: .direct, match: match)])
|
||||
let workflow = RulesWorkflow(
|
||||
preset: .chinaDirect,
|
||||
loadCustom: { [custom] },
|
||||
builtinSnapshots: BuiltinRuleSnapshots(loader: { source in
|
||||
source == .geolocationCN ? snapshot : rulesFixture(source)
|
||||
@@ -148,6 +149,7 @@ final class RulesWorkflowTests: XCTestCase {
|
||||
|
||||
func testCorruptUserDocumentAndMissingBuiltinStayDistinctFromEmptySearch() async throws {
|
||||
let workflow = RulesWorkflow(
|
||||
preset: .chinaDirect,
|
||||
loadCustom: { throw CustomRuleStoreError.corrupt(detail: "fixture") },
|
||||
builtinSnapshots: BuiltinRuleSnapshots(loader: { source in
|
||||
if source == .chinaIPv4 { throw RuleSnapshotError.missing }
|
||||
@@ -169,6 +171,7 @@ final class RulesWorkflowTests: XCTestCase {
|
||||
func testPackagedCollectionLoadsMetadataShippedRulesAndFixedSemanticPolicy() async throws {
|
||||
let bundle = AppArtifact.bundle
|
||||
let workflow = RulesWorkflow(
|
||||
preset: .chinaDirect,
|
||||
loadCustom: { [] },
|
||||
builtinSnapshots: BuiltinRuleSnapshots(bundle: bundle))
|
||||
await workflow.refresh()
|
||||
|
||||
Reference in New Issue
Block a user