From 1f5cd2af737c0b319ced41c021663da082e40e7e Mon Sep 17 00:00:00 2001 From: Juan Garibay Date: Thu, 17 Sep 2026 16:04:41 -0400 Subject: [PATCH] test(hooks): build the pre-push python fixture env without mutation AGENTS.md makes immutability mandatory and the helper built `env` by assigning into it. Rather than reassigning a `let` through spreads, the two stub paths are now resolved before the object exists, so `env` is a single `const` built in one expression with the conditional keys spread in. Nothing to mutate and nothing to rebind. --- tests/scripts/codex-hooks.test.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/scripts/codex-hooks.test.js b/tests/scripts/codex-hooks.test.js index a6f9f3fd6..366f98f0c 100644 --- a/tests/scripts/codex-hooks.test.js +++ b/tests/scripts/codex-hooks.test.js @@ -328,27 +328,28 @@ function runHermeticPythonPrePush({ const initialized = spawnSync('git', ['init', '--quiet'], { cwd: projectDir }); assert.strictEqual(initialized.status, 0, initialized.stderr?.toString()); + const venvDir = venvName === null ? null : path.join(tempDir, venvName); + const venvPython = venvDir === null ? null : path.join(venvDir, 'bin', 'python'); + if (venvPython !== null) { + writeExecutable(venvPython, `#!/bin/sh\nprintf '%s\\n' "$0|$*" >> "${toBashPath(callsPath)}"\nexit 0\n`); + } + + const overrideStub = overrideVersionLine === null + ? null + : path.join(tempDir, 'bin', 'fake-pytest'); + if (overrideStub !== null) { + writeExecutable(overrideStub, `#!/bin/sh\nif [ "$1" = "--version" ]; then printf '%s\\n' '${overrideVersionLine}'; exit 0; fi\nprintf '%s\\n' "$0|$*" >> "${toBashPath(callsPath)}"\nexit 0\n`); + } + + const override = overrideStub === null ? pytestCmd : toBashPath(overrideStub); const env = { ECC_SKIP_GIT_HOOKS: '0', ECC_SKIP_PREPUSH: '0', MSYS_NO_PATHCONV: '1', + ...(venvDir === null ? {} : { VIRTUAL_ENV: toBashPath(venvDir) }), + ...(override === null ? {} : { ECC_PYTEST_CMD: override }), }; - let venvPython = null; - if (venvName) { - venvPython = path.join(tempDir, venvName, 'bin', 'python'); - writeExecutable(venvPython, `#!/bin/sh\nprintf '%s\\n' "$0|$*" >> "${toBashPath(callsPath)}"\nexit 0\n`); - env.VIRTUAL_ENV = toBashPath(path.join(tempDir, venvName)); - } - - if (overrideVersionLine !== null) { - const stub = path.join(tempDir, 'bin', 'fake-pytest'); - writeExecutable(stub, `#!/bin/sh\nif [ "$1" = "--version" ]; then printf '%s\\n' '${overrideVersionLine}'; exit 0; fi\nprintf '%s\\n' "$0|$*" >> "${toBashPath(callsPath)}"\nexit 0\n`); - env.ECC_PYTEST_CMD = toBashPath(stub); - } else if (pytestCmd !== null) { - env.ECC_PYTEST_CMD = pytestCmd; - } - const result = runBash(prePushHook, { env, cwd: projectDir,