Skip to content

Commit cafc9c4

Browse files
committed
Merge main into test to include PR #74 Windows fix
2 parents e46f503 + 54896f4 commit cafc9c4

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/workato_platform_cli/cli/utils/config/profiles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ def save_profiles(self, profiles_config: ProfilesConfig) -> None:
296296
# Set secure permissions (only user can read/write)
297297
temp_file.chmod(0o600)
298298

299-
# Atomic rename
300-
temp_file.rename(self.profiles_file)
299+
# Atomic replace (works cross-platform, including Windows)
300+
temp_file.replace(self.profiles_file)
301301

302302
def get_profile(self, profile_name: str) -> ProfileData | None:
303303
"""Get profile data by name"""

tests/unit/config/test_profiles.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,36 @@ def test_save_profiles(self, tmp_path: Path) -> None:
298298
assert saved_data["current_profile"] == "dev"
299299
assert "dev" in saved_data["profiles"]
300300

301+
def test_save_profiles_overwrites_existing(self, tmp_path: Path) -> None:
302+
"""Test saving profiles overwrites existing file (Windows compatibility)."""
303+
with patch("pathlib.Path.home", return_value=tmp_path):
304+
manager = ProfileManager()
305+
306+
# First save
307+
profile1 = ProfileData(
308+
region="us", region_url="https://www.workato.com", workspace_id=123
309+
)
310+
config1 = ProfilesConfig(current_profile="dev", profiles={"dev": profile1})
311+
manager.save_profiles(config1)
312+
313+
# Second save should overwrite without error
314+
profile2 = ProfileData(
315+
region="eu", region_url="https://app.eu.workato.com", workspace_id=456
316+
)
317+
config2 = ProfilesConfig(
318+
current_profile="prod", profiles={"dev": profile1, "prod": profile2}
319+
)
320+
manager.save_profiles(config2)
321+
322+
# Verify the second save succeeded
323+
profiles_file = tmp_path / ".workato" / "profiles"
324+
with open(profiles_file) as f:
325+
saved_data = json.load(f)
326+
327+
assert saved_data["current_profile"] == "prod"
328+
assert "dev" in saved_data["profiles"]
329+
assert "prod" in saved_data["profiles"]
330+
301331
def test_get_profile_success(self, tmp_path: Path) -> None:
302332
"""Test getting profile data."""
303333
profile = ProfileData(

0 commit comments

Comments
 (0)