import XCTest
import PhysarumEngine
@testable import Physarum
/// The editor-remote wire protocol must survive a JSON round-trip unchanged so the ATV
/// host reconstructs exactly what the phone sent. Equatable comparison proves field fidelity.
final class RemoteMessageTests: XCTestCase {
private func roundTrip(_ m: RemoteMessage) throws -> RemoteMessage {
try JSONDecoder().decode(RemoteMessage.self, from: JSONEncoder().encode(m))
}
func testIntentRoundTrips() throws {
let intents: [ControlIntent] = [.next, .previous, .togglePlaylist, .jumpTo("p-1"), .showOverlay, .dismissOverlay]
for i in intents {
XCTAssertEqual(try roundTrip(.intent(i)), .intent(i))
}
}
func testParamsAndHelloRoundTrip() throws {
let p = PresetCatalog.loadAll()[0].params
XCTAssertEqual(try roundTrip(.params(p)), .params(p))
let state = RemoteState(selectedID: "p-1", params: p, cycling: true)
XCTAssertEqual(try roundTrip(.hello(state)), .hello(state))
}
func testAudioFactorsRoundTrips() throws {
var f = AudioFactors()
f[.moveSpeed] = 1.4; f[.saturation] = 0.6
let frame = AudioFactorFrame(f)
XCTAssertEqual(try roundTrip(.audioFactors(frame)), .audioFactors(frame))
XCTAssertEqual(try roundTrip(.audioFactors(.neutral)), .audioFactors(.neutral))
}
}