Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/workato_platform_cli/cli/utils/config/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/config/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading