"""Helper utilities for PlanGenerationGraph Robot tests."""

from __future__ import annotations

import sys
import tempfile
from pathlib import Path

CURRENT_DIR = Path(__file__).resolve().parent
PROJECT_ROOT = CURRENT_DIR.parent
SRC_DIR = PROJECT_ROOT / "src"
if str(SRC_DIR) not in sys.path:
    sys.path.insert(0, str(SRC_DIR))

from langchain_community.llms import FakeListLLM  # noqa: E402

from cleveragents.agents.plan_generation import PlanGenerationGraph  # noqa: E402
from cleveragents.domain.models.core import Context  # noqa: E402


def run_context_summary() -> None:
    """Generate plan context metadata to validate Robot tests."""

    graph = PlanGenerationGraph(llm=FakeListLLM(responses=["test response"] * 3))
    with tempfile.NamedTemporaryFile(delete=False, suffix=".py") as tmp:
        tmp.write(b"def main():\n    return True\n")
        tmp_path = Path(tmp.name)

    content = tmp_path.read_text()
    contexts = [Context(plan_id=1, path=str(tmp_path), content=content)]
    try:
        result = graph._load_context({"contexts": contexts})
        assert result["context_summary"], "context_summary should not be empty"
        assert result["context_dependencies"], (
            "context_dependencies should not be empty"
        )
        print("Context analysis summary ready")
    finally:
        tmp_path.unlink(missing_ok=True)


if __name__ == "__main__":
    run_context_summary()
