fix(cli): support headless console login
This commit is contained in:
parent
3cdd431794
commit
88bafec7f4
2 changed files with 14 additions and 2 deletions
|
|
@ -7,7 +7,13 @@ import { effectCmd } from "../effect-cmd"
|
||||||
import * as Prompt from "../effect/prompt"
|
import * as Prompt from "../effect/prompt"
|
||||||
import open from "open"
|
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))
|
const println = (msg: string) => Effect.sync(() => UI.println(msg))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,19 @@
|
||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
import stripAnsi from "strip-ansi"
|
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", () => {
|
describe("console account display", () => {
|
||||||
test("uses console.opencode.ai as the default login URL", () => {
|
test("uses console.opencode.ai as the default login URL", () => {
|
||||||
expect(defaultConsoleUrl).toBe("https://console.opencode.ai")
|
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", () => {
|
test("includes the account url in account labels", () => {
|
||||||
expect(stripAnsi(formatAccountLabel({ email: "one@example.com", url: "https://one.example.com" }, false))).toBe(
|
expect(stripAnsi(formatAccountLabel({ email: "one@example.com", url: "https://one.example.com" }, false))).toBe(
|
||||||
"one@example.com https://one.example.com",
|
"one@example.com https://one.example.com",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue