mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-19 03:54:59 +00:00
主窗口诊断区(spec #21 D5/D11): - RuntimeLog 增加事件接收缝,GUI 侧接入 RuntimeEventStore 内存环形缓冲 (容量 500),wrapper 侧不变(stderr → agent.log 收敛) - 主窗口侧栏新增「服务器/诊断」分区切换;诊断区日志查看器双源:GUI 事件 实时呈现 + agent.log 尾部(1s 轮询),均可复制 - DiagnosticReportBuilder 显式触发的脱敏诊断导出:只含状态、存在性、权限、 大小/时间、数量与脱敏元数据;不读 Keychain 与契约/目录内容;原始错误 detail 不入导出,家目录前缀改写为「~」;服务器地址与备注不进入任何输出 - 投毒夹具测试验证导出不含任何敏感类目(密码/插件参数/地址/备注/token/JSON) Closes #34
62 lines
2.1 KiB
Swift
62 lines
2.1 KiB
Swift
import XCTest
|
|
|
|
@testable import ShadowsocksX_NG2
|
|
|
|
/// GUI 事件环形缓冲与 RuntimeLog 接收缝(issue #34):顺序保持、容量封顶、
|
|
/// emit 路由与恢复。
|
|
final class RuntimeEventStoreTests: XCTestCase {
|
|
override func tearDown() {
|
|
super.tearDown()
|
|
// 恢复生产接线,避免污染同进程内其他测试。
|
|
RuntimeLog.setSink(RuntimeEventStore.shared)
|
|
}
|
|
|
|
func testAppendKeepsChronologicalOrderAndRendersLine() {
|
|
let store = RuntimeEventStore()
|
|
let first = Date(timeIntervalSince1970: 1_000)
|
|
let second = Date(timeIntervalSince1970: 2_000)
|
|
|
|
store.append(text: "first event", timestamp: first)
|
|
store.append(text: "second event", timestamp: second)
|
|
|
|
let snapshot = store.snapshot
|
|
XCTAssertEqual(snapshot.map(\.text), ["first event", "second event"])
|
|
XCTAssertEqual(snapshot.map(\.id), [0, 1])
|
|
// 行格式 = 固定格式时间戳 + 两空格 + 事件文本(不锚定时区,格式器随本机)。
|
|
XCTAssertEqual(
|
|
snapshot[0].renderedLine,
|
|
RuntimeEventStore.Entry.timestampFormatter.string(from: first) + " first event")
|
|
XCTAssertEqual(
|
|
snapshot[1].renderedLine,
|
|
RuntimeEventStore.Entry.timestampFormatter.string(from: second) + " second event")
|
|
}
|
|
|
|
func testCapacityKeepsMostRecentEvents() {
|
|
let store = RuntimeEventStore(capacity: 3)
|
|
for index in 0..<5 {
|
|
store.append(text: "event-\(index)", timestamp: Date())
|
|
}
|
|
|
|
XCTAssertEqual(store.snapshot.map(\.text), ["event-2", "event-3", "event-4"])
|
|
}
|
|
|
|
func testEmitRoutesToRegisteredSink() {
|
|
let store = RuntimeEventStore()
|
|
RuntimeLog.setSink(store)
|
|
defer { RuntimeLog.setSink(RuntimeEventStore.shared) }
|
|
|
|
RuntimeLog.emit(.contractWritten(serverCount: 2))
|
|
|
|
XCTAssertEqual(store.snapshot.last?.text, "contract written (servers=2)")
|
|
XCTAssertEqual(store.snapshot.count, 1)
|
|
}
|
|
|
|
func testEmitWithoutSinkStillWritesStderrOnly() {
|
|
RuntimeLog.setSink(nil)
|
|
defer { RuntimeLog.setSink(RuntimeEventStore.shared) }
|
|
|
|
// 未注册接收缝时 emit 只走 stderr,不崩溃即可(GUI 启动前的事件路径)。
|
|
RuntimeLog.emit(.agentRegistered)
|
|
}
|
|
}
|