from __future__ import annotations

import json
import unittest
from pathlib import Path


PROJECT_ROOT = Path(__file__).resolve().parents[1]


class DeploymentEntrypointTests(unittest.TestCase):
    def test_default_container_opens_only_xml_processing_mutation(self) -> None:
        dockerfile = (PROJECT_ROOT / "Dockerfile").read_text(encoding="utf-8")
        commands = [
            json.loads(line.removeprefix("CMD "))
            for line in dockerfile.splitlines()
            if line.startswith("CMD ")
        ]

        self.assertEqual(len(commands), 1)
        command = commands[0]
        self.assertEqual(command[:3], ["python", "-m", "arr_web.run"])
        self.assertIn("--enable-processing", command)
        self.assertNotIn("--enable-monthly-generation", command)
        self.assertNotIn("--enable-company-reports", command)
        self.assertNotIn("--enable-agent-writeback", command)
        self.assertNotIn("requirements-arr-mcp.txt", dockerfile)
        self.assertNotIn("8890", dockerfile)

    def test_compose_has_no_agent_or_mcp_runtime_surface(self) -> None:
        compose = (PROJECT_ROOT / "compose.yaml").read_text(encoding="utf-8")
        caddy = (PROJECT_ROOT / "deploy" / "Caddyfile").read_text(encoding="utf-8")
        root_requirements = (PROJECT_ROOT / "requirements.txt").read_text(
            encoding="utf-8"
        )
        monthly_requirements = (
            PROJECT_ROOT / "requirements-monthly-reports.txt"
        ).read_text(encoding="utf-8")
        company_requirements = (
            PROJECT_ROOT / "requirements-company-reports.txt"
        ).read_text(encoding="utf-8")

        self.assertIn("--enable-processing", compose)
        self.assertIn("--enable-company-reports", compose)
        self.assertNotIn("\n  mcp:", compose)
        self.assertNotIn("DEERFLOW", compose)
        self.assertNotIn("ARR_MCP", compose)
        self.assertNotIn("ARR_AGENT", compose)
        self.assertNotIn("MCP_PUBLIC_HOST", caddy)
        self.assertIn("ARR_WEB_USERNAME", compose)
        self.assertIn("ARR_WEB_PASSWORD", compose)
        self.assertIn("/healthz", compose)
        self.assertNotIn("WEB_BASIC_AUTH", compose)
        self.assertNotIn("basic_auth", caddy)
        self.assertNotIn("requirements-agent-integration", root_requirements)
        self.assertNotIn("requirements-arr-mcp", root_requirements)
        self.assertIn("openpyxl", monthly_requirements)
        self.assertIn("openpyxl", company_requirements)
        self.assertFalse((PROJECT_ROOT / "company_reports" / "xlsx" / "package.json").exists())
        self.assertFalse((PROJECT_ROOT / "monthly_reports" / "xlsx" / "package.json").exists())
        self.assertNotIn("artifact-tool", compose)


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