diff --git a/.changeset/fix-setup-desktop-clarity.md b/.changeset/fix-setup-desktop-clarity.md new file mode 100644 index 0000000..a0113ee --- /dev/null +++ b/.changeset/fix-setup-desktop-clarity.md @@ -0,0 +1,5 @@ +--- +'@beeper/cli': patch +--- + +Clarify that `setup --desktop` creates a separate CLI-managed Desktop profile on its own port, and point to `--local` for an already-running Desktop. When starting that profile throws, print the error as a warning instead of discarding it. Setup still continues to the readiness check. diff --git a/packages/cli/README.md b/packages/cli/README.md index 9545291..b9eeac1 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -437,7 +437,7 @@ Flags: | Flag | Type | Description | | --- | --- | --- | | `--channel=` | option | Install release channel Default: stable | -| `--desktop` | boolean | Set up a local Beeper Desktop target | +| `--desktop` | boolean | Set up a separate CLI-managed Beeper Desktop profile; use --local for an already-running Desktop | | `--email=` | option | Sign in with an email address | | `--install` | boolean | Allow installing missing managed runtime | | `--local` | boolean | Use the local Beeper Desktop session on this device | diff --git a/packages/cli/docs/setup.md b/packages/cli/docs/setup.md index dbcd2c5..4e1741d 100644 --- a/packages/cli/docs/setup.md +++ b/packages/cli/docs/setup.md @@ -20,6 +20,7 @@ beeper install server [--channel stable|nightly] [--server-env production|stagi ## Notes - `setup --local` reuses the local Beeper Desktop session (fastest trusted-device path). +- `setup --desktop` starts a separate CLI-managed Beeper Desktop profile on its own port. Use `setup --local` for an already-running Desktop. - `setup --oauth` runs browser-based OAuth/PKCE against the resolved target. - `setup --remote URL` configures a remote Beeper Desktop or Server target. - `setup --desktop --install` or `setup --server --install` installs the runtime if missing, then sets up. diff --git a/packages/cli/src/commands/setup.ts b/packages/cli/src/commands/setup.ts index f59baab..20ba4d8 100644 --- a/packages/cli/src/commands/setup.ts +++ b/packages/cli/src/commands/setup.ts @@ -31,7 +31,7 @@ export default class Setup extends BeeperCommand { oauth: Flags.boolean({ default: false, description: 'Authorize the target with browser OAuth/PKCE' }), remote: Flags.string({ description: 'Connect to a remote Beeper Desktop or Server URL' }), server: Flags.boolean({ default: false, description: 'Set up a local Beeper Server target' }), - desktop: Flags.boolean({ default: false, description: 'Set up a local Beeper Desktop target' }), + desktop: Flags.boolean({ default: false, description: 'Set up a separate CLI-managed Beeper Desktop profile; use --local for an already-running Desktop' }), install: Flags.boolean({ default: false, description: 'Allow installing missing managed runtime' }), channel: Flags.string({ options: ['stable', 'nightly'], default: 'stable', description: 'Install release channel' }), 'server-env': Flags.string({ options: ['production', 'staging'], default: 'production', description: 'Server environment (production or staging)' }), @@ -222,7 +222,10 @@ export default class Setup extends BeeperCommand { const target = await readTarget(id) ?? await createProfileTarget(type, id, { serverEnv: flags['server-env'], port: undefined }) if (!flags.target) await updateConfig(config => ({ ...config, defaultTarget: config.defaultTarget ?? target.id })) await startProfile(target).catch(error => { - if (type === 'desktop') return undefined + if (type === 'desktop') { + this.warn(`Could not launch Beeper Desktop: ${error instanceof Error ? error.message : String(error)}`) + return undefined + } throw error }) if (flags.email) { diff --git a/packages/cli/test/setup-managed.test.ts b/packages/cli/test/setup-managed.test.ts new file mode 100644 index 0000000..0b07c09 --- /dev/null +++ b/packages/cli/test/setup-managed.test.ts @@ -0,0 +1,81 @@ +import { chmod, mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import { fileURLToPath } from 'node:url' +import { describe, expect, it } from 'bun:test' + +const cliRoot = fileURLToPath(new URL('..', import.meta.url)) + +describe('managed setup launch failures', () => { + for (const json of [false, true]) { + it(`warns and checks Desktop readiness with json=${json}`, async () => { + const result = await runSetup('desktop', json) + expect(result.code).toBe(0) + expect(result.stderr).toContain('Could not launch Beeper Desktop: test launch failed') + if (json) { + const output = JSON.parse(result.stdout) + expect(output.success).toBe(true) + expect(output.data.readiness.state).toBe('target-unreachable') + expect(output.data.readiness.message).toContain('test target unavailable') + } else { + expect(result.stdout).toContain('target unreachable') + expect(result.stdout).toContain('test target unavailable') + } + }, 20_000) + } + + it('still fails when Server cannot launch', async () => { + const result = await runSetup('server', true) + expect(result.code).not.toBe(0) + expect(JSON.parse(result.stderr).error).toBe('test launch failed') + expect(result.stdout).toBe('') + }, 20_000) +}) + +async function runSetup(type: 'desktop' | 'server', json: boolean) { + const tempDir = await mkdtemp(join(tmpdir(), 'beeper-setup-managed-')) + const server = Bun.serve({ + port: 0, + hostname: '127.0.0.1', + fetch: () => new Response('test target unavailable', { status: 503 }), + }) + try { + const configDir = join(tempDir, 'config') + await mkdir(join(configDir, 'targets'), { recursive: true }) + await writeFile(join(configDir, 'targets', 'test.json'), JSON.stringify({ + id: 'test', type, managed: true, baseURL: server.url.origin, dataDir: join(tempDir, 'profile'), + })) + const preload = join(tempDir, 'mock-launch.ts') + const profilesURL = new URL('../dist/lib/profiles.js', import.meta.url).href + await writeFile(preload, `import { mock } from 'bun:test' +import * as profiles from ${JSON.stringify(profilesURL)} +mock.module(${JSON.stringify(profilesURL)}, () => ({ + ...profiles, + startProfile: async () => { throw new Error('test launch failed') }, +})) +const { default: Setup } = await import(${JSON.stringify(new URL('../dist/commands/setup.js', import.meta.url).href)}) +await Setup.run(process.argv.slice(2), ${JSON.stringify(cliRoot)}) +`) + // A missed mock must never reach the system Desktop opener. + const binDir = join(tempDir, 'bin') + await mkdir(binDir) + await writeFile(join(binDir, 'open'), '#!/bin/sh\nexit 1\n') + await chmod(join(binDir, 'open'), 0o755) + const child = Bun.spawn([ + process.execPath, preload, `--${type}`, '--target', 'test', + ...(json ? ['--json'] : []), + ], { + cwd: cliRoot, + env: { ...process.env, PATH: binDir, BEEPER_READONLY: '0', BEEPER_CLI_CONFIG_DIR: configDir, BEEPER_NO_LOGO: '1' }, + stdout: 'pipe', + stderr: 'pipe', + }) + const [code, stdout, stderr] = await Promise.all([ + child.exited, new Response(child.stdout).text(), new Response(child.stderr).text(), + ]) + return { code, stdout, stderr } + } finally { + server.stop(true) + await rm(tempDir, { recursive: true, force: true }) + } +}