2
from git.exc import GitCommandError
3
from git.repo.base import Repo
5
from autogpt.agents.agent import Agent
6
from autogpt.agents.utils.exceptions import CommandExecutionError
7
from autogpt.commands.git_operations import clone_repository
8
from autogpt.file_storage.base import FileStorage
12
def mock_clone_from(mocker):
13
return mocker.patch.object(Repo, "clone_from")
16
def test_clone_auto_gpt_repository(storage: FileStorage, mock_clone_from, agent: Agent):
17
mock_clone_from.return_value = None
19
repo = "github.com/Significant-Gravitas/Auto-GPT.git"
22
clone_path = storage.get_path("auto-gpt-repo")
24
expected_output = f"Cloned {url} to {clone_path}"
26
clone_result = clone_repository(url=url, clone_path=clone_path, agent=agent)
28
assert clone_result == expected_output
29
mock_clone_from.assert_called_once_with(
30
url=f"{scheme}{agent.legacy_config.github_username}:{agent.legacy_config.github_api_key}@{repo}", # noqa: E501
35
def test_clone_repository_error(storage: FileStorage, mock_clone_from, agent: Agent):
36
url = "https://github.com/this-repository/does-not-exist.git"
37
clone_path = storage.get_path("does-not-exist")
39
mock_clone_from.side_effect = GitCommandError(
40
"clone", "fatal: repository not found", ""
43
with pytest.raises(CommandExecutionError):
44
clone_repository(url=url, clone_path=clone_path, agent=agent)