Files
openclaw/apps/ios/Tests/WatchSessionActivationGateTests.swift
2026-07-06 09:16:02 +01:00

56 lines
2.2 KiB
Swift

import Foundation
import Testing
@testable import OpenClaw
struct WatchSessionActivationGateTests {
@Test func `iPhone observes watch pairing and install changes`() throws {
let sourceURL = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent()
.deletingLastPathComponent()
.appendingPathComponent("Sources/Services/WatchConnectivityTransport.swift")
let source = try String(contentsOf: sourceURL, encoding: .utf8)
#expect(source.contains("func sessionWatchStateDidChange(_ session: WCSession)"))
#expect(source.contains("paired=\\(session.isPaired) installed=\\(session.isWatchAppInstalled)"))
}
@Test func `concurrent waiters share one activation`() async throws {
let gate = WatchSessionActivationGate(timeoutNanoseconds: 1_000_000_000)
#expect(gate.beginActivation())
#expect(!gate.beginActivation())
let first = Task { try await gate.waitUntilActivated() }
let second = Task { try await gate.waitUntilActivated() }
gate.complete(activated: true, errorDescription: nil)
try await first.value
try await second.value
}
@Test func `activation timeout remains retryable`() async throws {
let gate = WatchSessionActivationGate(timeoutNanoseconds: 1_000_000)
#expect(gate.beginActivation())
await #expect(throws: WatchSessionActivationError.self) {
try await gate.waitUntilActivated()
}
#expect(gate.beginActivation())
gate.complete(activated: true, errorDescription: nil)
try await gate.waitUntilActivated()
}
@Test func `activation errors reach every waiter`() async {
let gate = WatchSessionActivationGate(timeoutNanoseconds: 1_000_000_000)
#expect(gate.beginActivation())
let first = Task { try await gate.waitUntilActivated() }
let second = Task { try await gate.waitUntilActivated() }
gate.complete(activated: false, errorDescription: "not paired")
await #expect(throws: WatchSessionActivationError.self) { try await first.value }
await #expect(throws: WatchSessionActivationError.self) { try await second.value }
}
}