Skip to content

Commit 50719c4

Browse files
committed
test(limrun): drive the scoped fingerprint through sendToDaemon
The client test now sends lease_allocate with an iOS and an Android lease backend over both transports and checks each body carries the fingerprint scoped to that platform, which fails if the client drops the backend. The Limrun docs name the compared variables, and the credentials module says why it keeps its own lease-backend-to-platform map.
1 parent 83cf66c commit 50719c4

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎src/daemon-client/__tests__/daemon-client-provider-credentials.test.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import { providerCredentialFingerprint } from '../../provider-credential-fingerp
1919
import { LIMRUN_CREDENTIAL_VARIABLES } from '../../provider-limrun-credentials.ts';
2020

2121
const API_KEY = 'lim-secret-key';
22+
const ANDROID_ATTACH = {
23+
LIM_ANDROID_INSTANCE_URL: 'https://region.limrun.example/v1/android_x/api',
24+
LIM_ANDROID_INSTANCE_TOKEN: 'android-token',
25+
LIM_ANDROID_INSTANCE_ADB_URL: 'wss://region.limrun.example/v1/android_x/adb',
26+
};
2227

2328
afterEach(() => {
2429
vi.unstubAllEnvs();
@@ -38,31 +43,44 @@ test.sequential.for(['socket', 'http'] as const)(
3843
vi.stubEnv('AGENT_DEVICE_DAEMON_AUTH_TOKEN', undefined);
3944
const stateDir = mkdtempForTestSync('agent-device-provider-credentials-daemon-');
4045
const daemon = await startLocalDaemon(stateDir, transport);
41-
const send = (command: string) =>
46+
const send = (command: string, leaseBackend?: 'ios-instance' | 'android-instance') =>
4247
sendToDaemon({
4348
session: 'default',
4449
command,
4550
positionals: [],
4651
flags: { stateDir, daemonTransport: transport },
47-
meta: { requestId: `req-${command}`, leaseProvider: 'limrun', tenantId: 'tenant-a' },
52+
meta: {
53+
requestId: `req-${command}`,
54+
leaseProvider: 'limrun',
55+
tenantId: 'tenant-a',
56+
...(leaseBackend ? { leaseBackend } : {}),
57+
},
4858
});
59+
const attachedEnv = { LIMRUN_API_KEY: API_KEY, ...ANDROID_ATTACH };
4960

5061
try {
5162
vi.stubEnv('LIMRUN_API_KEY', API_KEY);
5263
await send('lease_allocate');
5364
await send('devices');
5465
vi.stubEnv('LIMRUN_API_KEY', undefined);
5566
await send('lease_allocate');
67+
for (const [name, value] of Object.entries(attachedEnv)) vi.stubEnv(name, value);
68+
await send('lease_allocate', 'ios-instance');
69+
await send('lease_allocate', 'android-instance');
5670
} finally {
5771
await daemon.close();
5872
fs.rmSync(stateDir, { recursive: true, force: true });
5973
}
6074

75+
const iosFingerprint = providerCredentialFingerprint('limrun', attachedEnv, 'ios-instance');
6176
expect(daemon.bodies.map(readFingerprint)).toEqual([
6277
providerCredentialFingerprint('limrun', { LIMRUN_API_KEY: API_KEY }),
6378
undefined,
6479
undefined,
80+
iosFingerprint,
81+
providerCredentialFingerprint('limrun', attachedEnv, 'android-instance'),
6582
]);
83+
expect(iosFingerprint).not.toBe(providerCredentialFingerprint('limrun', attachedEnv));
6684
for (const body of daemon.bodies) expect(body).not.toContain(API_KEY);
6785
},
6886
);

‎src/provider-limrun-credentials.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export const LIMRUN_CREDENTIAL_VARIABLES: readonly string[] = [
2727
...INSTANCE_VARS.android,
2828
];
2929

30+
// Mirrors platformForLimrunLeaseBackend in provider-limrun, which exposes only its root entry, and
31+
// that entry loads the Limrun SDK; importing it here would load the SDK on every credential read.
3032
const LEASE_BACKEND_PLATFORMS: ReadonlyMap<string, 'ios' | 'android'> = new Map([
3133
['ios-instance', 'ios'],
3234
['android-instance', 'android'],

‎website/docs/docs/limrun.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ agent-device disconnect
4343

4444
On an attached Android instance, agent-device does not replace an existing port reverse mapping. If the owner already maps a device port, such as `tcp:8081` for their Metro server, a reverse to that port fails and the owner's mapping stays in place. The error has `details.reason: 'android_port_reverse_rebind_refused'` when `adb reverse --list` shows the mapping. Otherwise it is a plain ADB failure.
4545

46-
A running daemon keeps the Limrun variables it started with. If your shell holds different ones, the first command that allocates a lease, such as `install` or `open`, refuses before it creates or attaches to an instance; run `agent-device daemon stop` (with the same `--state-dir`) and rerun the command. Only the account variables and the leased platform's instance variables are compared. A shell that sets none of these variables uses the daemon's.
46+
A running daemon keeps the Limrun variables it started with. If your shell holds different account variables, or different instance variables for the platform being leased, the first command that allocates a lease, such as `install` or `open`, refuses before it creates or attaches to an instance; run `agent-device daemon stop` (with the same `--state-dir`) and rerun the command. A shell that sets none of the compared variables uses the daemon's.
4747

4848
`install`, and `apps` before the first `open`, still need `LIMRUN_API_KEY`, because they use Limrun asset storage. After `open`, `apps` lists the apps installed on the instance without the key. Install the app before you hand over the instance. From the Node.js runtime, `getDeviceSession(device).installRemoteApp(url)` installs from a signed asset URL without the API key.
4949

0 commit comments

Comments
 (0)