|
1 | 1 | import { describe, expect, test } from 'vitest'; |
2 | 2 | import type { CliFlags } from '@agent-device/contracts/command'; |
3 | | -import type { AgentDeviceClient } from '../../client/client-types.ts'; |
| 3 | +import { createAgentDeviceClient } from '../../agent-device-client.ts'; |
| 4 | +import { createTransport } from '../../__tests__/client-transport-fixture.ts'; |
4 | 5 | import { gestureCliReaders } from './gesture.ts'; |
5 | 6 | import { interactionCommandFamily } from './index.ts'; |
6 | 7 |
|
7 | 8 | const NO_FLAGS = {} as CliFlags; |
8 | 9 |
|
9 | | -/** |
10 | | - * The gesture `run` projection is exercised through the family's executable |
11 | | - * definition — the same `invoke` path the CLI/daemon/MCP surfaces dispatch |
12 | | - * through — with a client that records which interaction method each gesture |
13 | | - * kind lands on and with which options. |
14 | | - */ |
15 | | -function recordingGestureClient(calls: Array<{ method: string; options: unknown }>) { |
16 | | - const interactions = new Proxy( |
17 | | - {}, |
18 | | - { |
19 | | - get: (_target, method: string) => async (options: unknown) => { |
20 | | - calls.push({ method, options }); |
21 | | - return { ok: true }; |
22 | | - }, |
23 | | - }, |
24 | | - ); |
25 | | - return { interactions } as unknown as AgentDeviceClient; |
26 | | -} |
27 | | - |
28 | 10 | function gestureDefinition() { |
29 | 11 | const definition = interactionCommandFamily.definitions.find((entry) => entry.name === 'gesture'); |
30 | 12 | if (!definition) throw new Error('missing gesture definition'); |
31 | 13 | return definition; |
32 | 14 | } |
33 | 15 |
|
34 | | -describe('gesture run dispatch', () => { |
35 | | - // Each entry pins both halves of the run projection: which |
36 | | - // `client.interactions.*` method the kind routes to and how its payload |
37 | | - // lands on that method's options (`gesture.test.ts` covers the reader and |
38 | | - // daemon writer, not this client-side projection). |
| 16 | +describe('gesture command transport', () => { |
39 | 17 | test.for([ |
40 | 18 | { |
41 | 19 | argv: ['pan', '10', '20', '5', '6', '300'], |
42 | | - method: 'pan', |
43 | | - options: { x: 10, y: 20, dx: 5, dy: 6, durationMs: 300 }, |
| 20 | + input: { kind: 'pan', origin: { x: 10, y: 20 }, delta: { x: 5, y: 6 }, durationMs: 300 }, |
44 | 21 | }, |
45 | 22 | { |
46 | 23 | argv: ['fling', 'up', '10', '20', '400'], |
47 | | - method: 'fling', |
48 | | - options: { direction: 'up', x: 10, y: 20, distance: 400 }, |
| 24 | + input: { kind: 'fling', direction: 'up', origin: { x: 10, y: 20 }, distance: 400 }, |
49 | 25 | }, |
50 | | - { argv: ['swipe', 'left-edge'], method: 'swipeGesture', options: { preset: 'left-edge' } }, |
51 | | - { argv: ['pinch', '2', '30', '40'], method: 'pinch', options: { scale: 2, x: 30, y: 40 } }, |
| 26 | + { argv: ['swipe', 'left-edge'], input: { kind: 'swipe', preset: 'left-edge' } }, |
| 27 | + { |
| 28 | + argv: ['pinch', '2', '30', '40'], |
| 29 | + input: { kind: 'pinch', scale: 2, origin: { x: 30, y: 40 } }, |
| 30 | + }, |
| 31 | + { argv: ['pinch', '2'], input: { kind: 'pinch', scale: 2 } }, |
52 | 32 | { |
53 | 33 | argv: ['rotate', '45', '10', '20'], |
54 | | - method: 'rotateGesture', |
55 | | - options: { degrees: 45, x: 10, y: 20 }, |
| 34 | + input: { kind: 'rotate', degrees: 45, origin: { x: 10, y: 20 } }, |
56 | 35 | }, |
57 | 36 | { |
58 | 37 | argv: ['transform', '10', '20', '5', '6', '1.5', '45', '250'], |
59 | | - method: 'transformGesture', |
60 | | - options: { x: 10, y: 20, dx: 5, dy: 6, scale: 1.5, degrees: 45, durationMs: 250 }, |
| 38 | + input: { |
| 39 | + kind: 'transform', |
| 40 | + origin: { x: 10, y: 20 }, |
| 41 | + delta: { x: 5, y: 6 }, |
| 42 | + scale: 1.5, |
| 43 | + degrees: 45, |
| 44 | + durationMs: 250, |
| 45 | + }, |
61 | 46 | }, |
62 | 47 | { |
63 | 48 | argv: ['drag', 'id="drag-source"', '@e2~s42', '700', '600', '200'], |
64 | | - method: 'drag', |
65 | | - options: { |
| 49 | + input: { |
| 50 | + kind: 'drag', |
66 | 51 | source: 'id="drag-source"', |
67 | 52 | destination: '@e2~s42', |
68 | 53 | sourceHoldMs: 700, |
69 | 54 | moveMs: 600, |
70 | 55 | destinationHoldMs: 200, |
71 | 56 | }, |
72 | 57 | }, |
73 | | - ])( |
74 | | - '%argv routes to client.interactions.%method with projected options', |
75 | | - async ({ argv, method, options }) => { |
76 | | - const calls: Array<{ method: string; options: unknown }> = []; |
77 | | - const input = gestureCliReaders.gesture(argv, NO_FLAGS); |
78 | | - await gestureDefinition().invoke(recordingGestureClient(calls), input); |
79 | | - expect(calls).toHaveLength(1); |
80 | | - expect(calls[0]?.method).toBe(method); |
81 | | - expect(calls[0]?.options).toMatchObject(options); |
82 | | - }, |
83 | | - ); |
84 | | - |
85 | | - test('pinch without an origin still projects the scale', async () => { |
86 | | - const calls: Array<{ method: string; options: unknown }> = []; |
87 | | - const input = gestureCliReaders.gesture(['pinch', '2'], NO_FLAGS); |
88 | | - await gestureDefinition().invoke(recordingGestureClient(calls), input); |
89 | | - const options = calls[0]?.options as { scale?: number; x?: unknown } | undefined; |
90 | | - expect(options).toMatchObject({ scale: 2 }); |
91 | | - expect(options?.x).toBeUndefined(); |
| 58 | + ])('$argv sends structured input through the client transport', async ({ argv, input }) => { |
| 59 | + const setup = createTransport(() => ({ ok: true, data: { message: 'Performed gesture' } })); |
| 60 | + const client = createAgentDeviceClient(setup.config, { transport: setup.transport }); |
| 61 | + const parsed = gestureCliReaders.gesture(argv, NO_FLAGS); |
| 62 | + const result = await gestureDefinition().invoke(client, { |
| 63 | + ...parsed, |
| 64 | + session: 'gesture-test', |
| 65 | + deviceTarget: 'mobile', |
| 66 | + udid: 'gesture-device', |
| 67 | + }); |
| 68 | + expect(result).toEqual({ message: 'Performed gesture' }); |
| 69 | + expect(setup.calls).toHaveLength(1); |
| 70 | + expect(setup.calls[0]).toMatchObject({ |
| 71 | + command: 'gesture', |
| 72 | + positionals: [], |
| 73 | + session: 'gesture-test', |
| 74 | + flags: { target: 'mobile', udid: 'gesture-device' }, |
| 75 | + }); |
| 76 | + expect(setup.calls[0]?.input).toEqual({ |
| 77 | + ...input, |
| 78 | + session: 'gesture-test', |
| 79 | + deviceTarget: 'mobile', |
| 80 | + udid: 'gesture-device', |
| 81 | + }); |
92 | 82 | }); |
93 | 83 | }); |
0 commit comments