import sys
import types

langgraph = types.ModuleType("langgraph")
langgraph_graph = types.ModuleType("langgraph.graph")
langgraph_graph.END = "END"
langgraph_graph.START = "START"
langgraph_graph.StateGraph = object
sys.modules.setdefault("langgraph", langgraph)
sys.modules.setdefault("langgraph.graph", langgraph_graph)

from app.modules.agent.engine.graphs.project_qa_step_graphs import ProjectQaRetrievalGraphFactory


class _FailingRag:
    async def retrieve(self, rag_session_id: str, query: str):
        raise AssertionError("legacy rag should not be called for explain_part")


def test_project_qa_retrieval_skips_legacy_rag_for_explain_part() -> None:
    factory = ProjectQaRetrievalGraphFactory(_FailingRag())

    result = factory._retrieve_context(
        {
            "scenario": "explain_part",
            "project_id": "rag-1",
            "resolved_request": {
                "original_message": "Explain how ConfigManager works",
                "normalized_message": "Explain how ConfigManager works",
            },
            "question_profile": {
                "domain": "code",
                "intent": "explain",
                "terms": ["configmanager"],
                "entities": ["ConfigManager"],
                "russian": False,
            },
            "files_map": {
                "src/config_manager/__init__.py": {
                    "content": "from .v2 import ConfigManagerV2 as ConfigManager",
                    "content_hash": "hash-1",
                }
            },
        }
    )

    bundle = result["source_bundle"]
    assert bundle["rag_items"] == []
    assert bundle["files_total"] >= 1
