feat: 优化运行时判定

This commit is contained in:
richarjiang
2026-09-24 14:27:07 +08:00
parent dfd3998399
commit f0ac603f27
25 changed files with 2368 additions and 58 deletions

44
tests/test_trajectory.py Normal file
View File

@@ -0,0 +1,44 @@
from laya_router.trajectory import (
Step,
consecutive_failures,
edited_without_verification,
repeated_command,
response_failed,
step_from_event,
target_paths,
was_inspected,
)
def test_patch_and_edit_paths():
assert target_paths("Edit", {"file_path": "src/app.py"}) == ("src/app.py",)
patch = "*** Update File: src/app.py\n*** Add File: src/new.py\n"
assert target_paths("apply_patch", {"command": patch}) == ("src/app.py", "src/new.py")
def test_failure_signals():
assert response_failed({"exit_code": 1})
assert not response_failed({"exit_code": 0})
assert response_failed("command failed: boom")
steps = [
Step("bash", "Bash", "pytest", failed=True),
Step("bash", "Bash", "pytest", failed=True),
]
assert consecutive_failures(steps) == 2
assert repeated_command(steps) == 2
steps.append(Step("bash", "Bash", "pytest", failed=False))
assert consecutive_failures(steps) == 0
def test_unread_edit_and_verification():
read = step_from_event("Read", {"file_path": "src/app.py"}, None, after=True)
edit = step_from_event("Edit", {"file_path": "src/app.py"}, None, after=True)
other = step_from_event("Edit", {"file_path": "src/other.py"}, None, after=True)
verify = step_from_event("Bash", {"command": "pytest -q"}, {"exit_code": 0}, after=True)
assert read is not None and edit is not None and other is not None and verify is not None
steps = [read, edit]
assert was_inspected(steps, "src/app.py")
assert not was_inspected(steps, "src/other.py")
assert edited_without_verification([edit, other])
assert not edited_without_verification([edit, verify])
assert step_from_event("Edit", {"file_path": "a.py"}, None, after=False) is None