fix(non-interactive-env): respect Windows command shell

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-13 20:07:46 +09:00
parent cab20568da
commit fef1d4530b
2 changed files with 73 additions and 4 deletions
+48 -2
View File
@@ -251,7 +251,7 @@ describe("non-interactive-env hook", () => {
expect(cmd).toContain("; git commit")
})
test("#given Windows with PowerShell env #when bash tool git command executes #then uses powershell syntax", async () => {
test("#given Windows cmd environment with PSModulePath #when bash tool git command executes #then uses cmd syntax", async () => {
delete process.env.SHELL
delete process.env.MSYSTEM
process.env.PSModulePath = "C:\\Program Files\\PowerShell\\Modules"
@@ -267,10 +267,56 @@ describe("non-interactive-env hook", () => {
output
)
const cmd = output.args.command as string
expect(cmd).toStartWith("set ")
expect(cmd).toContain(" && git status")
expect(cmd).toContain('GIT_EDITOR=":"')
expect(cmd).not.toContain("$env:")
expect(cmd).not.toContain("export ")
})
test("#given Windows SHELL=cmd.exe #when bash tool git command executes #then uses cmd syntax", async () => {
process.env.SHELL = "C:\\Windows\\System32\\cmd.exe"
delete process.env.MSYSTEM
process.env.PSModulePath = "C:\\Program Files\\PowerShell\\Modules"
Object.defineProperty(process, "platform", { value: "win32" })
const hook = createNonInteractiveEnvHook(mockCtx)
const output: { args: Record<string, unknown>; message?: string } = {
args: { command: "git status" },
}
await hook["tool.execute.before"](
{ tool: "bash", sessionID: "test", callID: "1" },
output
)
const cmd = output.args.command as string
expect(cmd).toStartWith("set ")
expect(cmd).toContain(" && git status")
expect(cmd).not.toContain("$env:")
expect(cmd).not.toContain("export ")
})
test("#given Windows SHELL=pwsh.exe #when bash tool git command executes #then uses powershell syntax", async () => {
process.env.SHELL = "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
delete process.env.MSYSTEM
process.env.PSModulePath = "C:\\Program Files\\PowerShell\\Modules"
Object.defineProperty(process, "platform", { value: "win32" })
const hook = createNonInteractiveEnvHook(mockCtx)
const output: { args: Record<string, unknown>; message?: string } = {
args: { command: "git status" },
}
await hook["tool.execute.before"](
{ tool: "bash", sessionID: "test", callID: "1" },
output
)
const cmd = output.args.command as string
expect(cmd).toStartWith("$env:")
expect(cmd).toContain("; git status")
expect(cmd).toContain("$env:GIT_EDITOR=':'")
expect(cmd).not.toContain("set ")
expect(cmd).not.toContain("export ")
})