"""Tests for xcsift installer module."""
import pytest
from pathlib import Path
from unittest.mock import patch, MagicMock
from xcsift_mcp.xcsift_installer import (
get_xcsift_path,
_get_platform_asset_name,
XcsiftNotFoundError,
)
class TestGetXcsiftPath:
"""Tests for get_xcsift_path function."""
def test_returns_path_when_in_path(self):
"""Should return path when xcsift is in PATH."""
with patch("shutil.which", return_value="/usr/local/bin/xcsift"):
result = get_xcsift_path()
assert result == "/usr/local/bin/xcsift"
def test_returns_none_when_not_found(self):
"""Should return None when xcsift is not found anywhere."""
with patch("shutil.which", return_value=None):
with patch("os.path.isfile", return_value=False):
result = get_xcsift_path()
assert result is None
def test_checks_common_paths(self):
"""Should check common Homebrew paths."""
with patch("shutil.which", return_value=None):
with patch("os.path.isfile") as mock_isfile:
with patch("os.access", return_value=True):
mock_isfile.side_effect = lambda p: p == "/opt/homebrew/bin/xcsift"
result = get_xcsift_path()
assert result == "/opt/homebrew/bin/xcsift"
class TestGetPlatformAssetName:
"""Tests for _get_platform_asset_name function."""
def test_darwin_arm64(self):
"""Should return correct asset name for Apple Silicon Mac."""
with patch("platform.system", return_value="Darwin"):
with patch("platform.machine", return_value="arm64"):
result = _get_platform_asset_name()
assert result == "xcsift-arm64-apple-darwin"
def test_darwin_x86_64(self):
"""Should return correct asset name for Intel Mac."""
with patch("platform.system", return_value="Darwin"):
with patch("platform.machine", return_value="x86_64"):
result = _get_platform_asset_name()
assert result == "xcsift-x86_64-apple-darwin"
def test_linux_raises_error(self):
"""Should raise error for Linux platform."""
with patch("platform.system", return_value="Linux"):
with pytest.raises(XcsiftNotFoundError) as exc_info:
_get_platform_asset_name()
assert "only available for macOS" in str(exc_info.value)
def test_unsupported_arch_raises_error(self):
"""Should raise error for unsupported architecture."""
with patch("platform.system", return_value="Darwin"):
with patch("platform.machine", return_value="i386"):
with pytest.raises(XcsiftNotFoundError) as exc_info:
_get_platform_asset_name()
assert "Unsupported architecture" in str(exc_info.value)