test_e2e_pipeline_e2e.py 2.59 KB
"""U-014's real-call coverage, scoped deliberately: plan_documents (4 real
Planner calls producing BRD/PRD/SDD/Benchmark for the snake-game scenario
REQ-01~14 uses throughout the SDD) is cheap and fast, like every other real
test this session (~$0.05-0.15/call). The Coder/Validator half
(run_end_to_end in full) is a different order of magnitude -- real code
generation + real test execution, plausibly minutes and real $ -- and isn't
run automatically here; see the session notes for why.

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

import json
import subprocess
import tempfile
import unittest

from src import agent_profile, e2e_pipeline, project_scaffold, schema, task_create
from src.test_support import skip_unless_env


@skip_unless_env("RUN_REAL_AGENT_E2E")
class RealPlanDocumentsTest(unittest.TestCase):
    def test_planner_produces_four_real_lineaged_artifacts(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)
            project_id = conn.execute("SELECT project_id FROM project").fetchone()[0]
            task_id = task_create.create_task(conn, project_id, "实现贪吃蛇游戏")["task_id"]

            # plan_documents (2026-08-01 rewiring) creates its own real
            # work_graph_run via plan_work_graph() -- no manual seed row
            # needed anymore.
            plan_result = e2e_pipeline.plan_documents(conn, task_id, "实现贪吃蛇游戏", tmp)
            artifact_ids = plan_result["artifact_ids"]

            for artifact_type, artifact_id in artifact_ids.items():
                row = conn.execute(
                    "SELECT validation_status, file_path FROM artifact WHERE artifact_id = ?", (artifact_id,)
                ).fetchone()
                self.assertEqual(row[0], "passed")
                with open(tmp + "/" + row[1], encoding="utf-8") as f:
                    content = f.read()
                self.assertTrue(len(content) > 100, "{} content suspiciously short: {!r}".format(artifact_type, content))

            prd_deps = json.loads(
                conn.execute(
                    "SELECT depends_on_artifact_ids FROM artifact WHERE artifact_id = ?", (artifact_ids["prd"],)
                ).fetchone()[0]
            )
            self.assertEqual(prd_deps, [artifact_ids["brd"]])


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