"""U-004's actual A-2 validation: a REAL `claude --agent planner -p` call against a deployed target project. Gated behind RUN_REAL_AGENT_E2E=1 (CLAUDE.md Testing constraint) -- costs real API usage, skipped by default in normal `python3 -m unittest` runs, matching graphloop's RUN_REAL_AGENT_E2E precedent. Run: RUN_REAL_AGENT_E2E=1 python3 -m unittest src.test_agent_e2e -v """ import json import subprocess import tempfile import unittest from src import agent_profile, project_scaffold, schema from src.test_support import skip_unless_env @skip_unless_env("RUN_REAL_AGENT_E2E") class RealPlannerInvocationTest(unittest.TestCase): def test_claude_agent_planner_starts_with_correct_identity(self): with tempfile.TemporaryDirectory() as tmp: subprocess.run(["git", "init"], cwd=tmp, check=True, capture_output=True) conn = schema.connect(":memory:") schema.create_schema(conn) project_scaffold.create_project(conn, tmp, init_git_if_missing=False) agent_profile.deploy_agent_definitions(tmp) result = subprocess.run( [ "claude", "--agent", "planner", "-p", "In one short sentence: what is your job, and what do you never do? Answer only, take no other action.", "--output-format", "json", "--permission-mode", "auto", ], cwd=tmp, stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=120, ) self.assertEqual(result.returncode, 0, msg=result.stderr) payload = json.loads(result.stdout) self.assertFalse(payload.get("is_error"), msg=payload) answer = payload["result"] self.assertTrue(answer, "planner returned an empty result") # A-2's actual question: did the identity come through, not the default # assistant persona? "不写业务代码" / "不实现" is the Planner's own red line. self.assertTrue( any(kw in answer for kw in ("规划", "需求", "Planning", "planning", "PRD", "SDD", "BRD")), "planner's answer doesn't look like the migrated planning identity: " + answer, ) if __name__ == "__main__": unittest.main()