diff --git a/src/workato_platform_cli/cli/utils/config/profiles.py b/src/workato_platform_cli/cli/utils/config/profiles.py index 992dadd..f024380 100644 --- a/src/workato_platform_cli/cli/utils/config/profiles.py +++ b/src/workato_platform_cli/cli/utils/config/profiles.py @@ -296,8 +296,8 @@ def save_profiles(self, profiles_config: ProfilesConfig) -> None: # Set secure permissions (only user can read/write) temp_file.chmod(0o600) - # Atomic rename - temp_file.rename(self.profiles_file) + # Atomic replace (works cross-platform, including Windows) + temp_file.replace(self.profiles_file) def get_profile(self, profile_name: str) -> ProfileData | None: """Get profile data by name""" diff --git a/tests/unit/config/test_profiles.py b/tests/unit/config/test_profiles.py index bb424b4..c83f78f 100644 --- a/tests/unit/config/test_profiles.py +++ b/tests/unit/config/test_profiles.py @@ -298,6 +298,36 @@ def test_save_profiles(self, tmp_path: Path) -> None: assert saved_data["current_profile"] == "dev" assert "dev" in saved_data["profiles"] + def test_save_profiles_overwrites_existing(self, tmp_path: Path) -> None: + """Test saving profiles overwrites existing file (Windows compatibility).""" + with patch("pathlib.Path.home", return_value=tmp_path): + manager = ProfileManager() + + # First save + profile1 = ProfileData( + region="us", region_url="https://www.workato.com", workspace_id=123 + ) + config1 = ProfilesConfig(current_profile="dev", profiles={"dev": profile1}) + manager.save_profiles(config1) + + # Second save should overwrite without error + profile2 = ProfileData( + region="eu", region_url="https://app.eu.workato.com", workspace_id=456 + ) + config2 = ProfilesConfig( + current_profile="prod", profiles={"dev": profile1, "prod": profile2} + ) + manager.save_profiles(config2) + + # Verify the second save succeeded + profiles_file = tmp_path / ".workato" / "profiles" + with open(profiles_file) as f: + saved_data = json.load(f) + + assert saved_data["current_profile"] == "prod" + assert "dev" in saved_data["profiles"] + assert "prod" in saved_data["profiles"] + def test_get_profile_success(self, tmp_path: Path) -> None: """Test getting profile data.""" profile = ProfileData(