refactor: unify skill source model

This commit is contained in:
2026-07-30 12:11:25 +08:00
parent 076d87e303
commit 7d1994cf93
18 changed files with 669 additions and 527 deletions
+50 -7
View File
@@ -8,6 +8,7 @@ import unittest
from pathlib import Path
from unittest.mock import patch
from skiff.project import normalize_skill_entry
from skiff.sources import fetch_source
REPO_ROOT = Path(__file__).resolve().parents[1]
@@ -25,12 +26,24 @@ def write_skill(root: Path, name: str) -> Path:
class CustomSourceTests(unittest.TestCase):
def test_legacy_manifest_sources_normalize_to_new_model(self) -> None:
self.assertEqual(
normalize_skill_entry({"name": "ack", "source": "owned"})["source"],
"builtin",
)
self.assertEqual(
normalize_skill_entry(
{"name": "think", "source": "registry", "registry": "waza"}
)["source"],
"catalog:waza",
)
def setUp(self) -> None:
self.temp_dir = tempfile.TemporaryDirectory()
self.home = Path(self.temp_dir.name)
self.skills_home = self.home / ".skills"
(self.skills_home / "skills").mkdir(parents=True)
(self.skills_home / "registry.yaml").write_text("", encoding="utf-8")
(self.skills_home / "catalog.yaml").write_text("", encoding="utf-8")
def tearDown(self) -> None:
self.temp_dir.cleanup()
@@ -74,6 +87,36 @@ class CustomSourceTests(unittest.TestCase):
config = self.home / ".config" / "skiff" / "config.yaml"
self.assertIn("company:", config.read_text(encoding="utf-8"))
def test_local_source_can_expose_a_single_skill(self) -> None:
source = self.home / "single-source"
source.mkdir()
source.joinpath("SKILL.md").write_text(
"---\nname: solo\ndescription: Test single source.\n---\n",
encoding="utf-8",
)
added = self.run_skiff(
"source",
"add",
"solo",
"--local",
str(source),
"--skills-path",
".",
)
installed = self.run_skiff(
"add",
"solo",
"-g",
"-a",
"codex",
)
self.assertEqual(added.returncode, 0, added.stderr)
self.assertEqual(installed.returncode, 0, installed.stderr)
self.assertEqual(
(self.home / ".codex" / "skills" / "solo").resolve(),
source.resolve(),
)
def test_project_add_persists_resolved_source_in_manifest(self) -> None:
company = self.home / "company"
expected = write_skill(company / "skills", "code-review")
@@ -136,17 +179,17 @@ class CustomSourceTests(unittest.TestCase):
result = self.run_skiff("add", "code-review", "-g", "-a", "codex")
self.assertNotEqual(result.returncode, 0)
self.assertIn("owned/code-review", result.stderr)
self.assertIn("builtin/code-review", result.stderr)
self.assertIn("company/code-review", result.stderr)
def test_custom_source_namespace_is_not_shadowed_by_registry_collection(self) -> None:
def test_custom_source_namespace_is_not_shadowed_by_catalog_collection(self) -> None:
company = self.home / "company"
expected = write_skill(company / "skills", "code-review")
registry_repo = self.home / "registry-repo"
write_skill(registry_repo / "skills", "other-skill")
self.skills_home.joinpath("registry.yaml").write_text(
catalog_repo = self.home / "catalog-repo"
write_skill(catalog_repo / "skills", "other-skill")
self.skills_home.joinpath("catalog.yaml").write_text(
"company:\n"
f" repo: {registry_repo}\n"
f" repo: {catalog_repo}\n"
" ref: main\n"
" path: skills\n",
encoding="utf-8",