fix(tools): mirror misplaced-arg recovery on the terminal side

Whole-bug-class sibling of the execute_code fix: terminal(code=...) —
the reverse confusion — fell through to command=None and failed with
'Invalid command: expected string, got NoneType', naming neither the
stray 'code' argument nor execute_code as the right tool. Mirror the
guard in _handle_terminal (verified live: the opaque NoneType error
reproduces on main). Mutation-checked: removing the guard fails the
new regression test.
This commit is contained in:
kshitij
2026-08-12 15:32:29 +05:30
parent c5e2bff6c1
commit a3bcb2c232
2 changed files with 23 additions and 0 deletions
+12
View File
@@ -577,6 +577,18 @@ class TestExecuteCodeEdgeCases(unittest.TestCase):
self.assertIn("terminal(command=...)", result["error"])
self.assertIn("execute_code(code=...)", result["error"])
def test_terminal_code_argument_points_to_execute_code(self):
"""Mirror recovery: terminal(code=...) names the stray argument and
redirects to execute_code, instead of the opaque
'Invalid command: expected string, got NoneType'."""
from tools.terminal_tool import _handle_terminal
result = json.loads(_handle_terminal({"code": "print(1)"}, task_id="test"))
self.assertIn("error", result)
self.assertIn("'code' parameter", result["error"])
self.assertIn("execute_code(code=...)", result["error"])
self.assertIn("terminal(command=...)", result["error"])
self.assertNotIn("NoneType", result["error"])
def test_empty_code_explains_required_parameter(self):
for code in ("", None):
with self.subTest(code=code):
+11
View File
@@ -3786,6 +3786,17 @@ TERMINAL_SCHEMA = {
def _handle_terminal(args, **kw):
# Mirror of execute_code's misplaced-argument recovery: models sometimes
# send execute_code's ``code`` argument here. Without this, the call
# falls through to command=None and fails with "Invalid command:
# expected string, got NoneType" — naming neither the stray argument
# nor the right tool.
if "command" not in args and "code" in args:
return tool_error(
"terminal received a 'code' parameter, but it requires a shell "
"command in 'command'. Use execute_code(code=...) for Python; "
"for shell, retry as terminal(command=...)."
)
return terminal_tool(
command=args.get("command"),
background=args.get("background", False),