From 05afc350e483e1a556cfd6d319759a740076b224 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Mar 2026 19:58:13 +0000 Subject: [PATCH] fix(builtins): make exported variables visible to Python's os.getenv Merge ctx.variables into env when running Python code so that variables set via `export VAR=val` are visible to os.getenv(). Also unskip two Python spec tests that now pass (getenv, nested dict access). Closes #316 https://claude.ai/code/session_01WZjYqxm5xMPAEe7FSHJkDy --- crates/bashkit/src/builtins/python.rs | 7 ++++++- crates/bashkit/tests/spec_cases/python/python.test.sh | 2 -- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/bashkit/src/builtins/python.rs b/crates/bashkit/src/builtins/python.rs index f7166cd2..82a13343 100644 --- a/crates/bashkit/src/builtins/python.rs +++ b/crates/bashkit/src/builtins/python.rs @@ -256,12 +256,17 @@ impl Builtin for Python { )); }; + // Merge env and variables so exported vars (set via `export`) are visible + // to Python's os.getenv(). Variables override env (bash semantics). + let mut merged_env = ctx.env.clone(); + merged_env.extend(ctx.variables.iter().map(|(k, v)| (k.clone(), v.clone()))); + run_python( &code, &filename, ctx.fs.clone(), ctx.cwd, - ctx.env, + &merged_env, &self.limits, ) .await diff --git a/crates/bashkit/tests/spec_cases/python/python.test.sh b/crates/bashkit/tests/spec_cases/python/python.test.sh index 6a61b3be..f518af26 100644 --- a/crates/bashkit/tests/spec_cases/python/python.test.sh +++ b/crates/bashkit/tests/spec_cases/python/python.test.sh @@ -409,7 +409,6 @@ print(a, b, c)" ### end ### python3_nested_dict_access -### skip: Monty dict literal in bash quoting needs single-quote support # Nested data structures python3 -c "data = {'users': [{'name': 'Alice'}]} print(data['users'][0]['name'])" @@ -511,7 +510,6 @@ print(count)" ### end ### python3_vfs_getenv -### skip: export propagation to ctx.env may not work in spec test runner # Read environment variables from Python export MY_TEST_VAR=hello_from_env python3 -c "import os