Skip to content

Commit 32309bb

Browse files
committed
refactor: fold limrun preinstall into allocation
1 parent 265259c commit 32309bb

3 files changed

Lines changed: 38 additions & 43 deletions

File tree

packages/provider-limrun/src/app-preinstall.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

packages/provider-limrun/src/runtime.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,12 @@ class LimrunRuntimeImplementation implements ProviderDeviceRuntime {
234234
const existing = this.sessions.get(lease.leaseId);
235235
if (existing) return { limrunInstanceId: existing.instanceId, device: existing.device };
236236

237-
const { resolvePreinstalledAppId, resolveRequestedLimrunAppAsset } =
238-
await import('./app-preinstall.ts');
239-
const { allocateLimrunAndroidSession, allocateLimrunIosSession } =
240-
await import('./session-allocation.ts');
237+
const {
238+
allocateLimrunAndroidSession,
239+
allocateLimrunIosSession,
240+
resolvePreinstalledAppId,
241+
resolveRequestedLimrunAppAsset,
242+
} = await import('./session-allocation.ts');
241243
const requestedAsset = await resolveRequestedLimrunAppAsset(this.limrun, platform, context);
242244
const session =
243245
platform === 'ios'

packages/provider-limrun/src/session-allocation.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import type Limrun from '@limrun/api';
2-
import type { DeviceLease } from '@agent-device/contracts/device';
2+
import type { DeviceLease, LeaseLifecycleContext } from '@agent-device/contracts/device';
33
import { AppError } from '@agent-device/kernel/errors';
44
import { createLimrunAndroidSession, type LimrunAndroidSession } from './android.ts';
55
import { buildLimrunDevice } from './device.ts';
66
import { createLimrunIosSession, type LimrunIosSession } from './ios.ts';
7-
import type { LimrunAppAsset } from './app-catalog.ts';
7+
import {
8+
resolveInstalledAppIdForAsset,
9+
resolveLimrunAppAsset,
10+
type LimrunAppAsset,
11+
} from './app-catalog.ts';
12+
import { createLimrunDeviceSession } from './device-session.ts';
813
import type { LimrunRuntimeDependencies } from './runtime-dependencies.ts';
914

1015
type LimrunInstance = {
@@ -28,6 +33,31 @@ type SessionAllocationParams = Readonly<{
2833
dependencies: LimrunRuntimeDependencies;
2934
}>;
3035

36+
export async function resolveRequestedLimrunAppAsset(
37+
limrun: Limrun,
38+
platform: 'android' | 'ios',
39+
context?: LeaseLifecycleContext,
40+
): Promise<LimrunAppAsset | undefined> {
41+
const value = context?.flags?.providerApp;
42+
const name = typeof value === 'string' ? value.trim() : '';
43+
if (!name) return undefined;
44+
return await resolveLimrunAppAsset(limrun, platform, name, context?.signal);
45+
}
46+
47+
export async function resolvePreinstalledAppId(
48+
session: LimrunAndroidSession | LimrunIosSession,
49+
asset: LimrunAppAsset,
50+
): Promise<string> {
51+
const apps = await createLimrunDeviceSession(session).listApps('user-installed');
52+
const matchedAppId = resolveInstalledAppIdForAsset(asset.name, apps);
53+
if (matchedAppId) return matchedAppId;
54+
throw new AppError(
55+
'COMMAND_FAILED',
56+
`Limrun installed ${asset.name}, but its application identifier could not be resolved unambiguously.`,
57+
{ asset: asset.name, installedApps: apps.map((app) => app.id) },
58+
);
59+
}
60+
3161
export async function allocateLimrunIosSession(
3262
params: SessionAllocationParams,
3363
): Promise<LimrunIosSession> {

0 commit comments

Comments
 (0)