fix: FileTools uses local workspace before API for file content (#6.2)
This commit is contained in:
@@ -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"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user