Skip to content

Commit 2700f2f

Browse files
thymikeeclaude
andcommitted
test(ios-runner): pin the error payload wire shape beside its model
Moves the wire-shape pin to a Models test file and adds a field-drift check: every stored ErrorPayload field except the runner-internal retryable failure must reach the encoded JSON. The exception-retry test builds its commands through the shared fixture helper. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 968ed2f commit 2700f2f

2 files changed

Lines changed: 35 additions & 14 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+LifecycleTests.swift‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,10 @@ extension RunnerTests {
4646
XCTAssertFalse(shouldRetryResponse(succeeded))
4747
}
4848

49-
func testTargetAppUnavailableErrorKeepsItsWireShape() throws {
50-
let encoded = try JSONEncoder().encode(ErrorPayload.targetAppUnavailable(bundleId: "com.example.app"))
51-
let object = try XCTUnwrap(JSONSerialization.jsonObject(with: encoded) as? [String: Any])
52-
XCTAssertEqual(Array(object.keys), ["message"])
53-
XCTAssertEqual(object["message"] as? String, "app 'com.example.app' is not available")
54-
XCTAssertEqual(
55-
ErrorPayload.targetAppUnavailable(bundleId: nil).message,
56-
"runner app is not available"
57-
)
58-
}
59-
6049
func testExceptionRetryIsLimitedToTheAxServerNotFoundReadOnlyCase() throws {
61-
let readText = try JSONDecoder().decode(Command.self, from: Data(#"{"command":"readText"}"#.utf8))
62-
let snapshot = try JSONDecoder().decode(Command.self, from: Data(#"{"command":"snapshot"}"#.utf8))
63-
let tap = try JSONDecoder().decode(Command.self, from: Data(#"{"command":"tap"}"#.utf8))
50+
let readText = try runnerCommandFixture(#"{"command":"readText"}"#)
51+
let snapshot = try runnerCommandFixture(#"{"command":"snapshot"}"#)
52+
let tap = try runnerCommandFixture(#"{"command":"tap"}"#)
6453
let axServerNotFound = "NSException: Error kAXErrorServerNotFound"
6554
XCTAssertTrue(shouldRetryException(readText, message: axServerNotFound))
6655
XCTAssertFalse(shouldRetryException(tap, message: axServerNotFound))
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Foundation
2+
import XCTest
3+
4+
#if AGENT_DEVICE_RUNNER_UNIT_TESTS
5+
extension RunnerTests {
6+
func testErrorPayloadEncodesEveryFieldButTheRunnerInternalRetryableFailure() throws {
7+
let payload = ErrorPayload(
8+
code: "CODE",
9+
message: "message",
10+
hint: "hint",
11+
retryableFailure: .targetAppUnavailable
12+
)
13+
let encoded = try JSONEncoder().encode(payload)
14+
let object = try XCTUnwrap(JSONSerialization.jsonObject(with: encoded) as? [String: Any])
15+
let storedFields = Set(Mirror(reflecting: payload).children.compactMap(\.label))
16+
XCTAssertEqual(Set(object.keys), storedFields.subtracting(["retryableFailure"]))
17+
}
18+
19+
func testTargetAppUnavailableErrorKeepsItsWireShape() throws {
20+
let encoded = try JSONEncoder().encode(
21+
ErrorPayload.targetAppUnavailable(bundleId: "com.example.app")
22+
)
23+
let object = try XCTUnwrap(JSONSerialization.jsonObject(with: encoded) as? [String: Any])
24+
XCTAssertEqual(Array(object.keys), ["message"])
25+
XCTAssertEqual(object["message"] as? String, "app 'com.example.app' is not available")
26+
XCTAssertEqual(
27+
ErrorPayload.targetAppUnavailable(bundleId: nil).message,
28+
"runner app is not available"
29+
)
30+
}
31+
}
32+
#endif

0 commit comments

Comments
 (0)