Skip to content

Commit b673aca

Browse files
committed
fix(cli): skip env platform binding when platform is explicit-only
1 parent f186e0a commit b673aca

2 files changed

Lines changed: 58 additions & 9 deletions

File tree

‎src/__tests__/cli-device-status.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,48 @@ test('device status matches explicit --serial when project agent-device.json set
297297
fs.rmSync(projectDir, { recursive: true, force: true });
298298
}
299299
});
300+
301+
test('device status ignores AGENT_DEVICE_PLATFORM env default when platform is omitted', async () => {
302+
const claimsDir = mkdtempForTestSync('agent-device-cli-claims-');
303+
const owner = readCurrentOwnerIdentity();
304+
try {
305+
fs.writeFileSync(
306+
path.join(claimsDir, 'android.json'),
307+
JSON.stringify({
308+
schemaVersion: 1,
309+
deviceKey: 'local:android:none:emulator-5560',
310+
device: {
311+
platform: 'android',
312+
id: 'emulator-5560',
313+
name: 'Android Emulator',
314+
kind: 'emulator',
315+
},
316+
session: 'android-session',
317+
workspace: '/worktrees/android',
318+
stateDir: process.cwd(),
319+
ownerPid: owner.pid,
320+
ownerStartTime: owner.startTime,
321+
ownerToken: 'android-token',
322+
createdAtMs: 1,
323+
updatedAtMs: 1,
324+
}),
325+
);
326+
327+
const result = await runCliCapture(
328+
['device', 'status', '--serial', 'emulator-5560', '--json'],
329+
{
330+
env: {
331+
AGENT_DEVICE_CLAIMS_DIR: claimsDir,
332+
AGENT_DEVICE_PLATFORM: 'ios',
333+
},
334+
},
335+
);
336+
assert.equal(result.code, null);
337+
const payload = JSON.parse(result.stdout);
338+
assert.equal(payload.success, true);
339+
assert.equal(payload.data.claims.length, 1);
340+
assert.equal(payload.data.claims[0].device.id, 'emulator-5560');
341+
} finally {
342+
fs.rmSync(claimsDir, { recursive: true, force: true });
343+
}
344+
});

‎src/cli.ts‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import type {
3535
} from '@agent-device/contracts/client';
3636
import { tryRunClientBackedCommand } from './cli/commands/router.ts';
3737
import { runAgentCdpCommand } from './cli/commands/agent-cdp.ts';
38-
import { readCliBatchStepsJson } from '@agent-device/command-surface';
38+
import { getCommandSchema, readCliBatchStepsJson } from '@agent-device/command-surface';
3939
import {
4040
createRequestId,
4141
emitDiagnostic,
@@ -365,14 +365,17 @@ async function resolveRunContextOrExit(
365365
configuredPlatform: parsed.flags.platform,
366366
configuredSession: parsed.flags.session,
367367
});
368-
const flags = binding.lockPolicy
369-
? { ...parsed.flags }
370-
: applyDefaultPlatformBinding(parsed.flags, {
371-
env: base.host.env,
372-
policyOverrides: parsed.flags,
373-
configuredPlatform: parsed.flags.platform,
374-
configuredSession: parsed.flags.session,
375-
});
368+
const skipPlatformDefault =
369+
getCommandSchema(base.command)?.explicitOnlyFlags?.includes('platform') === true;
370+
const flags =
371+
binding.lockPolicy || skipPlatformDefault
372+
? { ...parsed.flags }
373+
: applyDefaultPlatformBinding(parsed.flags, {
374+
env: base.host.env,
375+
policyOverrides: parsed.flags,
376+
configuredPlatform: parsed.flags.platform,
377+
configuredSession: parsed.flags.session,
378+
});
376379
// A leased remote config, or a connect without one (it always leases through a provider), needs
377380
// an explicit session before anything is resolved or leased (#3931).
378381
const leasedConnect = base.command === 'connect' && !flags.remoteConfig;
@@ -785,6 +788,7 @@ function resolveActiveConnectionDefaults(options: {
785788
options.command === 'connection' ||
786789
options.command === 'daemon' ||
787790
options.command === 'plugins' ||
791+
options.command === 'device' ||
788792
options.command === 'proxy'
789793
) {
790794
return null;

0 commit comments

Comments
 (0)