Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
viewport: CGRect
) -> [XCUIElementSnapshot] {
let frame = snapshot.frame
let hostWindow = snapshot.elementType == .window && SnapshotGeometry.isPositiveFinite(frame) ? frame : viewport
let matches: Bool
switch source {
case .blockingSystemModal:
Expand All @@ -66,8 +65,10 @@
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] }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · Nested dismiss-popup window on a foldable's inner panel is now rejected as off screen

The new placement check tests a window against the box it sits in, and at the observation root that box is the application frame: observeAlert calls alertSnapshots(in: snapshot, source: source, viewport: snapshot.frame) (RunnerTests+AlertObservation.swift:44), where snapshot is ownerApp.snapshot(), an .application node, so the children — the app's windows — are matched against the application frame.

Suggested change
if matches && Self.isPlaced(frame, in: viewport) { return [snapshot] }
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.
// A foldable's inner-panel window extends past the application frame that names one panel,
// so a window that matches is also placed in the box it hosts (#4001).
let childViewport = snapshot.elementType == .window && SnapshotGeometry.isPositiveFinite(frame) ? frame : viewport
if matches, source == .dismissPopup, Self.isPlaced(frame, in: childViewport) { return [snapshot] }
return snapshot.children.flatMap { alertSnapshots(in: $0, source: source, viewport: childViewport) }

Suggested change

Decide whether a dismiss-popup window on a foldable's inner panel — a window whose center sits outside the 466-wide application frame, the geometry this PR adds a test for — must still be observed. If it must, place a window that matches (or any window) against the union of the box it sits in and the screen rather than against the box it sits in alone, and pin the answer with a dismissPopup case using the 951x669 inner-panel window and the 466x678 application frame.

Details

The PR's own second test records the foldable geometry: the inner-panel window is 951x669 inside a 466x678 application frame (testAnInnerPanelAlertIsPlacedInItsWindowNotTheApplicationFrame, lines 358-360). That window's center is (475.5, 334.5), and isPlaced compares exactly the center (hostWindow.contains(CGPoint(x: frame.midX, y: frame.midY)), RunnerTests+SystemModal.swift:167-170). With x = 475.5 > 466, isPlaced returns false for that window frame inside that application frame.

So for source == .dismissPopup — the only source that matches a window itself (line 66) — a popup window that lives in the inner-panel window of the shape this PR just documented is refused, and observeAlert reports .absent for a popup that is on screen. That is the same failure #​4001 fixed for SpringBoard alerts by comparing an alert against its hosting window instead of the application frame (the comment at RunnerTests+SystemModal.swift:165-166: "the application frame names only one of them"), now reintroduced one level up for the popup source.

The case is partly masked in handleAlert: an .absent verification is answered as ok (alertVerificationResponse maps .disappeared to ok), so the visible symptom is a confirmed answer that was never proved. The direct cost is the guard in observeAlert: if both an inner-panel popup window and another marked window are present, candidates.count <= 1 fails (line 45) and the observation stays unavailable, so a genuine dismissal is reported as ALERT_CONFIRMATION_UNAVAILABLE instead of a confirmed answer.

persona: swift-ios

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · Off-screen dismiss-popup windows are rejected only at the level the match happens; a marked window nested inside an off-screen window is still accepted

alertSnapshots now checks a matching window against the viewport it was handed (line 68), which fixes a marked top-level window that sits off screen. The box it then hands to children (line 70) is the window's own frame unconditionally, without any check that this window is itself placed in viewport. That is required for the foldable case (the 951x669 inner-panel window is not placed in the 466x678 application frame, and the new testAnInnerPanelAlertIsPlacedInItsWindowNotTheApplicationFrame depends on it), but it means the new rejection is depth-sensitive: for source == .dismissPopup an off-screen window W1 (say x = 1000) that hosts another window W2 carrying the "dismiss popup" marker is accepted, because W2 is matched against W1's own frame and isPlaced compares only W2's centre with W1's frame, which trivially contains it. The runner then resolves an alert on a window that is off screen — the exact condition this PR set out to reject. The invariant the code now relies on is silently "a matching .window snapshot is always a direct child of the box it is measured against"; nothing in the type, the recursion or the tests enforces it, and the new fixture test only covers the one-level case (testDismissPopupWindowIsPlacedInTheBoxItSitsIn). Suggested action: either carry the placed-ness of each window ancestor down the recursion (e.g. keep an onScreenBox that a window may replace only while every enclosing box it sits in is placed), or add a fixture for a marked window nested inside an off-screen window so the accepted outcome is at least a deliberate, tested one.

Suggested change

Decide whether a marked window nested inside an off-screen window may be answered, and encode it: either gate a window's right to become the child box on it being placed in the box it sits in (without breaking the unplaced inner-panel foldable window) or add a fixture test for a marked window inside an off-screen window.

Details

persona: senior-developer

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Nit · childViewport shadows the viewport parameter the line above already reads

In alertSnapshots, the new childViewport local differs from the existing viewport parameter by one word and one branch, so a reader has to re-read both isPlaced(frame, in: viewport) and alertSnapshots(in: $0, source: source, viewport: childViewport) to tell which box each call uses. Naming it after the role it plays for the recursion (e.g. hostWindow, the name the predecessor used for this same expression, or boxForChildren) keeps the two boxes distinct at a glance. Behavior is correct either way; this is naming only.

Suggested change

Rename the new childViewport local to a name that says whose box it is (the window hosting the children), so it is not confused with the viewport parameter used one line earlier for the placement check.

Details

persona: maintainability

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

// 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
Comment thread
thymikee marked this conversation as resolved.
Resolved
return snapshot.children.flatMap { alertSnapshots(in: $0, source: source, viewport: childViewport) }

Check warning on line 71 in apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift

View check run for this annotation

apex-sentinel-staging / Apex Sentinel

minor: Nested dismiss-popup window on a foldable's inner panel is now rejected as off screen

The new placement check tests a window against the box it sits in, and at the observation root that box is the application frame: `observeAlert` calls `alertSnapshots(in: snapshot, source: source, viewport: snapshot.frame)` (RunnerTests+AlertObservation.swift:44), where `snapshot` is `ownerApp.snapshot()`, an `.application` node, so the children — the app's windows — are matched against the application frame. The PR's own second test records the foldable geometry: the inner-panel window is 951x669 inside a 466x678 application frame (`testAnInnerPanelAlertIsPlacedInItsWindowNotTheApplicationFrame`, lines 358-360). That window's center is (475.5, 334.5), and `isPlaced` compares exactly the center (`hostWindow.contains(CGPoint(x: frame.midX, y: frame.midY))`, RunnerTests+SystemModal.swift:167-170). With `x = 475.5 > 466`, `isPlaced` returns false for that window frame inside that application frame. So for `source == .dismissPopup` — the only source that matches a window itself (line 66) — a popup window that lives in the inner-panel window of the shape this PR just documented is refused, and `observeAlert` reports `.absent` for a popup that is on screen. That is the same failure #​4001 fixed for SpringBoard alerts by comparing an alert against its hosting window instead of the application frame (the comment at RunnerTests+SystemModal.swift:165-166: "the application frame names only one of them"), now reintroduced one level up for the popup source. The case is partly masked in `handleAlert`: an `.absent` verification is answered as `ok` (`alertVerificationResponse` maps `.disappeared` to ok), so the visible symptom is a confirmed answer that was never proved. The direct cost is the guard in `observeAlert`: if both an inner-panel popup window and another marked window are present, `candidates.count <= 1` fails (line 45) and the observation stays `unavailable`, so a genuine dismissal is reported as `ALERT_CONFIRMATION_UNAVAILABLE` instead of a confirmed answer.

Check warning on line 71 in apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift

View check run for this annotation

apex-sentinel-staging / Apex Sentinel

minor: Off-screen dismiss-popup windows are rejected only at the level the match happens; a marked window nested inside an off-screen window is still accepted

`alertSnapshots` now checks a matching window against the `viewport` it was handed (line 68), which fixes a marked top-level window that sits off screen. The box it then hands to children (line 70) is the window's own frame unconditionally, without any check that this window is itself placed in `viewport`. That is required for the foldable case (the 951x669 inner-panel window is not placed in the 466x678 application frame, and the new `testAnInnerPanelAlertIsPlacedInItsWindowNotTheApplicationFrame` depends on it), but it means the new rejection is depth-sensitive: for `source == .dismissPopup` an off-screen window W1 (say x = 1000) that hosts another window W2 carrying the "dismiss popup" marker is accepted, because W2 is matched against W1's own frame and `isPlaced` compares only W2's centre with W1's frame, which trivially contains it. The runner then resolves an alert on a window that is off screen — the exact condition this PR set out to reject. The invariant the code now relies on is silently "a matching `.window` snapshot is always a direct child of the box it is measured against"; nothing in the type, the recursion or the tests enforces it, and the new fixture test only covers the one-level case (`testDismissPopupWindowIsPlacedInTheBoxItSitsIn`). Suggested action: either carry the placed-ness of each window ancestor down the recursion (e.g. keep an `onScreenBox` that a window may replace only while every enclosing box it sits in is placed), or add a fixture for a marked window nested inside an off-screen window so the accepted outcome is at least a deliberate, tested one.

Check notice on line 71 in apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift

View check run for this annotation

apex-sentinel-staging / Apex Sentinel

nit: `childViewport` shadows the `viewport` parameter the line above already reads

In `alertSnapshots`, the new `childViewport` local differs from the existing `viewport` parameter by one word and one branch, so a reader has to re-read both `isPlaced(frame, in: viewport)` and `alertSnapshots(in: $0, source: source, viewport: childViewport)` to tell which box each call uses. Naming it after the role it plays for the recursion (e.g. `hostWindow`, the name the predecessor used for this same expression, or `boxForChildren`) keeps the two boxes distinct at a glance. Behavior is correct either way; this is naming only.
}

private func containsDismissPopupMarker(_ snapshot: XCUIElementSnapshot) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,39 @@
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(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Nit · New unreadable-host-window test relies on XCTExpectFailure absorbing a second, unrelated XCTest failure

testAlertActivationRefusesAnUnreadableHostWindowWithoutTapping points alert.window at app.windows.matching(identifier: "agent-device-missing-window").firstMatch, an element that does not exist in the fixture. activateAlertButton then reads window.frame (RunnerTests+Alert.swift:177) and button.frame reads and the coordinate-context read on a non-existent element raise XCTFailure issues (or, depending on the SDK, a caught XCUIElementQueryError), which is why the test needs XCTExpectFailure at all. Its issueMatcher keeps only issues whose compactDescription contains "agent-device-missing-window", so any additional issue raised along that path — a differently-worded frame-read failure on the same missing window, or one from the tap-synthesis path — fails the test on a runner whose diagnostics differ from the one this was validated on, while the assertion actually under test (outcome == .unsupported) is unaffected by the wording.

Suggested change
let alert = RunnerAlert(
let frame = button.frame
let options = XCTExpectedFailure.Options()
options.issueMatcher = { $0.compactDescription.contains("agent-device") }
options.isStrict = false
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)
}

Suggested change

Keep the refusal assertion, and make the unreadable window a value the test controls (for example a stub or override that returns CGRect.null for the window frame) so no XCTest issue has to be absorbed by XCTExpectFailure.

Details

The behavior the test pins (a refused tap when the host window cannot be read, so the tap is not routed through the owner app's first window on a foldable) is worth keeping; only the expected-failure matching is fragile.

Also raised here

Also raised at this location by senior-developer: New test matches an XCTest issue by error text rather than by a typed reason — options.issueMatcher = { $0.compactDescription.contains("agent-device-missing-window") } accepts the expected failure by substring of the rendered issue text. AGENTS.md says: "Use typed reasons and details for behavior. Do not match error text." Two consequences on this line: the test still passes if XCTest changes the wording of its no-match failure as long as the identifier stays in it, and any other issue that merely mentions that identifier (for example from a different read inside activateAlertButton) would satisfy the expectation, so a passing test would not prove the refusal came from the window read the test names. RunnerTests+TextInputProbeTests.testTextInputProbeContainmentExcludesRequiredReadsAndLaterIssues shows a stricter shape — matching issue.type and the full compactDescription, and counting how many issues were absorbed — which would say here that exactly one issue, of the expected type, was consumed.

persona: swift-ios, senior-developer

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

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)
}

Check notice on line 132 in apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertObservationTests.swift

View check run for this annotation

apex-sentinel-staging / Apex Sentinel

nit: New unreadable-host-window test relies on XCTExpectFailure absorbing a second, unrelated XCTest failure

`testAlertActivationRefusesAnUnreadableHostWindowWithoutTapping` points `alert.window` at `app.windows.matching(identifier: "agent-device-missing-window").firstMatch`, an element that does not exist in the fixture. `activateAlertButton` then reads `window.frame` (RunnerTests+Alert.swift:177) and `button.frame` reads and the coordinate-context read on a non-existent element raise XCTFailure issues (or, depending on the SDK, a caught `XCUIElementQueryError`), which is why the test needs `XCTExpectFailure` at all. Its `issueMatcher` keeps only issues whose `compactDescription` contains "agent-device-missing-window", so any additional issue raised along that path — a differently-worded frame-read failure on the same missing window, or one from the tap-synthesis path — fails the test on a runner whose diagnostics differ from the one this was validated on, while the assertion actually under test (`outcome == .unsupported`) is unaffected by the wording. The behavior the test pins (a refused tap when the host window cannot be read, so the tap is not routed through the owner app's first window on a foldable) is worth keeping; only the expected-failure matching is fragile. ### Also raised here Also raised at this location by senior-developer: New test matches an XCTest issue by error text rather than by a typed reason — `options.issueMatcher = { $0.compactDescription.contains("agent-device-missing-window") }` accepts the expected failure by substring of the rendered issue text. AGENTS.md says: "Use typed reasons and details for behavior. Do not match error text." Two consequences on this line: the test still passes if XCTest changes the wording of its no-match failure as long as the identifier stays in it, and any _other_ issue that merely mentions that identifier (for example from a different read inside `activateAlertButton`) would satisfy the expectation, so a passing test would not prove the refusal came from the window read the test names. \`RunnerTests+TextInputProb…

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"]
Expand Down Expand Up @@ -307,5 +340,25 @@
)
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)
}

@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
}
Loading