"""
test_git_evidence_filter.py — utils/git_evidence_filter.py 단위 테스트.

task-2480: runtime noise 경로 필터의 동작을 검증한다.
- runtime 경로 (logs/, memory/runtime/, memory/state/, memory/events/heartbeat*,
  memory/heartbeats/) 는 is_runtime_path() 가 True 를 반환해야 한다.
- source/test/scripts/workflows 경로는 False 를 반환해야 한다.
- filter_runtime_paths 는 혼합 리스트에서 runtime 만 제거해야 한다.
"""

import os
import sys

sys.path.insert(
    0,
    os.environ.get(
        "WORKSPACE_ROOT",
        "/home/jay/workspace/.worktrees/task-2480-dev3",
    ),
)

from utils.git_evidence_filter import filter_runtime_paths, is_runtime_path  # type: ignore[import-not-found]  # noqa: E402


# ── runtime 경로는 True ──────────────────────────────────────────────────


def test_is_runtime_path_logs_dir():
    assert is_runtime_path("logs/test.log") is True


def test_is_runtime_path_memory_runtime():
    assert is_runtime_path("memory/runtime/test") is True


def test_is_runtime_path_memory_state():
    assert is_runtime_path("memory/state/test") is True


def test_is_runtime_path_events_heartbeat():
    assert is_runtime_path("memory/events/heartbeat-task-1") is True


def test_is_runtime_path_heartbeats_dir():
    assert is_runtime_path("memory/heartbeats/task-x.heartbeat") is True


# ── 실제 코드 경로는 False ─────────────────────────────────────────────────


def test_is_runtime_path_source_not_runtime():
    assert is_runtime_path("server/main.py") is False


def test_is_runtime_path_tests_not_runtime():
    assert is_runtime_path("tests/test_x.py") is False


def test_is_runtime_path_scripts_not_runtime():
    assert is_runtime_path("scripts/finish-task.sh") is False


def test_is_runtime_path_workflows_not_runtime():
    assert is_runtime_path(".github/workflows/ci.yml") is False


# ── filter_runtime_paths 동작 ──────────────────────────────────────────────


def test_filter_runtime_paths():
    mixed = [
        "logs/done-watcher.log",          # runtime
        "memory/runtime/foo.json",         # runtime
        "memory/state/bar.json",           # runtime
        "memory/heartbeats/task-1.heartbeat",  # runtime
        "memory/events/heartbeat-task-1",  # runtime
        "server/main.py",                  # keep
        "tests/test_x.py",                 # keep
        "scripts/finish-task.sh",          # keep
        ".github/workflows/ci.yml",        # keep
    ]
    result = filter_runtime_paths(mixed)
    assert result == [
        "server/main.py",
        "tests/test_x.py",
        "scripts/finish-task.sh",
        ".github/workflows/ci.yml",
    ]
