문제: new-project.sh로 만든 프로젝트에는 분야 전문가를 어디에 적고, 리드가 바뀐 경로로 무엇을 고르고, 넘김과 충돌을 어떻게 남기는지 정한 자리가 없다. lead 스킬은 그 repo의 docs/work/experts.md를 읽는다. 고른 방법: template/docs/work/experts.md(큰 그림 읽는 순서, 명단, 경로 → 렌즈, 넘김 지도, 정해 둔 충돌, 비용 재는 법)를 빈 양식으로 두고, 루트 AGENTS.md 「일하는 방식」에 한 줄, CLAUDE.md에 플러그인 새 스킬과 전문가 모양 한 줄을 더한다. 루트 40줄 상한은 그대로 지킨다. 버린 대안: 빈 .claude/skills·agents 예시 파일. 예시가 그대로 남으면 모든 세션 목록에 들어가는 빈 전문가가 된다. 위험: 양식만이라 채우기 전에는 lead가 경로표 없이 고른다(스킬이 그때는 바뀐 경로와 위험 신호로만 고르게 되어 있다). 검증: python3 -m unittest discover -s tests → 11건 통과 (새 시험: 양식의 여섯 절, AGENTS.md·CLAUDE.md가 가리키는지).
170 lines
8.7 KiB
Python
170 lines
8.7 KiB
Python
"""템플릿·new-project.sh·verify.sh·매니페스트 시험. 표준 라이브러리와 git·bash·flock만 쓴다.
|
|
|
|
python3 -m unittest discover -s tests
|
|
"""
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
NEW_PROJECT = os.path.join(REPO, "scripts", "new-project.sh")
|
|
URL = "https://git.example.com/team/claude-harness.git"
|
|
GIT_ENV = {"GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@example.com", "GIT_COMMITTER_NAME": "t",
|
|
"GIT_COMMITTER_EMAIL": "t@example.com", "GIT_CONFIG_COUNT": "1", "GIT_CONFIG_KEY_0": "core.hooksPath",
|
|
"GIT_CONFIG_VALUE_0": "/dev/null"}
|
|
|
|
|
|
def sh(args, cwd=None, env=None, check=True):
|
|
full = {**os.environ, **GIT_ENV, **(env or {})}
|
|
r = subprocess.run(args, cwd=cwd, env=full, capture_output=True, text=True, timeout=60)
|
|
if check and r.returncode != 0:
|
|
raise AssertionError("%s → %d\n%s\n%s" % (args, r.returncode, r.stdout, r.stderr))
|
|
return r
|
|
|
|
|
|
def read(path):
|
|
with open(path, encoding="utf-8") as f:
|
|
return f.read()
|
|
|
|
|
|
class NewProjectTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.target = os.path.join(self.tmp.name, "order-service")
|
|
sh([NEW_PROJECT, self.target, "--description", "주문을 받는 서비스다."], env={"HARNESS_GIT_URL": URL})
|
|
|
|
def tearDown(self):
|
|
self.tmp.cleanup()
|
|
|
|
def path(self, *parts):
|
|
return os.path.join(self.target, *parts)
|
|
|
|
def test_names_are_filled_and_nothing_is_left(self):
|
|
agents = read(self.path("AGENTS.md"))
|
|
self.assertTrue(agents.startswith("# AGENTS.md — order-service의 정본"))
|
|
self.assertIn("주문을 받는 서비스다.", agents)
|
|
self.assertIn("# 비전 — order-service", read(self.path("docs", "vision.md")))
|
|
for folder, _, files in os.walk(self.target):
|
|
if ".git" in folder.split(os.sep):
|
|
continue
|
|
for f in files:
|
|
self.assertNotIn("{{", read(os.path.join(folder, f)), os.path.join(folder, f))
|
|
|
|
def test_root_instructions_stay_short(self):
|
|
self.assertLessEqual(len(read(self.path("AGENTS.md")).splitlines()), 40)
|
|
self.assertTrue(read(self.path("CLAUDE.md")).startswith("@AGENTS.md\n"))
|
|
|
|
def test_settings_enable_plugin_and_deny_env_without_agent_deny(self):
|
|
settings = json.loads(read(self.path(".claude", "settings.json")))
|
|
self.assertIs(settings["enabledPlugins"]["harness@claude-harness"], True)
|
|
source = settings["extraKnownMarketplaces"]["claude-harness"]["source"]
|
|
self.assertEqual((source["source"], source["url"]), ("git", URL))
|
|
deny = settings["permissions"]["deny"]
|
|
self.assertIn("Read(**/.env)", deny)
|
|
self.assertIn("Edit(**/.env)", deny)
|
|
self.assertFalse([d for d in deny if d.startswith("Agent")], "Agent 금지는 넣지 않는다(결정 Q5)")
|
|
self.assertFalse([d for d in deny if "example" in d])
|
|
|
|
def test_experts_manual_skeleton_is_copied_and_routed(self):
|
|
manual = read(self.path("docs", "work", "experts.md"))
|
|
for section in ("## 1. 큰 그림을 읽는 순서", "## 2. 명단", "## 3. 경로 → 전문가", "## 4. 넘김 지도",
|
|
"## 5. 충돌", "## 6. 비용"):
|
|
self.assertIn(section, manual)
|
|
self.assertIn("`docs/work/experts.md`", read(self.path("AGENTS.md")))
|
|
self.assertIn("`lead`", read(self.path("CLAUDE.md")))
|
|
|
|
def test_ledger_and_git_are_ready(self):
|
|
self.assertEqual(read(self.path("docs", "ledger", "estimates.jsonl")), "")
|
|
self.assertIn("estimates.jsonl merge=union", read(self.path(".gitattributes")))
|
|
self.assertTrue(os.path.isdir(self.path(".git")))
|
|
self.assertTrue(os.access(self.path("scripts", "verify.sh"), os.X_OK))
|
|
|
|
def test_verify_docs_passes_on_fresh_project_and_fails_on_long_agents(self):
|
|
r = sh([self.path("scripts", "verify.sh"), "docs"], cwd=self.target)
|
|
self.assertIn("(채울 것", r.stderr)
|
|
with open(self.path("AGENTS.md"), "a", encoding="utf-8") as f:
|
|
f.write("줄\n" * 10)
|
|
r = sh([self.path("scripts", "verify.sh"), "docs"], cwd=self.target, check=False)
|
|
self.assertEqual(r.returncode, 1)
|
|
r = sh([self.path("scripts", "verify.sh"), "unit"], cwd=self.target, check=False)
|
|
self.assertEqual(r.returncode, 3)
|
|
|
|
def test_refuses_non_empty_target(self):
|
|
r = sh([NEW_PROJECT, self.target], check=False)
|
|
self.assertEqual(r.returncode, 1)
|
|
self.assertIn("덮지 않는다", r.stderr)
|
|
|
|
|
|
class VerifyRemoteTest(unittest.TestCase):
|
|
"""--on <호스트> 운반부를 가짜 ssh(호스트를 무시하고 이 기계에서 실행)로 시험한다."""
|
|
|
|
def test_patch_is_applied_in_a_fresh_worktree_and_cleaned_up(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
project, bare, remote = (os.path.join(d, n) for n in ("project", "origin.git", "remote"))
|
|
home = os.path.join(d, "home")
|
|
os.makedirs(home)
|
|
sh([NEW_PROJECT, project], env={"HARNESS_GIT_URL": URL})
|
|
sh(["git", "add", "-A"], cwd=project)
|
|
sh(["git", "commit", "-q", "-m", "init"], cwd=project)
|
|
sh(["git", "clone", "-q", "--bare", project, bare])
|
|
sh(["git", "remote", "add", "origin", bare], cwd=project)
|
|
sh(["git", "fetch", "-q", "origin"], cwd=project)
|
|
sh(["git", "clone", "-q", bare, remote])
|
|
with open(os.path.join(project, "docs", "notes.md"), "w", encoding="utf-8") as f:
|
|
f.write("커밋 안 한 새 파일\n")
|
|
with open(os.path.join(project, "AGENTS.md"), "a", encoding="utf-8") as f:
|
|
f.write("고친 줄\n")
|
|
fake_ssh = os.path.join(d, "fake-ssh")
|
|
with open(fake_ssh, "w") as f:
|
|
f.write('#!/bin/sh\nshift\nexec bash -c "$*"\n')
|
|
os.chmod(fake_ssh, 0o755)
|
|
env = {"VERIFY_SSH": fake_ssh, "VERIFY_REMOTE_REPO": remote, "VERIFY_LOCK": os.path.join(d, "lock"),
|
|
"HOME": home}
|
|
r = sh(["scripts/verify.sh", "docs", "--on", "build-host", "--log", "t"], cwd=project, env=env,
|
|
check=False)
|
|
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
|
log = read(os.path.join(home, "t-logs", "docs.log"))
|
|
self.assertIn("(채울 것", log)
|
|
worktrees = sh(["git", "worktree", "list"], cwd=remote).stdout.strip().splitlines()
|
|
self.assertEqual(len(worktrees), 1, worktrees)
|
|
|
|
r = sh(["scripts/verify.sh", "docs", "--on", "build-host"], cwd=project,
|
|
env={**env, "VERIFY_REMOTE_REPO": os.path.join(d, "missing")}, check=False)
|
|
self.assertEqual(r.returncode, 4)
|
|
|
|
|
|
class ManifestTest(unittest.TestCase):
|
|
def test_marketplace_points_at_the_plugin(self):
|
|
market = json.loads(read(os.path.join(REPO, ".claude-plugin", "marketplace.json")))
|
|
entry = next(p for p in market["plugins"] if p["name"] == "harness")
|
|
plugin_dir = os.path.join(REPO, entry["source"])
|
|
manifest = json.loads(read(os.path.join(plugin_dir, ".claude-plugin", "plugin.json")))
|
|
self.assertEqual(manifest["name"], "harness")
|
|
self.assertRegex(manifest["version"], r"^\d+\.\d+\.\d+$")
|
|
self.assertNotIn("version", entry, "버전은 plugin.json 한 곳에 둔다")
|
|
hooks = json.loads(read(os.path.join(plugin_dir, "hooks", "hooks.json")))["hooks"]
|
|
self.assertEqual(sorted(hooks), ["PostToolUse", "PreToolUse", "SessionStart", "Stop"])
|
|
|
|
def test_skills_are_model_invoked_with_trigger_paragraphs(self):
|
|
skills = os.path.join(REPO, "plugins", "harness", "skills")
|
|
names = sorted(os.listdir(skills))
|
|
self.assertEqual(names, ["estimate", "harness-eval", "lead", "new-expert", "retro", "techdebt"])
|
|
for name in names:
|
|
head = read(os.path.join(skills, name, "SKILL.md")).split("---")[1]
|
|
self.assertNotIn("disable-model-invocation", head, "새 스킬은 모델이 부른다(결정 Q9)")
|
|
description = head.split("description:", 1)[1].strip()
|
|
self.assertTrue(description.startswith("Use "), name)
|
|
self.assertLessEqual(len(description), 1024, name) # 스킬 규격 상한(Claude Code 목록은 1,536자에서 자른다)
|
|
# 과다 호출을 부르는 강조, 본문 대신 따라 하게 되는 예시 대화를 설명에 넣지 않는다
|
|
for banned in ("PROACTIVELY", "MUST", "CRITICAL", "IMPORTANT", "<example>"):
|
|
self.assertNotIn(banned, description, name)
|
|
|
|
def test_repo_root_instructions_stay_short(self):
|
|
self.assertLessEqual(len(read(os.path.join(REPO, "AGENTS.md")).splitlines()), 40)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|