Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /promptdriven_pdd /tests /test_agentic_split_real.py
| """Real-LLM tests for the agentic split orchestrator. | |
| These tests hit the configured LLM provider and cost money. They verify | |
| that the pipeline produces sensible results on real code — something mocked | |
| unit tests cannot do. | |
| Skip gate: set ``PDD_RUN_REAL_LLM_TESTS=1`` to run. | |
| Expensive tests additionally require ``PDD_RUN_AGENTIC_TESTS=1``. | |
| Oracle: an old monolithic ``pdd_executor.py`` (3,186 lines) from a downstream | |
| reference repository was manually split into 11 source + 8 runtime files. We | |
| compare the agentic split's diagnosis and proposals against that manual split | |
| to evaluate quality. | |
| Manual split reference (commit ece9067a in the downstream reference repo): | |
| pdd_executor/ (11 files): | |
| orchestrator.py (807), pr_creation.py (488), waterfall_runner.py (400), | |
| env_setup.py (376), process_runner.py (356), post_cli_processing.py (339), | |
| result_handlers.py (315), branch_checkout.py (310), credentials_loop.py (225), | |
| git_helpers.py (71), __init__.py (86) | |
| runtime/ (6 files + credentials/): | |
| artifacts.py (62), labels.py (51), output.py (72), redaction.py (57), | |
| workflow_state.py (86), credentials/classifier.py, credentials/keys.py | |
| """ | |
| from __future__ import annotations | |
| import json | |
| import os | |
| import subprocess | |
| import tempfile | |
| from pathlib import Path | |
| from typing import Optional | |
| from unittest.mock import patch | |
| import pytest | |
| pytestmark = pytest.mark.real | |
| def _skip_unless_real(): | |
| if not (os.getenv("PDD_RUN_REAL_LLM_TESTS") or os.getenv("PDD_RUN_ALL_TESTS") == "1"): | |
| pytest.skip("Real LLM tests require API access; set PDD_RUN_REAL_LLM_TESTS=1") | |
| # Skip when no agentic task provider is installed (e.g., cloud VMs that have | |
| # LLM API access but lack the claude/gemini CLI binaries needed by run_agentic_task). | |
| # Without this check, every LLM step fails and the test fails instead of skipping. | |
| from pdd.agentic_common import get_available_agents | |
| if not get_available_agents(): | |
| pytest.skip( | |
| "No agentic task provider available (claude/gemini/codex CLI not found). " | |
| "Install the CLI and configure credentials to run these tests." | |
| ) | |
| def _skip_unless_agentic(): | |
| _skip_unless_real() | |
| if not os.getenv("PDD_RUN_AGENTIC_TESTS") == "1": | |
| pytest.skip("Agentic tests are expensive (~$5-20); set PDD_RUN_AGENTIC_TESTS=1") | |
| def _get_pdd_repo_root() -> Optional[Path]: | |
| """Resolve the current pdd repo root.""" | |
| for candidate in [ | |
| Path.cwd(), | |
| Path(__file__).resolve().parents[1], | |
| ]: | |
| if (candidate / "pdd" / "agentic_split_orchestrator.py").exists(): | |
| return candidate | |
| return None | |
| def _get_reference_repo_root() -> Optional[Path]: | |
| """Resolve the downstream reference repo root for expensive real tests.""" | |
| candidate = os.getenv("PDD_AGENTIC_SPLIT_REFERENCE_REPO") | |
| if candidate: | |
| path = Path(candidate).expanduser() | |
| if (path / "extensions" / "github_pdd_app").exists(): | |
| return path | |
| return None | |
| def _extract_presplit_pdd_executor(reference_repo: Path) -> Optional[Path]: | |
| """Extract the monolithic pdd_executor.py from before the manual split. | |
| Returns the path to a temp file, or None if the commit isn't available. | |
| """ | |
| try: | |
| result = subprocess.run( | |
| ["git", "show", "00a2c553e:extensions/github_pdd_app/src/workers/pdd_executor.py"], | |
| cwd=str(reference_repo), | |
| capture_output=True, text=True, timeout=30, | |
| ) | |
| if result.returncode != 0: | |
| return None | |
| tmp = Path(tempfile.mktemp(suffix=".py", prefix="pdd_executor_presplit_")) | |
| tmp.write_text(result.stdout) | |
| return tmp | |
| except (subprocess.TimeoutExpired, OSError): | |
| return None | |
| # Manual split children names (what the human decided) | |
| MANUAL_SPLIT_CHILDREN = { | |
| "orchestrator", "pr_creation", "waterfall_runner", "env_setup", | |
| "process_runner", "post_cli_processing", "result_handlers", | |
| "branch_checkout", "credentials_loop", "git_helpers", | |
| } | |
| MANUAL_SPLIT_RUNTIME = { | |
| "artifacts", "labels", "output", "redaction", "workflow_state", | |
| "classifier", "keys", | |
| } | |
| # ========================================================================= | |
| # LEAVE_ALONE tests (~$1 each) | |
| # ========================================================================= | |
| class TestLeaveAlone: | |
| """Files that should NOT be split — cohesive or too small.""" | |
| def test_leave_alone_cohesive_orchestrator(self): | |
| """agentic_bug_orchestrator.py is a cohesive state machine. | |
| Despite being >1200 lines, it implements one workflow. The diagnose | |
| step should return LEAVE_ALONE with COHESIVE_WORKFLOW rationale. | |
| """ | |
| _skip_unless_real() | |
| root = _get_pdd_repo_root() | |
| if root is None: | |
| pytest.skip("pdd repo not found") | |
| target = root / "pdd" / "agentic_bug_orchestrator.py" | |
| if not target.exists(): | |
| pytest.skip(f"Target not found: {target}") | |
| from pdd.agentic_split_orchestrator import run_agentic_split_orchestrator | |
| ok, msg, cost, model, files = run_agentic_split_orchestrator( | |
| str(target), cwd=root, quiet=True, diagnose_only=True, | |
| ) | |
| assert ok is False, "diagnose_only always returns False" | |
| msg_lower = msg.lower() | |
| assert "leave_alone" in msg_lower or "leave alone" in msg_lower, ( | |
| f"Expected LEAVE_ALONE for cohesive orchestrator, got: {msg}" | |
| ) | |
| assert cost > 0, "Should have made real LLM calls" | |
| def test_leave_alone_small_file(self): | |
| """A small file (<200 lines) should not be split.""" | |
| _skip_unless_real() | |
| root = _get_pdd_repo_root() | |
| if root is None: | |
| pytest.skip("pdd repo not found") | |
| # Find a small Python file in pdd/ | |
| small_files = sorted( | |
| (f for f in (root / "pdd").glob("*.py") | |
| if f.stat().st_size < 5000 and f.name != "__init__.py"), | |
| key=lambda f: f.stat().st_size, | |
| ) | |
| if not small_files: | |
| pytest.skip("No small Python files found") | |
| target = small_files[0] | |
| from pdd.agentic_split_orchestrator import run_agentic_split_orchestrator | |
| ok, msg, cost, model, files = run_agentic_split_orchestrator( | |
| str(target), cwd=root, quiet=True, diagnose_only=True, | |
| ) | |
| assert ok is False | |
| # Small files should either LEAVE_ALONE or fail for missing arch entry | |
| assert "leave_alone" in msg.lower() or "leave alone" in msg.lower() or "stale" in msg.lower(), ( | |
| f"Expected LEAVE_ALONE or ARCHITECTURE_STALE for small file {target.name}, got: {msg}" | |
| ) | |
| # ========================================================================= | |
| # pdd_executor diagnosis and proposal tests (~$5-8) | |
| # ========================================================================= | |
| class TestPddExecutorDiagnosis: | |
| """Test that the agentic split correctly diagnoses pdd_executor as splittable.""" | |
| def test_pdd_executor_not_leave_alone(self): | |
| """The 3,186-line monolithic pdd_executor should NOT get LEAVE_ALONE. | |
| It has multiple distinct concerns: env setup, credential handling, | |
| process management, PR creation, waterfall execution, result handling. | |
| """ | |
| _skip_unless_agentic() | |
| reference_repo = _get_reference_repo_root() | |
| if reference_repo is None: | |
| pytest.skip("Set PDD_AGENTIC_SPLIT_REFERENCE_REPO to run this test") | |
| tmp_file = _extract_presplit_pdd_executor(reference_repo) | |
| if tmp_file is None: | |
| pytest.skip("Could not extract pre-split pdd_executor (commit 00a2c553e)") | |
| try: | |
| from pdd.agentic_split_orchestrator import run_agentic_split_orchestrator | |
| ok, msg, cost, model, files = run_agentic_split_orchestrator( | |
| str(tmp_file), cwd=reference_repo, quiet=True, diagnose_only=True, | |
| experimental_language=True, | |
| ) | |
| assert ok is False, "diagnose_only always returns False" | |
| # Should NOT be leave_alone — this file is genuinely splittable | |
| assert "leave_alone" not in msg.lower(), ( | |
| f"pdd_executor (3186 lines, multiple concerns) should NOT be " | |
| f"LEAVE_ALONE. Got: {msg}" | |
| ) | |
| assert cost > 0 | |
| finally: | |
| tmp_file.unlink(missing_ok=True) | |
| class TestPddExecutorProposal: | |
| """Test that proposals overlap with the manual split's logical boundaries.""" | |
| def test_proposal_identifies_known_concerns(self): | |
| """The propose step should identify concerns that match the manual split. | |
| Manual split children: orchestrator, pr_creation, waterfall_runner, | |
| env_setup, process_runner, post_cli_processing, result_handlers, | |
| branch_checkout, credentials_loop, git_helpers. | |
| We check that the agent's proposed child names overlap with at least | |
| 3 of these known concern areas (exact name matching is too strict — | |
| the agent might name them differently but capture the same concept). | |
| """ | |
| _skip_unless_agentic() | |
| reference_repo = _get_reference_repo_root() | |
| if reference_repo is None: | |
| pytest.skip("Set PDD_AGENTIC_SPLIT_REFERENCE_REPO to run this test") | |
| tmp_file = _extract_presplit_pdd_executor(reference_repo) | |
| if tmp_file is None: | |
| pytest.skip("Could not extract pre-split pdd_executor") | |
| try: | |
| from pdd.agentic_split_orchestrator import run_agentic_split_orchestrator | |
| ok, msg, cost, model, files = run_agentic_split_orchestrator( | |
| str(tmp_file), cwd=reference_repo, quiet=True, propose_only=True, | |
| experimental_language=True, | |
| ) | |
| # Propose-only returns False with "Propose only complete" | |
| assert "propose" in msg.lower() or cost > 0, f"Unexpected result: {msg}" | |
| # The step 4 output is in the state — we can't easily access it | |
| # from the return value, but the fact that it didn't abort with | |
| # NO_IMPROVEMENT_POSSIBLE means it found viable options. | |
| assert "no_improvement" not in msg.lower(), ( | |
| f"Expected viable split options for pdd_executor, got: {msg}" | |
| ) | |
| finally: | |
| tmp_file.unlink(missing_ok=True) | |
| # ========================================================================= | |
| # Full extraction test (~$15-20, gated by PDD_RUN_AGENTIC_TESTS) | |
| # ========================================================================= | |
| class TestPddExecutorFullExtraction: | |
| """Full pipeline run — most expensive test, compare against manual split.""" | |
| def test_full_extraction_creates_children(self): | |
| """Run the complete 9-step pipeline on pdd_executor. | |
| After extraction, verify: | |
| 1. Worktree was created | |
| 2. Child files exist | |
| 3. No file exceeds 800 lines | |
| 4. At least 3 children were created | |
| """ | |
| _skip_unless_agentic() | |
| reference_repo = _get_reference_repo_root() | |
| if reference_repo is None: | |
| pytest.skip("Set PDD_AGENTIC_SPLIT_REFERENCE_REPO to run this test") | |
| tmp_file = _extract_presplit_pdd_executor(reference_repo) | |
| if tmp_file is None: | |
| pytest.skip("Could not extract pre-split pdd_executor") | |
| try: | |
| from pdd.agentic_split_orchestrator import run_agentic_split_orchestrator | |
| ok, msg, cost, model, changed_files = run_agentic_split_orchestrator( | |
| str(tmp_file), cwd=reference_repo, quiet=False, | |
| experimental_language=True, | |
| skip_regen_gate=True, # Skip regen for speed in testing | |
| ) | |
| # Log results for manual comparison | |
| print(f"\n{'='*60}") | |
| print(f"Agentic split result: {'SUCCESS' if ok else 'FAILED'}") | |
| print(f"Message: {msg}") | |
| print(f"Cost: ${cost:.4f}") | |
| print(f"Changed files ({len(changed_files)}):") | |
| for f in changed_files: | |
| print(f" - {f}") | |
| print(f"{'='*60}") | |
| # Even if the gate aborts, we want to see what was produced | |
| if changed_files: | |
| assert len(changed_files) >= 3, ( | |
| f"Expected at least 3 children from a 3186-line file, " | |
| f"got {len(changed_files)}: {changed_files}" | |
| ) | |
| print("\n--- COMPARISON: Manual vs Agentic ---") | |
| print(f"Manual split: {len(MANUAL_SPLIT_CHILDREN)} source children + " | |
| f"{len(MANUAL_SPLIT_RUNTIME)} runtime children") | |
| print(f"Agentic split: {len(changed_files)} changed files") | |
| print(f"Manual children: {sorted(MANUAL_SPLIT_CHILDREN)}") | |
| print(f"Agentic files: {sorted(changed_files)}") | |
| finally: | |
| tmp_file.unlink(missing_ok=True) | |
Xet Storage Details
- Size:
- 13.4 kB
- Xet hash:
- 52e0f95aa2621b4b39715d9ecc3935f426fc000e052748b9e2695165455f0425
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.