Skip to content

Commit 95a5238

Browse files
committed
fix(interaction): fail the empty-fill clear closed on every backend
Addresses the P1 review on #2066, then closes the same fail-open class on the backends the PR did not reach: - Android: an empty expectation no longer matches when the verification scan observed NO input node at all — actual is null both for a cleared field and for a wrong point/lost focus, and three empty samples of nothing were a stable success for a clear that never touched a field. - Apple runner: when the empty-replacement path cannot resolve a clear target (including the synthesized first-responder route, whose target carries no element), it returns the typed TEXT_INPUT_NOT_FOCUSED failure instead of falling through to the vacuous-typing verified-success return. Regression runs in the ios.yml XCTest lane. - webdriver: fill is tap + sendKeys and owns no clear mechanism, so an empty fill refuses as UNSUPPORTED_OPERATION before touching the device, instead of reporting a clear it cannot perform. - linux + web coordinate fill: typing zero characters over the select-all selection left the old value intact; the empty fill now deletes the selection. - recording: an empty --record-as literal matches inside every string; it now parameterizes only the fill's own text field instead of rewriting every empty field and empty evidence label in the entry. (The session-wide echo registry already excluded empty literals.) - help: the text-entry topic taught agents that fill "" is not a clear-field command; it now states the new contract. Each new test was observed red against the pre-fix code.
1 parent cbcbb43 commit 95a5238

15 files changed

Lines changed: 183 additions & 11 deletions

File tree

‎.github/workflows/ios.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ jobs:
144144
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testPenalizedCoordinateTapOnNonTextControlDoesNotAuthorizeBareType \
145145
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testBareDelayedTypeFailsWhenTappedInputDisappearsMidCommand \
146146
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testSynthesizedTextCommitProgressWalksExpectedPrefixOnly \
147+
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testEmptyReplacementWithoutResolvableTargetFailsClosed \
147148
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testTextEntryTapWitnessIsBoundToTargetIdentity \
148149
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testCoordinateTapTextInputProbeSkipsPenalizedXCTestChannel \
149150
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testCoordinateTextInputCandidateMustBeEnabledAndContainTheTouchPoint \

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,20 @@ extension RunnerTests {
1919
// is vacuous but the clear is not. Returning here unconditionally left the old value in
2020
// place while the response reported "typed". Append (`type`) and unrepaired entry stay
2121
// no-ops, which is what an empty payload means for them.
22-
if repairMode == .replacement, let clearTarget = resolveTextEntryElement(app: app, target: target) {
22+
if repairMode == .replacement {
23+
guard let clearTarget = resolveTextEntryElement(app: app, target: target) else {
24+
// No resolvable input means no clear happened — including the synthesized
25+
// first-responder route, whose target carries no element. Success here would claim a
26+
// clear the runner never performed.
27+
logTextEntryPhase(commandId: commandId, phase: "total", startedAt: totalStartedAt, chars: 0, mode: repairMode)
28+
return TextEntryResult(
29+
verified: nil,
30+
repaired: false,
31+
expectedText: "",
32+
observedText: nil,
33+
failure: .notFocused
34+
)
35+
}
2336
clearTextInput(clearTarget)
2437
// nil means the value is unreadable (secure fields), not "not empty": leave `verified`
2538
// nil there rather than reporting a mismatch the runner cannot actually observe.

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,26 @@ extension RunnerTests {
445445
XCTAssertEqual(result.failure, .commitNotObserved)
446446
}
447447

448+
// `fill <target> ""` is the clear-field primitive (#2063). When no clear target resolves —
449+
// Springboard's home screen has no focused text input — the empty-text replacement path must
450+
// fail closed: it used to fall through to the vacuous-typing early return and report
451+
// `verified: true` for a clear that never ran.
452+
func testEmptyReplacementWithoutResolvableTargetFailsClosed() {
453+
let result = typeTextReliably(
454+
app: springboard,
455+
target: TextEntryTarget(element: nil, refreshPoint: nil, prefersFocusedElement: false),
456+
text: "",
457+
delaySeconds: 0,
458+
repairMode: .replacement,
459+
xCTestChannelPenalized: false,
460+
synthesizer: RecordingTextEntrySynthesizer()
461+
)
462+
463+
XCTAssertEqual(result.failure, .notFocused)
464+
XCTAssertNil(result.verified)
465+
XCTAssertNil(result.observedText)
466+
}
467+
448468
// Companion to the above: text carrying a submit key must skip the wait entirely, same as the
449469
// append route (`awaitSynthesizedFirstResponderCommit`) — the app may clear or rewrite the field
450470
// on submit, so there is nothing meaningful to poll toward.

‎packages/provider-webdriver/src/webdriver-interactor.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,27 @@ test('fill caps each probe timeout by the readiness budget remaining', async ()
228228
* past the whole readiness budget is safe for every case — once readiness
229229
* resolves there are no pending timers left to fire.
230230
*/
231+
// `fill <target> ""` is the clear-field primitive (#2063). This backend's fill is tap +
232+
// sendKeys and owns no clear mechanism, so an empty fill must refuse up front — sending zero
233+
// keys and reporting success would claim a clear that never ran, before even touching the
234+
// device.
235+
test('fill refuses empty text as an unsupported clear rather than a vacuous success', async () => {
236+
const world = createTextEntryWorld();
237+
const interactor = createWebDriverInteractor({
238+
client: world.client,
239+
backend: 'xctest',
240+
capabilities: createCloudWebDriverCapabilities({ provider: 'test', platform: 'ios' }),
241+
});
242+
243+
await assert.rejects(interactor.fill(12, 24, ''), (error: AppError) => {
244+
assert.equal(error.code, 'UNSUPPORTED_OPERATION');
245+
assert.match(error.message, /clear field/);
246+
return true;
247+
});
248+
// Fail-closed means untouched: no tap, no keys, no probes reached the device.
249+
assert.deepEqual(world.transcript, []);
250+
});
251+
231252
async function runFill(world: ReturnType<typeof createTextEntryWorld>) {
232253
vi.useFakeTimers();
233254
try {

‎packages/provider-webdriver/src/webdriver-interactor.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ class WebDriverInteractor implements Interactor {
215215
_delayMs?: number,
216216
): Promise<Record<string, unknown>> {
217217
this.requireSupport('fill');
218+
// This backend's fill is tap + sendKeys: it never clears the existing value, so the
219+
// clear-field request (`fill <target> ""`, #2063) has no mechanism here — sending zero keys
220+
// and reporting success would claim a clear that never ran.
221+
if (text.length === 0) {
222+
throw new AppError(
223+
'UNSUPPORTED_OPERATION',
224+
'fill with empty text (clear field) is not supported on the webdriver backend',
225+
{
226+
hint: 'Use a visible clear/reset control in the app, or fill the field with the intended replacement text directly.',
227+
},
228+
);
229+
}
218230
// #1658: both readings are taken BEFORE the tap, because each is only
219231
// evidence as a change. A keyboard that was already up says nothing about
220232
// which field owns first responder now, and a focused element is only

‎src/cli-schema/cli-help-topics.test.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,7 @@ test('usageForCommand resolves workflow help topic', async () => {
159159
assert.match(help, /geometry never chooses a winner/);
160160
assert.match(help, /iOS AX flags are unreliable on deep RN trees/);
161161
assert.match(help, /targetHittable: false plus a hint -- verify or re-target, not a failure/);
162-
assert.match(
163-
help,
164-
/Empty replacement is not a clear-field command \(do not plan fill <target> ""\)/,
165-
);
162+
assert.match(help, /fill <target> "" clears the field \(replace with nothing\)/);
166163
assert.match(help, /retry with --delay-ms before clipboard paste/);
167164
assert.match(
168165
help,

‎src/cli-schema/cli-help.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Selectors:
153153
154154
Text entry:
155155
fill replaces; type appends to an already-focused field: fill 'id="field-email"' "[email protected]"; type "Handle with care" --delay-ms 80
156-
Empty replacement is not a clear-field command (do not plan fill <target> ""); use a visible clear/reset control, or report the gap.
156+
fill <target> "" clears the field (replace with nothing); the empty argument must be present -- fill <target> alone is a missing argument.
157157
Plain fill/type first; if an iOS debounced/search-as-you-type field drops characters, retry with --delay-ms before clipboard paste.
158158
The keyboard usually does not block interactions -- press the next target directly. keyboard dismiss taps its own dismiss key when one exists, else UNSUPPORTED_OPERATION. Android: try dismiss before back. iOS: when both fail, do not tap a static text/heading hoping it is safe; prefer type "\\n" to submit.
159159
iOS paste-prompt limits and Android IME/handwriting capture quirks: help debugging.

‎src/daemon/__tests__/session-action-recorder.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,48 @@ test.each(['', ' '])(
238238
},
239239
);
240240

241+
test('an empty parameterized clear rewrites only its own text, never other empty fields', () => {
242+
// `fill <target> "" --record-as VAR` (#2063): the empty literal matches inside every string,
243+
// so it must redact nothing beyond the fill's own semantic text — an unrelated empty field or
244+
// empty evidence label is not an echo of the (empty) value.
245+
const session = makeIosSession('default');
246+
recordActionEntry(session, {
247+
command: 'fill',
248+
positionals: ['id="search"', ''],
249+
flags: { recordAs: 'QUERY' },
250+
result: {
251+
text: '',
252+
message: 'Filled 0 chars',
253+
selector: 'id="search"',
254+
backend: { detail: '' },
255+
},
256+
targetEvidence: {
257+
role: 'textinput',
258+
label: '',
259+
ancestry: [{ role: 'form', label: '' }],
260+
sibling: 0,
261+
viewportOrder: 0,
262+
verification: 'verified',
263+
},
264+
});
265+
266+
expect(session.actions[0]).toMatchObject({
267+
positionals: ['id="search"', '${QUERY}'],
268+
result: {
269+
text: '${QUERY}',
270+
message: 'Filled 0 chars',
271+
selector: 'id="search"',
272+
backend: { detail: '' },
273+
},
274+
targetEvidence: {
275+
label: '',
276+
ancestry: [{ role: 'form', label: '' }],
277+
},
278+
});
279+
// The empty literal is never registered for session-wide echo protection either.
280+
expect(session.recordedFillLiterals?.has('') ?? false).toBe(false);
281+
});
282+
241283
test('whitespace-only fills collapse ambiguous recorder output and keys', () => {
242284
const session = makeIosSession('default');
243285
const whitespace = ' ';

‎src/daemon/parameterized-recorded-fill.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ export function parameterizeRecordedFillTargetEvidence(
258258
placeholder: string,
259259
): TargetAnnotationV1 | undefined {
260260
if (!evidence) return evidence;
261+
// An empty literal (#2063) would equate every EMPTY label with the fill value; an empty
262+
// label is not an echo of anything, so the evidence stays untouched.
263+
if (!literal) return evidence;
261264
return {
262265
...evidence,
263266
...(evidence.label === literal ? { label: placeholder } : {}),
@@ -360,7 +363,10 @@ function filterSensitiveSelectorCandidates(
360363
}
361364

362365
function parameterizeSensitiveString(value: string, literal: string, placeholder: string): string {
363-
if (!literal) return value === literal ? placeholder : value;
366+
// The empty literal (`fill <target> "" --record-as VAR`, #2063) matches inside every string:
367+
// it reveals nothing if echoed, so it redacts nothing. Only the fill's own semantic `text`
368+
// field is force-parameterized, by `parameterizeRecordedFillPayload`, not here.
369+
if (!literal) return value;
364370

365371
const unparameterizedSegments = placeholder ? value.split(placeholder) : [value];
366372
if (unparameterizedSegments.every((segment) => !segment.includes(literal))) return value;

‎src/platforms/android/__tests__/text-input-fill.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,28 @@ test('verifyAndroidFilledTextInHierarchy accepts a cleared field for an empty ex
375375
assert.equal(clearedWithoutAttribute.ok, true);
376376
});
377377

378+
test('verifyAndroidFilledTextInHierarchy refuses an empty expectation when no input is observed at all', () => {
379+
// `actual` is null both for a cleared field and for NO field: a wrong point or lost focus
380+
// must not satisfy the empty expectation, or three such samples become a stable success for
381+
// a clear that never touched an app input.
382+
const noInputAnywhere = verifyAndroidFilledTextInHierarchy(
383+
'<?xml version="1.0" encoding="UTF-8"?><hierarchy><node package="com.example" class="android.widget.FrameLayout" bounds="[0,0][1080,1920]"/></hierarchy>',
384+
10,
385+
10,
386+
'',
387+
);
388+
assert.equal(noInputAnywhere.ok, false);
389+
assert.equal(noInputAnywhere.actualInput, null);
390+
391+
const inputElsewhere = verifyAndroidFilledTextInHierarchy(
392+
'<?xml version="1.0" encoding="UTF-8"?><hierarchy><node package="com.example" class="android.widget.EditText" bounds="[500,500][700,600]"/></hierarchy>',
393+
10,
394+
10,
395+
'',
396+
);
397+
assert.equal(inputElsewhere.ok, false);
398+
});
399+
378400
test('verifyAndroidFilledTextInHierarchy still refuses a non-empty field for an empty expectation', () => {
379401
const verification = verifyAndroidFilledTextInHierarchy(
380402
androidInputXml({ text: 'still here' }),

0 commit comments

Comments
 (0)