from __future__ import annotations

import unittest

from govoplan_core.celery_app import celery
from govoplan_core.settings import settings


class CeleryQueueContractTests(unittest.TestCase):
    def test_default_worker_queues_cover_every_routed_task(self) -> None:
        configured = {
            value.strip()
            for value in settings.celery_queues.split(",")
            if value.strip()
        }
        routes = celery.conf.task_routes
        self.assertIsInstance(routes, dict)
        routed = {
            str(route["queue"])
            for route in routes.values()
            if isinstance(route, dict) and route.get("queue")
        }

        self.assertEqual(set(), routed - configured)

    def test_delivery_tasks_keep_worker_loss_protection(self) -> None:
        self.assertTrue(celery.conf.task_acks_late)
        self.assertTrue(celery.conf.task_reject_on_worker_lost)
        self.assertEqual(1, celery.conf.worker_prefetch_multiplier)


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

