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.
This commit is contained in:
Juan Garibay
2026-09-17 16:04:41 -04:00
parent 5cbe78c22b
commit 1f5cd2af73
+16 -15
View File
@@ -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,