test(non-interactive-env): add idempotency test for env prefix injection
This commit is contained in:
@@ -111,6 +111,34 @@ describe("non-interactive-env hook", () => {
|
||||
|
||||
expect(output.args.command).toBeUndefined()
|
||||
})
|
||||
|
||||
test("#given git command already has prefix #when hook executes again #then does not duplicate prefix", async () => {
|
||||
const hook = createNonInteractiveEnvHook(mockCtx)
|
||||
|
||||
// First call: transforms the command
|
||||
const output1: { args: Record<string, unknown>; message?: string } = {
|
||||
args: { command: "git commit -m 'test'" },
|
||||
}
|
||||
await hook["tool.execute.before"](
|
||||
{ tool: "bash", sessionID: "test", callID: "1" },
|
||||
output1
|
||||
)
|
||||
|
||||
const firstResult = output1.args.command as string
|
||||
expect(firstResult).toStartWith("export ")
|
||||
|
||||
// Second call: takes the already-prefixed command
|
||||
const output2: { args: Record<string, unknown>; message?: string } = {
|
||||
args: { command: firstResult },
|
||||
}
|
||||
await hook["tool.execute.before"](
|
||||
{ tool: "bash", sessionID: "test", callID: "2" },
|
||||
output2
|
||||
)
|
||||
|
||||
// Should be exactly the same (no double prefix)
|
||||
expect(output2.args.command).toBe(firstResult)
|
||||
})
|
||||
})
|
||||
|
||||
describe("shell escaping", () => {
|
||||
|
||||
Reference in New Issue
Block a user