📦 deps(skills): add karpathy thirdparty sync

This commit is contained in:
csh
2026-04-23 09:31:45 +08:00
parent 96b705b00b
commit 08ca87b74c
4 changed files with 161 additions and 2 deletions
+74 -2
View File
@@ -1,4 +1,8 @@
import json
import os
import shutil
import subprocess
import tempfile
import unittest
from pathlib import Path
@@ -19,12 +23,42 @@ def load_manifest() -> dict:
return json.loads(MANIFEST.read_text(encoding="utf-8"))
def bash_path(path: Path) -> str:
resolved = path.resolve()
if os.name != "nt":
return resolved.as_posix()
drive = resolved.drive.rstrip(":").lower()
rest = resolved.as_posix()[2:]
return f"/mnt/{drive}{rest}"
def run_command(*args: str, cwd: Path | None = None) -> subprocess.CompletedProcess[str]:
return subprocess.run(
list(args),
cwd=cwd,
capture_output=True,
text=True,
)
class ThirdpartySkillsPipelineTests(unittest.TestCase):
def test_manifest_declares_superpowers_and_ui_ux_pro_max(self):
def test_manifest_declares_all_thirdparty_sources(self):
data = load_manifest()
self.assertEqual(
[entry["id"] for entry in data["sources"]],
["superpowers", "ui-ux-pro-max"],
["superpowers", "ui-ux-pro-max", "andrej-karpathy-skills"],
)
def test_karpathy_manifest_uses_copy_skill_dirs_sync_mode(self):
data = load_manifest()
karpathy = next(
item for item in data["sources"] if item["id"] == "andrej-karpathy-skills"
)
self.assertEqual(karpathy["sync_mode"], "copy_skill_dirs")
self.assertEqual(karpathy["snapshot_dir"], "andrej-karpathy-skills")
self.assertEqual(karpathy["skills_subdir"], "skills")
self.assertEqual(
karpathy["source_list"], "codex/skills/.sources/andrej-karpathy-skills.list"
)
def test_ui_ux_pro_max_uses_render_codex_skill_sync_mode(self):
@@ -108,6 +142,44 @@ class ThirdpartySkillsPipelineTests(unittest.TestCase):
self.assertNotIn("exclude_skill_dirs", text)
self.assertNotIn("is_excluded_skill_dir", text)
def test_sync_script_generates_karpathy_outputs_in_temp_repo(self):
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_root = Path(tmp_dir)
mirror = tmp_root / "origin.git"
work = tmp_root / "work"
clone_mirror = run_command("git", "clone", "--mirror", str(ROOT), str(mirror))
self.assertEqual(clone_mirror.returncode, 0, msg=clone_mirror.stderr)
clone_work = run_command("git", "clone", str(mirror), str(work))
self.assertEqual(clone_work.returncode, 0, msg=clone_work.stderr)
set_remote = run_command(
"git", "-C", str(work), "remote", "set-url", "origin", bash_path(mirror)
)
self.assertEqual(set_remote.returncode, 0, msg=set_remote.stderr)
shutil.copy2(MANIFEST, work / ".gitea" / "ci" / "thirdparty_skills.json")
sync_result = run_command("bash", ".gitea/ci/sync_thirdparty_skills.sh", cwd=work)
self.assertEqual(
sync_result.returncode,
0,
msg=sync_result.stdout + sync_result.stderr,
)
generated_list = (
work / "codex" / "skills" / ".sources" / "andrej-karpathy-skills.list"
)
generated_skill = (
work / "codex" / "skills" / "karpathy-guidelines" / "SKILL.md"
)
self.assertTrue(generated_list.is_file())
self.assertTrue(generated_skill.is_file())
self.assertIn(
"karpathy-guidelines", generated_list.read_text(encoding="utf-8")
)
if __name__ == "__main__":
unittest.main()