Skip to content

Commit 6603d28

Browse files
committed
test: reconcile unified gestures with helper ownership
1 parent a8514d0 commit 6603d28

3 files changed

Lines changed: 55 additions & 61 deletions

File tree

src/platforms/android/__tests__/multitouch-helper-install.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,44 @@ beforeEach(() => {
1515
resetAndroidMultiTouchHelperInstallCache();
1616
});
1717

18+
test('helper install uses replace and test-package semantics', async () => {
19+
const fixture = await makeInstallFixture('helper-apk');
20+
const installCalls: unknown[] = [];
21+
const adb: AndroidAdbExecutor = async (args) => {
22+
if (args.includes('--show-versioncode')) {
23+
return { exitCode: 1, stdout: '', stderr: 'not found' };
24+
}
25+
throw new Error(`unexpected adb call: ${args.join(' ')}`);
26+
};
27+
const provider: AndroidAdbProvider = {
28+
exec: adb,
29+
install: async (installedPath, options) => {
30+
installCalls.push({ installedPath, options });
31+
return { exitCode: 0, stdout: '', stderr: '' };
32+
},
33+
};
34+
35+
const result = await ensureAndroidMultiTouchHelper({
36+
adb,
37+
adbProvider: provider,
38+
artifact: fixture.artifact,
39+
deviceKey: 'android:emulator-5554',
40+
});
41+
42+
assert.equal(result.reason, 'missing');
43+
assert.deepEqual(installCalls, [
44+
{
45+
installedPath: fixture.artifact.apkPath,
46+
options: {
47+
replace: true,
48+
allowTestPackages: true,
49+
allowFailure: true,
50+
timeoutMs: 30_000,
51+
},
52+
},
53+
]);
54+
});
55+
1856
test('same-version helper is current only when installed APK bytes match', async () => {
1957
const fixture = await makeInstallFixture('current-helper');
2058
const { adb, provider, pulls, installs } = makeInstalledHelperDevice({

src/platforms/android/__tests__/multitouch-helper-ownership.test.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import assert from 'node:assert/strict';
22
import { beforeEach, test, vi } from 'vitest';
33
import { ANDROID_EMULATOR } from '../../../__tests__/test-utils/index.ts';
4+
import { buildGesturePlan } from '../../../contracts/gesture-plan.ts';
45
import { withAndroidAdbProvider } from '../adb-executor.ts';
56
import {
7+
performGestureAndroid,
68
resetAndroidMultiTouchHelperInstallCache,
7-
swipeGestureAndroid,
89
} from '../multitouch-helper.ts';
910
import { stopAndroidSnapshotHelperSessionForDevice } from '../snapshot-helper.ts';
1011
import {
@@ -72,13 +73,20 @@ test('helper gesture releases persistent snapshot instrumentation before touch i
7273
},
7374
{ serial: ANDROID_EMULATOR.id },
7475
async () =>
75-
await swipeGestureAndroid(ANDROID_EMULATOR, {
76-
x1: 340,
77-
y1: 400,
78-
x2: 60,
79-
y2: 400,
80-
durationMs: 300,
81-
}),
76+
await performGestureAndroid(
77+
ANDROID_EMULATOR,
78+
buildGesturePlan(
79+
{
80+
intent: 'pan',
81+
pointerCount: 1,
82+
origin: { x: 340, y: 400 },
83+
delta: { x: -280, y: 0 },
84+
durationMs: 300,
85+
},
86+
{ x: 0, y: 0, width: 400, height: 800 },
87+
'android',
88+
),
89+
),
8290
);
8391

8492
assert.equal(result?.backend, 'android-multitouch-helper');

src/platforms/android/__tests__/multitouch-helper.test.ts

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
import assert from 'node:assert/strict';
2-
import crypto from 'node:crypto';
3-
import { promises as fs } from 'node:fs';
4-
import os from 'node:os';
5-
import path from 'node:path';
62
import { beforeEach, test } from 'vitest';
73
import { ANDROID_EMULATOR } from '../../../__tests__/test-utils/index.ts';
84
import { buildGesturePlan } from '../../../contracts/gesture-plan.ts';
95
import {
10-
ensureAndroidMultiTouchHelper,
116
normalizeAndroidMultiTouchHelperGestureRequest,
127
parseAndroidMultiTouchHelperOutput,
138
performGestureAndroid,
149
resetAndroidMultiTouchHelperInstallCache,
1510
runAndroidMultiTouchHelperGesture,
1611
} from '../multitouch-helper.ts';
17-
import {
18-
withAndroidAdbProvider,
19-
type AndroidAdbExecutor,
20-
type AndroidAdbProvider,
21-
} from '../adb-executor.ts';
12+
import { withAndroidAdbProvider } from '../adb-executor.ts';
2213
import {
2314
ANDROID_MULTITOUCH_HELPER_MANIFEST as manifest,
2415
androidMultiTouchResultRecord as resultRecord,
2516
} from './multitouch-helper.fixtures.ts';
26-
import type { GesturePlan } from '../../../contracts/gesture-plan.ts';
2717

2818
const viewport = { x: 0, y: 0, width: 400, height: 800 };
2919

@@ -219,45 +209,3 @@ test('helper failures remain structured and actionable', async () => {
219209
{ code: 'COMMAND_FAILED', message: 'injectInputEvent returned false' },
220210
);
221211
});
222-
223-
test('helper install uses replace and test-package semantics', async () => {
224-
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'multitouch-helper-install-'));
225-
const apkPath = path.join(tmpDir, 'helper.apk');
226-
await fs.writeFile(apkPath, 'helper-apk');
227-
const installCalls: unknown[] = [];
228-
const adb: AndroidAdbExecutor = async (args) => {
229-
if (args.includes('--show-versioncode')) {
230-
return { exitCode: 1, stdout: '', stderr: 'not found' };
231-
}
232-
throw new Error(`unexpected adb call: ${args.join(' ')}`);
233-
};
234-
const adbProvider: AndroidAdbProvider = {
235-
exec: adb,
236-
install: async (installedPath, options) => {
237-
installCalls.push({ installedPath, options });
238-
return { exitCode: 0, stdout: '', stderr: '' };
239-
},
240-
};
241-
const result = await ensureAndroidMultiTouchHelper({
242-
adb,
243-
adbProvider,
244-
artifact: { apkPath, manifest: { ...manifest, sha256: sha256Text('helper-apk') } },
245-
deviceKey: 'android:emulator-5554',
246-
});
247-
assert.equal(result.reason, 'missing');
248-
assert.deepEqual(installCalls, [
249-
{
250-
installedPath: apkPath,
251-
options: {
252-
replace: true,
253-
allowTestPackages: true,
254-
allowFailure: true,
255-
timeoutMs: 30_000,
256-
},
257-
},
258-
]);
259-
});
260-
261-
function sha256Text(text: string): string {
262-
return crypto.createHash('sha256').update(text).digest('hex');
263-
}

0 commit comments

Comments
 (0)