Skip to content

Commit 35fd994

Browse files
committed
fix(ios): read text value unreadability through one shared rule on every route
1 parent dcaad95 commit 35fd994

8 files changed

Lines changed: 202 additions & 66 deletions

‎apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ - (void)viewDidLoad {
663663
]];
664664
}
665665
if (maskedValue) {
666+
if ([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-text-entry-prefilled"]) {
667+
textField.text = @"stale-secret";
668+
}
666669
// The show/hide toggle sits over the field's right edge, where the runner's caret edge-tap
667670
// lands. Counting its presses tells the test whether a repair reached for the field again.
668671
UIButton *toggle = [UIButton buttonWithType:UIButtonTypeSystem];

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ extension RunnerTests {
6767
/// already reported success. The expected value is the
6868
/// final text itself, and a settled mismatch is always reported: see
6969
/// `awaitSynthesizedReplacementCommitOutcome`'s doc comment. Text carrying a submit key is
70-
/// skipped outright: the app may clear or rewrite the field on submit. So is a secure field,
71-
/// whose value is never readable.
70+
/// skipped outright: the app may clear or rewrite the field on submit. So is a field whose
71+
/// value is unreadable: secure, or masked the way a React Native `secureTextEntry` input is.
7272
func awaitSynthesizedReplacementCommit(
7373
app: XCUIApplication,
7474
target: TextEntryTarget,
@@ -83,7 +83,7 @@ extension RunnerTests {
8383
let outcome = Self.awaitSynthesizedReplacementCommitOutcome(
8484
expectedText: expectedText,
8585
placeholder: ingredients.placeholder,
86-
fieldIsSecure: ingredients.fieldIsSecure,
86+
fieldIsUnreadable: ingredients.fieldIsUnreadable,
8787
now: { Date() },
8888
observe: ingredients.observe,
8989
waitForNextObservation: ingredients.waitForNextObservation
@@ -134,21 +134,25 @@ extension RunnerTests {
134134
expectedText: String
135135
) -> (
136136
placeholder: String?,
137-
fieldIsSecure: Bool,
138-
observe: () -> String?,
137+
fieldIsUnreadable: Bool,
138+
observe: () -> TextValueRead,
139139
waitForNextObservation: () -> Void
140140
) {
141141
let field = resolveTextEntryElement(app: app, target: target)
142142
let placeholder = field?.placeholderValue
143143
let waitStartedAt = Date()
144144
return (
145145
placeholder: placeholder,
146-
fieldIsSecure: field?.elementType == .secureTextField,
146+
fieldIsUnreadable: textValueRead(for: field) == .unreadable,
147147
observe: {
148-
let observedText = self.editableTextValue(
148+
let observed = self.textValueRead(
149149
for: self.resolveTextEntryElement(app: app, target: target),
150150
treatingPlaceholderAsEmpty: true
151151
)
152+
var observedText: String?
153+
if case .text(let value) = observed {
154+
observedText = value
155+
}
152156
// Cadence evidence stays value-free: the polled value is user content typed through
153157
// `fill` and must never reach runner.log. Lengths and the expected-prefix walk
154158
// are enough to distinguish throttling (prefix grows slowly) from a wedge (it freezes).
@@ -157,7 +161,7 @@ extension RunnerTests {
157161
observedLen: observedText?.count ?? -1,
158162
expectedPrefixLen: observedText.map { Self.commonPrefixLength($0, expectedText) } ?? -1
159163
)
160-
return observedText
164+
return observed
161165
},
162166
// XCUI resolution shares the automation channel with the in-flight synthesized event.
163167
// Sparse reads let the target consume that event instead of continuously interrupting it.

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,6 @@ extension RunnerTests {
246246
case stop
247247
}
248248

249-
/// What the field reads between a replacement's clear passes.
250-
enum ClearedFieldRead: Equatable {
251-
case text(String)
252-
/// The field never exposes its value: a secure field.
253-
case unreadable
254-
/// The read could not answer, or no input resolves.
255-
case unavailable
256-
}
257-
258249
/// How a replacing post's clear ended.
259250
enum SynthesizedClearOutcome: Equatable {
260251
case cleared
@@ -270,7 +261,7 @@ extension RunnerTests {
270261
/// answer ends the clear, so the post never types over text it could not see removed.
271262
static func clearForSynthesizedReplacement(
272263
clearOnce: () -> SynthesizedStepDispatch,
273-
read: () -> ClearedFieldRead
264+
read: () -> TextValueRead
274265
) -> SynthesizedClearOutcome {
275266
for pass in 1...SynthesizedTextPlan.Step.maxClearPassCount {
276267
guard clearOnce() == .posted else { return .stopped }
@@ -527,16 +518,18 @@ extension RunnerTests {
527518
static func awaitSynthesizedReplacementCommitOutcome(
528519
expectedText: String,
529520
placeholder: String?,
530-
fieldIsSecure: Bool = false,
521+
fieldIsUnreadable: Bool = false,
531522
stallBudget: TimeInterval = TextEntryTiming.synthesizedCommitStallTimeout,
532523
ceiling: TimeInterval = TextEntryTiming.synthesizedCommitCeiling,
533524
now: () -> Date = { Date() },
534-
observe: () -> String?,
525+
observe: () -> TextValueRead,
535526
waitForNextObservation: () -> Void
536527
) -> SynthesizedTextCommitOutcome {
537-
// A secure field never exposes its value, so every read is nil and the wait could only expire.
538-
// The element route leaves such a field unverified rather than failed; so does this one.
539-
if fieldIsSecure {
528+
// An unreadable field never exposes its value, so every read could only expire the wait. The
529+
// element route leaves such a field unverified rather than failed; so does this one. A masked
530+
// value appears only once the burst lands, so a read that turns unreadable mid-wait ends it
531+
// the same way.
532+
if fieldIsUnreadable {
540533
return .unobservable
541534
}
542535
// A placeholder-equal AX value cannot prove a commit: an input handler may clear the field
@@ -550,7 +543,15 @@ extension RunnerTests {
550543
// happens before condemning a commit is a read. Checking first would condemn a commit that
551544
// landed during the final poll sleep — the exact loaded-host timing this wait exists for.
552545
while true {
553-
let observedText = observe()
546+
let observedText: String?
547+
switch observe() {
548+
case .unreadable:
549+
return .unobservable
550+
case .text(let value):
551+
observedText = value
552+
case .unavailable:
553+
observedText = nil
554+
}
554555
if observedText == expectedText {
555556
return .settled
556557
}

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

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,36 +445,71 @@ extension RunnerTests {
445445
.trimmingCharacters(in: .whitespacesAndNewlines)
446446
}
447447

448-
func editableTextValue(
448+
/// What a text entry element's value says about its text.
449+
enum TextValueRead: Equatable {
450+
case text(String)
451+
/// The value carries no information about the text: a secure field, or a masked value.
452+
case unreadable
453+
/// The read could not answer, or no input resolves.
454+
case unavailable
455+
}
456+
457+
/// What a text entry element's accessibility value says about its text. The one owner of the
458+
/// "value unreadable" rule: a `.secureTextField`, or a plain field whose value is a password
459+
/// mask, as a React Native `secureTextEntry` input reports (tester-army/e2e#872). Every route
460+
/// that decides readability reads through here, so none can disagree with another.
461+
func textValueRead(
449462
for element: (any XCUIElementAttributes)?,
450463
treatingPlaceholderAsEmpty: Bool = false
451-
) -> String? {
464+
) -> TextValueRead {
452465
guard let element else {
453-
return nil
466+
return .unavailable
454467
}
455-
switch element.elementType {
468+
let elementType = element.elementType
469+
switch elementType {
456470
case .textField, .searchField, .textView:
457471
let value = String(describing: element.value ?? "")
458472
if treatingPlaceholderAsEmpty && isPlaceholderValue(value, for: element) {
459-
return ""
460-
}
461-
// A React Native `secureTextEntry` field reports as a plain text field whose value is the
462-
// masked rendering, so it is as unreadable as a `.secureTextField` and must not be compared
463-
// against the typed text (tester-army/e2e#872).
464-
if Self.isMaskedTextValue(value) {
465-
return nil
473+
return .text("")
466474
}
467-
return value
475+
return Self.textValueRead(elementType: elementType, value: value)
476+
default:
477+
return Self.textValueRead(elementType: elementType, value: "")
478+
}
479+
}
480+
481+
/// `textValueRead(for:)` with the element's type and value already read, so the rule is
482+
/// exercisable without an element.
483+
static func textValueRead(elementType: XCUIElement.ElementType, value: String) -> TextValueRead {
484+
switch elementType {
468485
case .secureTextField:
469-
return nil
486+
return .unreadable
487+
case .textField, .searchField, .textView:
488+
return isMaskedTextValue(value) ? .unreadable : .text(value)
470489
default:
490+
return .unavailable
491+
}
492+
}
493+
494+
/// The element's text when it can be read, nil when it is unreadable or unavailable. Callers
495+
/// that need the two told apart read `textValueRead(for:)` instead.
496+
func editableTextValue(
497+
for element: (any XCUIElementAttributes)?,
498+
treatingPlaceholderAsEmpty: Bool = false
499+
) -> String? {
500+
guard case .text(let value) = textValueRead(
501+
for: element,
502+
treatingPlaceholderAsEmpty: treatingPlaceholderAsEmpty
503+
) else {
471504
return nil
472505
}
506+
return value
473507
}
474508

475509
/// Whether an accessibility value is a masked rendering of a secure field: one or more
476510
/// password bullets and nothing else. The bullet count need not match the typed length, so
477-
/// such a value carries no information about what the field holds.
511+
/// such a value carries no information about what the field holds. A field whose real text is
512+
/// only bullets is unreadable too, so a failed fill into it reports unverified, not a mismatch.
478513
static func isMaskedTextValue(_ value: String) -> Bool {
479514
let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
480515
guard !trimmed.isEmpty else {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,9 @@ extension RunnerTests {
6565

6666
/// What `target`'s input reads between a replacement's clear passes, read inside the same issue
6767
/// containment, with a placeholder read as empty. A read that cannot answer is `.unavailable`.
68-
func clearedFieldRead(app: XCUIApplication, target: TextEntryTarget) -> ClearedFieldRead {
69-
let probed = containingTextInputProbeIssues(fallback: ClearedFieldRead.unavailable) { _ in
70-
guard let input = resolveTextEntryElement(app: app, target: target) else { return .unavailable }
71-
if input.elementType == .secureTextField { return .unreadable }
72-
return editableTextValue(for: input, treatingPlaceholderAsEmpty: true).map { .text($0) } ?? .unavailable
68+
func clearedFieldRead(app: XCUIApplication, target: TextEntryTarget) -> TextValueRead {
69+
let probed = containingTextInputProbeIssues(fallback: TextValueRead.unavailable) { _ in
70+
textValueRead(for: resolveTextEntryElement(app: app, target: target), treatingPlaceholderAsEmpty: true)
7371
}
7472
guard case .success(let read) = probed else { return .unavailable }
7573
return read

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension RunnerTests {
3535
stallBudget: 3,
3636
ceiling: 10,
3737
now: clock.read,
38-
observe: { String(expected.prefix(landed * 2)) },
38+
observe: { .text(String(expected.prefix(landed * 2))) },
3939
waitForNextObservation: {
4040
landed += 1
4141
clock.advance(2)
@@ -61,7 +61,7 @@ extension RunnerTests {
6161
stallBudget: 3,
6262
ceiling: 10,
6363
now: clock.read,
64-
observe: { "ha" },
64+
observe: { .text("ha") },
6565
waitForNextObservation: {
6666
polls += 1
6767
clock.advance(1)
@@ -82,7 +82,7 @@ extension RunnerTests {
8282
stallBudget: 3,
8383
ceiling: 10,
8484
now: clock.read,
85-
observe: { "ha" },
85+
observe: { .text("ha") },
8686
waitForNextObservation: { clock.advance(1) }
8787
)
8888
XCTAssertEqual(outcome, .notObserved)
@@ -102,7 +102,7 @@ extension RunnerTests {
102102
stallBudget: 3,
103103
ceiling: 10,
104104
now: clock.read,
105-
observe: { observations[min(index, observations.count - 1)] },
105+
observe: { .text(observations[min(index, observations.count - 1)]) },
106106
waitForNextObservation: {
107107
index += 1
108108
clock.advance(1)
@@ -127,7 +127,7 @@ extension RunnerTests {
127127
stallBudget: 3,
128128
ceiling: 10,
129129
now: clock.read,
130-
observe: { String(expected.prefix(landed)) },
130+
observe: { .text(String(expected.prefix(landed))) },
131131
waitForNextObservation: {
132132
landed += 1
133133
clock.advance(2)

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,40 @@ extension RunnerTests {
137137
}
138138
}
139139

140+
/// A React Native `secureTextEntry` input reports as a plain text field whose value is a mask
141+
/// (tester-army/e2e#872). On the penalized route the commit wait could never observe the typed
142+
/// text, so it ran out its stall budget into TEXT_INPUT_COMMIT_NOT_OBSERVED, and a pre-filled
143+
/// one ended the clear as a field that could not be read. Both read through the shared rule now
144+
/// and are typed into unverified, with nothing tapping the show/hide toggle over the field edge.
145+
@MainActor
146+
func testSynthesizedReplacementLeavesAMaskedFieldUnverified() throws {
147+
for prefilled in [false, true] {
148+
let textField = try focusSynthesizedReplacementField(extraLaunchArguments: [
149+
"--agent-device-text-entry-masked-value",
150+
] + (prefilled ? ["--agent-device-text-entry-prefilled"] : []))
151+
defer { tearDownSynthesizedReplacementField() }
152+
let togglePresses = app.staticTexts["agent-device-masked-toggle-presses"]
153+
XCTAssertTrue(togglePresses.waitForExistence(timeout: appExistenceTimeout))
154+
XCTAssertEqual(
155+
textField.value as? String,
156+
prefilled ? String(repeating: "\u{2022}", count: 6) : "",
157+
"prefilled: \(prefilled)"
158+
)
159+
160+
let response = try replaceSynthesizedFieldText(
161+
textField,
162+
text: "not-a-secret-123",
163+
commandId: prefilled ? "fill-masked-prefilled" : "fill-masked-empty"
164+
)
165+
166+
XCTAssertTrue(response.ok, "prefilled: \(prefilled) \(String(describing: response.error))")
167+
XCTAssertEqual(response.data?.textEntryRoute, "synthesized-first-responder-replacement")
168+
XCTAssertEqual(response.data?.message, "typed", "prefilled: \(prefilled)")
169+
XCTAssertEqual(textField.value as? String, String(repeating: "\u{2022}", count: 8), "prefilled: \(prefilled)")
170+
XCTAssertEqual(togglePresses.label, "presses=0", "prefilled: \(prefilled)")
171+
}
172+
}
173+
140174
/// A replacement the command budget cannot carry is refused before the first character is posted,
141175
/// so a `fill` cannot end in a transport timeout that leaves the runner typing into a field nobody
142176
/// is waiting for and the next command finding it busy.

0 commit comments

Comments
 (0)