Skip to content

Commit d3e00c2

Browse files
committed
fix(extensions): preserve skills mode on update
Keep command registration disabled when updating extensions in AI-skills mode, allowing the update path to continue registering the rendered skill artifact. Assisted-by: OpenAI Codex (model: GPT-6 Luna high, autonomous)
1 parent 67e0f72 commit d3e00c2

3 files changed

Lines changed: 82 additions & 2 deletions

File tree

‎src/specify_cli/extensions/__init__.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,6 +3215,7 @@ def install_from_archive(
32153215
priority: int = 10,
32163216
force: bool = False,
32173217
*,
3218+
register_commands: bool = True,
32183219
archive_file: BinaryIO | None = None,
32193220
source_name: str | None = None,
32203221
content_type: str | None = None,
@@ -3230,6 +3231,8 @@ def install_from_archive(
32303231
priority: Resolution priority (lower = higher precedence, default 10)
32313232
force: If True and extension is already installed, remove it first
32323233
before proceeding with installation
3234+
register_commands: Whether to register command files for the active
3235+
integration; skills are registered independently when enabled
32333236
archive_file: Already-open archive stream to consume instead of
32343237
reopening ``zip_path``
32353238
@@ -3294,6 +3297,7 @@ def install_from_archive(
32943297
return self.install_from_directory(
32953298
extension_dir,
32963299
speckit_version,
3300+
register_commands=register_commands,
32973301
priority=priority,
32983302
force=force,
32993303
catalog_name=catalog_name,
@@ -3449,6 +3453,7 @@ def install_from_zip(
34493453
priority: int = 10,
34503454
force: bool = False,
34513455
*,
3456+
register_commands: bool = True,
34523457
archive_file: BinaryIO | None = None,
34533458
source_name: str | None = None,
34543459
content_type: str | None = None,
@@ -3460,6 +3465,7 @@ def install_from_zip(
34603465
return self.install_from_archive(
34613466
zip_path,
34623467
speckit_version,
3468+
register_commands=register_commands,
34633469
priority=priority,
34643470
force=force,
34653471
archive_file=archive_file,

‎src/specify_cli/extensions/_command_update_transaction.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,9 @@ def backup_extension_skills(skill_names, *, skills_dir=None):
554554
_ = manager.install_from_zip(
555555
archive_path,
556556
speckit_version,
557+
register_commands=not is_ai_skills_enabled(
558+
_commands.load_init_options(project_root)
559+
),
557560
catalog_name=update.catalog_name,
558561
)
559562

‎tests/specify_cli/extensions/test_command_update.py‎

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import json
99
import shutil
10+
import zipfile
1011
from pathlib import Path
1112
from unittest.mock import patch
1213

@@ -349,10 +350,18 @@ def test_update_success_preserves_installed_at(
349350
v2_dir = self._create_extension_source(tmp_path, "2.0.0")
350351

351352
def fake_install_from_zip(
352-
self_obj, _zip_path, speckit_version, *, catalog_name=None
353+
self_obj,
354+
_zip_path,
355+
speckit_version,
356+
*,
357+
register_commands=True,
358+
catalog_name=None,
353359
):
354360
return self_obj.install_from_directory(
355-
v2_dir, speckit_version, catalog_name=catalog_name
361+
v2_dir,
362+
speckit_version,
363+
register_commands=register_commands,
364+
catalog_name=catalog_name,
356365
)
357366

358367
with patch.object(Path, "cwd", return_value=project_dir), \
@@ -667,6 +676,68 @@ def test_update_bundled_blocked_when_no_local_copy_exists(self, tmp_path):
667676
assert "upgrade spec-kit" in flat
668677
assert ExtensionManager(project_dir).registry.get("test-ext")["version"] == "1.0.0"
669678

679+
def test_update_preserves_skills_mode_registration(self, tmp_path, monkeypatch):
680+
"""Updating an extension must keep Claude skills in skills mode."""
681+
fake_home = tmp_path / "home"
682+
fake_home.mkdir()
683+
monkeypatch.setattr(Path, "home", lambda: fake_home)
684+
685+
project_dir = tmp_path / "project"
686+
(project_dir / ".specify").mkdir(parents=True)
687+
(project_dir / ".claude" / "skills").mkdir(parents=True)
688+
(project_dir / ".specify" / "init-options.json").write_text(
689+
json.dumps({"ai": "claude", "ai_skills": True, "script": "sh"}),
690+
encoding="utf-8",
691+
)
692+
693+
manager = ExtensionManager(project_dir)
694+
v1_dir = self._create_extension_source(tmp_path, "1.0.0")
695+
manager.install_from_directory(v1_dir, "0.1.0", register_commands=False)
696+
697+
skill_name = "speckit-test-ext-hello"
698+
skill_file = project_dir / ".claude" / "skills" / skill_name / "SKILL.md"
699+
original_skill = skill_file.read_text(encoding="utf-8")
700+
old_entry = manager.registry.get("test-ext")
701+
assert old_entry["registered_skills"] == [skill_name]
702+
assert old_entry.get("registered_commands", {}) == {}
703+
704+
v2_dir = self._create_extension_source(tmp_path, "2.0.0")
705+
zip_path = tmp_path / "test-ext-2.0.0.zip"
706+
with zipfile.ZipFile(zip_path, "w") as archive:
707+
for path in v2_dir.rglob("*"):
708+
if path.is_file():
709+
archive.write(path, path.relative_to(v2_dir))
710+
711+
runner = CliRunner()
712+
with (
713+
patch.object(Path, "cwd", return_value=project_dir),
714+
patch.object(
715+
ExtensionCatalog,
716+
"get_extension_info",
717+
return_value={
718+
"id": "test-ext",
719+
"name": "Test Extension",
720+
"version": "2.0.0",
721+
"_install_allowed": True,
722+
},
723+
),
724+
patch.object(
725+
ExtensionCatalog, "download_extension", return_value=zip_path
726+
),
727+
):
728+
result = runner.invoke(
729+
app,
730+
["extension", "update", "test-ext"],
731+
input="y\n",
732+
catch_exceptions=True,
733+
)
734+
735+
assert result.exit_code == 0, result.output
736+
updated = ExtensionManager(project_dir).registry.get("test-ext")
737+
assert updated["registered_skills"] == [skill_name]
738+
assert updated.get("registered_commands", {}) == {}
739+
assert skill_file.read_text(encoding="utf-8") == original_skill
740+
670741
def test_update_failure_rolls_back_registry_hooks_and_commands(self, tmp_path, monkeypatch):
671742
"""Failed update should restore original registry, hooks, and command files."""
672743
from specify_cli import app

0 commit comments

Comments
 (0)