Skip to content

Build and run agents you can see, understand and trust.

fix(tool): skip a PowerShell candidate that cannot run (#3699)

Kiko0301ccbcf48d5998
diff --git a/src/agentscope/tool/_builtin/_powershell.py b/src/agentscope/tool/_builtin/_powershell.py
index 1403dbcc7..33ec8d39a 100644
--- a/src/agentscope/tool/_builtin/_powershell.py
+++ b/src/agentscope/tool/_builtin/_powershell.py
@@ -129,7 +129,8 @@ are easier for the user to review and authorize:
],
timeout=10.0,
)
- if probe.exit_code != 127:
+ # A timed-out probe should fall through to the next shell.
+ if probe.exit_code == 0:
self._executable = candidate
break
else:
diff --git a/tests/builtin_powershell_test.py b/tests/builtin_powershell_test.py
index fa84127cc..48b93756e 100644
--- a/tests/builtin_powershell_test.py
+++ b/tests/builtin_powershell_test.py
@@ -378,5 +378,30 @@ class PowerShellWindowsIntegrationTest(IsolatedAsyncioTestCase):
self.assertEqual(chunks[0].content[0].text.strip(), "2")
+class PowerShellExecutableResolutionTest(IsolatedAsyncioTestCase):
+ """Pick a shell that the probe proved it can actually start."""
+
+ async def test_probe_that_cannot_run_falls_back_to_the_next_shell(
+ self,
+ ) -> None:
+ """A probe killed before answering is not a usable shell."""
+ backend = AsyncMock()
+ backend.exec_shell.side_effect = [
+ ExecResult(-1, b"", b"timed out"),
+ ExecResult(0, b"", b""),
+ ]
+ tool = PowerShell(backend=backend)
+
+ self.assertEqual(
+ await tool._resolve_executable(),
+ "powershell.exe",
+ )
+ self.assertEqual(
+ await tool._resolve_executable(),
+ "powershell.exe",
+ )
+ self.assertEqual(backend.exec_shell.await_count, 2)
+
+
if __name__ == "__main__":
unittest.main()