Skip to content

Commit 62b47bc

Browse files
committed
fix(ios): preserve fill semantics across fast paths
1 parent de23cf1 commit 62b47bc

6 files changed

Lines changed: 69 additions & 66 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@ extension RunnerTests {
1919
static let verificationStabilityWindow: TimeInterval = 0.2
2020
}
2121

22+
struct SynthesizedReplacementStep: Equatable {
23+
let text: String
24+
let replacesExistingText: Bool
25+
}
26+
27+
static func synthesizedReplacementSteps(
28+
text: String,
29+
delaySeconds: Double
30+
) -> [SynthesizedReplacementStep] {
31+
let characters = Array(text)
32+
guard delaySeconds > 0, characters.count > 1 else {
33+
return [SynthesizedReplacementStep(text: text, replacesExistingText: true)]
34+
}
35+
return characters.enumerated().map { index, character in
36+
SynthesizedReplacementStep(
37+
text: String(character),
38+
replacesExistingText: index == 0
39+
)
40+
}
41+
}
42+
2243
struct TextEntryResult {
2344
let verified: Bool?
2445
let repaired: Bool

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,19 @@ extension RunnerTests {
6666
)
6767
)
6868
}
69+
70+
func testSynthesizedReplacementPacesCharactersAfterSelectingOnce() {
71+
XCTAssertEqual(
72+
Self.synthesizedReplacementSteps(text: "abc", delaySeconds: 0.05),
73+
[
74+
SynthesizedReplacementStep(text: "a", replacesExistingText: true),
75+
SynthesizedReplacementStep(text: "b", replacesExistingText: false),
76+
SynthesizedReplacementStep(text: "c", replacesExistingText: false),
77+
]
78+
)
79+
XCTAssertEqual(
80+
Self.synthesizedReplacementSteps(text: "abc", delaySeconds: 0),
81+
[SynthesizedReplacementStep(text: "abc", replacesExistingText: true)]
82+
)
83+
}
6984
}

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ extension RunnerTests {
2525
) {
2626
#if os(iOS)
2727
NSLog("AGENT_DEVICE_RUNNER_TEXT_ENTRY_ROUTE route=synthesized-first-responder-replacement")
28-
if let message = RunnerSynthesizedTextEntry.replaceText(
29-
withApplication: app,
30-
text: text
31-
) {
32-
NSException(
33-
name: NSExceptionName.internalInconsistencyException,
34-
reason: message
35-
).raise()
28+
let steps = Self.synthesizedReplacementSteps(text: text, delaySeconds: delaySeconds)
29+
for (index, step) in steps.enumerated() {
30+
let message = step.replacesExistingText
31+
? RunnerSynthesizedTextEntry.replaceText(withApplication: app, text: step.text)
32+
: RunnerSynthesizedTextEntry.synthesizeText(withApplication: app, text: step.text)
33+
if let message {
34+
NSException(
35+
name: NSExceptionName.internalInconsistencyException,
36+
reason: message
37+
).raise()
38+
}
39+
if index + 1 < steps.count {
40+
sleepFor(delaySeconds)
41+
}
3642
}
3743
logTextEntryPhase(
3844
commandId: commandId,

‎packages/contracts/src/interaction-guarantees.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ export const INTERACTION_DISPATCH_PATHS: Record<InteractionPathId, InteractionPa
226226
},
227227
'direct-ios-selector': {
228228
description:
229-
'Simple selectors on iOS are sent to the XCTest runner, which queries and taps natively without a daemon tree capture.',
230-
commands: ['press', 'fill'],
229+
'Simple press selectors on iOS are sent to the XCTest runner, which queries and taps natively without a daemon tree capture. Fill deliberately resolves through the runtime tree so AX-hostile text inputs carry typed target evidence into coordinate entry.',
230+
commands: ['press'],
231231
guarantees: {
232232
disambiguation: {
233233
kind: 'waived',

‎src/daemon/handlers/interaction-touch.ts‎

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -595,18 +595,7 @@ async function dispatchFillViaRuntime(
595595
);
596596
if (refPreamble.response) return refPreamble.response;
597597
const { staleRefsWarning } = refPreamble;
598-
// ADR 0012 step 4: guarded replay dispatches take the runtime tree path —
599-
// see dispatchTargetedTouchViaRuntime.
600598
const replayTargetGuard = req.internal?.replayTargetGuard;
601-
const directResponse = replayTargetGuard
602-
? null
603-
: await maybeDispatchDirectIosSelectorFill(
604-
params,
605-
session,
606-
parsedTarget.target,
607-
parsedTarget.text,
608-
);
609-
if (directResponse) return directResponse;
610599

611600
return await dispatchRuntimeInteraction(params, {
612601
refContext:
@@ -676,21 +665,6 @@ async function prepareFillRefTarget(
676665
return { staleRefsWarning };
677666
}
678667

679-
async function maybeDispatchDirectIosSelectorFill(
680-
params: InteractionHandlerParams & { captureSnapshotForSession: CaptureSnapshotForSession },
681-
session: SessionState,
682-
target: InteractionTarget,
683-
text: string,
684-
): Promise<DaemonResponse | null> {
685-
const directSelector = readDirectIosSelectorFillTarget({
686-
session,
687-
target,
688-
flags: params.req.flags,
689-
});
690-
if (!directSelector) return null;
691-
return await dispatchDirectIosSelectorFill(params, session, directSelector, text);
692-
}
693-
694668
function buildFillResponsePayloads(params: {
695669
session: SessionState;
696670
result: FillCommandResult;
@@ -721,36 +695,6 @@ function buildFillResponsePayloads(params: {
721695
});
722696
}
723697

724-
function readDirectIosSelectorFillTarget(params: {
725-
session: SessionState;
726-
target: InteractionTarget;
727-
flags: CommandFlags | undefined;
728-
}): DirectIosSelectorTarget | null {
729-
const { session, target, flags } = params;
730-
if (target.kind !== 'selector') return null;
731-
if (session.recordSession) return null;
732-
if (commandSupportsVerifyEvidence('fill') && flags?.verify === true) return null;
733-
if (commandSupportsSettleObservation('fill') && flags?.settle === true) return null;
734-
return readDirectSelectorWithMaestroFallback(session, target.selector, flags);
735-
}
736-
737-
async function dispatchDirectIosSelectorFill(
738-
params: InteractionHandlerParams,
739-
session: SessionState,
740-
selector: DirectIosSelectorTarget,
741-
text: string,
742-
): Promise<DaemonResponse | null> {
743-
return await dispatchDirectIosSelectorInteraction({
744-
params,
745-
session,
746-
selector,
747-
command: 'fill',
748-
positionals: [text],
749-
extra: { selector: selector.raw, text },
750-
fallbackPhase: 'ios_direct_selector_fill_fallback',
751-
});
752-
}
753-
754698
async function dispatchRuntimeInteraction<
755699
TResult extends PressCommandResult | FillCommandResult | LongPressCommandResult,
756700
>(

‎test/integration/interaction-contract/direct-ios-selector.contract.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ test(scenario('resolutionDisclosure'), async () => {
9393
});
9494
});
9595

96+
test('default simple-selector fill resolves through the runtime before typing', async () => {
97+
await withIosContractDaemon(
98+
[runnerSnapshotEntry(RECORDING_TARGET_NODES), runnerTypeEntry({ x: 180, y: 262 })],
99+
async (daemon, transcript) => {
100+
assertRpcOk(await daemon.callCommand('fill', ['id=email', '[email protected]']));
101+
102+
assert.equal(transcript.calls[0]?.command, 'ios.runner.snapshot');
103+
assert.equal(transcript.calls[1]?.command, 'ios.runner.type');
104+
const typeRequest = transcript.calls[1]?.request as Record<string, unknown> | undefined;
105+
assert.equal(typeRequest?.selectorKey, undefined);
106+
assert.equal(typeRequest?.x, 180);
107+
assert.equal(typeRequest?.y, 262);
108+
assert.equal(typeRequest?.resolvedTextInputTarget, true);
109+
},
110+
);
111+
});
112+
96113
test('recorded simple iOS selector click and fill use runtime resolution and persist target-v1 evidence', async () => {
97114
await withIosContractDaemon(
98115
[

0 commit comments

Comments
 (0)