Skip to content

Commit 3d44b6d

Browse files
committed
refactor(type): single-pass daemon routing, shared binder source, owner cell tests
Review follow-ups on #1935. - The type handler now calls the bound executor directly: the interaction- runtime hop validated and formatted what executeBoundTypeText validates and formats again, so it is gone — no boundTypeText backend member, no second result rebuild. The ADR 0014 frame expiry moves to the handler. - New contracts/interactor-operation-binding.ts: one local resolver and one fail-closed provider resolver shared by the screenshot, focus, and type binders — three private copies retired, provider error text preserved. - provider-limrun/interaction-operations.ts: the interactor-backed interaction cells move out of the app-log owner (586 -> 563 lines, below its pre-unit size); text interaction is composed by that owner, not defined in it. - Every owner runtime test now pins the focusPoint/typeText fact cells and bound-operation presence for its exact kinds: apple, android (incl. the synthetic-simulator refusal), harmonyos, linux, web, vega (refusal + hint), webdriver (reachability-gated, incl. inactive session), limrun (live + recovery). The webdriver unsupported-capability row documents that interaction gates on interactor reachability, not capture declarations. - The Linux replay assertion is now change-sensitive: type "555" then wait for a 555 node — no calculator button carries that label, so the wait passes only if the keystrokes landed in the display; deleting the type step turns it red.
1 parent 82fb8c2 commit 3d44b6d

17 files changed

Lines changed: 226 additions & 127 deletions

File tree

‎packages/contracts/src/focus-runtime.ts‎

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { DeviceInfo } from '@agent-device/kernel/device';
2-
import { AppError } from '@agent-device/kernel/errors';
32
import type { Point } from '@agent-device/kernel/snapshot';
3+
import {
4+
localInteractorSource,
5+
providerInteractorSource,
6+
type LocalInteractorOperationResolver,
7+
type ProviderInteractorOperationResolver,
8+
} from './interactor-operation-binding.ts';
49
import type { Interactor, RunnerContext } from './interactor-types.ts';
510
import type { RuntimeOperationFact } from './platform-runtime.ts';
611
import type { SessionSurface } from './session-surface.ts';
@@ -58,10 +63,7 @@ function bindFocusPoint(
5863
});
5964
}
6065

61-
export type LocalFocusInteractorResolver = (
62-
device: DeviceInfo,
63-
runner: RunnerContext,
64-
) => Promise<Interactor>;
66+
export type LocalFocusInteractorResolver = LocalInteractorOperationResolver;
6567

6668
export function bindLocalFocusInteractor(
6769
params: Readonly<{
@@ -70,13 +72,10 @@ export function bindLocalFocusInteractor(
7072
resolveInteractor: LocalFocusInteractorResolver;
7173
}>,
7274
): FocusRuntimeOperations {
73-
return bindFocusPoint(
74-
params.signal,
75-
async (runner) => await params.resolveInteractor(params.device, runner),
76-
);
75+
return bindFocusPoint(params.signal, localInteractorSource(params));
7776
}
7877

79-
export type ProviderFocusInteractorResolver = (runner: RunnerContext) => Interactor | undefined;
78+
export type ProviderFocusInteractorResolver = ProviderInteractorOperationResolver;
8079

8180
/** Provider bindings fail closed when their exact owner no longer exposes its interactor. */
8281
export function bindProviderFocusInteractor(
@@ -86,13 +85,5 @@ export function bindProviderFocusInteractor(
8685
resolveInteractor: ProviderFocusInteractorResolver;
8786
}>,
8887
): FocusRuntimeOperations {
89-
return bindFocusPoint(params.signal, async (runner) => {
90-
const interactor = params.resolveInteractor(runner);
91-
if (interactor) return interactor;
92-
throw new AppError(
93-
'UNSUPPORTED_OPERATION',
94-
'Provider-owned focus operation has no bound provider interactor.',
95-
{ reason: 'provider-runtime-interactor-missing', deviceId: params.device.id },
96-
);
97-
});
88+
return bindFocusPoint(params.signal, providerInteractorSource({ ...params, operation: 'focus' }));
9889
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { DeviceInfo } from '@agent-device/kernel/device';
2+
import { AppError } from '@agent-device/kernel/errors';
3+
import type { Interactor, RunnerContext } from './interactor-types.ts';
4+
5+
/**
6+
* The two ways an interactor-backed operation reaches its mechanics, shared by every binder that
7+
* rides the `Interactor` seam (screenshot, focus, type, element-text). Each operation module owns
8+
* its input/result contract; what they must NOT each own is a private copy of interactor
9+
* resolution — that is duplication of mechanism, and the provider fail-closed rule below must be
10+
* one rule, not one per operation.
11+
*/
12+
export type LocalInteractorOperationResolver = (
13+
device: DeviceInfo,
14+
runner: RunnerContext,
15+
) => Promise<Interactor>;
16+
17+
export type ProviderInteractorOperationResolver = (runner: RunnerContext) => Interactor | undefined;
18+
19+
/** Resolves the already-selected local owner's interactor for one bound operation. */
20+
export function localInteractorSource(
21+
params: Readonly<{ device: DeviceInfo; resolveInteractor: LocalInteractorOperationResolver }>,
22+
): (runner: RunnerContext) => Promise<Interactor> {
23+
return async (runner) => await params.resolveInteractor(params.device, runner);
24+
}
25+
26+
/**
27+
* Resolves a provider's own interactor for one bound operation, failing closed when the exact
28+
* owner no longer exposes it: facts advertised the operation, so a missing interactor is an
29+
* ownership bug to surface, never a refusal to degrade around.
30+
*/
31+
export function providerInteractorSource(
32+
params: Readonly<{
33+
device: DeviceInfo;
34+
operation: string;
35+
resolveInteractor: ProviderInteractorOperationResolver;
36+
}>,
37+
): (runner: RunnerContext) => Promise<Interactor> {
38+
return async (runner) => {
39+
const interactor = params.resolveInteractor(runner);
40+
if (interactor) return interactor;
41+
throw new AppError(
42+
'UNSUPPORTED_OPERATION',
43+
`Provider-owned ${params.operation} operation has no bound provider interactor.`,
44+
{ reason: 'provider-runtime-interactor-missing', deviceId: params.device.id },
45+
);
46+
};
47+
}

‎packages/contracts/src/screenshot-runtime.ts‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { DeviceInfo } from '@agent-device/kernel/device';
2-
import { AppError } from '@agent-device/kernel/errors';
2+
import {
3+
localInteractorSource,
4+
providerInteractorSource,
5+
type LocalInteractorOperationResolver,
6+
type ProviderInteractorOperationResolver,
7+
} from './interactor-operation-binding.ts';
38
import type { Interactor, RunnerContext, ScreenshotOptions } from './interactor-types.ts';
49
import type { RuntimeOperationFact } from './platform-runtime.ts';
510

@@ -59,30 +64,22 @@ export function bindLocalScreenshotInteractor(
5964
params: Readonly<{
6065
device: DeviceInfo;
6166
signal: AbortSignal;
62-
resolveInteractor: (device: DeviceInfo, runner: RunnerContext) => Promise<Interactor>;
67+
resolveInteractor: LocalInteractorOperationResolver;
6368
}>,
6469
): ScreenshotRuntimeOperations {
65-
return bindScreenshotCapture(
66-
params.signal,
67-
async (runner) => await params.resolveInteractor(params.device, runner),
68-
);
70+
return bindScreenshotCapture(params.signal, localInteractorSource(params));
6971
}
7072

7173
/** Provider bindings fail closed when their exact owner no longer exposes its interactor. */
7274
export function bindProviderScreenshotInteractor(
7375
params: Readonly<{
7476
device: DeviceInfo;
7577
signal: AbortSignal;
76-
resolveInteractor: (runner: RunnerContext) => Interactor | undefined;
78+
resolveInteractor: ProviderInteractorOperationResolver;
7779
}>,
7880
): ScreenshotRuntimeOperations {
79-
return bindScreenshotCapture(params.signal, async (runner) => {
80-
const interactor = params.resolveInteractor(runner);
81-
if (interactor) return interactor;
82-
throw new AppError(
83-
'UNSUPPORTED_OPERATION',
84-
'Provider-owned screenshot operation has no bound provider interactor.',
85-
{ reason: 'provider-runtime-interactor-missing', deviceId: params.device.id },
86-
);
87-
});
81+
return bindScreenshotCapture(
82+
params.signal,
83+
providerInteractorSource({ ...params, operation: 'screenshot' }),
84+
);
8885
}

‎packages/contracts/src/type-text-runtime.ts‎

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { DeviceInfo } from '@agent-device/kernel/device';
2-
import { AppError } from '@agent-device/kernel/errors';
2+
import {
3+
localInteractorSource,
4+
providerInteractorSource,
5+
type LocalInteractorOperationResolver,
6+
type ProviderInteractorOperationResolver,
7+
} from './interactor-operation-binding.ts';
38
import type { Interactor, RunnerContext, TypeTextBackendResult } from './interactor-types.ts';
49
import type { RuntimeOperationFact } from './platform-runtime.ts';
510
import type { SessionSurface } from './session-surface.ts';
@@ -60,10 +65,7 @@ function bindTypeText(
6065
});
6166
}
6267

63-
export type LocalTypeTextInteractorResolver = (
64-
device: DeviceInfo,
65-
runner: RunnerContext,
66-
) => Promise<Interactor>;
68+
export type LocalTypeTextInteractorResolver = LocalInteractorOperationResolver;
6769

6870
export function bindLocalTypeTextInteractor(
6971
params: Readonly<{
@@ -72,13 +74,10 @@ export function bindLocalTypeTextInteractor(
7274
resolveInteractor: LocalTypeTextInteractorResolver;
7375
}>,
7476
): TypeTextRuntimeOperations {
75-
return bindTypeText(
76-
params.signal,
77-
async (runner) => await params.resolveInteractor(params.device, runner),
78-
);
77+
return bindTypeText(params.signal, localInteractorSource(params));
7978
}
8079

81-
export type ProviderTypeTextInteractorResolver = (runner: RunnerContext) => Interactor | undefined;
80+
export type ProviderTypeTextInteractorResolver = ProviderInteractorOperationResolver;
8281

8382
/** Provider bindings fail closed when their exact owner no longer exposes its interactor. */
8483
export function bindProviderTypeTextInteractor(
@@ -88,13 +87,5 @@ export function bindProviderTypeTextInteractor(
8887
resolveInteractor: ProviderTypeTextInteractorResolver;
8988
}>,
9089
): TypeTextRuntimeOperations {
91-
return bindTypeText(params.signal, async (runner) => {
92-
const interactor = params.resolveInteractor(runner);
93-
if (interactor) return interactor;
94-
throw new AppError(
95-
'UNSUPPORTED_OPERATION',
96-
'Provider-owned type operation has no bound provider interactor.',
97-
{ reason: 'provider-runtime-interactor-missing', deviceId: params.device.id },
98-
);
99-
});
90+
return bindTypeText(params.signal, providerInteractorSource({ ...params, operation: 'type' }));
10091
}

‎packages/platform-android/src/runtime.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ test.each([
105105
expect(facts.operations.setViewport).toMatchObject({ available: false });
106106
expect(binding.operations.setViewport).toBeUndefined();
107107
expect(facts.operations.captureScreenshot).toEqual({ available: true });
108+
// Interaction cells (R40/R41): every real Android kind drives touch and text through adb;
109+
// only the synthetic `simulator` row (covered below) lacks a device behind it.
110+
expect(facts.operations.focusPoint).toEqual({ available: true });
111+
expect(facts.operations.typeText).toEqual({ available: true });
112+
expect(binding.operations.focusPoint).toBeTypeOf('function');
113+
expect(binding.operations.typeText).toBeTypeOf('function');
108114
expect(binding.operations.captureScreenshot).toBeTypeOf('function');
109115
expect(binding.operations.captureSnapshot).toBeTypeOf('function');
110116
expect(binding.operations.readTextAtPoint).toBeTypeOf('function');
@@ -276,6 +282,15 @@ test.each([
276282
expect(facts.operations.bootTargetHeadless.available).toBe(runtimeDevice.kind === 'emulator');
277283
expect(facts.operations.captureSnapshot.available).toBe(runtimeDevice.kind !== 'simulator');
278284
expect(facts.operations.readTextAtPoint.available).toBe(runtimeDevice.kind !== 'simulator');
285+
// R40/R41: the synthetic simulator row is the one Android cell with no adb touch or text.
286+
expect(facts.operations.focusPoint.available).toBe(runtimeDevice.kind !== 'simulator');
287+
expect(facts.operations.typeText.available).toBe(runtimeDevice.kind !== 'simulator');
288+
expect(binding.operations.focusPoint).toBeTypeOf(
289+
runtimeDevice.kind === 'simulator' ? 'undefined' : 'function',
290+
);
291+
expect(binding.operations.typeText).toBeTypeOf(
292+
runtimeDevice.kind === 'simulator' ? 'undefined' : 'function',
293+
);
279294
expect(binding.operations.captureSnapshot).toBeTypeOf(
280295
runtimeDevice.kind === 'simulator' ? 'undefined' : 'function',
281296
);

‎packages/platform-apple/src/runtime.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ test.each([
7272
expect(facts.operations.listApps.available).toBe(
7373
device.appleOs !== 'watchos' && device.iosPhysicalDeviceBackend !== 'xctest',
7474
);
75+
// R40/R41: touch and text ride the Apple interactor, which exists for the simulator and
76+
// physical device kinds — every leaf in this table is one of those two, so both cells are
77+
// available across it (parity with the retired buckets).
78+
expect(facts.operations.focusPoint).toEqual({ available: true });
79+
expect(facts.operations.typeText).toEqual({ available: true });
80+
expect(binding.operations.focusPoint).toBeTypeOf('function');
81+
expect(binding.operations.typeText).toBeTypeOf('function');
7582
for (const operation of ['appLogInspect', 'appLogDoctor', 'appLogStart'] as const) {
7683
const fact = facts.operations[operation];
7784
expect(fact.available).toBe(available);

‎packages/platform-harmonyos/src/runtime.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ test.each([
7676
// legacy dispatch already did once its Apple-runner fall-through failed.
7777
expect(facts.operations.readTextAtPoint).toMatchObject({ available: false });
7878
expect(binding.operations.readTextAtPoint).toBeUndefined();
79+
// R40/R41: hdc drives touch and text on both real kinds this table enumerates.
80+
expect(facts.operations.focusPoint).toEqual({ available: true });
81+
expect(facts.operations.typeText).toEqual({ available: true });
82+
expect(binding.operations.focusPoint).toBeTypeOf('function');
83+
expect(binding.operations.typeText).toBeTypeOf('function');
7984
await expect(binding.operations.ensureReady?.({})).resolves.toMatchObject({ booted: true });
8085
await expect(
8186
binding.operations.listApps?.({ device: runtimeDevice, filter: 'all' }),

‎packages/platform-linux/src/runtime.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ test.each([
110110
);
111111
expect(binding.facts.operations.setViewport).toMatchObject({ available: false });
112112
expect(binding.operations.setViewport).toBeUndefined();
113+
// R40/R41: the desktop is the only Linux cell with a pointer and keyboard to drive.
114+
expect(binding.facts.operations.focusPoint.available).toBe(device.kind === 'device');
115+
expect(binding.facts.operations.typeText.available).toBe(device.kind === 'device');
116+
expect(binding.operations.focusPoint).toBeTypeOf(
117+
device.kind === 'device' ? 'function' : 'undefined',
118+
);
119+
expect(binding.operations.typeText).toBeTypeOf(
120+
device.kind === 'device' ? 'function' : 'undefined',
121+
);
113122
expect(binding.facts.operations.captureScreenshot.available).toBe(device.kind === 'device');
114123
expect(binding.operations.captureScreenshot).toBeTypeOf(
115124
device.kind === 'device' ? 'function' : 'undefined',

‎packages/platform-vega/src/runtime.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ test.each([
135135
reason: 'unsupported-platform-leaf',
136136
});
137137
expect(binding.operations.captureSnapshot).toBeUndefined();
138+
// R40/R41: Vega exposes remote navigation only; touch and text refuse with the owner hint.
139+
expect(binding.facts.operations.focusPoint).toMatchObject({
140+
available: false,
141+
reason: 'unsupported-platform-leaf',
142+
hint: expect.stringContaining('remote navigation only'),
143+
});
144+
expect(binding.facts.operations.typeText).toMatchObject({
145+
available: false,
146+
reason: 'unsupported-platform-leaf',
147+
hint: expect.stringContaining('remote navigation only'),
148+
});
149+
expect(binding.operations.focusPoint).toBeUndefined();
150+
expect(binding.operations.typeText).toBeUndefined();
138151
expect(binding.facts.operations.readTextAtPoint.available).toBe(false);
139152
expect(binding.operations.readTextAtPoint).toBeUndefined();
140153
expect(binding.facts.operations.setViewport).toMatchObject({ available: false });

‎packages/platform-web/src/runtime.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ test('preserves a narrow web provider dump including empty successful entries',
5858
// legacy `read` dispatch had no web arm at all and threw on every call before falling back.
5959
expect(binding.facts.operations.readTextAtPoint.available).toBe(false);
6060
expect(binding.operations.readTextAtPoint).toBeUndefined();
61+
// R40/R41: the browser device drives touch and text through the one web interactor.
62+
expect(binding.facts.operations.focusPoint).toEqual({ available: true });
63+
expect(binding.facts.operations.typeText).toEqual({ available: true });
64+
expect(binding.operations.focusPoint).toBeTypeOf('function');
65+
expect(binding.operations.typeText).toBeTypeOf('function');
6166
expect(binding.operations.captureSnapshot).toBeTypeOf('function');
6267
expectLifecycleFacts(binding);
6368
});
@@ -145,6 +150,10 @@ test.each([
145150
expect(binding.operations.setViewport).toBeUndefined();
146151
expect(binding.facts.operations.captureScreenshot.available).toBe(false);
147152
expect(binding.operations.captureScreenshot).toBeUndefined();
153+
expect(binding.facts.operations.focusPoint.available).toBe(false);
154+
expect(binding.operations.focusPoint).toBeUndefined();
155+
expect(binding.facts.operations.typeText.available).toBe(false);
156+
expect(binding.operations.typeText).toBeUndefined();
148157
expect(binding.operations.captureSnapshot).toBeUndefined();
149158
},
150159
);

0 commit comments

Comments
 (0)