mirror of
https://github.com/callstack/agent-device.git
synced 2026-09-14 20:06:34 +08:00
a13a6832ee
* feat: add selector-targeted drag gestures * fix: address drag gesture review feedback * fix: satisfy drag review quality gates * fix(android): lower drag trajectories piecewise * test(replay): validate drag fixture selectors * fix(ios): ignore full-viewport chrome containers * test(drag): prove destination on live devices
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import type { AgentDeviceBackend } from '../../../src/backend.ts';
|
|
import type { SnapshotState } from '@agent-device/kernel/snapshot';
|
|
import { createLocalArtifactAdapter } from '../../../src/io.ts';
|
|
import {
|
|
createAgentDevice,
|
|
createMemorySessionStore,
|
|
localCommandPolicy,
|
|
} from '../../../src/runtime.ts';
|
|
|
|
type ContractBackendOverrides = Partial<
|
|
Pick<
|
|
AgentDeviceBackend,
|
|
| 'captureSnapshot'
|
|
| 'tap'
|
|
| 'tapTarget'
|
|
| 'fill'
|
|
| 'fillTarget'
|
|
| 'performGesture'
|
|
| 'resolveGestureViewport'
|
|
>
|
|
> & {
|
|
platform?: AgentDeviceBackend['platform'];
|
|
};
|
|
|
|
/**
|
|
* The plain runtime harness for contract scenarios on the paths that never
|
|
* touch the runner: runtime-selector, runtime-ref, native-ref (backend
|
|
* tapTarget/fillTarget present) and coordinate. Path forcing is natural:
|
|
* selector/ref targets pick the runtime path, a `tapTarget`/`fillTarget`
|
|
* backend picks the native-ref fast path, x/y picks the coordinate path.
|
|
*/
|
|
export function createContractDevice(
|
|
snapshot: SnapshotState,
|
|
overrides: ContractBackendOverrides = {},
|
|
): ReturnType<typeof createAgentDevice> {
|
|
return createAgentDevice({
|
|
backend: {
|
|
platform: overrides.platform ?? 'ios',
|
|
captureSnapshot: async (...args) =>
|
|
overrides.captureSnapshot ? await overrides.captureSnapshot(...args) : { snapshot },
|
|
tap: async (...args) => await overrides.tap?.(...args),
|
|
tapTarget: overrides.tapTarget,
|
|
fill: async (...args) => await overrides.fill?.(...args),
|
|
fillTarget: overrides.fillTarget,
|
|
typeText: async () => {},
|
|
performGesture: overrides.performGesture,
|
|
resolveGestureViewport: overrides.resolveGestureViewport,
|
|
} satisfies AgentDeviceBackend,
|
|
artifacts: createLocalArtifactAdapter(),
|
|
sessions: createMemorySessionStore([{ name: 'default', snapshot }]),
|
|
policy: localCommandPolicy(),
|
|
});
|
|
}
|