fix(git): forward status mode to runtimes (#1153)

Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
Isaac Sanchez-Hawkins
2026-05-08 15:57:25 +03:00
committed by GitHub
co-authored by Isaac Sanchez
parent 14c0bfe0bc
commit 28f7a52ec8
5 changed files with 63 additions and 6 deletions
+50
View File
@@ -0,0 +1,50 @@
import { describe, expect, test } from "bun:test"
import type { GitAPI, GitStatus } from "./api/types"
import { getGitStatus } from "./gitApi"
const status: GitStatus = {
current: "main",
tracking: null,
ahead: 0,
behind: 0,
files: [],
isClean: true,
}
const withRuntimeGit = async (git: GitAPI, callback: () => Promise<void>) => {
const previousWindowDescriptor = Object.getOwnPropertyDescriptor(globalThis, "window")
Object.defineProperty(globalThis, "window", {
configurable: true,
value: {
__OPENCHAMBER_RUNTIME_APIS__: { git },
},
})
try {
await callback()
} finally {
if (previousWindowDescriptor) {
Object.defineProperty(globalThis, "window", previousWindowDescriptor)
} else {
delete (globalThis as { window?: Window }).window
}
}
}
describe("getGitStatus", () => {
test("forwards light-mode options to runtime git APIs", async () => {
let received: { directory: string; options?: { mode?: "light" } } | null = null
const runtimeGit = {
getGitStatus: async (directory: string, options?: { mode?: "light" }) => {
received = { directory, options }
return status
},
} as Partial<GitAPI> as GitAPI
await withRuntimeGit(runtimeGit, async () => {
await getGitStatus("/repo", { mode: "light" })
})
expect(received).toEqual({ directory: "/repo", options: { mode: "light" } })
})
})
+1 -1
View File
@@ -66,7 +66,7 @@ export async function checkIsGitRepository(directory: string): Promise<boolean>
export async function getGitStatus(directory: string, options?: { mode?: 'light' }): Promise<import('./api/types').GitStatus> {
const runtime = getRuntimeGit();
if (runtime) return runtime.getGitStatus(directory);
if (runtime) return runtime.getGitStatus(directory, options);
return gitHttp.getGitStatus(directory, options);
}