Skip to content

Commit f757b60

Browse files
committed
fix: keep native press readiness off cold import paths
1 parent b7e3793 commit f757b60

5 files changed

Lines changed: 28 additions & 32 deletions

File tree

‎packages/command-runtime/src/commands/interaction/runtime/interactions.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
} from './post-action-observation.ts';
2222
import { resolveInteractionTarget, type InteractionTarget } from './resolution.ts';
2323
import { guardResolvedTargetAgainstMotion } from './moving-target-gate.ts';
24-
import { guardPressReadiness } from './press-readiness.ts';
2524
import { pointObservationOf } from './target-visibility-stages.ts';
2625
import { dispatchNativeRefInteraction } from './native-ref-interaction.ts';
2726
import type {
@@ -170,13 +169,15 @@ async function tapCommand(
170169
resolved,
171170
);
172171
if (
172+
runtime.backend.readPressReadiness &&
173173
(options.count ?? 1) === 1 &&
174174
(options.intervalMs ?? 0) === 0 &&
175175
(options.holdMs ?? 0) === 0 &&
176176
(options.jitterPx ?? 0) === 0 &&
177177
options.doubleTap !== true &&
178178
(options.button ?? 'primary') === 'primary'
179179
) {
180+
const { guardPressReadiness } = await import('./press-readiness.ts');
180181
atRest = await guardPressReadiness(runtime, options, resolutionRequest, atRest);
181182
}
182183
const point = requireResolvedPoint(atRest);

packages/contracts/src/selector-observation-runtime.test.ts renamed to packages/command-runtime/src/commands/interaction/runtime/press-readiness-binding.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { readFileSync } from 'node:fs';
22
import { expect, test } from 'vitest';
3-
import {
4-
matchesAuthorizedPressTarget,
5-
type AuthorizedPressTarget,
6-
} from './selector-observation-runtime.ts';
3+
import { matchesAuthorizedPressTarget } from './press-readiness-binding.ts';
4+
import type { AuthorizedPressTarget } from '@agent-device/contracts/selector-observation-runtime';
75

86
// Shared with the native mutation-read: identity or capture geometry changes must never rebind input.
97
const cases = JSON.parse(
108
readFileSync(
11-
new URL('../../../contracts/fixtures/authorized-press-target.json', import.meta.url),
9+
new URL('../../../../../../contracts/fixtures/authorized-press-target.json', import.meta.url),
1210
'utf8',
1311
),
1412
) as {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { areCapturedRectsAtSamePosition } from '@agent-device/kernel/rect-center';
2+
import type { AuthorizedPressTarget } from '@agent-device/contracts/selector-observation-runtime';
3+
4+
/** Exact native identity plus the existing capture-rounding band, shared with canonical rechecks. */
5+
export function matchesAuthorizedPressTarget(
6+
expected: AuthorizedPressTarget,
7+
candidate: Omit<AuthorizedPressTarget, 'point'>,
8+
): boolean {
9+
return (
10+
expected.type === candidate.type &&
11+
(['identifier', 'label', 'value'] as const).every(
12+
(key) =>
13+
(key === 'value' && expected.type === 'SecureTextField') ||
14+
(expected[key] ?? '').trim().normalize('NFC') ===
15+
(candidate[key] ?? '').trim().normalize('NFC'),
16+
) &&
17+
areCapturedRectsAtSamePosition(expected.rect, candidate.rect)
18+
);
19+
}

‎packages/command-runtime/src/commands/interaction/runtime/press-readiness.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@ import type {
44
} from '@agent-device/contracts/interaction';
55
import type { AgentDeviceRuntime, CommandContext } from '@agent-device/contracts/runtime-contract';
66
import type { BackendCommandContext } from '@agent-device/contracts/backend';
7-
import {
8-
matchesAuthorizedPressTarget,
9-
type NativePressReadiness,
10-
} from '@agent-device/contracts/selector-observation-runtime';
7+
import type { NativePressReadiness } from '@agent-device/contracts/selector-observation-runtime';
8+
import { matchesAuthorizedPressTarget } from './press-readiness-binding.ts';
119
import { readSnapshotNativePressTargets } from '@agent-device/contracts/capture';
12-
import {
13-
getRequestExecutionDeadlineMs,
14-
getRequestResultDeadlineMs,
15-
} from '@agent-device/host-kit/request';
1610
import { AppError, discloseDispatch } from '@agent-device/kernel/errors';
1711
import { INTERACTION_ERROR_REASONS } from '@agent-device/selectors/interaction-error';
1812
import { toBackendContext } from '../../runtime-common.ts';
@@ -27,6 +21,8 @@ export async function guardPressReadiness(
2721
original: ResolvedInteractionTarget,
2822
): Promise<ResolvedInteractionTarget> {
2923
if (!runtime.backend.readPressReadiness || original.kind === 'point') return original;
24+
const { getRequestExecutionDeadlineMs, getRequestResultDeadlineMs } =
25+
await import('@agent-device/host-kit/request');
3026
const deadline = Math.min(
3127
getRequestExecutionDeadlineMs(options.requestId) ?? Infinity,
3228
getRequestResultDeadlineMs(options.requestId) ?? Infinity,

‎packages/contracts/src/selector-observation-runtime.ts‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { areCapturedRectsAtSamePosition } from '@agent-device/kernel/rect-center';
21
import type { Point, Rect, SnapshotNativePressTarget } from '@agent-device/kernel/snapshot';
32
import type { ElementSelectorKey } from './interactor-types.ts';
43
import type { RuntimeOperationFact } from './platform-runtime.ts';
@@ -23,23 +22,6 @@ export type NativePressReadiness =
2322
| 'ambiguous'
2423
| 'surface-mismatch';
2524

26-
/** Exact native identity plus the existing capture-rounding band, shared with canonical rechecks. */
27-
export function matchesAuthorizedPressTarget(
28-
expected: AuthorizedPressTarget,
29-
candidate: Omit<AuthorizedPressTarget, 'point'>,
30-
): boolean {
31-
return (
32-
expected.type === candidate.type &&
33-
(['identifier', 'label', 'value'] as const).every(
34-
(key) =>
35-
(key === 'value' && expected.type === 'SecureTextField') ||
36-
(expected[key] ?? '').trim().normalize('NFC') ===
37-
(candidate[key] ?? '').trim().normalize('NFC'),
38-
) &&
39-
areCapturedRectsAtSamePosition(expected.rect, candidate.rect)
40-
);
41-
}
42-
4325
export type QuerySelectorInput = ObservationInput &
4426
(
4527
| Readonly<{

0 commit comments

Comments
 (0)