"""
test_composite_constants.py

composite_constants.py 상수 검증 테스트 (아르고스 작성)
"""

import os
import sys
from pathlib import Path

import pytest

_WORKSPACE = Path(os.environ.get("WORKSPACE_ROOT", "/home/jay/workspace"))
if str(_WORKSPACE) not in sys.path:
    sys.path.insert(0, str(_WORKSPACE))

from utils.composite_constants import (
    COMPOSITE_ALLOWED_TEAMS,
    DEFAULT_HANDOFF_FIELDS,
    HANDOFF_REQUIRED_FIELDS,
    MAX_COMPOSITE_TEAMS,
)


class TestCompositeConstants:
    """COMPOSITE_ALLOWED_TEAMS 및 관련 상수 검증"""

    def test_allowed_teams_is_frozenset(self):
        assert isinstance(COMPOSITE_ALLOWED_TEAMS, frozenset)

    def test_allowed_teams_contains_expected(self):
        expected = {"marketing", "design", "consulting", "publishing"}
        assert COMPOSITE_ALLOWED_TEAMS == expected

    def test_max_composite_teams_is_3(self):
        assert MAX_COMPOSITE_TEAMS == 3

    def test_handoff_fields_keys_are_frozensets(self):
        for key in HANDOFF_REQUIRED_FIELDS:
            assert isinstance(key, frozenset), f"Key {key} is not frozenset"

    def test_handoff_fields_values_are_lists(self):
        for key, value in HANDOFF_REQUIRED_FIELDS.items():
            assert isinstance(value, list), f"Value for {key} is not list"
            assert len(value) > 0, f"Value for {key} is empty"

    def test_default_handoff_fields_is_list(self):
        assert isinstance(DEFAULT_HANDOFF_FIELDS, list)
        assert len(DEFAULT_HANDOFF_FIELDS) > 0

    def test_handoff_marketing_design_exists(self):
        key = frozenset({"marketing", "design"})
        assert key in HANDOFF_REQUIRED_FIELDS

    def test_allowed_teams_no_dev_teams(self):
        """COMPOSITE_ALLOWED_TEAMS에 dev팀이 포함되지 않음을 검증"""
        for team in COMPOSITE_ALLOWED_TEAMS:
            assert not team.startswith("dev"), f"dev team found in COMPOSITE_ALLOWED_TEAMS: {team}"

    def test_team_bot_not_contaminated(self):
        """TEAM_BOT에 composite 팀이 없음을 검증 (오염 방지)"""
        from dispatch import TEAM_BOT
        for team in COMPOSITE_ALLOWED_TEAMS:
            assert team not in TEAM_BOT, f"composite team {team} found in TEAM_BOT"
