Skip to content

Commit ccae703

Browse files
committed
fix: address PR review round 4
- Reorder kimi migration: run super().setup() first so hyphenated targets exist, then migrate dotted dirs (prevents user content loss) - Move _strip_ansi() to shared tests/conftest.py, import from there in test_extensions.py, test_presets.py, test_ai_skills.py - Remove now-unused re imports from all three test files
1 parent 984528e commit ccae703

5 files changed

Lines changed: 28 additions & 23 deletions

File tree

src/specify_cli/integrations/kimi/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,19 @@ def setup(
6363
) -> list[Path]:
6464
"""Install skills with optional legacy dotted-name migration."""
6565
parsed_options = parsed_options or {}
66+
67+
# Run base setup first so hyphenated targets (speckit-*) exist,
68+
# then migrate/clean legacy dotted dirs without risking user content loss.
69+
created = super().setup(
70+
project_root, manifest, parsed_options=parsed_options, **opts
71+
)
72+
6673
if parsed_options.get("migrate_legacy", False):
6774
skills_dir = self.skills_dest(project_root)
6875
if skills_dir.is_dir():
6976
_migrate_legacy_kimi_dotted_skills(skills_dir)
7077

71-
return super().setup(
72-
project_root, manifest, parsed_options=parsed_options, **opts
73-
)
78+
return created
7479

7580

7681
def _migrate_legacy_kimi_dotted_skills(skills_dir: Path) -> tuple[int, int]:

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Shared test helpers for the Spec Kit test suite."""
2+
3+
import re
4+
5+
_ANSI_ESCAPE_RE = re.compile(r"\x1b\[[0-?]*[ -/]*[@-~]")
6+
7+
8+
def strip_ansi(text: str) -> str:
9+
"""Remove ANSI escape codes from Rich-formatted CLI output."""
10+
return _ANSI_ESCAPE_RE.sub("", text)

tests/test_ai_skills.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
- CLI validation: --ai-skills requires --ai
1111
"""
1212

13-
import re
1413
import zipfile
1514
import pytest
1615
import tempfile
@@ -21,6 +20,7 @@
2120
from unittest.mock import patch
2221

2322
import specify_cli
23+
from tests.conftest import strip_ansi
2424

2525
from specify_cli import (
2626
_get_skills_dir,
@@ -923,7 +923,7 @@ def test_ai_skills_flag_appears_in_help(self):
923923
runner = CliRunner()
924924
result = runner.invoke(app, ["init", "--help"])
925925

926-
plain = re.sub(r'\x1b\[[0-9;]*m', '', result.output)
926+
plain = strip_ansi(result.output)
927927
assert "--ai-skills" in plain
928928
assert "agent skills" in plain.lower()
929929

tests/test_extensions.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
- Catalog stack (multi-catalog support)
1010
"""
1111

12-
import re
1312
import pytest
1413
import json
1514
import tempfile
1615
import shutil
1716
from pathlib import Path
1817
from datetime import datetime, timezone
1918

19+
from tests.conftest import strip_ansi
2020
from specify_cli.extensions import (
2121
CatalogEntry,
2222
CORE_COMMAND_NAMES,
@@ -34,11 +34,6 @@
3434
)
3535

3636

37-
def _strip_ansi(text: str) -> str:
38-
"""Remove ANSI escape codes from Rich-formatted CLI output."""
39-
return re.sub(r'\x1b\[[0-9;]*m', '', text)
40-
41-
4237
# ===== Fixtures =====
4338

4439
@pytest.fixture
@@ -3132,7 +3127,7 @@ def test_list_shows_extension_id(self, extension_dir, project_dir):
31323127
result = runner.invoke(app, ["extension", "list"])
31333128

31343129
assert result.exit_code == 0, result.output
3135-
plain = _strip_ansi(result.output)
3130+
plain = strip_ansi(result.output)
31363131
# Verify the extension ID is shown in the output
31373132
assert "test-ext" in plain
31383133
# Verify name and version are also shown
@@ -3367,7 +3362,7 @@ def test_list_shows_priority(self, extension_dir, project_dir):
33673362
result = runner.invoke(app, ["extension", "list"])
33683363

33693364
assert result.exit_code == 0, result.output
3370-
plain = _strip_ansi(result.output)
3365+
plain = strip_ansi(result.output)
33713366
assert "Priority: 7" in plain
33723367

33733368
def test_set_priority_changes_priority(self, extension_dir, project_dir):
@@ -3389,7 +3384,7 @@ def test_set_priority_changes_priority(self, extension_dir, project_dir):
33893384
result = runner.invoke(app, ["extension", "set-priority", "test-ext", "5"])
33903385

33913386
assert result.exit_code == 0, result.output
3392-
plain = _strip_ansi(result.output)
3387+
plain = strip_ansi(result.output)
33933388
assert "priority changed: 10 → 5" in plain
33943389

33953390
# Reload registry to see updated value
@@ -3412,7 +3407,7 @@ def test_set_priority_same_value_no_change(self, extension_dir, project_dir):
34123407
result = runner.invoke(app, ["extension", "set-priority", "test-ext", "5"])
34133408

34143409
assert result.exit_code == 0, result.output
3415-
plain = _strip_ansi(result.output)
3410+
plain = strip_ansi(result.output)
34163411
assert "already has priority 5" in plain
34173412

34183413
def test_set_priority_invalid_value(self, extension_dir, project_dir):

tests/test_presets.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"""
1212

1313
import pytest
14-
import re
1514
import json
1615
import tempfile
1716
import shutil
@@ -21,6 +20,7 @@
2120

2221
import yaml
2322

23+
from tests.conftest import strip_ansi
2424
from specify_cli.presets import (
2525
PresetManifest,
2626
PresetRegistry,
@@ -36,11 +36,6 @@
3636
from specify_cli.extensions import ExtensionRegistry
3737

3838

39-
def _strip_ansi(text: str) -> str:
40-
"""Remove ANSI escape codes from Rich-formatted CLI output."""
41-
return re.sub(r'\x1b\[[0-9;]*m', '', text)
42-
43-
4439
# ===== Fixtures =====
4540

4641

@@ -2447,7 +2442,7 @@ def test_set_priority_changes_priority(self, project_dir, pack_dir):
24472442
result = runner.invoke(app, ["preset", "set-priority", "test-pack", "5"])
24482443

24492444
assert result.exit_code == 0, result.output
2450-
plain = _strip_ansi(result.output)
2445+
plain = strip_ansi(result.output)
24512446
assert "priority changed: 10 → 5" in plain
24522447

24532448
# Reload registry to see updated value
@@ -2470,7 +2465,7 @@ def test_set_priority_same_value_no_change(self, project_dir, pack_dir):
24702465
result = runner.invoke(app, ["preset", "set-priority", "test-pack", "5"])
24712466

24722467
assert result.exit_code == 0, result.output
2473-
plain = _strip_ansi(result.output)
2468+
plain = strip_ansi(result.output)
24742469
assert "already has priority 5" in plain
24752470

24762471
def test_set_priority_invalid_value(self, project_dir, pack_dir):

0 commit comments

Comments
 (0)