mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-22 13:34:00 +00:00
RuntimeFileStore.writeRuntimeReceipt 生产零调用(17 处调用全为测试夹具), 从生产 interface 删除;测试侧经 RuntimeReceiptFixture 的 extension 以同签名 承接,调用点零改动。收据格式知识仍由 RuntimeDeploymentReceipt 类型承载, GUI 侧只保留 readRuntimeReceipt 读缝。 评审候选⑥ 6a:wrapper 是唯一收据写者,GUI 永不伪造收据。
24 lines
1.0 KiB
Swift
24 lines
1.0 KiB
Swift
import Foundation
|
||
|
||
@testable import ShadowsocksX_NG2
|
||
|
||
/// 测试支持:模拟 wrapper 写入部署收据。生产唯一收据写者是 Agent wrapper
|
||
/// (AgentContract.writeRuntimeReceipt),GUI 侧只有读(readRuntimeReceipt);
|
||
/// 收据格式知识由 Domain 的 RuntimeDeploymentReceipt 类型承载,此处只复刻
|
||
/// wrapper 的「写动作」供夹具布置磁盘状态。
|
||
extension RuntimeFileStore {
|
||
func writeRuntimeReceipt(for document: SslocalRuntimeDocument, processID: Int32) throws {
|
||
guard let digest = document.deploymentSHA256 else {
|
||
throw PersistenceError.ioFailure(detail: "Runtime contract digest is unavailable")
|
||
}
|
||
let receipt = RuntimeDeploymentReceipt(processID: processID, contractSHA256: digest)
|
||
let encoder = JSONEncoder()
|
||
encoder.outputFormatting = [.sortedKeys]
|
||
do {
|
||
try AtomicFileWriter.write(try encoder.encode(receipt), to: runtimeStatusFileURL)
|
||
} catch {
|
||
throw PersistenceError.ioFailure(detail: String(describing: error))
|
||
}
|
||
}
|
||
}
|