feat(codex): auto-install git bash via winget on windows

This commit is contained in:
YeonGyu-Kim
2026-05-31 11:00:30 +09:00
parent 021d4e3c97
commit 4fded80f6a
8 changed files with 351 additions and 26 deletions
+71 -1
View File
@@ -2,7 +2,7 @@
/// <reference types="bun-types" />
import { describe, expect, test } from "bun:test"
import { resolveGitBash } from "./git-bash"
import { prepareGitBashForInstall, resolveGitBash } from "./git-bash"
const PROGRAM_FILES_GIT_BASH = "C:\\Program Files\\Git\\bin\\bash.exe"
const PROGRAM_FILES_X86_GIT_BASH = "C:\\Program Files (x86)\\Git\\bin\\bash.exe"
@@ -115,4 +115,74 @@ describe("git-bash", () => {
expect(result.installHint).toContain("OMO_CODEX_GIT_BASH_PATH=C:\\path\\to\\bash.exe")
expect(result.installHint).toContain("rerun `bunx omo install --platform=codex`")
})
test("#given Windows without Git Bash and winget is allowed #when preparing #then winget runs and resolver is retried", async () => {
// given
const runCalls: string[] = []
const resolutions = [
{ found: false, checkedPaths: [PROGRAM_FILES_GIT_BASH], installHint: "install hint" } as const,
{ found: true, path: PROGRAM_FILES_GIT_BASH, source: "program-files" } as const,
]
let resolveCallCount = 0
// when
const result = await prepareGitBashForInstall({
platform: "win32",
env: {},
cwd: "C:\\repo",
resolveGitBash: () => resolutions[resolveCallCount++] ?? resolutions[resolutions.length - 1],
runCommand: async (command, args, options) => {
runCalls.push([command, ...args, options.cwd].join(" "))
},
})
// then
expect(runCalls).toEqual(["winget install --id Git.Git -e --source winget C:\\repo"])
expect(resolveCallCount).toBe(2)
expect(result).toEqual({ found: true, path: PROGRAM_FILES_GIT_BASH, source: "program-files" })
})
test("#given Windows without Git Bash and skip env is set #when preparing #then winget is not run and install hint is returned", async () => {
// given
const runCalls: string[] = []
const missingResolution = {
found: false,
checkedPaths: [PROGRAM_FILES_GIT_BASH, PROGRAM_FILES_X86_GIT_BASH],
installHint: "install hint",
} as const
// when
const result = await prepareGitBashForInstall({
platform: "win32",
env: { OMO_CODEX_SKIP_GIT_BASH_AUTO_INSTALL: "1" },
cwd: "C:\\repo",
resolveGitBash: () => missingResolution,
runCommand: async (command, args, options) => {
runCalls.push([command, ...args, options.cwd].join(" "))
},
})
// then
expect(runCalls).toEqual([])
expect(result).toEqual(missingResolution)
})
test("#given non-Windows platform #when preparing #then winget is never called", async () => {
// given
const runCalls: string[] = []
// when
const result = await prepareGitBashForInstall({
platform: "linux",
env: {},
cwd: "/repo",
runCommand: async (command, args, options) => {
runCalls.push([command, ...args, options.cwd].join(" "))
},
})
// then
expect(runCalls).toEqual([])
expect(result).toEqual({ found: true, path: null, source: "not-required" })
})
})