Files
tsl-devkit/tests/test_thirdparty_skills_pipeline.py
T
csh 3d83740f88 Squashed 'docs/standards/playbook/' changes from c3f8137..25d895d
25d895d 🐛 fix(gitea_workflow): clean up temp repos after job steps
2bc3b11 🐛 fix(gitea_workflow): clean up temporary repo dirs in workflows
98c3f30 📝 docs(agent_rules): allow plan execution on current branch
16c7230 📝 docs(prompts): define custom verify layering
8efc4dd 🐛 fix(skills): quote commit-message description
bc8498f 🐛 fix(ci): install tomli for gitea tests
55cda3b 🐛 fix(tests): report missing toml parser clearly
c0729c7 🐛 fix(playbook): import Optional for cli compatibility
63e24bf 📦 deps(skills): sync thirdparty skills
d2f9356 🐛 fix(ci): isolate gitea workflow repos
588b81d 🐛 fix(ci): inline gitea workflow bootstrap
e0b1c3a ♻️ refactor(skills): standardize first-party skill contracts
2c5050d ♻️ refactor(skills): rename repo skills source dir
f049dfb 📦 deps(skills): drop duplicate first-party superpowers skills
234b335  feat(workflow): add superpowers planning and execution state tracking
c1702a6 📝 docs(markdown): format tracked markdown and drop stale templates
2325409 📝 docs(markdown): clarify optional markdownlint usage
214c44e 🔧 chore(markdown): add markdownlint baseline and lint fixes
a22b324 📝 docs(templates): add execution and memory-bank prompt templates
223a797 📝 docs(templates): update README for Claude Code and current features
4ac8672 📝 docs: simplify README + platform-agnostic tools + auto-create local rules
2431c9d 📝 docs: add claude_md config and use cross-platform paths
d64b248 📝 docs: fix README.md inaccuracies and add Claude Code info
c8d6bf2 🐛 fix(playbook): use relative paths in CLAUDE.md when not at project root
6518f0f  feat(playbook): auto-create CLAUDE.md with path discovery
6ec9a45  feat(skills): add skill_link symlink support + platform-agnostic prompt
9f8b6b5 📝 docs: update README and config example for Claude Code support
79cff6c 📝 docs(skills): add Claude Code platform support
452c6f5  feat(playbook): auto-inject AGENTS.md into CLAUDE.md
e1dbf3c 🐛 fix(skills): remove dual-path from commit-message skill
f3a7259 🔧 chore(ci): use prepare_repo.sh in both workflows
da08212 🔧 chore(ci): extract prepare_repo.sh and clean up workflows
7ade85e 🗑️ remove(tsl): drop syntax_book/, data/ source and build script
f94dba0 ♻️ refactor(skills): update playbook.py and tests for thirdparty/ layout
b3df412 ♻️ refactor(skills): separate thirdparty skills into thirdparty/ subdirectory
64950e7 📦 deps(skills): sync thirdparty skills
a2e3cb0  feat(playbook): add no_backup deploy controls
8609d59 🐛 fix(docs): repair reference catalog source links
956da11 🐛 fix(playbook): publish hidden ci test fixes
3f67754 📦 deps(skills): sync thirdparty skills
08ca87b 📦 deps(skills): add karpathy thirdparty sync
96b705b 📝 docs(tsl): rebuild canonical syntax and routing manual
3ed5052 📦 deps(skills): sync thirdparty skills
60108dd 📦 deps(skills): sync thirdparty skills
da85d4e 🐛 fix(thirdparty): prune nested project snapshots
a2a697e 📦 deps(skills): sync thirdparty skills
9df610a 🐛 fix(thirdparty): exclude duplicated superpowers skills
33dd5bb 🐛 fix(thirdparty): preserve optional manifest fields
91b0ea7 🐛 fix(thirdparty): preserve manifest during snapshot update
2e26f98 🔧 chore(thirdparty): generalize skills sync pipeline
5b9c1e3 📦 deps(skills): sync superpowers
2f2d34a 📝 docs(readme): normalize subtree command spacing
62db7db 🐛 fix(ci): serialize superpowers update and sync
3463223 🐛 fix(ci): use literal superpowers sync paths
48f6de8 📦 deps(skills): sync superpowers
4b23529 🔧 chore(ci): merge superpowers update and sync workflow
a56d75b 📦 deps(skills): sync superpowers
84bcefa 🔧 chore(ci): use ci[bot] commit author name
00a07e5 📦 deps(skills): sync superpowers
7b84daf 🐛 fix(templates): enforce main loop progress tracking
51373d7 🔧 chore(ci): automate superpowers sync workflow
eaaa39c 🐛 fix(ci): prevent stale superpowers sync from restoring skills block
79755c6 📦 deps(skills): sync superpowers
836d878 📦 deps(skills): sync superpowers
8216c9f 📦 deps(skills): sync superpowers
9439505 🐛 fix(playbook): address reported repo issues

git-subtree-dir: docs/standards/playbook
git-subtree-split: 25d895d8b3f56624ccfe99ad7289e9eb49e0f316
2026-05-24 13:04:14 +08:00

187 lines
8.4 KiB
Python

import json
import os
import shutil
import subprocess
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
MANIFEST = ROOT / ".gitea" / "ci" / "thirdparty_skills.json"
WORKFLOW = ROOT / ".gitea" / "workflows" / "update-thirdparty-skills.yml"
LEGACY_WORKFLOW = ROOT / ".gitea" / "workflows" / "update-thirdparty-superpowers.yml"
UPDATE_SCRIPT = ROOT / ".gitea" / "ci" / "update_thirdparty_skills.sh"
SYNC_SCRIPT = ROOT / ".gitea" / "ci" / "sync_thirdparty_skills.sh"
SKILLS_MD = ROOT / "SKILLS.md"
SUPERPOWERS_LIST = ROOT / "skills" / "thirdparty" / ".sources" / "superpowers.list"
UI_UX_PRO_MAX_LIST = ROOT / "skills" / "thirdparty" / ".sources" / "ui-ux-pro-max.list"
UI_UX_PRO_MAX_DIR = ROOT / "skills" / "thirdparty" / "ui-ux-pro-max"
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_all_thirdparty_sources(self):
data = load_manifest()
self.assertEqual(
[entry["id"] for entry in data["sources"]],
["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"], "skills/thirdparty/.sources/andrej-karpathy-skills.list"
)
def test_ui_ux_pro_max_uses_render_skill_sync_mode(self):
data = load_manifest()
ui_skill = next(item for item in data["sources"] if item["id"] == "ui-ux-pro-max")
self.assertEqual(ui_skill["sync_mode"], "render_skill")
self.assertEqual(ui_skill["snapshot_dir"], "ui-ux-pro-max")
def test_superpowers_manifest_prunes_non_superpowers_paths(self):
data = load_manifest()
superpowers = next(item for item in data["sources"] if item["id"] == "superpowers")
self.assertEqual(superpowers["remove_paths"], ["skills/ui-ux-pro-max"])
def test_workflow_uses_generic_scripts_and_single_serial_job(self):
text = WORKFLOW.read_text(encoding="utf-8")
self.assertFalse(LEGACY_WORKFLOW.exists())
self.assertIn("update_and_sync:", text)
self.assertNotIn("\n update:\n", text)
self.assertNotIn("\n sync:\n", text)
self.assertIn("bash .gitea/ci/update_thirdparty_skills.sh", text)
self.assertIn("bash .gitea/ci/sync_thirdparty_skills.sh", text)
self.assertNotIn("git merge", text)
self.assertNotIn("git pull", text)
def test_workflow_has_serial_concurrency_and_literal_generic_paths(self):
text = WORKFLOW.read_text(encoding="utf-8")
self.assertIn("concurrency:", text)
self.assertIn("update-thirdparty-${{ github.repository }}", text)
self.assertIn('MANIFEST_PATH: ".gitea/ci/thirdparty_skills.json"', text)
self.assertIn('TARGET_BRANCH="$THIRDPARTY_BRANCH" bash .gitea/ci/update_thirdparty_skills.sh', text)
self.assertIn('TARGET_BRANCH="main" \\', text)
self.assertIn('MANIFEST_PATH="$MANIFEST_PATH" \\', text)
def test_generic_scripts_exist_and_use_manifest(self):
update_text = UPDATE_SCRIPT.read_text(encoding="utf-8")
sync_text = SYNC_SCRIPT.read_text(encoding="utf-8")
self.assertIn('MANIFEST_PATH="${MANIFEST_PATH:-.gitea/ci/thirdparty_skills.json}"', update_text)
self.assertIn('MANIFEST_PATH="${MANIFEST_PATH:-.gitea/ci/thirdparty_skills.json}"', sync_text)
self.assertIn('TARGET_BRANCH="${TARGET_BRANCH:-thirdparty/skill}"', update_text)
self.assertIn('TARGET_BRANCH="${TARGET_BRANCH:-main}"', sync_text)
self.assertIn(':package: deps(thirdparty): update snapshots', update_text)
self.assertIn(':package: deps(skills): sync thirdparty skills', sync_text)
def test_skills_doc_points_to_generic_thirdparty_sources(self):
text = SKILLS_MD.read_text(encoding="utf-8")
self.assertIn("## 9. Third-party Skills", text)
self.assertIn("来源:`skills/thirdparty/.sources/`(第三方来源清单目录)。", text)
self.assertNotIn("Third-party Skills (superpowers)", text)
def test_superpowers_and_ui_ux_pro_max_source_lists_exist(self):
self.assertTrue(SUPERPOWERS_LIST.is_file())
self.assertTrue(UI_UX_PRO_MAX_LIST.is_file())
self.assertIn("using-superpowers", SUPERPOWERS_LIST.read_text(encoding="utf-8"))
self.assertIn("ui-ux-pro-max", UI_UX_PRO_MAX_LIST.read_text(encoding="utf-8"))
def test_ui_ux_pro_max_output_exists_with_data_and_scripts(self):
self.assertTrue((UI_UX_PRO_MAX_DIR / "SKILL.md").is_file())
self.assertTrue((UI_UX_PRO_MAX_DIR / "data").is_dir())
self.assertTrue((UI_UX_PRO_MAX_DIR / "scripts").is_dir())
def test_update_script_materializes_manifest_before_target_checkout(self):
text = UPDATE_SCRIPT.read_text(encoding="utf-8")
self.assertIn('manifest_copy="$tmp_dir/thirdparty_skills.json"', text)
self.assertIn('cp "$MANIFEST_PATH" "$manifest_copy"', text)
self.assertIn('MANIFEST_PATH="$manifest_copy"', text)
self.assertIn("remove_paths", text)
self.assertIn('remove_snapshot_paths "$snapshot_dir" "$remove_paths"', text)
self.assertIn("- Remove-Paths:", text)
self.assertIn('if ! emit_sources_tsv > "$sources_file"; then', text)
self.assertNotIn("done < <(emit_sources_tsv)", text)
self.assertLess(
text.index('cp "$MANIFEST_PATH" "$manifest_copy"'),
text.index('git checkout -B "$TARGET_BRANCH" "origin/$TARGET_BRANCH"'),
)
def test_sync_script_assumes_thirdparty_snapshot_is_already_clean(self):
text = SYNC_SCRIPT.read_text(encoding="utf-8")
self.assertIn('"\\x1f".join(', text)
self.assertIn("while IFS=$'\\x1f' read -r", text)
self.assertNotIn("while IFS=$'\\t' read -r", text)
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")
shutil.copy2(SYNC_SCRIPT, work / ".gitea" / "ci" / "sync_thirdparty_skills.sh")
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 / "skills" / "thirdparty" / ".sources" / "andrej-karpathy-skills.list"
)
generated_skill = (
work / "skills" / "thirdparty" / "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()