@@ -621,4 +621,53 @@ async def test_output_redirection_with_append(executor, temp_test_dir, monkeypat
621
621
lines = result ["stdout" ].strip ().split ("\n " )
622
622
assert len (lines ) == 2
623
623
assert lines [0 ] == "hello"
624
- assert lines [1 ] == "world"
624
+
625
+
626
+ @pytest .mark .asyncio
627
+ async def test_execute_with_custom_env (executor , temp_test_dir , monkeypatch ):
628
+ """Test command execution with custom environment variables"""
629
+ clear_env (monkeypatch )
630
+ monkeypatch .setenv ("ALLOW_COMMANDS" , "env,printenv" )
631
+
632
+ custom_env = {"TEST_VAR1" : "test_value1" , "TEST_VAR2" : "test_value2" }
633
+
634
+ # Test env command
635
+ result = await executor .execute (["env" ], directory = temp_test_dir , envs = custom_env )
636
+ assert "TEST_VAR1=test_value1" in result ["stdout" ]
637
+ assert "TEST_VAR2=test_value2" in result ["stdout" ]
638
+
639
+ # Test specific variable
640
+ result = await executor .execute (
641
+ ["printenv" , "TEST_VAR1" ], directory = temp_test_dir , envs = custom_env
642
+ )
643
+ assert result ["stdout" ].strip () == "test_value1"
644
+
645
+
646
+ @pytest .mark .asyncio
647
+ async def test_execute_env_override (executor , temp_test_dir , monkeypatch ):
648
+ """Test that custom environment variables override system variables"""
649
+ clear_env (monkeypatch )
650
+ monkeypatch .setenv ("ALLOW_COMMANDS" , "env" )
651
+ monkeypatch .setenv ("TEST_VAR" , "original_value" )
652
+
653
+ # Override system environment variable
654
+ result = await executor .execute (
655
+ ["env" ], directory = temp_test_dir , envs = {"TEST_VAR" : "new_value" }
656
+ )
657
+
658
+ assert "TEST_VAR=new_value" in result ["stdout" ]
659
+ assert "TEST_VAR=original_value" not in result ["stdout" ]
660
+
661
+
662
+ @pytest .mark .asyncio
663
+ async def test_execute_with_empty_env (executor , temp_test_dir , monkeypatch ):
664
+ """Test command execution with empty environment variables"""
665
+ clear_env (monkeypatch )
666
+ monkeypatch .setenv ("ALLOW_COMMANDS" , "env" )
667
+
668
+ result = await executor .execute (["env" ], directory = temp_test_dir , envs = {})
669
+
670
+ # Command should still work with system environment
671
+ assert result ["error" ] is None
672
+ assert result ["status" ] == 0
673
+ assert len (result ["stdout" ]) > 0
0 commit comments