Skip to content

Commit 2386729

Browse files
amankansal-ltclaude
andcommitted
test(limrun): refuse profile fields on an attached instance too
Allocate and connect against an existing instance (LIM_IOS_INSTANCE_URL and token, no API key) accept the consumed --provider-app and refuse the rest, like a created instance. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e0425c8 commit 2386729

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎src/__tests__/cloud-connect-profile-fields.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from 'node:fs';
44
import path from 'node:path';
55
import { AppError } from '@agent-device/kernel/errors';
66
import { resolveCloudWebDriverConnectProfile } from '../cli/connection/cloud-webdriver-profile.ts';
7+
import { resolveLimrunConnectProfile } from '../cli/connection/limrun-profile.ts';
78
import { runCliCapture } from './cli-capture.ts';
89
import { mkdtempForTestSync } from './test-utils/tmp-dir.ts';
910

@@ -34,6 +35,33 @@ test('connect limrun refuses profile fields Limrun does not read', async () => {
3435
]);
3536
});
3637

38+
test('connect limrun applies the same refusal when attaching to an existing instance', () => {
39+
const tempRoot = mkdtempForTestSync('agent-device-connect-limrun-attach-profile-fields-');
40+
const connect = (flags: Record<string, unknown>) =>
41+
resolveLimrunConnectProfile({
42+
stateDir: path.join(tempRoot, '.state'),
43+
cwd: tempRoot,
44+
env: {
45+
LIM_IOS_INSTANCE_URL: 'https://region.limrun.example/v1/ios_x/api',
46+
LIM_IOS_INSTANCE_TOKEN: 'ios-instance-token',
47+
},
48+
flags: { json: false, help: false, version: false, platform: 'ios', ...flags },
49+
});
50+
51+
try {
52+
assert.equal(connect({ providerApp: 'Example.ipa' }).flags.providerApp, 'Example.ipa');
53+
assert.throws(
54+
() => connect({ providerOsVersion: '18.0' }),
55+
(error: unknown) =>
56+
error instanceof AppError &&
57+
error.code === 'INVALID_ARGS' &&
58+
JSON.stringify(error.details?.flags) === '["--provider-os-version"]',
59+
);
60+
} finally {
61+
fs.rmSync(tempRoot, { recursive: true, force: true });
62+
}
63+
});
64+
3765
test('connect browserstack refuses AWS Device Farm flags', () => {
3866
const tempRoot = mkdtempForTestSync('agent-device-connect-browserstack-reject-');
3967

‎src/__tests__/limrun-runtime.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,3 +973,22 @@ test('Limrun without an API key refuses operations that need one', async () => {
973973
}
974974
assert.throws(() => new LimrunRuntime({}), /requires an apiKey or instance access/);
975975
});
976+
977+
test('Limrun attaches an existing instance under a consumed field and refuses a refused one', async () => {
978+
const runtime = new LimrunRuntime({ instances: { ios: ATTACHED_IOS } });
979+
const allocateLease = runtime.leaseLifecycle.allocate;
980+
if (!allocateLease) throw new Error('Limrun runtime must provide lease allocation');
981+
try {
982+
await assert.rejects(
983+
allocateLease(iosLease('lease-refused'), { flags: { providerOsVersion: '18.0' } }),
984+
(error: unknown) => error instanceof AppError && error.code === 'INVALID_ARGS',
985+
);
986+
assert.equal(vi.mocked(createIosInstanceClient).mock.calls.length, 0);
987+
const ios = await allocateLease(iosLease('lease-attached-ios'), {
988+
flags: { providerApp: 'Example.ipa' },
989+
});
990+
assert.match(String(ios?.limrunInstanceId), /^attached-[a-f0-9]{12}$/);
991+
} finally {
992+
await runtime.shutdown();
993+
}
994+
});

0 commit comments

Comments
 (0)