From 9bd29056c699554c643b119f3ff453595b40d05e Mon Sep 17 00:00:00 2001 From: Reinier Criel Date: Thu, 6 Nov 2025 11:02:03 -0800 Subject: [PATCH] Some cleanup --- packages/safe-chain/bin/aikido-python.js | 8 +-- packages/safe-chain/bin/aikido-python3.js | 8 +-- .../src/shell-integration/setup-ci.spec.js | 63 +------------------ test/e2e/Dockerfile | 1 + 4 files changed, 10 insertions(+), 70 deletions(-) diff --git a/packages/safe-chain/bin/aikido-python.js b/packages/safe-chain/bin/aikido-python.js index fba6b70..e3d9046 100644 --- a/packages/safe-chain/bin/aikido-python.js +++ b/packages/safe-chain/bin/aikido-python.js @@ -8,12 +8,12 @@ import { main } from "../src/main.js"; // Set eco system setEcoSystem(ECOSYSTEM_PY); - -// Strip '-m pip' or '-m pip3' from args if present +// Strip nodejs and wrapper script from args let argv = process.argv.slice(2); -if (argv[0] === '-m' && argv[1] === 'pip') { +// If no args are passed, argv[0] and argv[1] are undefined, so this condition just evaluates to false and does not throw. +if (argv[0] === '-m' && (argv[1] === 'pip' || argv[1] === 'pip3')) { setEcoSystem(ECOSYSTEM_PY); - setCurrentPipInvocation(PIP_INVOCATIONS.PY_PIP); + setCurrentPipInvocation(argv[1] === 'pip3' ? PIP_INVOCATIONS.PY3_PIP : PIP_INVOCATIONS.PY_PIP); initializePackageManager(PIP_PACKAGE_MANAGER); argv = argv.slice(2); var exitCode = await main(argv); diff --git a/packages/safe-chain/bin/aikido-python3.js b/packages/safe-chain/bin/aikido-python3.js index c74a3f3..8e16d6c 100644 --- a/packages/safe-chain/bin/aikido-python3.js +++ b/packages/safe-chain/bin/aikido-python3.js @@ -10,12 +10,12 @@ setEcoSystem(ECOSYSTEM_PY); // Strip nodejs and wrapper script from args let argv = process.argv.slice(2); -if (argv[0] === '-m' && argv[1] === 'pip') { +// If no args are passed, argv[0] and argv[1] are undefined, so this condition just evaluates to false and does not throw. +if (argv[0] === '-m' && (argv[1] === 'pip' || argv[1] === 'pip3')) { setEcoSystem(ECOSYSTEM_PY); - setCurrentPipInvocation(PIP_INVOCATIONS.PY3_PIP); + setCurrentPipInvocation(argv[1] === 'pip3' ? PIP_INVOCATIONS.PY3_PIP : PIP_INVOCATIONS.PY_PIP); initializePackageManager(PIP_PACKAGE_MANAGER); - // Strip '-m pip' or '-m pip3' from args if present - argv = argv.slice(2); + argv = argv.slice(2); var exitCode = await main(argv); process.exit(exitCode); } else { diff --git a/packages/safe-chain/src/shell-integration/setup-ci.spec.js b/packages/safe-chain/src/shell-integration/setup-ci.spec.js index 5471f36..92ef82e 100644 --- a/packages/safe-chain/src/shell-integration/setup-ci.spec.js +++ b/packages/safe-chain/src/shell-integration/setup-ci.spec.js @@ -146,66 +146,5 @@ describe("Setup CI shell integration", () => { const unixNpmShim = path.join(mockShimsDir, "npm"); assert.ok(!fs.existsSync(unixNpmShim), "Unix npm shim should not exist on Windows"); }); - - it("should create python and python3 shims from unix-python wrapper template", async () => { - // Add unix-python wrapper template to mock templates - const unixPythonTemplatePath = path.join( - mockTemplateDir, - "path-wrappers", - "templates", - "unix-python-wrapper.template.sh" - ); - fs.writeFileSync( - unixPythonTemplatePath, - "#!/bin/bash\n# Python wrapper\nexec aikido-pip \"$@\"\n", - "utf-8" - ); - - await setupCi(); - - // Check if python shim was created - const pythonShimPath = path.join(mockShimsDir, "python"); - assert.ok(fs.existsSync(pythonShimPath), "python shim should exist"); - // Check if python3 shim was created - const python3ShimPath = path.join(mockShimsDir, "python3"); - assert.ok(fs.existsSync(python3ShimPath), "python3 shim should exist"); - // Check content of python shim - const pythonShimContent = fs.readFileSync(pythonShimPath, "utf-8"); - assert.ok(pythonShimContent.includes("Python wrapper"), "python shim should use unix-python wrapper template"); - // Check content of python3 shim - const python3ShimContent = fs.readFileSync(python3ShimPath, "utf-8"); - assert.ok(python3ShimContent.includes("Python wrapper"), "python3 shim should use unix-python wrapper template"); - }); - - it("should create python.cmd and python3.cmd shims from windows-python wrapper template on win32 platform", async () => { - mockPlatform = "win32"; - // Add windows-python wrapper template to mock templates - const windowsPythonTemplatePath = path.join( - mockTemplateDir, - "path-wrappers", - "templates", - "windows-python-wrapper.template.cmd" - ); - fs.writeFileSync( - windowsPythonTemplatePath, - "@echo off\nREM Python wrapper\n{{AIKIDO_COMMAND}} %*\n", - "utf-8" - ); - - await setupCi(); - - // Check if python.cmd shim was created - const pythonCmdShimPath = path.join(mockShimsDir, "python.cmd"); - assert.ok(fs.existsSync(pythonCmdShimPath), "python.cmd shim should exist"); - // Check if python3.cmd shim was created - const python3CmdShimPath = path.join(mockShimsDir, "python3.cmd"); - assert.ok(fs.existsSync(python3CmdShimPath), "python3.cmd shim should exist"); - // Check content of python.cmd shim - const pythonCmdShimContent = fs.readFileSync(pythonCmdShimPath, "utf-8"); - assert.ok(pythonCmdShimContent.includes("Python wrapper"), "python.cmd should use windows-python wrapper template"); - // Check content of python3.cmd shim - const python3CmdShimContent = fs.readFileSync(python3CmdShimPath, "utf-8"); - assert.ok(python3CmdShimContent.includes("Python wrapper"), "python3.cmd should use windows-python wrapper template"); - }); }); -}); \ No newline at end of file +}); diff --git a/test/e2e/Dockerfile b/test/e2e/Dockerfile index 6c9743e..778924a 100644 --- a/test/e2e/Dockerfile +++ b/test/e2e/Dockerfile @@ -50,6 +50,7 @@ RUN volta install pnpm@${PNPM_VERSION} # Install Bun RUN curl -fsSL https://bun.sh/install | bash + # Install Python and pip (pip3) RUN apt-get update && apt-get install -y python${PYTHON_VERSION} python3-pip && \ ln -sf /usr/bin/python${PYTHON_VERSION} /usr/local/bin/python3 && \