From f3b09b4748c867f2cdceca0b319fd65d36a45273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 31 Oct 2026 08:01:22 +0100 Subject: [PATCH 1/2] fix(ios): place a matched window in the box it sits in A dismiss-popup candidate is itself a window, so measuring it against its own frame accepted any window, even one off screen. A window is now placed in its parent's box and is the box only for what it hosts. Also pin the refusal when the hosting window can no longer be read. Co-Authored-By: Claude Opus 5.5 --- .../RunnerTests+AlertObservation.swift | 7 +-- .../RunnerTests+AlertObservationTests.swift | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift index 11397272f5..9ed0e068d6 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift @@ -54,7 +54,6 @@ extension RunnerTests { viewport: CGRect ) -> [XCUIElementSnapshot] { let frame = snapshot.frame - let hostWindow = snapshot.elementType == .window && SnapshotGeometry.isPositiveFinite(frame) ? frame : viewport let matches: Bool switch source { case .blockingSystemModal: @@ -66,8 +65,10 @@ extension RunnerTests { case .dismissPopup: matches = snapshot.elementType == .window && containsDismissPopupMarker(snapshot) } - if matches && Self.isPlaced(frame, in: hostWindow) { return [snapshot] } - return snapshot.children.flatMap { alertSnapshots(in: $0, source: source, viewport: hostWindow) } + if matches && Self.isPlaced(frame, in: viewport) { return [snapshot] } + // A window is placed in the box it sits in, and is itself the box of what it hosts. + let childViewport = snapshot.elementType == .window && SnapshotGeometry.isPositiveFinite(frame) ? frame : viewport + return snapshot.children.flatMap { alertSnapshots(in: $0, source: source, viewport: childViewport) } } private func containsDismissPopupMarker(_ snapshot: XCUIElementSnapshot) -> Bool { diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertObservationTests.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertObservationTests.swift index ac603efae3..671f1fafbf 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertObservationTests.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertObservationTests.swift @@ -104,6 +104,39 @@ extension RunnerTests { XCTAssertEqual(app.staticTexts["agent-device-alert-actions"].label, "First actions: 0; replacement actions: 0") } + @MainActor + func testAlertActivationRefusesAnUnreadableHostWindowWithoutTapping() throws { + app.launchArguments = ["--agent-device-alert-replacement-regression"] + app.launch() + defer { + invalidateCachedTarget(reason: "unit_test_cleanup") + app.terminate() + } + XCTAssertTrue(app.alerts.firstMatch.waitForFixtureExistence(timeout: appExistenceTimeout)) + let resolved = try resolveAlertBeforeTheCommand() + let alert = RunnerAlert( + root: resolved.root, + ownerApp: resolved.ownerApp, + buttons: resolved.buttons, + source: resolved.source, + window: app.windows.matching(identifier: "agent-device-missing-window").firstMatch + ) + let button = try XCTUnwrap(alert.buttons.first { $0.label == "OK" }) + + let frame = button.frame + let options = XCTExpectedFailure.Options() + options.issueMatcher = { $0.compactDescription.contains("agent-device-missing-window") } + var outcome: RunnerInteractionOutcome? + XCTExpectFailure("The unreadable window is the condition under test", options: options) { + outcome = activateAlertButton(alert, button: button, action: "accept", frame: frame, deadline: .distantFuture) + } + + guard case .unsupported? = outcome else { + return XCTFail("an unreadable host window must refuse the tap, got \(String(describing: outcome))") + } + XCTAssertEqual(app.staticTexts["agent-device-alert-actions"].label, "First actions: 0; replacement actions: 0") + } + @MainActor func testAlertDeadlineDuringSynthesisPreparationLeavesTheOriginalUntouched() throws { app.launchArguments = ["--agent-device-alert-replacement-regression"] @@ -307,5 +340,17 @@ extension RunnerTests { ) XCTAssertEqual(alertSnapshots(in: window, source: .appAlert, viewport: window.frame).map(\.elementType), [.alert]) } + + @MainActor + func testDismissPopupWindowIsPlacedInTheBoxItSitsIn() { + let viewport = CGRect(x: 0, y: 0, width: 402, height: 874) + let popup = { (x: CGFloat) in + ElementAttributesFixture(.window, CGRect(x: x, y: 0, width: 402, height: 874), children: [ + ElementAttributesFixture(.other, CGRect(x: x, y: 0, width: 402, height: 874), label: "dismiss popup") + ]) + } + XCTAssertEqual(alertSnapshots(in: popup(0), source: .dismissPopup, viewport: viewport).count, 1) + XCTAssertTrue(alertSnapshots(in: popup(1000), source: .dismissPopup, viewport: viewport).isEmpty) + } #endif } From 262450865dd47d99ce3f4fa9a6d205cc7075df4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 31 Oct 2026 12:07:01 +0100 Subject: [PATCH 2/2] test(ios): pin an inner-panel alert to its window, not the application frame Co-Authored-By: Claude Opus 5.5 --- .../UnitTests/RunnerTests+AlertObservationTests.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertObservationTests.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertObservationTests.swift index 671f1fafbf..a8d5311a40 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertObservationTests.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertObservationTests.swift @@ -352,5 +352,13 @@ extension RunnerTests { XCTAssertEqual(alertSnapshots(in: popup(0), source: .dismissPopup, viewport: viewport).count, 1) XCTAssertTrue(alertSnapshots(in: popup(1000), source: .dismissPopup, viewport: viewport).isEmpty) } + + @MainActor + func testAnInnerPanelAlertIsPlacedInItsWindowNotTheApplicationFrame() { + let alert = ElementAttributesFixture(.alert, CGRect(x: 341, y: 250, width: 270, height: 170)) + let innerPanel = ElementAttributesFixture(.window, CGRect(x: 0, y: 0, width: 951, height: 669), children: [alert]) + let root = ElementAttributesFixture(.application, CGRect(x: 0, y: 0, width: 466, height: 678), children: [innerPanel]) + XCTAssertEqual(alertSnapshots(in: root, source: .appAlert, viewport: root.frame).map(\.elementType), [.alert]) + } #endif }