"""task-92.1 검증: _build_work_philosophy_section() 추가 테스트"""
import sys
sys.path.insert(0, "/home/jay/workspace")

from prompts.team_prompts import build_prompt, _build_work_philosophy_section


def test_work_philosophy_section_exists():
    """_build_work_philosophy_section() 함수가 존재하고 문자열을 반환하는지"""
    result = _build_work_philosophy_section()
    assert isinstance(result, str)
    assert len(result) > 0


def test_work_philosophy_contains_all_principles():
    """5가지 원칙(A~E)이 모두 포함되는지"""
    result = _build_work_philosophy_section()
    assert "계획 우선 원칙" in result
    assert "결정론적 실행" in result
    assert "피드백 사이클" in result
    assert "문서화 의무" in result
    assert "감사추적" in result


def test_work_philosophy_section_title():
    """섹션 제목이 올바른지"""
    result = _build_work_philosophy_section()
    assert "## 작업 철학 (아누 가이드)" in result


def test_dev1_prompt_contains_philosophy():
    """dev1-team 프롬프트에 작업 철학 섹션이 포함되는지"""
    prompt = build_prompt("dev1-team", "test-1", "테스트 작업")
    assert "## 작업 철학 (아누 가이드)" in prompt


def test_dev2_prompt_contains_philosophy():
    """dev2-team 프롬프트에 작업 철학 섹션이 포함되는지"""
    prompt = build_prompt("dev2-team", "test-2", "테스트 작업")
    assert "## 작업 철학 (아누 가이드)" in prompt


def test_dev3_prompt_contains_philosophy():
    """dev3-team (direct 타입) 프롬프트에 작업 철학 섹션이 포함되는지"""
    prompt = build_prompt("dev3-team", "test-3", "테스트 작업")
    assert "## 작업 철학 (아누 가이드)" in prompt


def test_philosophy_before_workflow():
    """작업 철학 섹션이 워크플로우 섹션 앞에 오는지"""
    for team_id, task_id in [("dev1-team", "test-4"), ("dev2-team", "test-5"), ("dev3-team", "test-6")]:
        prompt = build_prompt(team_id, task_id, "테스트 작업")
        philosophy_idx = prompt.index("## 작업 철학 (아누 가이드)")
        workflow_idx = prompt.index("## 워크플로우")
        assert philosophy_idx < workflow_idx, f"{team_id}: 작업 철학이 워크플로우 앞에 와야 함"


def test_existing_sections_intact():
    """기존 섹션들이 손상되지 않았는지"""
    # dev1-team (direct)
    prompt1 = build_prompt("dev1-team", "test-7", "테스트 작업")
    assert "## 팀원 코워크 (Task tool 사용)" in prompt1
    assert "## 워크플로우" in prompt1
    assert "## 작업 규칙" in prompt1
    assert "## 보고서 작성 전 셀프 QC" in prompt1

    # dev3-team (direct)
    prompt3 = build_prompt("dev3-team", "test-8", "테스트 작업")
    assert "## 작업 지시" in prompt3
    assert "## 워크플로우" in prompt3


def test_cowork_section_unchanged():
    """코워크 섹션이 변경되지 않았는지 (불칸, 이리스 등 포함 확인)"""
    prompt = build_prompt("dev1-team", "test-9", "테스트 작업")
    assert "불칸" in prompt
    assert "이리스" in prompt
    assert "아테나" in prompt
    assert "아르고스" in prompt
