Files
Adolfo Reyna 9fd04b0ce4 feat(privacy-host): add signed native calendar contacts and reminders host
Add the owner-only AF_UNIX Reyna CLI privacy host, strict signed-app installation, and typed native routing for Calendar, Contacts, and Reminders.\n\nAdd bounded system-status paths and config-only direct local-service wrappers. Preserve MacMiniMCP pending explicit cutover approval.\n\nApple Notes is intentionally deferred: no native Notes operations, Apple Events declaration, or Automation helper are included; legacy Notes handling remains untouched.
2026-08-03 20:27:54 -04:00

64 lines
2.6 KiB
Swift

import XCTest
@testable import ReynaCLIHostCore
final class ProtocolTests: XCTestCase {
func testServiceHealthReturnsOKWithSameIdAndProtocolVersion() throws {
let req = Request(id: "x", operation: "service.health", arguments: Args())
let resp = dispatch(request: req)
XCTAssertEqual(resp.id, "x", "response must echo same id")
XCTAssertTrue(resp.ok, "service.health should be ok:true")
XCTAssertNotNil(resp.result, "result must be present on success")
XCTAssertEqual(resp.result?.operation, "service.health")
XCTAssertFalse(resp.result?.protocol_version.isEmpty ?? true, "protocol_version must be nonempty")
XCTAssertNil(resp.error, "error must be nil on success")
}
func testServiceHealthDecodedFromJSON() throws {
let json = #"{"id":"abc-123","operation":"service.health","arguments":{}}"#
let data = json.data(using: .utf8)!
let decoder = JSONDecoder()
let req = try decoder.decode(Request.self, from: data)
let resp = dispatch(request: req)
XCTAssertEqual(resp.id, "abc-123")
XCTAssertTrue(resp.ok)
XCTAssertEqual(resp.result?.operation, "service.health")
XCTAssertFalse(resp.result?.protocol_version.isEmpty ?? true)
}
func testUnknownOperationReturnsError() throws {
let req = Request(id: "y", operation: "does.not.exist", arguments: Args())
let resp = dispatch(request: req)
XCTAssertEqual(resp.id, "y")
XCTAssertFalse(resp.ok, "unknown operation must return ok:false")
XCTAssertNil(resp.result, "result must be nil on failure")
XCTAssertNotNil(resp.error)
XCTAssertEqual(resp.error?.code, "unknown_operation")
}
func testUnknownOperationJSONRoundTrip() throws {
let json = #"{"id":"1","operation":"foo.bar","arguments":{}}"#
let req = try JSONDecoder().decode(Request.self, from: json.data(using: .utf8)!)
let resp = dispatch(request: req)
let encoded = try JSONEncoder().encode(resp)
let decoded = try JSONDecoder().decode(Response.self, from: encoded)
XCTAssertEqual(decoded.id, "1")
XCTAssertFalse(decoded.ok)
XCTAssertEqual(decoded.error?.code, "unknown_operation")
}
func testDispatchIsDeterministic() throws {
let req = Request(id: "same", operation: "service.health", arguments: Args())
let r1 = dispatch(request: req)
let r2 = dispatch(request: req)
XCTAssertEqual(r1.id, r2.id)
XCTAssertEqual(r1.ok, r2.ok)
XCTAssertEqual(r1.result?.protocol_version, r2.result?.protocol_version)
}
}