"""`.claude/`의 서브에이전트 정의가 소유자 결정(2026-11-07)대로인지 본다. 결과만 받는 일은 서브에이전트, 파일을 바꾸는 위임은 하위 세션이다(docs/work/delegate.md 4.3절). python3 -m unittest discover -s scripts/tests """ from __future__ import annotations import json import re import unittest from pathlib import Path REPO = Path(__file__).resolve().parent.parent.parent AGENTS = REPO / ".claude/agents" WRITE_TOOLS = {"Edit", "Write", "MultiEdit", "NotebookEdit"} def front_matter(path: Path) -> dict[str, str]: text = path.read_text(encoding="utf-8") match = re.match(r"^---\n(.*?)\n---\n", text, re.S) if not match: return {} fields = {} for line in match.group(1).splitlines(): key, _, value = line.partition(":") fields[key.strip()] = value.strip() return fields class SubagentTest(unittest.TestCase): def test_the_agent_tool_is_no_longer_denied(self) -> None: settings = json.loads((REPO / ".claude/settings.json").read_text(encoding="utf-8")) deny = settings.get("permissions", {}).get("deny", []) self.assertFalse([rule for rule in deny if rule == "Agent" or rule.startswith("Agent(")]) def test_each_definition_names_itself_and_says_when_to_use_it(self) -> None: definitions = sorted(AGENTS.glob("*.md")) self.assertEqual([path.stem for path in definitions], ["arch-reviewer", "code-simplifier", "verify-api"]) for path in definitions: fields = front_matter(path) self.assertEqual(fields.get("name"), path.stem, path) self.assertRegex(fields.get("description", ""), r"쓴다", path) self.assertTrue(fields.get("tools"), f"{path} must list its tools; an empty list inherits every tool") def test_no_subagent_can_edit_files(self) -> None: for path in AGENTS.glob("*.md"): tools = {tool.strip() for tool in front_matter(path).get("tools", "").split(",")} self.assertFalse(tools & WRITE_TOOLS, f"{path} returns results only; it must not hold {tools & WRITE_TOOLS}") def test_the_reviewers_have_no_shell_that_could_change_the_tree_except_read_commands(self) -> None: self.assertNotIn("Bash", front_matter(AGENTS / "code-simplifier.md")["tools"]) reviewer = (AGENTS / "arch-reviewer.md").read_text(encoding="utf-8") self.assertIn("파일을 쓰거나 고치지 않는다", reviewer) def test_verify_api_runs_the_app_on_the_desktop_under_the_shared_lock(self) -> None: text = (AGENTS / "verify-api.md").read_text(encoding="utf-8") for fragment in ("docs/work/operate.md", "flock /tmp/claude-gates/heavy.lock", "scripts/bootstrap-local.sh", "stash@{0}", "down"): self.assertIn(fragment, text) if __name__ == "__main__": unittest.main()