Files
ShadowsocksX-NG/ShadowsocksX-NG2/Tests/ProxyRuntimeControllerTests+ResyncAndSettings.swift
T
Qiu Yuzhou a8cd6262c2 feat(proxy): remove PAC and accept ACL system proxy path
Remove the PAC product feature entirely: PAC HTTP service, port, health
probe, runtime extension, PAC URL system proxy projection, PAC rule
editing, and GFWList URL settings. The product now exposes rule / global /
direct modes only, all projected as a local SOCKS system-proxy target.

First-run defaults are rule + proxyWhenUnmatched, agent on, system proxy
off. Homepage and status menu share one ProxyControlSnapshot showing the
three modes and rule sub-options. Manual servers, subscriptions, Legacy
import, and independent SOCKS/HTTP inbounds are retained.

Fix: include verbose in SslocalListenFingerprint so a verbose-only
contract change restarts sslocal instead of leaving RUST_LOG stale.

Revise CONTEXT.md vocabulary, ADR-0007, and ADR-0009. Record GFWList
exception shadowing, IPv6 system-exception, DNS, and traffic-coverage
boundaries. Add host acceptance evidence document.

Closes #67
2026-09-26 21:58:12 +08:00

93 lines
3.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Combine
import XCTest
@testable import ShadowsocksX_NG2
extension ProxyRuntimeControllerTests {
// MARK: GUI 重启重同步(D5)
func testResyncWithRegisteredAgentAndMatchingContractSkipsRewrite() async throws {
let seeded = try makeSeededCatalog()
let controller = makeController(
probe: ProxyRuntimeFixture.FakeProbe.reachable(), agentStatus: .notRegistered)
try await controller.activate(seeded.server)
await controller.setAgentEnabled(true)
XCTAssertTrue(agent.registerCount >= 1)
let contractMtime =
try FileManager.default.attributesOfItem(
atPath: runtime.contract.path
)[.modificationDate] as? Date
// 模拟 GUI 重启:全新控制器,agent 已注册、wrapper pid 存活(本测试进程)。
try Data("\(ProcessInfo.processInfo.processIdentifier)".utf8).write(to: runtime.pidFile)
let restarted = makeController(
probe: ProxyRuntimeFixture.FakeProbe.reachable(), agentStatus: .registered)
await restarted.resyncOnLaunch()
XCTAssertEqual(restarted.state, .running)
XCTAssertEqual(agent.registerCount, 1, "已注册不再重复注册")
let afterResyncMtime =
try FileManager.default.attributesOfItem(
atPath: runtime.contract.path
)[.modificationDate] as? Date
XCTAssertEqual(contractMtime, afterResyncMtime, "相同契约内容跳过写入(幂等)")
XCTAssertTrue(
signals.signalsSent.filter { $0.signal != 0 }.isEmpty,
"内容一致不需要 reload 信号")
}
func testLegacyImportBoundaryStopsRuntimeWithoutRestoringSystemProxy() async throws {
let seeded = try makeSeededCatalog()
let settingsStore = InMemoryProxySettingsStore()
var importedSettings = ProxySettings()
importedSettings.preferredMode = .global
settingsStore.saved = importedSettings
let controller = makeController(
probe: ProxyRuntimeFixture.FakeProbe.reachable(),
settingsStore: settingsStore,
systemProxy: systemProxy)
try await controller.activate(seeded.server)
await controller.setAgentEnabled(true)
XCTAssertEqual(controller.state, .running)
await controller.legacyImportDidCommit()
XCTAssertEqual(controller.state, .off)
XCTAssertEqual(controller.settings, importedSettings)
XCTAssertEqual(controller.activeTargetID, seeded.server)
XCTAssertEqual(systemProxy.restoreCount, 0, "Legacy 导入不能写入或恢复系统代理")
XCTAssertTrue(systemProxy.applied.isEmpty, "导入边界不应重新应用系统代理")
}
func testUpdatingSettingsPersistsAndReactivatesTheRuntimeContract() async throws {
let seeded = try makeSeededCatalog()
let settingsStore = InMemoryProxySettingsStore()
let controller = makeController(
probe: ProxyRuntimeFixture.FakeProbe.reachable(),
settingsStore: settingsStore,
settings: ProxySettings(
listen: ActivationFixture.listen, systemProxyEnabled: true))
try await controller.activate(seeded.server)
await controller.setAgentEnabled(true)
var next = controller.settings
next.timeoutSeconds = 120
next.verboseLogging = true
next.proxyExceptions = "localhost, 127.0.0.1"
try await controller.updateSettings(next)
let document = try XCTUnwrap(RuntimeFileStore(fileURL: runtime.contract).loadDocument())
XCTAssertEqual(controller.settings, next)
XCTAssertEqual(settingsStore.saved, next)
XCTAssertEqual(document.timeout, 120)
XCTAssertTrue(document.listen.verbose)
XCTAssertEqual(
systemProxy.applied.last?.exceptions,
FixedLocalProxyRanges.systemProxyExceptions(including: ["localhost", "127.0.0.1"]),
"系统代理意图开启时随设置更新重新应用")
}
}