fix(doctor): detect gh when Bun.which misses it
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
/// <reference types="bun-types" />
|
||||||
|
|
||||||
|
import { afterEach, describe, expect, it, mock } from "bun:test"
|
||||||
|
|
||||||
|
const originalWhich = Bun.which
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
Bun.which = originalWhich
|
||||||
|
mock.restore()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("getGhCliInfo", () => {
|
||||||
|
it("falls back to gh --version when Bun.which cannot find gh", async () => {
|
||||||
|
// given
|
||||||
|
Bun.which = mock(() => null)
|
||||||
|
mock.module("../spawn-with-timeout", () => ({
|
||||||
|
spawnWithTimeout: mock((command: string[]) => {
|
||||||
|
if (command.join(" ") === "gh --version") {
|
||||||
|
return Promise.resolve({ stdout: "gh version 2.82.1\n", stderr: "", exitCode: 0, timedOut: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve({ stdout: "", stderr: "not logged in", exitCode: 1, timedOut: false })
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
const { getGhCliInfo } = await import("./tools-gh")
|
||||||
|
|
||||||
|
// when
|
||||||
|
const info = await getGhCliInfo()
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(info.installed).toBe(true)
|
||||||
|
expect(info.version).toBe("2.82.1")
|
||||||
|
expect(info.path).toBe(null)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -80,6 +80,20 @@ async function getGhAuthStatus(): Promise<{
|
|||||||
export async function getGhCliInfo(): Promise<GhCliInfo> {
|
export async function getGhCliInfo(): Promise<GhCliInfo> {
|
||||||
const binaryStatus = await checkBinaryExists("gh")
|
const binaryStatus = await checkBinaryExists("gh")
|
||||||
if (!binaryStatus.exists) {
|
if (!binaryStatus.exists) {
|
||||||
|
const version = await getGhVersion()
|
||||||
|
if (version) {
|
||||||
|
const authStatus = await getGhAuthStatus()
|
||||||
|
return {
|
||||||
|
installed: true,
|
||||||
|
version,
|
||||||
|
path: null,
|
||||||
|
authenticated: authStatus.authenticated,
|
||||||
|
username: authStatus.username,
|
||||||
|
scopes: authStatus.scopes,
|
||||||
|
error: authStatus.error,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
installed: false,
|
installed: false,
|
||||||
version: null,
|
version: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user