Skip to content

Commit f54a67a

Browse files
committed
test(composition): pin the composed snapshot-helper stop rule against the mechanics leaf
From #3519's review, landed here so the daemon lane keeps no root mock: one root-owned case calls the REAL platformResourceCleanup.stopSnapshotHelper over the mocked android mechanics leaf and asserts an Android device reaches stopAndroidSnapshotHelperSessionForDevice(device) while a non-Android device does not. Both legs were proven to bite by temporarily inverting and then deleting the platform guard.
1 parent be4609a commit f54a67a

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { beforeEach, expect, test, vi } from 'vitest';
2+
3+
// Root composition owns the rule that only an Android device has an adb snapshot-helper session to
4+
// stop. The daemon never names this leaf: it calls the composed `platformResourceCleanup` port, so
5+
// the rule is pinned here against the real composed module over the mocked mechanics leaf.
6+
const mockStopAndroidSnapshotHelperSessionForDevice = vi.hoisted(() => vi.fn(async () => {}));
7+
vi.mock('@agent-device/platform-android/mechanics', async (importOriginal) => {
8+
const actual = await importOriginal<typeof import('@agent-device/platform-android/mechanics')>();
9+
return {
10+
...actual,
11+
stopAndroidSnapshotHelperSessionForDevice: mockStopAndroidSnapshotHelperSessionForDevice,
12+
};
13+
});
14+
15+
import { ANDROID_EMULATOR, IOS_SIMULATOR } from '@agent-device/test-kit/device-fixtures';
16+
import { platformResourceCleanup } from '../../platform-runtime-resource-cleanup.ts';
17+
18+
beforeEach(() => {
19+
vi.clearAllMocks();
20+
});
21+
22+
test('the composed cleanup stops the snapshot helper for an Android device', async () => {
23+
await platformResourceCleanup.stopSnapshotHelper(ANDROID_EMULATOR);
24+
25+
expect(mockStopAndroidSnapshotHelperSessionForDevice).toHaveBeenCalledExactlyOnceWith(
26+
ANDROID_EMULATOR,
27+
);
28+
});
29+
30+
test('the composed cleanup names no snapshot helper for a non-Android device', async () => {
31+
await platformResourceCleanup.stopSnapshotHelper(IOS_SIMULATOR);
32+
33+
expect(mockStopAndroidSnapshotHelperSessionForDevice).not.toHaveBeenCalled();
34+
});

0 commit comments

Comments
 (0)