"""ChatGPT Codex 对齐第一批:技能包校验。 只校验技能文件本身,不启动 worker、不跑模型、不改生产行为: 每个 cloud/skills/<名>/SKILL.md 必须有 name + description frontmatter、名字与目录一致、正文非空、不含密钥占位。 """ import os import re import unittest from pathlib import Path SKILLS_DIR = Path(__file__).resolve().parents[1] / "skills" EXPECTED = {"live-info", "document-tools", "image-workflow"} def _frontmatter(text): m = re.match(r"^---\n(.*?)\n---\n", text, re.DOTALL) if not m: return None out = {} for line in m.group(1).splitlines(): if ":" in line: k, v = line.split(":", 1) out[k.strip()] = v.strip() return out class ChatGptCodexSkillsTestCase(unittest.TestCase): def test_expected_skills_exist(self): names = {p.name for p in SKILLS_DIR.iterdir() if p.is_dir()} self.assertEqual(names, EXPECTED) def test_skill_frontmatter_and_body(self): for name in sorted(EXPECTED): path = SKILLS_DIR / name / "SKILL.md" self.assertTrue(path.is_file(), str(path)) text = path.read_text(encoding="utf-8") fm = _frontmatter(text) self.assertIsNotNone(fm, name) self.assertEqual(fm.get("name"), name) desc = fm.get("description", "") self.assertTrue(desc, name) self.assertLessEqual(len(desc), 200, name) body = text.split("---", 2)[-1].strip() self.assertTrue(len(body) > 200, name) for bad in ("API_KEY", "sk-", "password"): self.assertNotIn(bad, text, name) if __name__ == "__main__": unittest.main()