Skip to content

Commit f83833c

Browse files
thymikeeclaude
andcommitted
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]>
1 parent 00ef131 commit f83833c

3 files changed

Lines changed: 36 additions & 18 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: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ extension RunnerTests {
122122
/// `testFillReadsEachResolvedFieldThroughOneSnapshot`: this fill made 17, and 19 when the focus step
123123
/// or the entry read the input again. A read costs two queries. A keyboard that arrives before the
124124
/// 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. The test skips when the log does not record
126-
/// `input-reports-keyboard-focus`, so its budget holds only for the route it is about.
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.
127128
@MainActor
128129
func testFillThatRaisesTheSoftwareKeyboardReusesTheReadThatConfirmedFocus() throws {
129130
app.launchArguments = [
@@ -155,22 +156,26 @@ extension RunnerTests {
155156
XCTAssertTrue(response.ok, String(describing: response.error))
156157
XCTAssertEqual(response.data?.textEntryRoute, "xctest-element")
157158
XCTAssertEqual(valueReads.value as? String, "hello")
158-
let evidence = try loggedTextEntryFocusEvidence(since: fillStartedAt)
159+
let focus = try XCTUnwrap(loggedTextEntryFocus(since: fillStartedAt), "the focus step logged no evidence line")
159160
try XCTSkipUnless(
160-
evidence == "input-reports-keyboard-focus",
161-
"focus was confirmed by \(evidence ?? "nothing"), which reads the input again by design"
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"
162163
)
163164
XCTAssertLessThanOrEqual(readsAfter - readsBefore, 17)
164165
}
165166

166-
/// The evidence name the focus step logged to `runner.log` after `start`, read from this
167-
/// process's own log.
168-
private func loggedTextEntryFocusEvidence(since start: Date) throws -> String? {
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)? {
169169
let store = try OSLogStore(scope: .currentProcessIdentifier)
170-
let marker = "AGENT_DEVICE_RUNNER_TEXT_ENTRY_FOCUS evidence="
170+
let marker = TextEntryFocusEvidence.logMarker
171171
return try store.getEntries(at: store.position(date: start))
172172
.compactMap { ($0 as? OSLogEntryLog)?.composedMessage }
173-
.compactMap { message in message.range(of: marker).map { String(message[$0.upperBound...]) } }
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+
}
174179
.last
175180
}
176181
#endif

0 commit comments

Comments
 (0)