77from mcp_shell_server .shell_executor import ShellExecutor
88
99
10+ def clear_env (monkeypatch ):
11+ monkeypatch .delenv ("ALLOW_COMMANDS" , raising = False )
12+ monkeypatch .delenv ("ALLOWED_COMMANDS" , raising = False )
13+
14+
1015@pytest .fixture
1116def temp_test_dir ():
1217 """Create a temporary directory for testing"""
@@ -20,15 +25,15 @@ async def test_empty_command_validation():
2025 """Test validation of empty commands"""
2126 executor = ShellExecutor ()
2227
23- # 空のコマンドのテスト
28+ # Test empty command
2429 with pytest .raises (ValueError , match = "Empty command" ):
2530 executor ._validate_command ([])
2631
2732
2833@pytest .mark .asyncio
2934async def test_no_allowed_commands_validation (monkeypatch ):
3035 """Test validation when no commands are allowed"""
31- # ALLOW_COMMANDSを削除
36+ # Remove ALLOW_COMMANDS
3237 monkeypatch .delenv ("ALLOW_COMMANDS" , raising = False )
3338 monkeypatch .delenv ("ALLOWED_COMMANDS" , raising = False )
3439
@@ -47,7 +52,7 @@ async def test_shell_operator_validation():
4752
4853 operators = [";" "&&" , "||" , "|" ]
4954 for op in operators :
50- # シェル操作子の検証
55+ # Test shell operator validation
5156 with pytest .raises (ValueError , match = f"Unexpected shell operator: { op } " ):
5257 executor ._validate_no_shell_operators (op )
5358
@@ -58,7 +63,7 @@ async def test_process_execution_timeout(monkeypatch, temp_test_dir):
5863 monkeypatch .setenv ("ALLOW_COMMANDS" , "sleep" )
5964 executor = ShellExecutor ()
6065
61- # プロセスのタイムアウトをテスト
66+ # Test process timeout
6267 command = ["sleep" , "5" ]
6368 with pytest .raises (asyncio .TimeoutError ):
6469 await asyncio .wait_for (executor .execute (command , temp_test_dir ), timeout = 0.1 )
@@ -70,6 +75,24 @@ async def test_process_failure(monkeypatch, temp_test_dir):
7075 monkeypatch .setenv ("ALLOW_COMMANDS" , "false" )
7176 executor = ShellExecutor ()
7277
73- # falseコマンドは常に終了コード1を返す
78+ # false command always returns exit code 1
7479 result = await executor .execute (["false" ], temp_test_dir )
7580 assert result ["status" ] == 1
81+
82+
83+ @pytest .mark .asyncio
84+ async def test_directory_validation ():
85+ """Test directory validation"""
86+ executor = ShellExecutor ()
87+
88+ # Test missing directory
89+ with pytest .raises (ValueError , match = "Directory is required" ):
90+ executor ._validate_directory (None )
91+
92+ # Test relative path
93+ with pytest .raises (ValueError , match = "Directory must be an absolute path" ):
94+ executor ._validate_directory ("relative/path" )
95+
96+ # Test non-existent directory
97+ with pytest .raises (ValueError , match = "Directory does not exist" ):
98+ executor ._validate_directory ("/nonexistent/directory" )
0 commit comments