Integrate live phone and watch remote prototype with guarded motion control
This commit is contained in:
@@ -91,3 +91,60 @@ private enum RelayTestError: Error { case failed }
|
||||
#expect(bridge.state == .inactive)
|
||||
#expect(fake.sent.count == 1)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Test func watchReachabilityLossRevokesArmedGrantAndNeverReplays() async throws {
|
||||
let fake = FakeWatchSession()
|
||||
let bridge = WatchRelayBridge(session: fake)
|
||||
bridge.activate(); bridge.activationDidComplete(error: nil); bridge.beginSession()
|
||||
let grant = RemoteSessionGrant(sessionID: UUID(), televisionID: UUID(), issuedAt: Date())
|
||||
fake.answer(try RelayContainer(kind: .session, value: grant).dictionary())
|
||||
await Task.yield()
|
||||
#expect(bridge.grant != nil)
|
||||
fake.isReachable = false; bridge.reachabilityDidChange()
|
||||
#expect(bridge.grant == nil)
|
||||
#expect(bridge.state == .ready(reachable: false))
|
||||
fake.isReachable = true; bridge.reachabilityDidChange()
|
||||
bridge.sendCommand(.right)
|
||||
#expect(fake.sent.count == 1)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Test func lateGrantAfterStopDoesNotRearmAndRepeatedConnectDoesNotDuplicate() async throws {
|
||||
let fake = FakeWatchSession()
|
||||
let bridge = WatchRelayBridge(session: fake)
|
||||
bridge.activate(); bridge.activationDidComplete(error: nil)
|
||||
bridge.beginSession(); bridge.beginSession()
|
||||
#expect(fake.sent.count == 1)
|
||||
let lateReply = fake.reply
|
||||
bridge.endSession()
|
||||
let grant = RemoteSessionGrant(sessionID: UUID(), televisionID: UUID(), issuedAt: Date())
|
||||
lateReply?(try RelayContainer(kind: .session, value: grant).dictionary())
|
||||
await Task.yield()
|
||||
#expect(bridge.grant == nil)
|
||||
#expect(bridge.state == .ready(reachable: true))
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Test func invalidationCompletesCommandOnceAndDiscardsLateSuccess() async throws {
|
||||
let fake = FakeWatchSession()
|
||||
let bridge = WatchRelayBridge(session: fake)
|
||||
bridge.activate(); bridge.activationDidComplete(error: nil); bridge.beginSession()
|
||||
let grant = RemoteSessionGrant(sessionID: UUID(), televisionID: UUID(), issuedAt: Date())
|
||||
fake.answer(try RelayContainer(kind: .session, value: grant).dictionary())
|
||||
await Task.yield()
|
||||
var completions = 0
|
||||
var succeeded = false
|
||||
bridge.sendCommand(.right) { result in
|
||||
completions += 1
|
||||
if case .success = result { succeeded = true }
|
||||
}
|
||||
let command = try RelayContainer(dictionary: fake.sent.last!).decode(CommandEnvelope.self, expectedKind: .command)
|
||||
let lateReply = fake.reply
|
||||
bridge.didDeactivate()
|
||||
lateReply?(try RelayContainer(kind: .receipt, value: CommandReceipt(id: command.id, status: .sentToTransport)).dictionary())
|
||||
for _ in 0..<10 { await Task.yield() }
|
||||
#expect(completions == 1)
|
||||
#expect(!succeeded)
|
||||
#expect(bridge.grant == nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user