@@ -1925,61 +1925,20 @@ def test_remove_npm_claude_windows_npm_path(
19251925class TestUpdateInstallMethodConfig :
19261926 """Test update_install_method_config() function for config updates."""
19271927
1928- @patch ('install_claude.run_command' )
1929- @patch ('install_claude.find_command_robust' )
1930- def test_update_config_cli_success (
1931- self , mock_find : MagicMock , mock_run : MagicMock ,
1932- ) -> None :
1933- """Test update_install_method_config returns True when CLI succeeds."""
1934- mock_find .return_value = '/usr/local/bin/claude'
1935- mock_run .return_value = MagicMock (returncode = 0 )
1936-
1937- result = install_claude .update_install_method_config ('native' )
1938-
1939- assert result is True
1940- mock_find .assert_called_once_with ('claude' )
1941- mock_run .assert_called_once ()
1942- # Verify correct CLI command
1943- args = mock_run .call_args [0 ][0 ]
1944- assert args == ['/usr/local/bin/claude' , 'config' , 'set' , '-g' , 'installMethod' , 'native' ]
1945-
1946- def test_update_config_no_cli_fallback_to_file (
1928+ def test_update_config_file_modification (
19471929 self , tmp_path : Path ,
19481930 ) -> None :
1949- """Test update_install_method_config uses file fallback when CLI not found ."""
1931+ """Test update_install_method_config updates config file ."""
19501932 config_file = tmp_path / '.claude.json'
19511933 config_file .write_text ('{"existingKey": "value"}' )
19521934
1953- with (
1954- patch ('install_claude.find_command_robust' , return_value = None ),
1955- patch ('install_claude.Path.home' , return_value = tmp_path ),
1956- ):
1957- result = install_claude .update_install_method_config ('native' )
1958-
1959- assert result is True
1960- # Verify file was updated
1961- config = json .loads (config_file .read_text ())
1962- assert config ['installMethod' ] == 'native'
1963- assert config ['existingKey' ] == 'value' # Preserved
1964-
1965- @patch ('install_claude.run_command' )
1966- @patch ('install_claude.find_command_robust' )
1967- def test_update_config_cli_fails_fallback_to_file (
1968- self , mock_find : MagicMock , mock_run : MagicMock , tmp_path : Path ,
1969- ) -> None :
1970- """Test update_install_method_config uses file fallback when CLI fails."""
1971- mock_find .return_value = '/usr/local/bin/claude'
1972- mock_run .return_value = MagicMock (returncode = 1 ) # CLI fails
1973-
1974- config_file = tmp_path / '.claude.json'
1975- config_file .write_text ('{}' )
1976-
19771935 with patch ('install_claude.Path.home' , return_value = tmp_path ):
19781936 result = install_claude .update_install_method_config ('native' )
19791937
19801938 assert result is True
19811939 config = json .loads (config_file .read_text ())
19821940 assert config ['installMethod' ] == 'native'
1941+ assert config ['existingKey' ] == 'value'
19831942
19841943 def test_update_config_creates_new_file (
19851944 self , tmp_path : Path ,
@@ -1988,10 +1947,7 @@ def test_update_config_creates_new_file(
19881947 config_file = tmp_path / '.claude.json'
19891948 assert not config_file .exists ()
19901949
1991- with (
1992- patch ('install_claude.find_command_robust' , return_value = None ),
1993- patch ('install_claude.Path.home' , return_value = tmp_path ),
1994- ):
1950+ with patch ('install_claude.Path.home' , return_value = tmp_path ):
19951951 result = install_claude .update_install_method_config ('native' )
19961952
19971953 assert result is True
@@ -2006,13 +1962,10 @@ def test_update_config_corrupted_file(
20061962 config_file = tmp_path / '.claude.json'
20071963 config_file .write_text ('not valid json {{{' )
20081964
2009- with (
2010- patch ('install_claude.find_command_robust' , return_value = None ),
2011- patch ('install_claude.Path.home' , return_value = tmp_path ),
2012- ):
1965+ with patch ('install_claude.Path.home' , return_value = tmp_path ):
20131966 result = install_claude .update_install_method_config ('native' )
20141967
2015- assert result is False # Should fail gracefully
1968+ assert result is False
20161969
20171970 def test_update_config_permission_denied (
20181971 self , tmp_path : Path ,
@@ -2022,7 +1975,6 @@ def test_update_config_permission_denied(
20221975 config_file .write_text ('{}' )
20231976
20241977 with (
2025- patch ('install_claude.find_command_robust' , return_value = None ),
20261978 patch ('install_claude.Path.home' , return_value = tmp_path ),
20271979 patch ('builtins.open' , side_effect = PermissionError ('Permission denied' )),
20281980 ):
@@ -2038,51 +1990,32 @@ def test_update_config_preserves_existing_keys(
20381990 existing_config = {
20391991 'theme' : 'dark' ,
20401992 'telemetry' : False ,
2041- 'installMethod' : 'global' , # Old value to be updated
1993+ 'installMethod' : 'global' ,
20421994 }
20431995 config_file .write_text (json .dumps (existing_config ))
20441996
2045- with (
2046- patch ('install_claude.find_command_robust' , return_value = None ),
2047- patch ('install_claude.Path.home' , return_value = tmp_path ),
2048- ):
1997+ with patch ('install_claude.Path.home' , return_value = tmp_path ):
20491998 result = install_claude .update_install_method_config ('native' )
20501999
20512000 assert result is True
20522001 config = json .loads (config_file .read_text ())
20532002 assert config ['installMethod' ] == 'native'
2054- assert config ['theme' ] == 'dark' # Preserved
2055- assert config ['telemetry' ] is False # Preserved
2003+ assert config ['theme' ] == 'dark'
2004+ assert config ['telemetry' ] is False
20562005
2057- @patch ('install_claude.run_command' )
2058- @patch ('install_claude.find_command_robust' )
2059- def test_update_config_npm_global_method (
2060- self , mock_find : MagicMock , mock_run : MagicMock ,
2006+ def test_update_config_npm_global_method_file (
2007+ self , tmp_path : Path ,
20612008 ) -> None :
20622009 """Test update_install_method_config works with npm-global method."""
2063- mock_find .return_value = '/usr/local/bin/claude'
2064- mock_run .return_value = MagicMock (returncode = 0 )
2065-
2066- result = install_claude .update_install_method_config ('npm-global' )
2067-
2068- assert result is True
2069- args = mock_run .call_args [0 ][0 ]
2070- assert args [- 1 ] == 'npm-global'
2071-
2072- @patch ('install_claude.run_command' )
2073- @patch ('install_claude.find_command_robust' )
2074- def test_update_config_windows_claude_path (
2075- self , mock_find : MagicMock , mock_run : MagicMock ,
2076- ) -> None :
2077- """Test update_install_method_config works with Windows claude path."""
2078- mock_find .return_value = r'C:\Users\test\.local\bin\claude.exe'
2079- mock_run .return_value = MagicMock (returncode = 0 )
2010+ config_file = tmp_path / '.claude.json'
2011+ config_file .write_text ('{}' )
20802012
2081- result = install_claude .update_install_method_config ('native' )
2013+ with patch ('install_claude.Path.home' , return_value = tmp_path ):
2014+ result = install_claude .update_install_method_config ('npm-global' )
20822015
20832016 assert result is True
2084- args = mock_run . call_args [ 0 ][ 0 ]
2085- assert args [ 0 ] == r'C:\Users\test\.local\bin\claude.exe '
2017+ config = json . loads ( config_file . read_text ())
2018+ assert config [ 'installMethod' ] == 'npm-global '
20862019
20872020
20882021class TestNativeInstallCallsConfigUpdate :
0 commit comments