Skip to content

Commit 7cedfc5

Browse files
committed
fix(ios): never treat placeholder equality as commit evidence
Review [P1]: an empty text field renders its placeholder AS its accessibility value, which is why editableTextValue(treatingPlaceholderAsEmpty:) classifies that value as empty. The previous revision's raw-exact short-circuit therefore matched BEFORE anything committed whenever the requested text was the placeholder: `type "0.00"` into a field placeheld "0.00" settled on the first read and returned ok with zero characters delivered — reintroducing the success-misdescribes-the-device failure this PR exists to remove. The state is structurally indeterminate. element.value is identical whether the placeholder is rendering or the committed text happens to equal it, and placeholderValue does not disambiguate, so no read resolves it and waiting the deadline out discovers nothing. placeholderMakesCommitUnobservable detects it up front and reports the commit unobserved, which the caller refuses on. commitObservation is deleted rather than narrowed: the raw match was only ever consulted in this exact case, and in this exact case it is not evidence. The failure message drops its deadline reference — this refusal never waits. Refs #1874
1 parent 0592cf4 commit 7cedfc5

4 files changed

Lines changed: 55 additions & 59 deletions

File tree

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

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

225-
/// Which reading of the field the commit wait compares against.
225+
/// Whether the field's placeholder makes this commit impossible to observe.
226226
///
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.
227+
/// An empty text field renders its placeholder AS its accessibility value, and
228+
/// `editableTextValue(treatingPlaceholderAsEmpty:)` classifies that value as empty for exactly
229+
/// that reason. When the expected final text IS the placeholder, both states — nothing
230+
/// committed, and everything committed — produce the identical read, before and after dispatch.
231+
/// Raw equality is therefore not evidence: accepting it would report success over a field that
232+
/// may have received nothing, which is the failure this whole wait exists to remove.
233233
///
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()
234+
/// No read can resolve the ambiguity, so the wait does not spend its deadline discovering that.
235+
/// It reports the commit unobserved immediately, which is what the caller refuses on.
236+
static func placeholderMakesCommitUnobservable(
237+
placeholder: String?,
238+
expectedText: String
239+
) -> Bool {
240+
guard let placeholder else { return false }
241+
let trimmedPlaceholder = placeholder.trimmingCharacters(in: .whitespacesAndNewlines)
242+
guard !trimmedPlaceholder.isEmpty else { return false }
243+
return trimmedPlaceholder == expectedText.trimmingCharacters(in: .whitespacesAndNewlines)
243244
}
244245

245246
/// The command-level consequence of a commit wait. `.unobservable` is not a failure: there was
@@ -276,16 +277,20 @@ extension RunnerTests {
276277
return .unobservable
277278
}
278279
let expectedText = textBefore + typedText
280+
if Self.placeholderMakesCommitUnobservable(
281+
placeholder: resolveTextEntryElement(app: app, target: target)?.placeholderValue,
282+
expectedText: expectedText
283+
) {
284+
return .notObserved
285+
}
279286
let deadline = Date().addingTimeInterval(TextEntryTiming.synthesizedCommitTimeout)
280287
return Self.awaitSynthesizedCommitOutcome(
281288
expectedText: expectedText,
282289
isExpired: { Date() >= deadline },
283290
observe: {
284-
let element = resolveTextEntryElement(app: app, target: target)
285-
return Self.commitObservation(
286-
rawValue: editableTextValue(for: element),
287-
expectedText: expectedText,
288-
normalizedValue: { editableTextValue(for: element, treatingPlaceholderAsEmpty: true) }
291+
editableTextValue(
292+
for: resolveTextEntryElement(app: app, target: target),
293+
treatingPlaceholderAsEmpty: true
289294
)
290295
},
291296
waitForNextObservation: { sleepFor(TextEntryTiming.pollInterval) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extension RunnerTests {
1616
case .synthesisUnavailable:
1717
return "Reliable text synthesis is unavailable while the software keyboard is hidden."
1818
case .commitNotObserved:
19-
return "The runner could not confirm the typed text committed before its deadline."
19+
return "The runner could not confirm the typed text reached the field."
2020
}
2121
}
2222

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

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

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-
""
151+
// Review [P1]: an empty field renders its placeholder AS its accessibility value, so when the
152+
// requested text IS the placeholder, the raw read equals the expected text BEFORE anything
153+
// commits. An earlier revision treated that equality as evidence and reported ok with zero
154+
// characters delivered — the success-misdescribes-the-device failure this PR removes. The state
155+
// is structurally indeterminate: no read distinguishes "placeholder rendering" from "committed
156+
// value", so it must not be a success.
157+
func testTextEqualToThePlaceholderIsNeverEvidenceOfACommit() {
158+
XCTAssertTrue(
159+
Self.placeholderMakesCommitUnobservable(placeholder: "0.00", expectedText: "0.00"),
160+
"the requested text equals the placeholder — a raw match proves nothing committed"
167161
)
168-
XCTAssertEqual(
169-
Self.commitObservation(
170-
rawValue: "hardware-",
171-
expectedText: "hardware-keyboard",
172-
normalizedValue: { "hardware-" }
173-
),
174-
"hardware-"
162+
// Both sides are compared trimmed, matching how isPlaceholderValue classifies the field.
163+
XCTAssertTrue(
164+
Self.placeholderMakesCommitUnobservable(placeholder: " 0.00 ", expectedText: "0.00")
175165
)
176-
XCTAssertNil(Self.commitObservation(rawValue: nil, expectedText: "x", normalizedValue: { nil }))
166+
// And the command consequence: this state refuses rather than reporting success.
167+
XCTAssertEqual(Self.textEntryFailure(forCommitOutcome: .notObserved), .commitNotObserved)
177168
}
178169

179-
func testCommitObservationDoesNotPayForASecondReadOnAnExactMatch() {
180-
var normalizedReads = 0
181-
_ = Self.commitObservation(
182-
rawValue: "0.00",
183-
expectedText: "0.00",
184-
normalizedValue: {
185-
normalizedReads += 1
186-
return ""
187-
}
170+
// The guard must stay narrow: it fires only when the WHOLE expected value is the placeholder.
171+
// Widening it would refuse ordinary typing into any placeheld field, which is most of them.
172+
func testPlaceholderGuardDoesNotFireOnOrdinaryTyping() {
173+
XCTAssertFalse(
174+
Self.placeholderMakesCommitUnobservable(placeholder: "0.00", expectedText: "0.005"),
175+
"a distinguishable value must still be observed rather than refused"
176+
)
177+
XCTAssertFalse(
178+
Self.placeholderMakesCommitUnobservable(placeholder: "Email", expectedText: "[email protected]")
188179
)
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)
180+
XCTAssertFalse(Self.placeholderMakesCommitUnobservable(placeholder: nil, expectedText: "0.00"))
181+
XCTAssertFalse(Self.placeholderMakesCommitUnobservable(placeholder: "", expectedText: ""))
182+
XCTAssertFalse(Self.placeholderMakesCommitUnobservable(placeholder: " ", expectedText: ""))
192183
}
193184

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

‎website/docs/docs/commands.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ agent-device gesture transform 200 420 80 -40 2 35 700 # combined pan, zoom, and
427427
`type` accepts text only. Do not pass `@ref` to `type`; use `fill @ref "text"` to target a field directly, or `press @ref` then `type "text"` to append in the focused field.
428428
If `type` reports `TEXT_INPUT_NOT_FOCUSED`, focus a visible text input and retry; when accessibility does not expose the input, use a coordinate focus command before typing.
429429
On iOS, if `type` reports `TEXT_INPUT_SYNTHESIS_UNAVAILABLE` while the software keyboard is hidden, show the software keyboard, then retry `type` or `fill`. The runner reports this error instead of risking partial input through an unreliable text-entry path.
430-
On iOS, if `type` reports `TEXT_INPUT_COMMIT_NOT_OBSERVED`, the runner could not confirm the typed text reached the field before its deadline. The field may hold none, part, or all of the text: read it back, then prefer `fill`, which replaces the whole value, over `type`, which appends to whatever committed. This covers the bare-type route, which observes the field after synthesizing; it is not a guarantee that every text-entry route verifies its result.
430+
On iOS, if `type` reports `TEXT_INPUT_COMMIT_NOT_OBSERVED`, the runner could not confirm the typed text reached the field — either it did not land before the runner's deadline, or the requested text is identical to the field's placeholder, which makes a committed value indistinguishable from an untouched one. The field may hold none, part, or all of the text: read it back, then prefer `fill`, which replaces the whole value, over `type`, which appends to whatever committed. This covers the bare-type route, which observes the field after synthesizing; it is not a guarantee that every text-entry route verifies its result.
431431
Use plain `fill` or `type` first for ordinary login and form fields. Use `--delay-ms` on `type` or `fill` only when a debounced search field or search-as-you-type input actually misses characters, or when the app must receive incremental updates.
432432
Delayed typing intentionally prefers paced character entry over clipboard-style fallbacks so the target field receives each incremental update.
433433
On Android, `fill` also verifies text and treats IME-owned capture as a terminal failure instead of retrying against the wrong field.

0 commit comments

Comments
 (0)