Establish watch relay contracts and platform package wiring

This commit is contained in:
2026-09-18 09:34:26 +04:00
parent a92698e1e6
commit 9b87299bf5
22 changed files with 778 additions and 159 deletions
@@ -0,0 +1,41 @@
import Foundation
import Testing
import RemoteCore
import WatchBridgePhone
private actor FakePhoneCoordinator: PhoneCommandCoordinating {
private(set) var receivedCommands: [CommandEnvelope] = []
private(set) var receivedPeers: [WatchPeerGeneration] = []
func watchBridgeDidActivate(peer: WatchPeerGeneration) {}
func watchBridgeDidDeactivate(peer: WatchPeerGeneration) {}
func beginWatchSession(_ request: BeginRemoteSessionRequest, peer: WatchPeerGeneration)
-> Result<RemoteSessionGrant, RelayFailure> {
.failure(RelayFailure(code: .unavailable))
}
func endWatchSession(_ request: EndRemoteSessionRequest, peer: WatchPeerGeneration)
-> Result<RemoteSessionEnded, RelayFailure> {
.failure(RelayFailure(code: .sessionInvalidated))
}
func submitWatchCommand(_ envelope: CommandEnvelope, peer: WatchPeerGeneration) -> CommandReceipt {
receivedCommands.append(envelope)
receivedPeers.append(peer)
return CommandReceipt(id: envelope.id, status: .rejected)
}
}
@Test func phoneDependencyUsesInjectedActorAndPreservesItsDecision() async {
let actor = FakePhoneCoordinator()
let dependency = PhoneRelayDependency(coordinator: actor)
#expect(dependency.coordinator === actor)
let peer = WatchPeerGeneration()
let now = Date(timeIntervalSince1970: 1_700_000_000)
let command = CommandEnvelope(
sessionID: UUID(), televisionID: UUID(), sequence: 1,
issuedAt: now, expiresAt: now.addingTimeInterval(0.5), command: .right
)
let receipt = await dependency.coordinator.submitWatchCommand(command, peer: peer)
#expect(receipt == CommandReceipt(id: command.id, status: .rejected))
#expect(await actor.receivedCommands == [command])
#expect(await actor.receivedPeers == [peer])
}