Skip to content

Commit 29243b0

Browse files
committed
test(ios): pin the placeholder fix at the boundary it actually lives on
Review [P1]: testValueEqualToThePlaceholder… injected an observe closure that already returned "0.00", so it never supplied the normalized "" that causes the failure. The raw-value short-circuit lived in the production observe closure, which that test bypassed entirely — reverting the fix left it green. The raw-exact/normalized-prefix choice moves into commitObservation, and the test drives it with (raw: "0.00", normalized: "", expected: "0.00"). Reverting commitObservation to always return the normalized reading now fails the exact-match assertion. normalizedValue is a closure rather than a value so an exact match still costs one accessibility read instead of two, on a path that polls every 20ms for up to three seconds; a second test pins that laziness. The old test is deleted rather than kept: its remaining assertion (an exact match settles without polling) is already covered by testSynthesizedCommitStopsAtTheFirstSettledObservation. Refs #1874
1 parent e479065 commit 29243b0

2 files changed

Lines changed: 64 additions & 22 deletions

File tree

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,26 @@ extension RunnerTests {
222222
}
223223
}
224224

225+
/// Which reading of the field the commit wait compares against.
226+
///
227+
/// The normalized read maps a value equal to the field's placeholder to "" (see
228+
/// `isPlaceholderValue`), and "" is a prefix of every expected value — so a commit that happens
229+
/// to equal the placeholder (`type "0.00"` into a field placeheld "0.00") reads as still pending
230+
/// and is condemned at the deadline despite having landed immediately. An exact raw match wins
231+
/// for that reason. Everything else keeps the normalized reading, which is what makes a real
232+
/// placeholder read as empty during the prefix walk.
233+
///
234+
/// `normalizedValue` is a closure so an exact match costs one accessibility read rather than
235+
/// two, on a path that polls every 20ms for up to three seconds.
236+
static func commitObservation(
237+
rawValue: String?,
238+
expectedText: String,
239+
normalizedValue: () -> String?
240+
) -> String? {
241+
if rawValue == expectedText { return rawValue }
242+
return normalizedValue()
243+
}
244+
225245
/// The command-level consequence of a commit wait. `.unobservable` is not a failure: there was
226246
/// no baseline to compare against, which is the pre-existing contract for submit-key text and
227247
/// unreadable fields, not evidence that anything went wrong.
@@ -262,14 +282,11 @@ extension RunnerTests {
262282
isExpired: { Date() >= deadline },
263283
observe: {
264284
let element = resolveTextEntryElement(app: app, target: target)
265-
// `treatingPlaceholderAsEmpty` maps a value equal to the field's placeholder to "", which
266-
// is a prefix of every expected value. Typing a string that happens to equal the
267-
// placeholder (`type "0.00"` into a field placeheld "0.00") would then read as pending
268-
// forever and be condemned at the deadline, having in fact committed immediately. The
269-
// exact raw match settles that case; the normalized read still drives the prefix walk,
270-
// where placeholder-as-empty is the reading we want.
271-
if editableTextValue(for: element) == expectedText { return expectedText }
272-
return editableTextValue(for: element, treatingPlaceholderAsEmpty: true)
285+
return Self.commitObservation(
286+
rawValue: editableTextValue(for: element),
287+
expectedText: expectedText,
288+
normalizedValue: { editableTextValue(for: element, treatingPlaceholderAsEmpty: true) }
289+
)
273290
},
274291
waitForNextObservation: { sleepFor(TextEntryTiming.pollInterval) }
275292
)

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

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,47 @@ extension RunnerTests {
148148
XCTAssertEqual(outcome, .settled)
149149
}
150150

151-
// Adversarial-review finding: `treatingPlaceholderAsEmpty` maps a value equal to the field's
152-
// placeholder to "", a prefix of everything. Typing a string that equals the placeholder
153-
// committed instantly yet read as pending until the deadline. The observation now settles on an
154-
// exact raw match, so this is the wait's view of that field.
155-
func testValueEqualToThePlaceholderSettlesInsteadOfStallingUntilTheDeadline() {
156-
var polls = 0
157-
let outcome = Self.awaitSynthesizedCommitOutcome(
151+
// The production normalization boundary. A committed value equal to the field's placeholder
152+
// normalizes to "", a prefix of everything, so the wait read it as pending until the deadline
153+
// and failed a `type` that had landed immediately. Reverting `commitObservation` to always
154+
// return the normalized reading makes the first case return "" and this test go red — which the
155+
// earlier version of this test did NOT do, because it injected an already-resolved observation.
156+
func testCommitObservationPrefersAnExactRawMatchOverPlaceholderNormalization() {
157+
XCTAssertEqual(
158+
Self.commitObservation(rawValue: "0.00", expectedText: "0.00", normalizedValue: { "" }),
159+
"0.00",
160+
"a committed value equal to the placeholder must not be read as empty"
161+
)
162+
// Everything that is not an exact match keeps the normalized reading, so a field genuinely
163+
// showing its placeholder still reads as empty and the prefix walk still works.
164+
XCTAssertEqual(
165+
Self.commitObservation(rawValue: "0.00", expectedText: "0.005", normalizedValue: { "" }),
166+
""
167+
)
168+
XCTAssertEqual(
169+
Self.commitObservation(
170+
rawValue: "hardware-",
171+
expectedText: "hardware-keyboard",
172+
normalizedValue: { "hardware-" }
173+
),
174+
"hardware-"
175+
)
176+
XCTAssertNil(Self.commitObservation(rawValue: nil, expectedText: "x", normalizedValue: { nil }))
177+
}
178+
179+
func testCommitObservationDoesNotPayForASecondReadOnAnExactMatch() {
180+
var normalizedReads = 0
181+
_ = Self.commitObservation(
182+
rawValue: "0.00",
158183
expectedText: "0.00",
159-
isExpired: { polls >= 4 },
160-
// What the fixed observe closure yields once the raw value matches: the exact text, not the
161-
// placeholder-normalized "" that the prefix walk would treat as still pending.
162-
observe: { "0.00" },
163-
waitForNextObservation: { polls += 1 }
184+
normalizedValue: {
185+
normalizedReads += 1
186+
return ""
187+
}
164188
)
165-
XCTAssertEqual(outcome, .settled)
166-
XCTAssertEqual(polls, 0, "an exact match must not poll at all")
189+
// The wait polls every 20ms for up to three seconds; the exact-match path must stay one
190+
// accessibility read, which is why the normalized reading is a closure.
191+
XCTAssertEqual(normalizedReads, 0)
167192
}
168193

169194
// The mapping the command actually refuses on. `.unobservable` must stay a success: it is the

0 commit comments

Comments
 (0)