Skip to content

Commit 8cd9a0f

Browse files
committed
fix(android-tools): keep inferOpenedAppBundleId best-effort on a mechanics load failure
Loading Android mechanics moved from the near-infallible root platform-runtime-open-target.ts to the real adb-backed mechanics module, but the wrapper call stayed unguarded. A loader failure now throws instead of leaving the app-bundle identity unset, even for a targetless open that never needed the loaded module. Wrap the load and delegate in try/catch so it degrades to the current bundle id, matching the pre-refactor behavior, and add a regression test with the loader rejecting on a targetless open. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0167UVzrdzVMCZqXgxtzWoTD
1 parent a0ad24c commit 8cd9a0f

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect, test, vi } from 'vitest';
2+
import type { DeviceInfo } from '@agent-device/kernel/device';
3+
4+
vi.mock('../platform-runtime-android-mechanics.ts', () => ({
5+
loadAndroidMechanics: vi.fn(async () => {
6+
throw new Error('adb host unavailable');
7+
}),
8+
}));
9+
10+
import { createAndroidApplicationTools } from '../platform-runtime-android-application-tools.ts';
11+
12+
const device: DeviceInfo = {
13+
platform: 'android',
14+
id: 'emulator-5554',
15+
name: 'Pixel 9 Pro XL',
16+
kind: 'emulator',
17+
booted: true,
18+
};
19+
20+
test('inferOpenedAppBundleId stays best-effort when Android mechanics fails to load for a targetless open', async () => {
21+
await expect(
22+
createAndroidApplicationTools().inferOpenedAppBundleId(device, undefined, undefined),
23+
).resolves.toBeUndefined();
24+
});

‎src/platform-runtime-android-application-tools.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ export function createAndroidApplicationTools(): AndroidApplicationTools {
2525
return Object.freeze({
2626
resolveOpenTarget: async (device, input) => await resolveAndroidOpenTarget(device, input),
2727
inferOpenedAppBundleId: async (device, target, currentAppBundleId) => {
28-
const { inferAndroidPackageAfterOpen } = await loadAndroidMechanics();
29-
return await inferAndroidPackageAfterOpen(device, target, currentAppBundleId);
28+
try {
29+
const { inferAndroidPackageAfterOpen } = await loadAndroidMechanics();
30+
return await inferAndroidPackageAfterOpen(device, target, currentAppBundleId);
31+
} catch {
32+
return currentAppBundleId;
33+
}
3034
},
3135
resetFramePerfStats: async (device, appBundleId) => {
3236
const { resetAndroidFramePerfStats } = await loadAndroidMechanics();

0 commit comments

Comments
 (0)