Skip to content

Commit ce821bb

Browse files
committed
fix(presets): distinguish skill ownership from preset command prefixes
A surviving preset named preset must not claim the removed preset ownership marker during partial-registration cleanup. Assisted-by: Codex (model: GPT-6, autonomous)
1 parent 1bcd341 commit ce821bb

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

‎src/specify_cli/presets/_manager_skills.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,13 @@ def _drop_survivor_owned_aliases(
999999
metadata = None
10001000
if isinstance(metadata, dict):
10011001
source = metadata.get("source")
1002-
if isinstance(source, str) and any(
1003-
source == f"preset:{other}" or source.startswith(f"{other}:")
1004-
for other in survivors
1002+
if (
1003+
isinstance(source, str)
1004+
and source != f"preset:{pack_id}"
1005+
and any(
1006+
source == f"preset:{other}" or source.startswith(f"{other}:")
1007+
for other in survivors
1008+
)
10051009
):
10061010
continue
10071011
kept.append(name)

‎tests/specify_cli/presets/test_manager_skills.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,6 +3124,46 @@ def fail_base(manifest, *args, **kwargs):
31243124
assert "Core custom body" in content and "Appended body" in content
31253125
assert "Base preset body" not in content
31263126

3127+
@pytest.mark.parametrize("survivor_id", ["unrelated", "preset"])
3128+
def test_remove_native_skill_with_survivor_named_preset(
3129+
self, project_dir, temp_dir, monkeypatch, survivor_id
3130+
):
3131+
"""A preset named ``preset`` must not own every ``preset:<id>``
3132+
marker when command cleanup handles a partial skills record."""
3133+
self._write_init_options(project_dir, ai="claude", ai_skills=True)
3134+
self._create_skill(project_dir / ".claude" / "skills", "speckit-custom")
3135+
manager = PresetManager(project_dir)
3136+
for preset_id, command in [
3137+
("base-preset", "speckit.custom"),
3138+
(survivor_id, "speckit.other"),
3139+
]:
3140+
preset = self._create_command_preset(temp_dir, preset_id, command, preset_id, preset_id)
3141+
manager.install_from_directory(preset, "0.1.5")
3142+
self._write_init_options(project_dir, ai="codex", ai_skills=True)
3143+
(project_dir / ".agents" / "skills").mkdir(parents=True)
3144+
original = manager._merge_pack_registered_skills
3145+
3146+
def fail_base_record(pack_id, written):
3147+
if pack_id == "base-preset" and written and "codex" in written:
3148+
raise OSError("simulated skill registry write failure")
3149+
return original(pack_id, written)
3150+
3151+
with monkeypatch.context() as patch:
3152+
patch.setattr(manager, "_merge_pack_registered_skills", fail_base_record)
3153+
with pytest.warns(UserWarning, match="simulated skill registry write failure"):
3154+
manager.register_enabled_presets_for_agent("codex")
3155+
3156+
skill = project_dir / ".agents" / "skills" / "speckit-custom" / "SKILL.md"
3157+
assert "preset:base-preset" in skill.read_text(encoding="utf-8")
3158+
base = manager.registry.get("base-preset")
3159+
assert "speckit.custom" in base["registered_commands"]["codex"]
3160+
assert not base["registered_skills"].get("codex")
3161+
3162+
assert manager.remove("base-preset") is True
3163+
3164+
assert not skill.exists()
3165+
assert manager.registry.is_installed(survivor_id)
3166+
31273167
def test_baseless_lower_composer_alias_stays_retired_after_rescaffold(
31283168
self, project_dir, temp_dir
31293169
):

0 commit comments

Comments
 (0)