"""Tests for harness/agent_adapter.py detect_available_agents()."""
import pytest
from unittest.mock import patch


class TestDetectAvailableAgents:
    """Test agent CLI auto-detection."""

    def test_no_agents_found(self):
        from harness.agent_adapter import detect_available_agents
        with patch("shutil.which", return_value=None):
            result = detect_available_agents()
            assert result == []

    def test_single_agent_found(self):
        from harness.agent_adapter import detect_available_agents
        def mock_which(binary):
            return "/usr/bin/codex" if binary == "codex" else None
        with patch("shutil.which", side_effect=mock_which):
            result = detect_available_agents()
            assert result == ["codex"]

    def test_multiple_agents_found(self):
        from harness.agent_adapter import detect_available_agents
        def mock_which(binary):
            if binary in ("codex", "claude"):
                return f"/usr/bin/{binary}"
            return None
        with patch("shutil.which", side_effect=mock_which):
            result = detect_available_agents()
            assert "codex" in result
            assert "claude" in result
            assert len(result) == 2

    def test_all_agents_found(self):
        from harness.agent_adapter import detect_available_agents
        with patch("shutil.which", return_value="/usr/bin/agent"):
            result = detect_available_agents()
            assert len(result) == 4
            assert set(result) == {"codex", "gemini", "copilot", "claude"}
