mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-09-20 12:13:38 +08:00
fix: support bounded recursive glob across lessons
This commit is contained in:
@@ -30,6 +30,8 @@ LESSONS = tuple(
|
||||
)
|
||||
)
|
||||
INTEGRATED_LESSON = ROOT / "s15_integrated_harness" / "code.py"
|
||||
GOAL_LESSON = ROOT / "s17_goal_loop" / "code.py"
|
||||
GLOB_LESSONS = (*LESSONS[1:], INTEGRATED_LESSON, GOAL_LESSON)
|
||||
|
||||
|
||||
class FakeMessagesApi:
|
||||
@@ -137,6 +139,42 @@ def bash_tool_call():
|
||||
)
|
||||
|
||||
|
||||
def run_glob_tool(lesson, workdir: Path, pattern: str) -> str:
|
||||
if hasattr(lesson, "run_glob"):
|
||||
return lesson.run_glob(pattern)
|
||||
session = object.__new__(lesson.AgentSession)
|
||||
session.workdir = workdir.resolve()
|
||||
return session._run_tool("glob", {"pattern": pattern})
|
||||
|
||||
|
||||
@pytest.mark.parametrize("lesson_path", GLOB_LESSONS,
|
||||
ids=lambda path: path.parent.name)
|
||||
def test_glob_double_star_matches_files_at_any_depth(
|
||||
tmp_path: Path, lesson_path: Path):
|
||||
(tmp_path / "root.py").write_text("")
|
||||
(tmp_path / "one" / "two").mkdir(parents=True)
|
||||
(tmp_path / "one" / "one.py").write_text("")
|
||||
(tmp_path / "one" / "two" / "deep.py").write_text("")
|
||||
lesson = load_lesson(tmp_path, lesson_path)
|
||||
|
||||
matches = set(run_glob_tool(lesson, tmp_path, "**/*.py").splitlines())
|
||||
|
||||
assert matches == {"root.py", "one/one.py", "one/two/deep.py"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("lesson_path", GLOB_LESSONS,
|
||||
ids=lambda path: path.parent.name)
|
||||
def test_glob_caps_large_result_sets(tmp_path: Path, lesson_path: Path):
|
||||
for index in range(205):
|
||||
(tmp_path / f"file-{index:03}.txt").write_text("")
|
||||
lesson = load_lesson(tmp_path, lesson_path)
|
||||
|
||||
lines = run_glob_tool(lesson, tmp_path, "*.txt").splitlines()
|
||||
|
||||
assert len(lines) == 201
|
||||
assert lines[-1] == "... (more matches omitted; narrow the pattern)"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("lesson_path", LESSONS, ids=lambda path: path.parent.name)
|
||||
@pytest.mark.parametrize("content", ([], None), ids=("empty-content", "empty-text"))
|
||||
def test_parent_loop_does_not_append_an_empty_tool_result_turn(
|
||||
|
||||
Reference in New Issue
Block a user