"""_inject_platform_rules() 오탐 방지 테스트."""
import pytest

# dispatch.py에서 _inject_platform_rules를 import
# dispatch.py의 위치: /home/jay/workspace/dispatch.py
import sys
sys.path.insert(0, "/home/jay/workspace")
from dispatch import _inject_platform_rules


# 규칙 파일이 존재하고 내용을 반환하도록 mock
MOCK_RULES = "## 네이버 블로그 작성 규칙\n1. 이모지 금지\n"


class TestInjectPlatformRulesPositive:
    """블로그 작성/발행 작업에서 규칙이 주입되어야 하는 케이스"""

    @pytest.fixture(autouse=True)
    def mock_rules_file(self, tmp_path, monkeypatch):
        """규칙 파일 mock"""
        rules_file = tmp_path / "config" / "naver-blog-rules.md"
        rules_file.parent.mkdir(parents=True)
        rules_file.write_text(MOCK_RULES, encoding="utf-8")
        monkeypatch.setattr("dispatch.WORKSPACE", tmp_path)

    def test_blog_writing(self):
        assert _inject_platform_rules("네이버 블로그 글 작성") is not None

    def test_blog_publishing(self):
        assert _inject_platform_rules("네이버 블로그 발행 자동화") is not None

    def test_blog_publish_naver_skill(self):
        assert _inject_platform_rules("blog-publish-naver 스킬로 발행") is not None

    def test_blog_posting(self):
        assert _inject_platform_rules("네이버 블로그 포스팅 대행") is not None

    def test_blog_writing_2(self):
        assert _inject_platform_rules("네이버 블로그 글쓰기") is not None

    def test_naver_blog_english(self):
        assert _inject_platform_rules("naver blog publish automation") is not None


class TestInjectPlatformRulesNegative:
    """블로그 작성이 아닌 작업에서 규칙이 주입되지 않아야 하는 케이스"""

    @pytest.fixture(autouse=True)
    def mock_rules_file(self, tmp_path, monkeypatch):
        rules_file = tmp_path / "config" / "naver-blog-rules.md"
        rules_file.parent.mkdir(parents=True)
        rules_file.write_text(MOCK_RULES, encoding="utf-8")
        monkeypatch.setattr("dispatch.WORKSPACE", tmp_path)

    def test_api_deprecation(self):
        assert _inject_platform_rules("네이버 블로그 SE API 폐기 → CDP 일원화") is None

    def test_code_verification(self):
        assert _inject_platform_rules("BlogAuto 코드 검증") is None

    def test_publish_test_execution(self):
        assert _inject_platform_rules("네이버 블로그 발행 테스트 실행") is None

    def test_refactoring(self):
        assert _inject_platform_rules("블로그 리팩토링 작업") is None

    def test_migration(self):
        assert _inject_platform_rules("네이버 블로그 시스템 마이그레이션") is None

    def test_no_blog_keywords(self):
        assert _inject_platform_rules("보험 상품 비교 페이지 개발") is None

    def test_debugging(self):
        assert _inject_platform_rules("네이버 블로그 발행 버그 수정") is None
