From 273c9a9d996af367847391d59068aba3fc7e8790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 19 Nov 2026 17:28:13 +0100 Subject: [PATCH] perf(ios): reuse the resolved window for a fill's content translation A coordinate replacement resolves the app's window for its tap context, then liveContentTranslation queried the windows again. The translation now comes from the context's own resolved window. A context without one (sole-screen frame, unreadable tree) or booked on a lit panel still reads fresh, so the off-origin window case from #3899 keeps its proof. Co-Authored-By: Claude Opus 5.5 --- .../RunnerTests+TextEntryFocus.swift | 2 +- .../RunnerTests+TextInputProbe.swift | 12 ++++++++++++ .../RunnerTests+TypeExecution.swift | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift index 90af951bb8..34d5e57b3e 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift @@ -115,7 +115,7 @@ extension RunnerTests { reusingFocusedInput: Bool = false, tapContext: SynthesizedCoordinateContext? = nil ) throws -> TextEntryTarget { - let contentTranslation = liveContentTranslation(app: app) + let contentTranslation = liveContentTranslation(app: app, reusing: tapContext) guard let x, let y else { let softwareKeyboardVisible = isKeyboardVisible(app: app) if !softwareKeyboardVisible, let rememberedTarget = rememberedTextEntryTarget(contentTranslation: contentTranslation) { diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputProbe.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputProbe.swift index f229bebe22..c4da84cf96 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputProbe.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputProbe.swift @@ -232,4 +232,16 @@ extension RunnerTests { guard case .success(let translation) = read else { return .unknown } return translation } + + /// The content vector of the window `context` already resolved for this command, so a text entry + /// does not query the windows twice. A context without its own resolved window (a sole-screen + /// frame, an unreadable tree) or one booked on a lit panel proves no window origin, so it reads. + func liveContentTranslation(app: XCUIApplication, reusing context: SynthesizedCoordinateContext?) -> TextEntryContentTranslation { + guard let context, context.resolvedWindow != nil, !context.treeUnreadable, requestLitPanel == nil else { + return liveContentTranslation(app: app) + } + let window = context.geometry.windowOnScreen.rect + return SnapshotContentTranslation.offset(reportedBox: CGRect(origin: .zero, size: window.size), viewportBox: window) + .map { .known($0) } ?? TextEntryContentTranslation.none + } } diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TypeExecution.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TypeExecution.swift index aaf9af4cc6..02c65d0afc 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TypeExecution.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TypeExecution.swift @@ -58,7 +58,7 @@ extension RunnerTests { // A replacement with no input at the point has nothing to bind to: its clear and its typed // text would reach the app-level first responder, so an empty point and a lookup that cannot // answer both refuse here, each under its own reason. - let contentTranslation = liveContentTranslation(app: activeApp) + let contentTranslation = liveContentTranslation(app: activeApp, reusing: treeContext) let inputAtPoint: TextInputAtPoint let inputsAtPoint: [ResolvedTextEntryInput] switch try coordinateTapTextInputIdentityAt(app: activeApp, x: x, y: y, contentTranslation: contentTranslation) {