문제: 새 프로젝트마다 루트 지침, Claude Code 설정, 검증 진입점, 비전·
문제 정의 양식, 장부를 손으로 다시 만든다. 플러그인으로는 루트 문서와
권한 deny를 나눠 줄 수 없다(플러그인 CLAUDE.md·권한은 읽히지 않는다).
고른 방법: 공통 동작은 플러그인, 프로젝트 파일은 template/ 복사로
나눈다(결정 Q15). scripts/new-project.sh가 template/을 빈 폴더에 복사하고
이름·설명·마켓 주소를 바꾼 뒤 git init까지 한다. 커밋은 하지 않는다.
- AGENTS.md 양식(40줄 이하, 결정 Q2)과 CLAUDE.md(@AGENTS.md)
- .claude/settings.json: .env deny, 마켓과 harness 플러그인 켜기.
Agent deny는 넣지 않는다(결정 Q5)
- scripts/verify.sh: 단계(docs·unit·pr·app) 뼈대와 --on <호스트> 운반부.
작업 트리를 패치로 옮겨 기준 커밋의 새 worktree에 적용하고 트리 해시를
맞춘 뒤 잠금 아래에서 돌린다. push하지 않는다(설계 6.1절)
- 빈 양식: docs/vision.md, docs/problem-statement.md, docs/adr/0000-template.md
- docs/ledger/: 빈 장부와 형식 설명, .gitattributes merge=union(결정 Q11)
repo 자신의 AGENTS.md·README·docs/README.md(설계와 다르게 정한 것)와
scripts/check.sh도 같이 둔다.
버린 대안: 템플릿만(공통 훅 수정이 모든 repo 손작업), 플러그인만(루트
문서·deny를 못 준다).
위험: verify.sh의 원격 운반부는 가짜 ssh(같은 기계)로만 시험했다. 실제
desktop에서는 아직 돌리지 않았다. unit·pr·app 단계 본문은 비어 있다
(종료 코드 3).
검증: scripts/check.sh 통과(플러그인 17, 템플릿 10, validate --strict).
템플릿 시험은 이름 바꾸기, 남은 {{…}} 없음, AGENTS.md 40줄 이하,
settings의 플러그인·deny, 빈 폴더가 아니면 멈춤, verify docs, 가짜 ssh로
패치 적용·트리 해시·worktree 정리와 원격 실패(종료 코드 4)를 본다.
scratchpad에 만든 시험 프로젝트에서 같은 것을 손으로 확인했다.
157 lines
7.8 KiB
Python
157 lines
7.8 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")
|
|
for name in ("estimate", "retro", "techdebt"):
|
|
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), 1536, 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()
|