Skip to content

Commit 00ef131

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

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

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

Lines changed: 23 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,10 @@ 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. 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.
124127
@MainActor
125128
func testFillThatRaisesTheSoftwareKeyboardReusesTheReadThatConfirmedFocus() throws {
126129
app.launchArguments = [
@@ -141,6 +144,7 @@ extension RunnerTests {
141144
)
142145

143146
let readsBefore = try XCTUnwrap(Int(valueReads.label))
147+
let fillStartedAt = Date()
144148
let response = executeTypeCommand(activeApp: app, command: fill)
145149
let readsAfter = try XCTUnwrap(Int(valueReads.label))
146150

@@ -151,7 +155,23 @@ extension RunnerTests {
151155
XCTAssertTrue(response.ok, String(describing: response.error))
152156
XCTAssertEqual(response.data?.textEntryRoute, "xctest-element")
153157
XCTAssertEqual(valueReads.value as? String, "hello")
154-
XCTAssertLessThanOrEqual(readsAfter - readsBefore, 18)
158+
let evidence = try loggedTextEntryFocusEvidence(since: fillStartedAt)
159+
try XCTSkipUnless(
160+
evidence == "input-reports-keyboard-focus",
161+
"focus was confirmed by \(evidence ?? "nothing"), which reads the input again by design"
162+
)
163+
XCTAssertLessThanOrEqual(readsAfter - readsBefore, 17)
164+
}
165+
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? {
169+
let store = try OSLogStore(scope: .currentProcessIdentifier)
170+
let marker = "AGENT_DEVICE_RUNNER_TEXT_ENTRY_FOCUS evidence="
171+
return try store.getEntries(at: store.position(date: start))
172+
.compactMap { ($0 as? OSLogEntryLog)?.composedMessage }
173+
.compactMap { message in message.range(of: marker).map { String(message[$0.upperBound...]) } }
174+
.last
155175
}
156176
#endif
157177
}

0 commit comments

Comments
 (0)