test(overlay): cover token guard outcomes
This commit is contained in:
@@ -259,23 +259,31 @@ final class VoiceWakeOverlayController: ObservableObject {
|
|||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
||||||
private func guardToken(_ token: UUID?, context: String) -> Bool {
|
private func guardToken(_ token: UUID?, context: String) -> Bool {
|
||||||
guard let active = self.activeToken else {
|
switch Self.evaluateToken(active: self.activeToken, incoming: token) {
|
||||||
self.logger.log(level: .info, "overlay drop \(context, privacy: .public) no_active")
|
case .accept:
|
||||||
return false
|
return true
|
||||||
}
|
case .dismiss:
|
||||||
if let token, token != active {
|
|
||||||
self.logger.log(
|
self.logger.log(
|
||||||
level: .info,
|
level: .info,
|
||||||
"""
|
"""
|
||||||
overlay drop \(context, privacy: .public) token_mismatch \
|
overlay drop \(context, privacy: .public) token_mismatch \
|
||||||
active=\(active.uuidString, privacy: .public) \
|
active=\(self.activeToken?.uuidString ?? "nil", privacy: .public) \
|
||||||
got=\(token.uuidString, privacy: .public)
|
got=\(token?.uuidString ?? "nil", privacy: .public)
|
||||||
""")
|
""")
|
||||||
// If tokens diverge, clear the stale overlay so the UI can resync.
|
|
||||||
self.dismiss(reason: .explicit, outcome: .empty)
|
self.dismiss(reason: .explicit, outcome: .empty)
|
||||||
return false
|
return false
|
||||||
|
case .drop:
|
||||||
|
self.logger.log(level: .info, "overlay drop \(context, privacy: .public) no_active")
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return true
|
}
|
||||||
|
|
||||||
|
enum GuardOutcome { case accept, dismiss, drop }
|
||||||
|
|
||||||
|
nonisolated static func evaluateToken(active: UUID?, incoming: UUID?) -> GuardOutcome {
|
||||||
|
guard let active else { return .drop }
|
||||||
|
if let incoming, incoming != active { return .dismiss }
|
||||||
|
return .accept
|
||||||
}
|
}
|
||||||
|
|
||||||
private func present() {
|
private func present() {
|
||||||
|
|||||||
21
apps/macos/Tests/ClawdisIPCTests/VoiceWakeOverlayTests.swift
Normal file
21
apps/macos/Tests/ClawdisIPCTests/VoiceWakeOverlayTests.swift
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import Foundation
|
||||||
|
import Testing
|
||||||
|
@testable import Clawdis
|
||||||
|
|
||||||
|
@Suite struct VoiceWakeOverlayTests {
|
||||||
|
@Test func guardTokenDropsWhenNoActive() {
|
||||||
|
let outcome = VoiceWakeOverlayController.evaluateToken(active: nil, incoming: UUID())
|
||||||
|
#expect(outcome == .drop)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func guardTokenAcceptsMatching() {
|
||||||
|
let token = UUID()
|
||||||
|
let outcome = VoiceWakeOverlayController.evaluateToken(active: token, incoming: token)
|
||||||
|
#expect(outcome == .accept)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func guardTokenDismissesMismatch() {
|
||||||
|
let outcome = VoiceWakeOverlayController.evaluateToken(active: UUID(), incoming: UUID())
|
||||||
|
#expect(outcome == .dismiss)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user