from __future__ import annotations

import pytest

from eip_mcp import api_client
from eip_mcp.server import _pick_main_file, _tool_get_code


def test_pick_main_file_returns_none_for_image_only_listing() -> None:
    files = [{"path": "screenshot.png", "size": 4096, "type": "image"}]

    assert _pick_main_file(files) is None


def test_tool_get_code_prompts_for_file_path_when_only_images_exist(monkeypatch: pytest.MonkeyPatch) -> None:
    monkeypatch.setattr(
        api_client,
        "list_exploit_files",
        lambda exploit_id: [{"path": "preview.png", "size": 8192, "type": "image"}],
    )

    def fail_get_code(exploit_id: int, file_path: str) -> str:
        raise AssertionError("get_exploit_code should not run for image-only listings")

    monkeypatch.setattr(api_client, "get_exploit_code", fail_get_code)

    result = _tool_get_code({"exploit_id": 61514})

    assert "Files in exploit 61514" in result
    assert "preview.png" in result
    assert "Specify file_path" in result
