============================= test session starts =============================
platform win32 -- Python 3.12.10, pytest-9.0.2, pluggy-1.6.0
rootdir: C:\Projects\GitHub\mcp-server-for-powershell
configfile: pyproject.toml
plugins: anyio-4.12.0
collected 13 items

tests\test_json_commands.py ......F.                                     [ 61%]
tests\test_restricted_path.py .....                                      [100%]

================================== FAILURES ===================================
_________________ TestJsonCommands.test_run_powershell_simple _________________

self = <test_json_commands.TestJsonCommands testMethod=test_run_powershell_simple>
mock_popen = <MagicMock name='Popen' id='3172694847232'>

    @patch('mcp_server_for_powershell.server.subprocess.Popen')
    def test_run_powershell_simple(self, mock_popen):
        # Mock process output
        process_mock = MagicMock()
        process_mock.communicate.return_value = ("Success", "")
        process_mock.returncode = 0
        mock_popen.return_value = process_mock
    
        json_input = json.dumps([{"command": "Get-Date"}])
        result = run_powershell(json=json_input)
    
        self.assertEqual(result, "Success")
    
        # Verify the command passed to pwsh
        args, kwargs = mock_popen.call_args
        cmd_list = args[0]
        self.assertIn("pwsh", cmd_list)
        self.assertIn("-EncodedCommand", cmd_list)
    
        # Decode and verify content
        encoded = cmd_list[cmd_list.index("-EncodedCommand") + 1]
        decoded_bytes = base64.b64decode(encoded)
        decoded_script = decoded_bytes.decode('utf-16le')
    
        # Verify language mode and command
>       self.assertTrue(decoded_script.startswith('$ExecutionContext.SessionState.LanguageMode = "ConstrainedLanguage"; '))
E       AssertionError: False is not true

tests\test_json_commands.py:65: AssertionError
=========================== short test summary info ===========================
FAILED tests/test_json_commands.py::TestJsonCommands::test_run_powershell_simple
======================== 1 failed, 12 passed in 1.03s =========================
