From 71462071e4186a8cfbde6a32f1ab11db688e902f Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Sun, 21 Jun 2026 19:51:52 +0200 Subject: [PATCH] feat: profiles rename_profile Co-Authored-By: Claude Opus 4.8 --- gates/profiles.py | 13 +++++++++++++ tests/test_profiles.py | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/gates/profiles.py b/gates/profiles.py index ff8798f..3f57ee2 100644 --- a/gates/profiles.py +++ b/gates/profiles.py @@ -57,3 +57,16 @@ def create_profile(base, name, pid, ts=0): reg["profiles"].append(entry) write_registry(base, reg) return entry + + +def rename_profile(base, pid, name): + reg = read_registry(base) + entry = find_by_id(reg, pid) + if not entry: + raise KeyError(pid) + other = find_by_name(reg, name) + if other and other["id"] != pid: + raise ValueError(f"profile name already exists: {name}") + entry["name"] = name + write_registry(base, reg) + return entry diff --git a/tests/test_profiles.py b/tests/test_profiles.py index 3448b92..8e15314 100644 --- a/tests/test_profiles.py +++ b/tests/test_profiles.py @@ -34,3 +34,16 @@ def test_create_duplicate_name_raises(tmp_path): pr.create_profile(str(tmp_path), "setA", "id1") with pytest.raises(ValueError): pr.create_profile(str(tmp_path), "setA", "id2") + +def test_rename_profile(tmp_path): + pr.create_profile(str(tmp_path), "old", "id1") + e = pr.rename_profile(str(tmp_path), "id1", "new") + assert e["name"] == "new" + assert pr.find_by_name(pr.read_registry(str(tmp_path)), "new")["id"] == "id1" + +def test_rename_to_existing_name_raises(tmp_path): + import pytest + pr.create_profile(str(tmp_path), "a", "id1") + pr.create_profile(str(tmp_path), "b", "id2") + with pytest.raises(ValueError): + pr.rename_profile(str(tmp_path), "id2", "a")