diff --git a/packages/safe-chain/src/packagemanager/pip/runPipCommand.js b/packages/safe-chain/src/packagemanager/pip/runPipCommand.js index 52a8691..cbf6c63 100644 --- a/packages/safe-chain/src/packagemanager/pip/runPipCommand.js +++ b/packages/safe-chain/src/packagemanager/pip/runPipCommand.js @@ -121,13 +121,13 @@ export async function runPip(command, args) { let cleanupConfigPath = null; // Track temp file for cleanup if (isConfigRelatedCommand) { - ui.writeVerbose( `Safe-chain: Skipping PIP_CONFIG_FILE override for 'pip ${args[0]}' command to allow persistent config/cache access.`); - - // Still set the fallback CA bundle environment variables to avoid edge cases where a + ui.writeVerbose(`Safe-chain: Skipping PIP_CONFIG_FILE override for 'pip ${args[0]}' command to allow persistent config/cache access.`); + + // Still set the fallback CA bundle environment variables to avoid edge cases where a // plugin or extension triggers a network call during config introspection // This can do no harm setFallbackCaBundleEnvironmentVariables(env, combinedCaPath); - + const result = await safeSpawn(command, args, { stdio: "inherit", env, @@ -147,6 +147,7 @@ export async function runPip(command, args) { await fs.writeFile(pipConfigPath, pipConfig); env.PIP_CONFIG_FILE = pipConfigPath; cleanupConfigPath = pipConfigPath; + } else if (fsSync.existsSync(env.PIP_CONFIG_FILE)) { ui.writeVerbose("Safe-chain: Merging user provided PIP_CONFIG_FILE with safe-chain certificate and proxy settings."); const userConfig = env.PIP_CONFIG_FILE; @@ -166,21 +167,19 @@ export async function runPip(command, args) { // Proxy if (typeof parsed.global.proxy !== "undefined") { - ui.writeWarning( - "Safe-chain: User defined proxy found in PIP_CONFIG_FILE. It will be overwritten in the temporary config.", - ); + ui.writeWarning("Safe-chain: User defined proxy found in PIP_CONFIG_FILE. It will be overwritten in the temporary config."); } if (proxy) { parsed.global.proxy = proxy; } - + const updated = ini.stringify(parsed); // Save to a new temp file to avoid overwriting user's original config await fs.writeFile(pipConfigPath, updated, "utf-8"); env.PIP_CONFIG_FILE = pipConfigPath; cleanupConfigPath = pipConfigPath; - + } else { // The user provided PIP_CONFIG_FILE does not exist on disk // PIP will handle this as an error and inform the user diff --git a/packages/safe-chain/src/packagemanager/pip/runPipCommand.spec.js b/packages/safe-chain/src/packagemanager/pip/runPipCommand.spec.js index 235b472..c469978 100644 --- a/packages/safe-chain/src/packagemanager/pip/runPipCommand.spec.js +++ b/packages/safe-chain/src/packagemanager/pip/runPipCommand.spec.js @@ -24,10 +24,7 @@ describe("runPipCommand environment variable handling", () => { // Capture the config file content before the function cleans it up if (options.env.PIP_CONFIG_FILE) { try { - capturedConfigContent = await fs.readFile( - options.env.PIP_CONFIG_FILE, - "utf-8", - ); + capturedConfigContent = await fs.readFile(options.env.PIP_CONFIG_FILE, "utf-8"); } catch { // Ignore if file doesn't exist or can't be read } @@ -211,7 +208,7 @@ describe("runPipCommand environment variable handling", () => { "install", "certifi", "--index-url", - "https://test.pypi.org/simple" + "https://test.pypi.org/simple", ]); assert.strictEqual(res.status, 0); // Env vars should be set unconditionally @@ -424,5 +421,5 @@ describe("runPipCommand environment variable handling", () => { assert.strictEqual(shouldBypassSafeChain("python", ["-m", "pip3"]), false); assert.strictEqual(shouldBypassSafeChain("python3", ["-m", "pip3"]), false); }); - + }); diff --git a/packages/safe-chain/src/registryProxy/builtInProxy/interceptors/npm/npmInterceptor.minPackageAge.spec.js b/packages/safe-chain/src/registryProxy/builtInProxy/interceptors/npm/npmInterceptor.minPackageAge.spec.js index 9bc8e58..a31cce2 100644 --- a/packages/safe-chain/src/registryProxy/builtInProxy/interceptors/npm/npmInterceptor.minPackageAge.spec.js +++ b/packages/safe-chain/src/registryProxy/builtInProxy/interceptors/npm/npmInterceptor.minPackageAge.spec.js @@ -386,10 +386,7 @@ describe("npmInterceptor minimum package age", async () => { }, }); - const modifiedBody = await runModifyNpmInfoRequest( - packageUrl, - originalBody, - ); + const modifiedBody = await runModifyNpmInfoRequest(packageUrl, originalBody); const modifiedJson = JSON.parse(modifiedBody); // All versions should remain unchanged since lodash is excluded @@ -449,10 +446,7 @@ describe("npmInterceptor minimum package age", async () => { }, }); - const modifiedBody = await runModifyNpmInfoRequest( - packageUrl, - originalBody, - ); + const modifiedBody = await runModifyNpmInfoRequest(packageUrl, originalBody); const modifiedJson = JSON.parse(modifiedBody); // All versions should remain for excluded scoped package