from pathlib import Path


def test_tool_descriptions_are_externalized():
    """Test that tool descriptions are in tool_prompts.py and referenced in server.py."""
    server_path = Path(__file__).resolve().parents[1] / "ims_mcp" / "server.py"
    prompts_path = Path(__file__).resolve().parents[1] / "ims_mcp" / "tool_prompts.py"

    server_source = server_path.read_text(encoding="utf-8")
    prompts_source = prompts_path.read_text(encoding="utf-8")

    # Verify server.py uses description= parameter
    assert "description=PROMPT_" in server_source
    assert server_source.count("@mcp.tool(name=") == 6
    assert server_source.count("description=PROMPT_GET_CONTEXT_INSTRUCTIONS") == 1
    assert server_source.count("description=PROMPT_QUERY_INSTRUCTIONS") == 1
    assert server_source.count("description=PROMPT_SUBMIT_FEEDBACK") == 1
    assert server_source.count("description=PROMPT_QUERY_PROJECT_CONTEXT") == 1
    assert server_source.count("description=PROMPT_STORE_PROJECT_CONTEXT") == 1
    assert server_source.count("description=PROMPT_DISCOVER_PROJECTS") == 1

    # Verify prompts are defined in tool_prompts.py
    assert "PROMPT_GET_CONTEXT_INSTRUCTIONS = " in prompts_source
    assert "PROMPT_QUERY_INSTRUCTIONS = " in prompts_source
    assert "PROMPT_SUBMIT_FEEDBACK = " in prompts_source
    assert "PROMPT_QUERY_PROJECT_CONTEXT = " in prompts_source
    assert "PROMPT_STORE_PROJECT_CONTEXT = " in prompts_source
    assert "PROMPT_DISCOVER_PROJECTS = " in prompts_source

    # Verify prompt content is in tool_prompts.py (not server.py)
    assert "get_context_instructions before ANY response or action" in prompts_source
    assert "get_context_instructions before ANY response or action" not in server_source
    assert "Fetch instruction docs. Prefer tags for known files and families" in prompts_source
    assert "Fetch instruction docs. Prefer tags for known files and families" not in server_source
    assert "List project datasets. Run before creating new project context." in prompts_source
    assert "List project datasets. Run before creating new project context." not in server_source
