From 314ce9f5c00dd53448c21cddc47cf9e34656ccb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Fri, 20 Nov 2026 17:14:34 +0100 Subject: [PATCH] fix(cli): run a command that takes no session while a leased connection is active --- src/__tests__/cli-leased-session.test.ts | 25 ++++++++++++++++++++++++ src/cli.ts | 8 ++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/__tests__/cli-leased-session.test.ts b/src/__tests__/cli-leased-session.test.ts index f0b8f22c43..5ddd9e9fda 100644 --- a/src/__tests__/cli-leased-session.test.ts +++ b/src/__tests__/cli-leased-session.test.ts @@ -348,6 +348,31 @@ test('a macos-app remote config with a host-allocated lease needs a session and fs.rmSync(solo.root, { recursive: true, force: true }); }); +test('a command that takes no session runs while a leased connection is active', async () => { + const solo = workspace(); + writeStoredConnection(solo, { + session: 'limrun-a', + tenant: 'limrun', + runId: 'run-limrun-a', + leaseBackend: 'ios-instance', + leaseProvider: 'limrun', + platform: 'ios', + }); + + // The active leased connection still makes a connection command name its session... + assertSessionRequired(await runAgentCommand(solo, ['snapshot'])); + // ...but `auth` runs on no connection, and `--session` is not one of its flags. + const environments: Record[] = [{}, { AGENT_DEVICE_SESSION: 'demo' }]; + for (const env of environments) { + const result = await runAgentCommand(solo, ['auth', 'status'], env); + assert.equal(result.code, null, result.stdout); + assert.equal(JSON.parse(result.stdout).data.authenticated, false); + assert.deepEqual(result.calls, []); + } + + fs.rmSync(solo.root, { recursive: true, force: true }); +}); + function writeLeasedProfile(workspace: Workspace): string { const remoteConfig = path.join(workspace.project, 'shared.remote.json'); fs.writeFileSync( diff --git a/src/cli.ts b/src/cli.ts index 692b988ef9..20b0d78ea6 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -41,6 +41,7 @@ import { applyDefaultPlatformBinding, type DevicePin, getCommandSchema, + isFlagSupportedForCommand, readCliBatchStepsJson, resolveBindingSettings, } from '@agent-device/command-surface'; @@ -787,10 +788,9 @@ function resolveActiveConnectionDefaults(options: { if ( options.command === 'connect' || options.command === 'connection' || - options.command === 'daemon' || - options.command === 'plugins' || - options.command === 'device' || - options.command === 'proxy' + // A command that cannot take a session (`auth`, `daemon`, `plugins`, `device`, `proxy`) runs + // on no connection. Reading the active one would refuse it for a session it cannot name. + !isFlagSupportedForCommand('session', options.command) ) { return null; }