test_work_graph_plan_e2e.py 1.98 KB
"""U-011's real-call coverage: does `--agent <name>` actually combine with
`--json-schema` correctly (planner identity AND schema-constrained output at
the same time)? Not documented anywhere, not exercised by U-004/U-005/U-006's
tests (which use one or the other, never both) -- genuinely uncertain until
tried for real. Gated behind RUN_REAL_AGENT_E2E=1 (CLAUDE.md Testing constraint).

Run: RUN_REAL_AGENT_E2E=1 python3 -m unittest src.test_work_graph_plan_e2e -v
"""

import subprocess
import tempfile
import unittest

from src import agent_profile, project_scaffold, schema, work_graph_plan
from src.test_support import skip_unless_env


@skip_unless_env("RUN_REAL_AGENT_E2E")
class RealPlanWorkGraphTest(unittest.TestCase):
    def test_planner_produces_a_valid_graph_manifest_for_real(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)
            conn.execute(
                "INSERT INTO task (task_id, project_id, goal_text, task_type, status, assigned_org_node) "
                "VALUES ('task-1', (SELECT project_id FROM project), '实现贪吃蛇游戏', 'goal', 'queued', 'planner')"
            )
            conn.commit()

            result = work_graph_plan.plan_work_graph(conn, "planner", "task-1", "实现贪吃蛇游戏", tmp)

        manifest = result["graph_manifest"]
        artifact_types = {node["artifact_type"] for node in manifest["nodes"]}
        self.assertEqual(artifact_types, {"brd", "prd", "sdd", "benchmark"})
        self.assertTrue(manifest["edges"], "expected at least one edge in the graph_manifest")
        for edge in manifest["edges"]:
            self.assertIn(edge["edge_type"], ("zero_token", "needs_judgment"))


if __name__ == "__main__":
    unittest.main()