fix: FileTools uses local workspace before API for file content (#6.2)

This commit is contained in:
meeks
2026-07-19 12:05:28 +02:00
parent 21eefd9824
commit 139fb44fac
3 changed files with 72 additions and 3 deletions
+28
View File
@@ -124,3 +124,31 @@ def test_update_file_failure() -> None:
"owner", "repo", "path/to/file", "msg", "content", "branch"
)
assert "Error updating file: API Error" in res
def test_get_file_content_uses_local_file_when_available(tmp_path: str) -> None:
import os
mock_client = _create_mock_client()
repo_dir = tmp_path / "owner" / "repo"
repo_dir.mkdir(parents=True)
file_path = repo_dir / "path" / "to" / "file"
file_path.parent.mkdir(parents=True)
file_path.write_text("local file content")
file_tools = FileTools(mock_client, str(tmp_path))
res = file_tools.get_file_content("owner", "repo", "path/to/file")
assert res == "1: local file content"
mock_client.files.get_file_content.assert_not_called()
def test_get_file_content_falls_back_to_api_when_no_local(tmp_path: str) -> None:
mock_client = _create_mock_client()
mock_client.files.get_file_content.return_value = "api content"
file_tools = FileTools(mock_client, str(tmp_path))
res = file_tools.get_file_content("owner", "repo", "path/to/file")
assert res == "1: api content"
mock_client.files.get_file_content.assert_called_once_with(
"owner", "repo", "path/to/file"
)