Skip to content

Commit bd7828a

Browse files
committed
fix: make alert synthesis refusal mapping explicit
1 parent c839d5c commit bd7828a

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,17 @@ extension RunnerTests {
169169
case .succeeded:
170170
outcome = .performed
171171
case .deadlineExceeded:
172-
break
172+
outcome = nil
173173
case .failed:
174174
outcome = .unsupported(
175175
message: message as String? ?? "private XCTest event synthesis failed",
176176
hint: "Inspect the current alert before deciding whether to act again."
177177
)
178178
@unknown default:
179-
break
179+
outcome = .unsupported(
180+
message: "private XCTest event synthesis returned an unknown status",
181+
hint: "Inspect the current alert before deciding whether to act again."
182+
)
180183
}
181184
#else
182185
outcome = activateElement(

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import XCTest
44
import ObjectiveC.runtime
55

66
private final class AlertTapDeadlineStub: NSObject {
7+
static var status: RunnerTapSynthesisStatus?
8+
79
@objc(synthesizeTapWithApplication:resolvedWindow:x:y:deadline:errorMessage:)
810
class func synthesizeTap(
911
application: XCUIApplication,
@@ -13,7 +15,7 @@ private final class AlertTapDeadlineStub: NSObject {
1315
deadline: NSDate?,
1416
errorMessage: AutoreleasingUnsafeMutablePointer<NSString?>?
1517
) -> RunnerTapSynthesisStatus {
16-
deadline == nil ? .succeeded : .deadlineExceeded
18+
status ?? (deadline == nil ? .succeeded : .deadlineExceeded)
1719
}
1820
}
1921
#endif
@@ -117,13 +119,23 @@ extension RunnerTests {
117119
let stub = try XCTUnwrap(class_getClassMethod(AlertTapDeadlineStub.self, selector))
118120
let original = method_getImplementation(method)
119121
method_setImplementation(method, method_getImplementation(stub))
120-
defer { method_setImplementation(method, original) }
122+
defer {
123+
AlertTapDeadlineStub.status = nil
124+
method_setImplementation(method, original)
125+
}
121126

122127
let outcome = activateAlertButton(alert, button: button, action: "accept", frame: frame, deadline: .distantFuture)
123128

124129
XCTAssertNil(outcome)
125130
XCTAssertTrue(app.alerts.firstMatch.exists)
126131
XCTAssertEqual(app.staticTexts["agent-device-alert-actions"].label, "First actions: 0; replacement actions: 0")
132+
133+
AlertTapDeadlineStub.status = RunnerTapSynthesisStatus(rawValue: 999)
134+
let unknown = activateAlertButton(alert, button: button, action: "accept", frame: frame, deadline: .distantFuture)
135+
guard case .unsupported? = unknown else {
136+
return XCTFail("an unknown native status must report failure rather than deadline expiry")
137+
}
138+
XCTAssertEqual(app.staticTexts["agent-device-alert-actions"].label, "First actions: 0; replacement actions: 0")
127139
}
128140

129141
@MainActor

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension RunnerTests {
4242
defer { method_setImplementation(method, original) }
4343
TapRecordSpy.syntheses = 0
4444

45-
let deadline = Date().addingTimeInterval(0.05)
45+
let deadline = Date().addingTimeInterval(1)
4646
var prepared = false
4747
var preparationBeganBeforeDeadline = false
4848
let window = TapWindowFixture {

0 commit comments

Comments
 (0)