fix(cli): support headless console login

This commit is contained in:
Test
2026-06-23 15:02:20 +00:00
parent 3cdd431794
commit 88bafec7f4
2 changed files with 14 additions and 2 deletions
+7 -1
View File
@@ -7,7 +7,13 @@ import { effectCmd } from "../effect-cmd"
import * as Prompt from "../effect/prompt"
import open from "open"
const openBrowser = (url: string) => Effect.promise(() => open(url).catch(() => undefined))
export const hasBrowserOpener = (platform: NodeJS.Platform, xdgOpen: string | null) =>
platform !== "linux" || xdgOpen !== null
const openBrowser = (url: string) => {
if (!hasBrowserOpener(process.platform, Bun.which("xdg-open"))) return Effect.void
return Effect.promise(() => open(url).catch(() => undefined))
}
const println = (msg: string) => Effect.sync(() => UI.println(msg))
+7 -1
View File
@@ -1,13 +1,19 @@
import { describe, expect, test } from "bun:test"
import stripAnsi from "strip-ansi"
import { defaultConsoleUrl, formatAccountLabel, formatOrgLine } from "../../src/cli/cmd/account"
import { defaultConsoleUrl, formatAccountLabel, formatOrgLine, hasBrowserOpener } from "../../src/cli/cmd/account"
describe("console account display", () => {
test("uses console.opencode.ai as the default login URL", () => {
expect(defaultConsoleUrl).toBe("https://console.opencode.ai")
})
test("skips automatic browser launch on Linux when xdg-open is unavailable", () => {
expect(hasBrowserOpener("linux", null)).toBe(false)
expect(hasBrowserOpener("linux", "/usr/bin/xdg-open")).toBe(true)
expect(hasBrowserOpener("darwin", null)).toBe(true)
})
test("includes the account url in account labels", () => {
expect(stripAnsi(formatAccountLabel({ email: "one@example.com", url: "https://one.example.com" }, false))).toBe(
"one@example.com https://one.example.com",