feat: standardize skill data management and actions
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,13 +2,16 @@
|
||||
"""skill-template 脚手架与 Git 防串库守护。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from _support import get_skill_root
|
||||
|
||||
TEMPLATE_MARKER = ".openclaw-skill-template"
|
||||
TEMPLATE_SLUG = "your-skill-slug"
|
||||
SCAFFOLD_TEST_SLUG = "query-demo-records"
|
||||
|
||||
|
||||
def _read_skill_slug() -> str:
|
||||
@@ -59,6 +62,55 @@ class TestScaffoldGuard(unittest.TestCase):
|
||||
msg="DEVELOPMENT.md must mention git remote self-check",
|
||||
)
|
||||
|
||||
def test_scaffold_replaces_slug_and_copies_actions_manifest(self) -> None:
|
||||
slug = _read_skill_slug()
|
||||
if slug != TEMPLATE_SLUG:
|
||||
self.skipTest("仅在 skill-template 源仓库运行 scaffold 集成测试")
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
repo_root = get_skill_root()
|
||||
scaffold_py = os.path.join(repo_root, "tools", "scaffold_skill.py")
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
dest = os.path.join(tmp, SCAFFOLD_TEST_SLUG)
|
||||
proc = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
scaffold_py,
|
||||
"--slug",
|
||||
SCAFFOLD_TEST_SLUG,
|
||||
"--destination",
|
||||
dest,
|
||||
],
|
||||
cwd=repo_root,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(proc.returncode, 0, msg=proc.stderr or proc.stdout)
|
||||
|
||||
actions_path = os.path.join(dest, "assets", "actions.json")
|
||||
self.assertTrue(os.path.isfile(actions_path), msg="scaffold must copy assets/actions.json")
|
||||
with open(actions_path, encoding="utf-8") as f:
|
||||
manifest = json.load(f)
|
||||
self.assertEqual(manifest.get("skill"), SCAFFOLD_TEST_SLUG)
|
||||
self.assertNotIn(TEMPLATE_SLUG, json.dumps(manifest))
|
||||
|
||||
actions_md = os.path.join(dest, "references", "ACTIONS.md")
|
||||
self.assertTrue(os.path.isfile(actions_md), msg="scaffold must copy references/ACTIONS.md")
|
||||
|
||||
schema_path = os.path.join(dest, "assets", "schemas", "skill-actions.schema.json")
|
||||
self.assertTrue(os.path.isfile(schema_path))
|
||||
|
||||
marker = os.path.join(dest, TEMPLATE_MARKER)
|
||||
self.assertFalse(os.path.isfile(marker))
|
||||
self.assertFalse(os.path.isdir(os.path.join(dest, ".git")))
|
||||
|
||||
constants_path = os.path.join(dest, "scripts", "util", "constants.py")
|
||||
with open(constants_path, encoding="utf-8") as f:
|
||||
constants_text = f.read()
|
||||
self.assertNotIn(TEMPLATE_SLUG, constants_text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user