Enforce session workspace boundaries

This commit is contained in:
武阳
2026-05-08 17:09:07 +08:00
parent 5b14f55736
commit 0bbba2b936
13 changed files with 509 additions and 52 deletions
+20
View File
@@ -51,6 +51,26 @@ class PythonExecToolTests(TestCase):
self.assertIn(str(scratchpad), result.content)
self.assertEqual(result.metadata.get('scratchpad_directory'), str(scratchpad))
def test_python_exec_runs_from_session_scratchpad(self) -> None:
with tempfile.TemporaryDirectory() as tmp_dir:
root = Path(tmp_dir)
scratchpad = (root / 'session' / 'scratchpad').resolve()
scratchpad.mkdir(parents=True)
config = AgentRuntimeConfig(
cwd=root,
permissions=AgentPermissions(allow_shell_commands=True),
)
context = build_tool_context(config, scratchpad_directory=scratchpad)
result = execute_tool(
default_tool_registry(),
'python_exec',
{'code': 'import os\nprint(os.getcwd())'},
context,
)
self.assertTrue(result.ok)
self.assertIn(str(scratchpad), result.content)
def test_python_exec_prefers_user_python_env(self) -> None:
with tempfile.TemporaryDirectory() as tmp_dir:
root = Path(tmp_dir)