Handle absolute workspace globs

This commit is contained in:
wuyang6
2026-06-24 15:06:12 +08:00
parent 3637e2c73a
commit 84ff22fc65
2 changed files with 45 additions and 1 deletions
+39
View File
@@ -99,6 +99,45 @@ class ExtendedToolTests(unittest.TestCase):
self.assertIn('[line truncated,', result.content)
self.assertLess(len(result.content), 1200)
def test_glob_search_accepts_absolute_path_inside_workspace(self) -> None:
registry = default_tool_registry()
with tempfile.TemporaryDirectory() as tmp_dir:
workspace = Path(tmp_dir)
target_dir = workspace / 'output'
target_dir.mkdir()
(target_dir / 'records.jsonl').write_text('{}\n', encoding='utf-8')
context = build_tool_context(
AgentRuntimeConfig(cwd=workspace),
tool_registry=registry,
)
result = execute_tool(
registry,
'glob_search',
{'pattern': str(target_dir / '*.jsonl')},
context,
)
self.assertTrue(result.ok)
self.assertIn('output/records.jsonl', result.content)
def test_glob_search_external_absolute_path_returns_no_matches(self) -> None:
registry = default_tool_registry()
with tempfile.TemporaryDirectory() as workspace_dir, tempfile.TemporaryDirectory() as external_dir:
external = Path(external_dir) / '*.jsonl'
context = build_tool_context(
AgentRuntimeConfig(cwd=Path(workspace_dir)),
tool_registry=registry,
)
result = execute_tool(
registry,
'glob_search',
{'pattern': str(external)},
context,
)
self.assertTrue(result.ok)
self.assertEqual(result.content, '(no matches)')
def test_read_file_can_read_explicit_external_path(self) -> None:
registry = default_tool_registry()
with tempfile.TemporaryDirectory() as workspace_dir, tempfile.TemporaryDirectory() as external_dir: