test: drop assertions that cannot fail and the doubles they exercised

Three tests claimed coverage they could not deliver:

- subscription URL credential cleanup asserted a lookup derived from the
  already-empty subscription list, so it held even on a leak; production has
  no separate URL credential store (SubscriptionRecord.url is a plain field)
- the runtime log event sweep planted no secret values, so its secret half
  could never fail; keep the live JSON-dump check and rename the test to match
- clipboard and QR saver tests exercised only in-memory doubles that live in
  production source and have no other caller; delete the six tests and the
  three doubles (AppKit adapters stay untested, as before)

Co-Authored-By: DeepSeek Harness <noreply@deepseek.com>
This commit is contained in:
Qiu Yuzhou
2026-10-21 00:45:44 +08:00
co-authored by DeepSeek Harness
parent 2c75ee67ec
commit 26ecc5a11e
6 changed files with 2 additions and 118 deletions
@@ -11,21 +11,3 @@ protocol ImageClipboard {
enum ImageClipboardFailure: Equatable, Error {
case writeFailed
}
/// 测试与 Preview 使用的内存实现:不触碰用户的真实 pasteboard。
@MainActor
final class InMemoryImageClipboard: ImageClipboard {
private(set) var pngData: Data?
var writeFailure: ImageClipboardFailure?
init(writeFailure: ImageClipboardFailure? = nil) {
self.writeFailure = writeFailure
}
func write(_ pngData: Data) throws {
if let writeFailure {
throw writeFailure
}
self.pngData = pngData
}
}
@@ -58,19 +58,3 @@ final class AppKitQrImageSaver: QrImageSaver {
}
}
}
/// Tests and previews receive the draft without opening a panel or writing a file.
@MainActor
final class InMemoryQrImageSaver: QrImageSaver {
var result: QrImageSaveResult
private(set) var drafts: [QrImageSaveDraft] = []
init(result: QrImageSaveResult = .cancelled) {
self.result = result
}
func save(_ draft: QrImageSaveDraft) -> QrImageSaveResult {
drafts.append(draft)
return result
}
}
@@ -11,24 +11,3 @@ protocol TextClipboard {
enum TextClipboardFailure: Equatable, Error {
case writeFailed
}
/// 测试与 Preview 使用的内存实现:不触碰用户的真实 pasteboard。
@MainActor
final class InMemoryTextClipboard: TextClipboard {
private(set) var text: String?
var writeFailure: TextClipboardFailure?
init(text: String? = nil, writeFailure: TextClipboardFailure? = nil) {
self.text = text
self.writeFailure = writeFailure
}
func read() -> String? { text }
func write(_ text: String) throws {
if let writeFailure {
throw writeFailure
}
self.text = text
}
}
@@ -2,62 +2,8 @@ import XCTest
@testable import ShadowsocksX_NG2
@MainActor
final class TextClipboardTests: XCTestCase {
func testMissingTextIsNormalEmptyState() {
let clipboard = InMemoryTextClipboard()
XCTAssertNil(clipboard.read())
}
func testPlainTextCanBeWrittenAndReadBack() throws {
let clipboard = InMemoryTextClipboard()
try clipboard.write("ss://example")
XCTAssertEqual(clipboard.read(), "ss://example")
}
func testWriteFailureIsTypedAndDoesNotExposePlatformDetails() {
let clipboard = InMemoryTextClipboard(writeFailure: .writeFailed)
XCTAssertThrowsError(try clipboard.write("secret")) { error in
XCTAssertEqual(error as? TextClipboardFailure, .writeFailed)
}
}
}
@MainActor
final class ImageClipboardTests: XCTestCase {
func testWrittenPNGIsStored() throws {
let clipboard = InMemoryImageClipboard()
try clipboard.write(Data([0x89, 0x50]))
XCTAssertEqual(clipboard.pngData, Data([0x89, 0x50]))
}
func testWriteFailureIsTypedAndDoesNotExposePlatformDetails() {
let clipboard = InMemoryImageClipboard(writeFailure: .writeFailed)
XCTAssertThrowsError(try clipboard.write(Data())) { error in
XCTAssertEqual(error as? ImageClipboardFailure, .writeFailed)
}
}
}
@MainActor
final class QrImageSaverTests: XCTestCase {
func testDraftIsPassedThroughToSaver() {
let saver = InMemoryQrImageSaver()
let draft = QrImageSaveDraft(data: Data([0x01]), suggestedFileName: "机房.png")
let outcome = saver.save(draft)
XCTAssertEqual(outcome, .cancelled)
XCTAssertEqual(saver.drafts, [draft])
}
func testSuggestedFileNameReplacesPathReservedCharacters() {
XCTAssertEqual(
QrImageSaveDraft.suggestedFileName(from: "机房/一号:备用"),
@@ -205,7 +205,6 @@ final class CatalogWorkflowSubscriptionTests: XCTestCase {
outcome.removedNodeIDs.contains(serverA) && outcome.removedNodeIDs.contains(record.groupID)
&& outcome.removedNodeIDs.contains(serverB),
"删除结果携带被删子树身份(selection invalidation,story 18/30)")
XCTAssertNil(readURLSecret(), "订阅 URL 凭据一并清理")
await waitUntilRuntimeSettles(runtime.convergeCount - convergesBefore == 1)
XCTAssertEqual(runtime.convergeCount - convergesBefore, 1, "删除经提交协调器触发活动目标重展开")
}
@@ -221,12 +220,6 @@ final class CatalogWorkflowSubscriptionTests: XCTestCase {
return only.id
}
/// 订阅 URL 秘密的观察口:创建后恰有一个订阅 URL 凭据;删除后应为 nil。
/// (凭据引用不进投影;经存储快照里的唯一 URL 值反查。)
private func readURLSecret() -> String? {
workflow.subscriptions.first.flatMap { try? workflow.subscriptionURL(for: $0.id) }
}
/// 建一个「创建 + 首刷成功(tree 文档,服务器 a/b)」的订阅。
func seedSuccessfulSubscription() async throws -> SubscriptionSummary {
fetcher = FakeSubscriptionFetcher(behavior: .success(SubscriptionDocs.tree()))
@@ -53,7 +53,7 @@ final class RuntimeLogRedactionTests: XCTestCase {
}
}
func testEveryRuntimeLogEventIsFreeOfSecretsAndJSONDumps() {
func testEveryRuntimeLogEventRendersWithoutJSONDumps() {
let events: [RuntimeLogEvent] = [
.contractWritten(serverCount: poisoned.servers.count),
.contractUnchanged,
@@ -81,6 +81,6 @@ final class RuntimeLogRedactionTests: XCTestCase {
]
let joined = events.map(\.description).joined(separator: "\n")
assertNoSecrets(joined)
XCTAssertFalse(joined.contains("{"), "日志不得携带 JSON 文档内容")
}
}