Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

test(release): select Git Bash for Windows Git layouts (#225)

Dipesh Babua33264976d3d
diff --git a/sdk/typescript/tests-ts/shell.test.ts b/sdk/typescript/tests-ts/shell.test.ts
index 8a5bbb04f..ea6c37639 100644
--- a/sdk/typescript/tests-ts/shell.test.ts
+++ b/sdk/typescript/tests-ts/shell.test.ts
@@ -1,5 +1,57 @@
+import { readFile } from "node:fs/promises";
+import { join } from "node:path";
import { expect, test } from "bun:test";
-import { runCommand } from "./support/shell.js";
+import { bashCommand, runCommand, writeSource } from "./support/shell.js";
+import { scopedTemporaryDirectory } from "./support/temporary-directories.js";
+
+test("resolves Bash within the selected Git installation", async () => {
+ await using fixture = await scopedTemporaryDirectory("git-bash-layout-");
+ const root = join(fixture.path, "Git");
+ const shell = join("bin", "bash.exe");
+ const gitIn = (directory: string) => join(root, directory, "git.exe");
+ writeSource(fixture.path, shell, "");
+ expect(bashCommand(null)).toBe("bash");
+ expect(bashCommand(gitIn("cmd"))).toBe("bash");
+ expect(bashCommand(gitIn(join("mingw64", "bin")))).toBe("bash");
+
+ writeSource(root, shell, "");
+ for (const directory of [
+ "cmd",
+ "bin",
+ "mingw32/bin",
+ "mingw64/bin",
+ "ucrt64/bin",
+ "clangarm64/bin",
+ ]) {
+ expect(bashCommand(gitIn(directory))).toBe(join(root, shell));
+ }
+ const nested = join("mingw64", shell);
+ writeSource(root, nested, "");
+ expect(bashCommand(gitIn("mingw64/bin"))).toBe(join(root, nested));
+ expect(bashCommand(gitIn("unrelated/bin"))).toBe("bash");
+});
+
+const installedGitBash =
+ process.platform === "win32" ? bashCommand(Bun.which("git")) : "bash";
+test.skipIf(installedGitBash === "bash")(
+ "Git Bash can write a Windows workflow output path",
+ async () => {
+ await using fixture = await scopedTemporaryDirectory(
+ "bash-workflow-output-",
+ );
+ const output = join(fixture.path, "step output");
+ const bash = bashCommand();
+ expect(bash).toBe(installedGitBash);
+ const result = await runCommand(bash, [
+ "-c",
+ 'printf done > "$1"',
+ "bash",
+ output,
+ ]);
+ expect(result.status, result.stderr).toBe(0);
+ expect(await readFile(output, "utf8")).toBe("done");
+ },
+);
test("captures asynchronous command input, output, and failure diagnostics", async () => {
const input = "literal %USERNAME% !EXPAND! caf\u00e9's \u96ea\n";
diff --git a/sdk/typescript/tests-ts/support/shell.ts b/sdk/typescript/tests-ts/support/shell.ts
index fa364fd5b..1225514d8 100644
--- a/sdk/typescript/tests-ts/support/shell.ts
+++ b/sdk/typescript/tests-ts/support/shell.ts
@@ -3,12 +3,19 @@ import { execFile, execFileSync } from "node:child_process";
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
-export function bashCommand(): string {
- if (process.platform !== "win32") return "bash";
- const git = Bun.which("git");
+export function bashCommand(
+ git = process.platform === "win32" ? Bun.which("git") : null,
+): string {
if (git === null) return "bash";
- const gitBash = join(dirname(dirname(git)), "bin", "bash.exe");
- return existsSync(gitBash) ? gitBash : "bash";
+ const parent = dirname(dirname(git));
+ const nestedGit =
+ /[\\/](?:mingw32|mingw64|ucrt64|clangarm64)[\\/]bin[\\/]git\.exe$/iu;
+ const roots = nestedGit.test(git) ? [parent, dirname(parent)] : [parent];
+ for (const root of roots) {
+ const gitBash = join(root, "bin", "bash.exe");
+ if (existsSync(gitBash)) return gitBash;
+ }
+ return "bash";
}
export function workflowBashCommand(): string {