"""Tests for the report module."""

import json

from mcp_diet.analyzer import analyze_tools
from mcp_diet.report import to_json, to_markdown
from tests.fixtures.sample_tools import ALL_TOOLS


class TestJsonReport:
    def test_valid_json(self):
        summary = analyze_tools(ALL_TOOLS)
        output = to_json(summary, "test-server")
        data = json.loads(output)

        assert data["server"] == "test-server"
        assert data["total_tokens"] > 0
        assert len(data["tools"]) == len(ALL_TOOLS)
        assert "top_offenders" in data

    def test_tool_fields(self):
        summary = analyze_tools(ALL_TOOLS)
        data = json.loads(to_json(summary))
        tool = data["tools"][0]

        assert "name" in tool
        assert "tokens" in tool
        assert "budget_pct" in tool
        assert "schema_depth" in tool
        assert "desc_length" in tool
        assert "grade" in tool


class TestMarkdownReport:
    def test_contains_table(self):
        summary = analyze_tools(ALL_TOOLS)
        md = to_markdown(summary, "test-server")

        assert "| Tool |" in md
        assert "test-server" in md
        assert "Total tokens:" in md

    def test_contains_all_tools(self):
        summary = analyze_tools(ALL_TOOLS)
        md = to_markdown(summary)

        for tool in ALL_TOOLS:
            assert tool.name in md
