import unittest
from bot.lib import report
from bot.lib.diff import Diff
from bot.lib.grep import CallSite


class TestReport(unittest.TestCase):
    def test_renders_at_risk_table(self):
        d = Diff(removed={"GetSpellInfo"}, added=set(), renamed=[])
        sites = [
            CallSite("GetSpellInfo", "CritMatic.lua", 412, "local n = GetSpellInfo(id)")
        ]
        md = report.render(
            branch="wow",
            new_version="11.3.0",
            new_build=110300,
            previous_version="11.2.7",
            previous_build=110207,
            detected_at="2026-05-06T13:42:11Z",
            diff=d,
            sites=sites,
        )
        self.assertIn("# CritMatic patch report", md)
        self.assertIn("11.3.0", md)
        self.assertIn("GetSpellInfo", md)
        self.assertIn("CritMatic.lua", md)
        self.assertIn("412", md)

    def test_renders_renamed_section_when_present(self):
        d = Diff(removed={"OldName"}, added={"NewName"}, renamed=[("OldName", "NewName")])
        md = report.render(
            branch="wow", new_version="x", new_build=1,
            previous_version="y", previous_build=0,
            detected_at="t", diff=d, sites=[],
        )
        self.assertIn("Possibly renamed", md)
        self.assertIn("OldName", md)
        self.assertIn("NewName", md)

    def test_renders_zero_at_risk_cleanly(self):
        d = Diff(removed=set(), added=set(), renamed=[])
        md = report.render(
            branch="wow", new_version="x", new_build=1,
            previous_version="y", previous_build=0,
            detected_at="t", diff=d, sites=[],
        )
        self.assertIn("At-risk call sites (0)", md)


if __name__ == "__main__":
    unittest.main()
