|
7 | 7 |
|
8 | 8 | import json |
9 | 9 | import shutil |
| 10 | +import zipfile |
10 | 11 | from pathlib import Path |
11 | 12 | from unittest.mock import patch |
12 | 13 |
|
@@ -349,10 +350,18 @@ def test_update_success_preserves_installed_at( |
349 | 350 | v2_dir = self._create_extension_source(tmp_path, "2.0.0") |
350 | 351 |
|
351 | 352 | 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, |
353 | 359 | ): |
354 | 360 | 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, |
356 | 365 | ) |
357 | 366 |
|
358 | 367 | 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): |
667 | 676 | assert "upgrade spec-kit" in flat |
668 | 677 | assert ExtensionManager(project_dir).registry.get("test-ext")["version"] == "1.0.0" |
669 | 678 |
|
| 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 | + |
670 | 741 | def test_update_failure_rolls_back_registry_hooks_and_commands(self, tmp_path, monkeypatch): |
671 | 742 | """Failed update should restore original registry, hooks, and command files.""" |
672 | 743 | from specify_cli import app |
|
0 commit comments