from __future__ import annotations

import unittest
from pathlib import Path

from database import ReviewDatabase


APP_ROOT = Path(__file__).resolve().parents[1]
FRONTEND_ROOT = APP_ROOT / "frontend"


class CleanupContractTests(unittest.TestCase):
    def test_retired_files_stay_absent(self) -> None:
        self.assertFalse((APP_ROOT / "demo_data.py").exists())
        self.assertFalse((FRONTEND_ROOT / "heaven-loading.js").exists())

    def test_only_active_heaven_loading_asset_is_loaded(self) -> None:
        html = (FRONTEND_ROOT / "index.html").read_text(encoding="utf-8")
        self.assertIn('src="/pages/heaven/loading-v2.js', html)
        self.assertNotIn('src="/heaven-loading.js', html)

    def test_audited_definition_only_functions_stay_absent(self) -> None:
        runtime = "\n".join(
            path.read_text(encoding="utf-8")
            for path in FRONTEND_ROOT.rglob("*.js")
            if "vendor" not in path.parts
        )
        for symbol in (
            "commonReviewColumns",
            "outcomeClass",
            "screenerResultMatchesSelection",
            "selectRegime",
            "showHeartRitualCurtain",
        ):
            with self.subTest(symbol=symbol):
                self.assertNotIn(symbol, runtime)

    def test_wencai_history_compatibility_is_retained(self) -> None:
        for method in (
            "list_wencai_saved_queries",
            "save_wencai_query",
            "delete_wencai_saved_query",
        ):
            with self.subTest(method=method):
                self.assertTrue(hasattr(ReviewDatabase, method))


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