Skip to content

Commit 483a130

Browse files
thymikeeclaude
andauthored
test(ios): hold the fill read-count pin to the route it measures (#3909)
* test(ios): hold the fill read-count pin to the route it measures The pin allowed 18 value reads for a fill whose focus tap raises the software keyboard, calling the extra read headroom. One read costs two counted queries, so the headroom was one query, and a keyboard that arrives before the field reports focus legitimately makes 19. Skip the pin unless runner.log records input-reports-keyboard-focus, and assert the 17 that route makes. Follow-up to #3906. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * test(ios): fail the fill pin on a missing focus line and skip multi-poll focus Address the review of #3909. The focus step's log line now carries its poll count, and the log marker and evidence name are shared with the test, so a rename fails the test instead of skipping it. The pin skips unless the first poll confirmed focus, where a second poll adds two queries by design. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
1 parent 6ea9f81 commit 483a130

3 files changed

Lines changed: 49 additions & 11 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,16 @@ extension RunnerTests {
325325
/// The app-wide keyboard-focus query answered with the tapped input.
326326
case focusQueryMatchesInput
327327

328+
/// The log line that records the evidence and the number of focus polls: `logMarker`, the name, then `polls=<n>`.
329+
static let logMarker = "AGENT_DEVICE_RUNNER_TEXT_ENTRY_FOCUS evidence="
330+
static let inputReportsKeyboardFocusName = "input-reports-keyboard-focus"
331+
328332
/// The name `runner.log` records.
329333
var name: String {
330334
switch self {
331335
case .focusEngine: return "focus-engine"
332336
case .focusedInput: return "focused-input"
333-
case .inputReportsKeyboardFocus: return "input-reports-keyboard-focus"
337+
case .inputReportsKeyboardFocus: return Self.inputReportsKeyboardFocusName
334338
case .keyboardAppeared: return "keyboard-appeared"
335339
case .focusQueryMatchesInput: return "focus-query-matches-input"
336340
}
@@ -341,6 +345,8 @@ extension RunnerTests {
341345
let element: XCUIElement?
342346
/// Nil when nothing confirmed focus before the focus timeout.
343347
let evidence: TextEntryFocusEvidence?
348+
/// The focus polls that ran, which is 1 when the first poll confirmed focus.
349+
let polls: Int
344350

345351
var focusConfirmed: Bool { evidence != nil }
346352
}

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ extension RunnerTests {
6464
keyboardVisibleBeforeTap: Bool? = nil
6565
) -> TextEntryStabilization {
6666
#if os(tvOS)
67-
return TextEntryStabilization(element: target, evidence: .focusEngine)
67+
return TextEntryStabilization(element: target, evidence: .focusEngine, polls: 0)
6868
#else
6969
let keyboardVisibleAtEntry = keyboardVisibleBeforeTap ?? isKeyboardVisible(app: app)
7070
let deadline = Date().addingTimeInterval(TextEntryTiming.focusTimeout)
71+
var polls = 0
7172
while Date() < deadline {
73+
polls += 1
7274
if let focused = focusedTextInput(app: app) {
73-
return TextEntryStabilization(element: focused, evidence: .focusedInput)
75+
return TextEntryStabilization(element: focused, evidence: .focusedInput, polls: polls)
7476
}
7577
#if os(iOS)
7678
// The tapped input's own read comes before the keyboard. While a software keyboard is
@@ -79,23 +81,23 @@ extension RunnerTests {
7981
// took focus.
8082
let read = target.flatMap(ResolvedTextEntryInput.init(reading:))
8183
if let read, let snapshot = read.snapshot, snapshotHasKeyboardFocus(snapshot) {
82-
return TextEntryStabilization(element: read.element, evidence: .inputReportsKeyboardFocus(read))
84+
return TextEntryStabilization(element: read.element, evidence: .inputReportsKeyboardFocus(read), polls: polls)
8385
}
8486
#endif
8587
// focusedTextInput is intentionally nil on iOS; the keyboard transitioning to visible after
8688
// our tap is also a focus-moved signal. Don't fast-path when it was already up.
8789
if keyboardBecameVisible(app: app, wasVisibleAtEntry: keyboardVisibleAtEntry) {
88-
return TextEntryStabilization(element: target, evidence: .keyboardAppeared)
90+
return TextEntryStabilization(element: target, evidence: .keyboardAppeared, polls: polls)
8991
}
9092
#if os(iOS)
9193
// The read came before the keyboard query, so it is not handed on as the post-focus read.
9294
if let read, keyboardFocusConfirmed(app: app, read: read) {
93-
return TextEntryStabilization(element: target, evidence: .focusQueryMatchesInput)
95+
return TextEntryStabilization(element: target, evidence: .focusQueryMatchesInput, polls: polls)
9496
}
9597
#endif
9698
sleepFor(TextEntryTiming.pollInterval)
9799
}
98-
return TextEntryStabilization(element: target, evidence: nil)
100+
return TextEntryStabilization(element: target, evidence: nil, polls: polls)
99101
#endif
100102
}
101103

@@ -148,7 +150,12 @@ extension RunnerTests {
148150
target: target,
149151
keyboardVisibleBeforeTap: keyboardVisibleBeforeTap
150152
)
151-
NSLog("AGENT_DEVICE_RUNNER_TEXT_ENTRY_FOCUS evidence=%@", stabilized.evidence?.name ?? "none")
153+
NSLog(
154+
"%@%@ polls=%d",
155+
TextEntryFocusEvidence.logMarker,
156+
stabilized.evidence?.name ?? "none",
157+
stabilized.polls
158+
)
152159
if case .inputReportsKeyboardFocus(let read) = stabilized.evidence {
153160
return focusedTextEntryTarget(read.element, read: read, requestedPoint: requestedPoint)
154161
}

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import OSLog
12
import XCTest
23

34
extension RunnerTests {
@@ -119,8 +120,11 @@ extension RunnerTests {
119120
/// A fill whose focus tap raises the software keyboard hands the read that confirmed focus to the
120121
/// entry as its first read. The fixture counts queries as in
121122
/// `testFillReadsEachResolvedFieldThroughOneSnapshot`: this fill made 17, and 19 when the focus step
122-
/// or the entry read the input again. The one read of headroom covers a keyboard that arrives
123-
/// before the field reports focus.
123+
/// or the entry read the input again. A read costs two queries. A keyboard that arrives before the
124+
/// field reports focus ends the poll without handing its read on, so the entry reads the input
125+
/// again and the fill makes 19 by design, and each poll before the last adds two more queries. The
126+
/// test skips unless the focus step's log line records `input-reports-keyboard-focus` on its first
127+
/// poll, so its budget holds only for the route it is about.
124128
@MainActor
125129
func testFillThatRaisesTheSoftwareKeyboardReusesTheReadThatConfirmedFocus() throws {
126130
app.launchArguments = [
@@ -141,6 +145,7 @@ extension RunnerTests {
141145
)
142146

143147
let readsBefore = try XCTUnwrap(Int(valueReads.label))
148+
let fillStartedAt = Date()
144149
let response = executeTypeCommand(activeApp: app, command: fill)
145150
let readsAfter = try XCTUnwrap(Int(valueReads.label))
146151

@@ -151,7 +156,27 @@ extension RunnerTests {
151156
XCTAssertTrue(response.ok, String(describing: response.error))
152157
XCTAssertEqual(response.data?.textEntryRoute, "xctest-element")
153158
XCTAssertEqual(valueReads.value as? String, "hello")
154-
XCTAssertLessThanOrEqual(readsAfter - readsBefore, 18)
159+
let focus = try XCTUnwrap(loggedTextEntryFocus(since: fillStartedAt), "the focus step logged no evidence line")
160+
try XCTSkipUnless(
161+
focus.evidence == TextEntryFocusEvidence.inputReportsKeyboardFocusName && focus.polls == 1,
162+
"focus was confirmed by \(focus.evidence) after \(focus.polls) polls, which reads the input more than once by design"
163+
)
164+
XCTAssertLessThanOrEqual(readsAfter - readsBefore, 17)
165+
}
166+
167+
/// The last evidence line the focus step logged after `start`, read from this process's unified log.
168+
private func loggedTextEntryFocus(since start: Date) throws -> (evidence: String, polls: Int)? {
169+
let store = try OSLogStore(scope: .currentProcessIdentifier)
170+
let marker = TextEntryFocusEvidence.logMarker
171+
return try store.getEntries(at: store.position(date: start))
172+
.compactMap { ($0 as? OSLogEntryLog)?.composedMessage }
173+
.compactMap { message -> (evidence: String, polls: Int)? in
174+
guard let range = message.range(of: marker) else { return nil }
175+
let fields = message[range.upperBound...].components(separatedBy: " polls=")
176+
guard fields.count == 2, let polls = Int(fields[1]) else { return nil }
177+
return (fields[0], polls)
178+
}
179+
.last
155180
}
156181
#endif
157182
}

0 commit comments

Comments
 (0)