Skip to content

Commit e6bdebf

Browse files
fix(cli): do not reapply an env platform to explicit-only commands
device status lists platform in explicitOnlyFlags, so the parser drops AGENT_DEVICE_PLATFORM. applyDefaultPlatformBinding then put it back, and device status --serial still filtered claims by that platform. Skip the binding when the command treats platform as explicit-only. A typed --platform still narrows the query.
1 parent a4295af commit e6bdebf

2 files changed

Lines changed: 64 additions & 9 deletions

File tree

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,58 @@ test('states that nothing is claimed when every claim is stale', async () => {
197197
}
198198
});
199199

200+
test('AGENT_DEVICE_PLATFORM does not narrow device status without --platform', async () => {
201+
// #4298: the parser drops an untyped platform, then session binding used to
202+
// put AGENT_DEVICE_PLATFORM back before device status read flags.platform.
203+
const claimsDir = mkdtempForTestSync('agent-device-cli-claims-');
204+
const owner = readCurrentOwnerIdentity();
205+
try {
206+
fs.writeFileSync(
207+
path.join(claimsDir, 'android.json'),
208+
JSON.stringify({
209+
schemaVersion: 1,
210+
deviceKey: 'local:android:none:emulator-5560',
211+
device: {
212+
platform: 'android',
213+
id: 'emulator-5560',
214+
name: 'Android Emu',
215+
kind: 'emulator',
216+
},
217+
session: 'android-session',
218+
workspace: '/worktrees/android',
219+
stateDir: process.cwd(),
220+
ownerPid: owner.pid,
221+
ownerStartTime: owner.startTime,
222+
ownerToken: 'android-token',
223+
createdAtMs: 1,
224+
updatedAtMs: 1,
225+
}),
226+
);
227+
const env = {
228+
AGENT_DEVICE_CLAIMS_DIR: claimsDir,
229+
AGENT_DEVICE_PLATFORM: 'ios',
230+
};
231+
232+
const untyped = await runCliCapture(
233+
['device', 'status', '--serial', 'emulator-5560', '--json'],
234+
{ env },
235+
);
236+
assert.equal(untyped.code, null);
237+
const untypedClaims = JSON.parse(untyped.stdout).data.claims;
238+
assert.equal(untypedClaims.length, 1);
239+
assert.equal(untypedClaims[0].device.name, 'Android Emu');
240+
241+
const typed = await runCliCapture(
242+
['device', 'status', '--serial', 'emulator-5560', '--platform', 'ios', '--json'],
243+
{ env },
244+
);
245+
assert.equal(typed.code, null);
246+
assert.equal(JSON.parse(typed.stdout).data.claims.length, 0);
247+
} finally {
248+
fs.rmSync(claimsDir, { recursive: true, force: true });
249+
}
250+
});
251+
200252
test('names a replaced-but-running daemon owner as stale rather than a live holder', async () => {
201253
const claimsDir = mkdtempForTestSync('agent-device-cli-claims-');
202254
const stateDir = path.join(claimsDir, 'state');

‎src/cli.ts‎

Lines changed: 12 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+
// Parser already dropped an untyped platform for explicitOnlyFlags.
369+
// Binding would read AGENT_DEVICE_PLATFORM again and narrow device claims (#4298).
370+
const flags =
371+
binding.lockPolicy || getCommandSchema(base.command)?.explicitOnlyFlags?.includes('platform')
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;

0 commit comments

Comments
 (0)