Files
claude-harness/tests/test_template.py
T
DongHyeonka 3bc36479d6 feat(plugin): 분야 전문가 협업 스킬 lead·new-expert·harness-eval을 더하고 0.3.0으로 올린다
문제: 여러 분야에 걸친 변경을 리뷰할 때 누구에게 무엇을 맡기고, 결과를
어떻게 합치고, 의견이 부딪치면 누가 정하는지 정한 절차가 없다. 전문가를
더하는 모양과 하네스 판을 비교하는 절차도 없다.

고른 방법:
- lead: 바뀐 경로·위험으로 분야 지식 스킬(렌즈)을 고르고, 고정 칸 brief로
  새 눈 reviewer를 병렬로 띄우고, High는 반증해 살아남은 것만 남기고,
  넘김은 한 번만 더, 충돌은 정한 일곱 순서로, 리뷰-수정은 세 번까지
  (두 번째부터 고친 diff만). 근거: Anthropic 위임 4요소, 공식 code-review의
  반증 필터, Claude Code 팀의 리뷰 라운드 상한.
- new-expert: 전문가 = paths 지식 스킬(함정이 맨 앞). 서브에이전트는 세
  조건(긴 출력, 버려도 되는 병렬, 지시 충돌·자기 리뷰) 중 하나를 보일 때만.
- harness-eval: 정답을 아는 과제를 판마다 돌려 장부 eval 줄로 비교.
  시킬 때만 돈다는 것을 설명에 쓴다.
- 13절 Q9(새 스킬은 모두 모델 호출, 발동 조건을 설명에)를 지킨다.
- 시험: 플러그인 스킬 목록을 고정하고, 설명이 1,024자 안이며
  PROACTIVELY·MUST·CRITICAL·IMPORTANT·<example>이 없는지 본다.
- 버린 대안: 분야 에이전트·범용 리뷰어를 플러그인에 싣기. 플러그인
  에이전트는 harness: 아래 이름이라 템플릿 것과 둘 다 목록에 뜬다.

위험: 세 스킬 설명(약 400~500자)이 모든 세션의 스킬 목록에 더해진다.
스킬 목록이 예산 근처인 기계에서는 덜 쓰는 스킬 설명이 먼저 잘린다.

검증: python3 -m unittest discover -s tests → 10건 통과,
claude plugin validate --strict plugins/harness → 통과.
2026-11-11 22:05:03 +09:00

162 lines
8.2 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_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()