From e5b7fd40bbc8f7909b03f7474c69b5a7ec3698df Mon Sep 17 00:00:00 2001 From: Strocs Date: Fri, 13 Feb 2026 21:51:38 -0300 Subject: [PATCH] test(non-interactive-env): add idempotency test for env prefix injection --- src/hooks/non-interactive-env/index.test.ts | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/hooks/non-interactive-env/index.test.ts b/src/hooks/non-interactive-env/index.test.ts index 7eed35294..8e4bed295 100644 --- a/src/hooks/non-interactive-env/index.test.ts +++ b/src/hooks/non-interactive-env/index.test.ts @@ -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; 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; 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", () => {