Skip to content

Commit da8e78e

Browse files
thymikeeclaude
andcommitted
refactor(apple): name a missing Simulator by leaving its key out
The runner sent an absent SIMULATOR_UDID as an empty string, and its bridge handler re-detected that with a second copy of the reader's 64-character UDID bound. The request builder is the only place that knows the UDID is absent, so it now leaves simulatorUdid out, and the handler refuses the surface proof with system-surface-host-unverified when the key is missing. The reader keeps the only UDID validation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6fb0dd1 commit da8e78e

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSnapshotBridge.m‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,10 @@ uint32_t RunnerSnapshotBridgeMaximumFrameBytes(void)
240240

241241
NSDictionary *RunnerSnapshotBridgeHandle(NSString *verb, NSString *bundleId, NSDictionary *request)
242242
{
243-
if ([verb isEqualToString:@"describe"] && request[@"surfaceHostExecutables"] != nil) {
244-
id udid = request[@"simulatorUdid"];
245-
if (![udid isKindOfClass:NSString.class] || [udid length] == 0 || [udid length] > 64) {
246-
return RunnerSnapshotBridgeFailure(request, @"unsupported", @"system-surface-host-unverified",
247-
@"the runner cannot identify its Simulator for the surface host check");
248-
}
243+
if ([verb isEqualToString:@"describe"] && request[@"surfaceHostExecutables"] != nil &&
244+
request[@"simulatorUdid"] == nil) {
245+
return RunnerSnapshotBridgeFailure(request, @"unsupported", @"system-surface-host-unverified",
246+
@"the runner cannot identify its Simulator for the surface host check");
249247
}
250248
if ([verb isEqualToString:@"target"]) {
251249
return RunnerSnapshotBridgeRead(request, RunnerSnapshotBridgeBudgetMs(request), ^{

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotBridge.swift‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ extension RunnerTests {
5151

5252
/// The reader's request dictionary. The tree and automation flags are the guest bridge's fixed
5353
/// `describe` contract, so the host does not repeat them on the runner transport.
54-
static func snapshotBridgeReaderRequest(_ payload: SnapshotBridgeCommandPayload) -> [String: Any] {
54+
static func snapshotBridgeReaderRequest(
55+
_ payload: SnapshotBridgeCommandPayload,
56+
simulatorUdid: String? = ProcessInfo.processInfo.environment["SIMULATOR_UDID"]
57+
) -> [String: Any] {
5558
var request: [String: Any] = [
5659
"verb": "describe",
5760
"requestId": payload.requestId,
@@ -74,9 +77,10 @@ extension RunnerTests {
7477
request["nativeLevelsHint"] = nativeLevelsHint
7578
}
7679
if let executables = payload.surfaceHostExecutables {
77-
// The runner runs inside the Simulator it reads, so it names that Simulator itself.
80+
// The runner runs inside the Simulator it reads, so it names that Simulator itself. Without one
81+
// the key stays out, and the runner refuses the surface proof for this capture.
7882
request["surfaceHostExecutables"] = executables
79-
request["simulatorUdid"] = ProcessInfo.processInfo.environment["SIMULATOR_UDID"] ?? ""
83+
if let simulatorUdid, !simulatorUdid.isEmpty { request["simulatorUdid"] = simulatorUdid }
8084
}
8185
return request
8286
}

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,23 @@ extension RunnerTests {
4848

4949
// The runner compiles the shared reader only for the iOS Simulator (RunnerSnapshotBridge.m).
5050
#if os(iOS) && targetEnvironment(simulator)
51-
func testMissingSimulatorIdentityRefusesSurfaceProofForThisCapture() {
52-
for udid in ["", String(repeating: "x", count: 65)] {
53-
let response = RunnerSnapshotBridgeHandle("describe", "com.example.app", [
54-
"requestId": "r", "surfaceHostExecutables": ["host"], "simulatorUdid": udid,
55-
"expectedPid": 9, "generation": "g",
56-
])
51+
func testMissingSimulatorIdentityRefusesSurfaceProofForThisCapture() throws {
52+
let payload = try JSONDecoder().decode(
53+
SnapshotBridgeCommandPayload.self,
54+
from: Data(
55+
#"{"verb":"describe","requestId":"r","generation":"g","expectedPid":9,"surfaceHostExecutables":["host"]}"#
56+
.utf8)
57+
)
58+
for udid: String? in [nil, ""] {
59+
let request = Self.snapshotBridgeReaderRequest(payload, simulatorUdid: udid)
60+
XCTAssertNil(request["simulatorUdid"])
61+
let response = RunnerSnapshotBridgeHandle("describe", "com.example.app", request)
5762
XCTAssertEqual(response["error_code"] as? String, "system-surface-host-unverified")
5863
XCTAssertEqual(response["pid"] as? Int, 9)
5964
XCTAssertEqual(response["generation"] as? String, "g")
6065
}
66+
let named = Self.snapshotBridgeReaderRequest(payload, simulatorUdid: "SIM")
67+
XCTAssertEqual(named["simulatorUdid"] as? String, "SIM")
6168
}
6269
func testReaderDoesNotRefuseTheBoundsOfAFirstRead() throws {
6370
var request = Self.snapshotBridgeReaderRequest(try firstReadPayload())

0 commit comments

Comments
 (0)