Add comprehensive test coverage for ChatViewModel and BLEService (#962)

* Add comprehensive test coverage for ChatViewModel and BLEService

This commit adds 14 new tests to improve the safety net for future
refactoring of ChatViewModel and BLEService:

New test files:
- ChatViewModelTorTests: Tor lifecycle notification handlers (8 tests)
- ChatViewModelDeliveryStatusTests: Delivery status state machine (6 tests)
- ChatViewModelRefactoringTests: Command routing and message handling (4 tests)
- BLEServiceCoreTests: Packet deduplication and stale broadcast filtering (2 tests)
- PublicMessagePipelineTests: Message ordering and deduplication (4 tests)
- MessageRouterTests: Transport selection and outbox behavior (4 tests)
- PrivateChatManagerTests: Chat selection and read receipts (2 tests)
- UnifiedPeerServiceTests: Fingerprint resolution and blocking (2 tests)
- RelayControllerTests: TTL, handshake, and fragment relay logic (4 tests)

Modified files:
- MockTransport: Added peer snapshot publishing on connect/disconnect
- TestHelpers: Added waitUntil polling helper for async tests
- MockIdentityManager: Extended for new test scenarios

Total: 454 tests across 64 suites (was 440)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix flaky test by using waitUntil instead of fixed sleep

Replace fixed 200ms sleep with waitUntil helper for more reliable
async assertion in routing tests. This prevents timing issues on CI.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
jack
2026-01-16 16:02:13 -10:00
committed by GitHub
co-authored by jack Claude Opus 4.5
parent 194dedac43
commit 806c420313
14 changed files with 1597 additions and 18 deletions
+26 -3
View File
@@ -13,6 +13,7 @@ final class MockIdentityManager: SecureIdentityStateManagerProtocol {
private let keychain: KeychainManagerProtocol
private var blockedFingerprints: Set<String> = []
private var blockedNostrPubkeys: Set<String> = []
private var socialIdentities: [String: SocialIdentity] = [:]
init(_ keychain: KeychainManagerProtocol) {
self.keychain = keychain
@@ -25,7 +26,7 @@ final class MockIdentityManager: SecureIdentityStateManagerProtocol {
func forceSave() {}
func getSocialIdentity(for fingerprint: String) -> SocialIdentity? {
nil
socialIdentities[fingerprint]
}
func upsertCryptographicIdentity(fingerprint: String, noisePublicKey: Data, signingPublicKey: Data?, claimedNickname: String?) {}
@@ -34,7 +35,14 @@ final class MockIdentityManager: SecureIdentityStateManagerProtocol {
[]
}
func updateSocialIdentity(_ identity: SocialIdentity) {}
func updateSocialIdentity(_ identity: SocialIdentity) {
socialIdentities[identity.fingerprint] = identity
if identity.isBlocked {
blockedFingerprints.insert(identity.fingerprint)
} else {
blockedFingerprints.remove(identity.fingerprint)
}
}
func getFavorites() -> Set<String> {
Set()
@@ -47,10 +55,25 @@ final class MockIdentityManager: SecureIdentityStateManagerProtocol {
}
func isBlocked(fingerprint: String) -> Bool {
blockedFingerprints.contains(fingerprint)
blockedFingerprints.contains(fingerprint) || socialIdentities[fingerprint]?.isBlocked == true
}
func setBlocked(_ fingerprint: String, isBlocked: Bool) {
if var identity = socialIdentities[fingerprint] {
identity.isBlocked = isBlocked
socialIdentities[fingerprint] = identity
} else {
let identity = SocialIdentity(
fingerprint: fingerprint,
localPetname: nil,
claimedNickname: "",
trustLevel: .unknown,
isFavorite: false,
isBlocked: isBlocked,
notes: nil
)
socialIdentities[fingerprint] = identity
}
if isBlocked {
blockedFingerprints.insert(fingerprint)
} else {