1010from swesmith .constants import ORG_NAME_GH
1111from swesmith .profiles import registry , RepoProfile
1212from swesmith .profiles .utils import INSTALL_CMAKE , INSTALL_BAZEL
13- from unittest .mock import patch
13+ from unittest .mock import MagicMock , patch
1414
1515
1616@pytest .fixture (autouse = True )
@@ -50,53 +50,49 @@ def test_image_name():
5050def test_repo_profile_clone ():
5151 """Test the RepoProfile.clone method, adapted from the original clone_repo test."""
5252 repo_profile = registry .get ("mewwts__addict.75284f95" )
53+ mirror_ssh = f"git@github.com:{ repo_profile .mirror_name } .git"
5354
54- # Test with default dest (should use repo_name)
55- # Patch GITHUB_TOKEN to None to ensure SSH URL format is used
55+ # Test public repo clone (HTTPS read URL, SSH push URL)
5656 expected_dest = repo_profile .repo_name
57- expected_cmd = f"git clone git@github.com:{ repo_profile .mirror_name } .git { repo_profile .repo_name } "
58-
5957 with (
60- patch .dict (os .environ , {}, clear = False ),
61- patch ("os.getenv" , return_value = None ),
58+ patch .object (repo_profile , "_is_repo_private" , return_value = False ),
6259 patch ("os.path.exists" , return_value = False ) as mock_exists ,
6360 patch ("subprocess.run" ) as mock_run ,
6461 ):
6562 result , cloned = repo_profile .clone ()
6663 mock_exists .assert_called_once_with (expected_dest )
67- mock_run .assert_called_once_with (
68- expected_cmd ,
69- check = True ,
70- shell = True ,
71- stdout = subprocess .DEVNULL ,
72- stderr = subprocess .DEVNULL ,
73- )
64+ assert mock_run .call_count == 2
65+ clone_call , seturl_call = mock_run .call_args_list
66+ assert clone_call .args [0 ] == f"git clone https://github.com/{ repo_profile .mirror_name } { expected_dest } "
67+ assert seturl_call .args [0 ] == f"git -C { expected_dest } remote set-url --push origin { mirror_ssh } "
7468 assert result == expected_dest
75- assert cloned == True
69+ assert cloned is True
7670
77- # Test with custom dest specified
78- custom_dest = "some_dir"
79- expected_cmd_with_dest = (
80- f"git clone git@github.com:{ repo_profile .mirror_name } .git { custom_dest } "
81- )
71+ # Test private repo clone (SSH for both read and push)
72+ with (
73+ patch .object (repo_profile , "_is_repo_private" , return_value = True ),
74+ patch ("os.path.exists" , return_value = False ),
75+ patch ("subprocess.run" ) as mock_run ,
76+ ):
77+ result , cloned = repo_profile .clone ()
78+ assert mock_run .call_count == 2
79+ clone_call , seturl_call = mock_run .call_args_list
80+ assert clone_call .args [0 ] == f"git clone { mirror_ssh } { expected_dest } "
81+ assert seturl_call .args [0 ] == f"git -C { expected_dest } remote set-url --push origin { mirror_ssh } "
82+ assert cloned is True
8283
84+ # Test with custom dest
85+ custom_dest = "some_dir"
8386 with (
84- patch .dict (os .environ , {}, clear = False ),
85- patch ("os.getenv" , return_value = None ),
86- patch ("os.path.exists" , return_value = False ) as mock_exists ,
87+ patch .object (repo_profile , "_is_repo_private" , return_value = False ),
88+ patch ("os.path.exists" , return_value = False ),
8789 patch ("subprocess.run" ) as mock_run ,
8890 ):
8991 result , cloned = repo_profile .clone (custom_dest )
90- mock_exists .assert_called_once_with (custom_dest )
91- mock_run .assert_called_once_with (
92- expected_cmd_with_dest ,
93- check = True ,
94- shell = True ,
95- stdout = subprocess .DEVNULL ,
96- stderr = subprocess .DEVNULL ,
97- )
92+ clone_call = mock_run .call_args_list [0 ]
93+ assert custom_dest in clone_call .args [0 ]
9894 assert result == custom_dest
99- assert cloned == True
95+ assert cloned is True
10096
10197 # Test when repo already exists
10298 with (
@@ -107,7 +103,7 @@ def test_repo_profile_clone():
107103 mock_exists .assert_called_once_with (custom_dest )
108104 mock_run .assert_not_called ()
109105 assert result == custom_dest
110- assert cloned == False
106+ assert cloned is False
111107
112108
113109def test_python_log_parser ():
@@ -312,18 +308,24 @@ def test_create_mirror():
312308 mock_repos .create_in_org .assert_not_called ()
313309 mock_run .assert_not_called ()
314310
315- # Test creating new mirror
311+ # Test creating new mirror (private source repo)
316312 with (
317313 patch .object (repo_profile , "_mirror_exists" , return_value = False ),
318314 patch ("os.listdir" , return_value = [repo_profile .repo_name ]),
319315 patch ("shutil.rmtree" ),
320316 patch .object (repo_profile .api , "repos" ) as mock_repos ,
321317 patch ("subprocess.run" ) as mock_run ,
322318 ):
319+ mock_repos .get .return_value = MagicMock (private = True )
323320 repo_profile .create_mirror ()
324321
325- # Should create mirror and run git commands
326- mock_repos .create_in_org .assert_called_once ()
322+ # Should query source repo visibility and create mirror with matching visibility
323+ mock_repos .get .assert_called_once_with (
324+ repo_profile .owner , repo_profile .repo
325+ )
326+ mock_repos .create_in_org .assert_called_once_with (
327+ repo_profile .org_gh , repo_profile .repo_name , private = True
328+ )
327329 assert mock_run .call_count == 3 # Three git commands
328330
329331
0 commit comments