Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-setup-desktop-clarity.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ Flags:
| Flag | Type | Description |
| --- | --- | --- |
| `--channel=<stable\|nightly>` | 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=<value>` | 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 |
Expand Down
1 change: 1 addition & 0 deletions packages/cli/docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/commands/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)' }),
Expand Down Expand Up @@ -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) {
Expand Down
81 changes: 81 additions & 0 deletions packages/cli/test/setup-managed.test.ts
Original file line number Diff line number Diff line change
@@ -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 })
}
}