Files
ShadowsocksX-NG/ShadowsocksX-NG2/Tests/SettingsWorkflowInterfaceTests+CommitFailures.swift
T
Qiu Yuzhou effae048b8 feat(settings): remove holistic preferences reset
Not every preference warrants a reset; future resets are per
configuration item, added only where a field truly needs one (tracked
in #69). The whole chain goes: the 恢复默认 button and its confirmation
alert in SettingsView, the SettingsWorkflow reset/confirm/cancel
commands and the confirmation machinery they existed for (the
SettingsConfirmation enum had a single case), the
SettingsCommitting.resetPreferences seam entry, the runtime
resetPreferences() and ProxySettingsFileStore.reset() with its
file-rollback helpers and the rollbackFailed store error.

CONTEXT.md drops the three stale reset phrases and now records the
domain decision: no restore-all-factory-defaults action for
preferences; a reset, where it exists, is scoped to one configuration
item. ADR-0004/0005/0011 carry amendment notes since their reset
sentences describe a removed capability (0004's also predate the
PAC removal).
2026-09-27 13:29:32 +08:00

72 lines
2.4 KiB
Swift

import XCTest
@testable import ShadowsocksX_NG2
extension SettingsWorkflowInterfaceTests {
// MARK: - 提交中与失败点名文案
func testCommitFailureSurfacesNamedReasonAndKeepsDraft() async throws {
committing.updateError = FakeCommitError.io
let workflow = makeWorkflow()
workflow.draft.timeoutSeconds = 120
_ = await workflow.save()
await waitUntil(workflow.lastFailure != nil)
XCTAssertEqual(workflow.lastFailure, .unknown)
XCTAssertEqual(workflow.lastFailure?.presentableMessage, AppPresentation.unknownError)
XCTAssertFalse(workflow.isCommitting)
XCTAssertEqual(workflow.draft.timeoutSeconds, 120, "失败不吞掉草稿")
XCTAssertEqual(committing.committedSettings.timeoutSeconds, 60, "失败不半提交")
XCTAssertTrue(workflow.isDirty)
}
func testStorageAndCredentialFailuresNameTheReason() async throws {
let workflow = makeWorkflow()
workflow.draft.timeoutSeconds = 120
committing.updateError = ProxySettingsStoreError.ioFailure(detail: "disk full")
_ = await workflow.save()
await waitUntil(!workflow.isCommitting)
XCTAssertEqual(
workflow.lastFailure,
.store(.ioFailure(detail: "disk full")))
XCTAssertTrue(workflow.lastFailure?.presentableMessage.contains("偏好文件") == true)
let reference = CredentialReference(rawValue: "test-ref")
committing.updateError = ProxySettingsStoreError.missingCredential(reference)
_ = await workflow.save()
await waitUntil(
workflow.lastFailure
== .store(.missingCredential(reference)))
XCTAssertEqual(
workflow.lastFailure,
.store(.missingCredential(reference)))
}
func testCommittingStateBlocksRepeatedSave() async throws {
committing.updateGate = AsyncGate()
let workflow = makeWorkflow()
workflow.draft.timeoutSeconds = 120
let first = Task { await workflow.save() }
await Task.yield()
await waitUntil(workflow.isCommitting)
XCTAssertTrue(workflow.isCommitting)
XCTAssertFalse(workflow.canSave, "提交中保存门禁关闭")
let second = await workflow.save()
committing.updateGate?.release()
_ = await first.value
XCTAssertEqual(second, .rejected(.inProgress))
XCTAssertEqual(committing.updateCalls.count, 1, "提交中不得重复触发")
}
private enum FakeCommitError: Error, CustomStringConvertible {
// swiftlint:disable:next identifier_name
case io
var description: String { "fake-io-error" }
}
}