Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Fix the copilot detector class inheritance #903

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/codegate/clients/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,14 @@ def client_name(self) -> ClientType:
return ClientType.OPEN_INTERPRETER


class CopilotDetector(HeaderDetector):
class CopilotDetector(BaseClientDetector):
"""
Detector for Copilot client based on user agent
"""

def __init__(self):
super().__init__("user-agent", "Copilot")
super().__init__()
self.user_agent_detector = UserAgentDetector("Copilot")

@property
def client_name(self) -> ClientType:
Expand Down
27 changes: 21 additions & 6 deletions tests/clients/test_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,20 +272,23 @@ async def get_json():


class TestCopilotDetector:
def test_successful_detection(self, mock_request):
@pytest.mark.asyncio
async def test_successful_detection(self, mock_request):
detector = CopilotDetector()
mock_request.headers = Headers({"user-agent": "Copilot"})
assert detector.detect(mock_request) is True
assert await detector.detect(mock_request) is True
assert detector.client_name == ClientType.COPILOT

def test_failed_detection(self, mock_request):
@pytest.mark.asyncio
async def test_failed_detection(self, mock_request):
detector = CopilotDetector()
mock_request.headers = Headers({"user-agent": "Different Client"})
assert detector.detect(mock_request) is False
assert await detector.detect(mock_request) is False

def test_missing_user_agent(self, mock_request):
@pytest.mark.asyncio
async def test_missing_user_agent(self, mock_request):
detector = CopilotDetector()
assert detector.detect(mock_request) is False
assert await detector.detect(mock_request) is False


class TestDetectClient:
Expand Down Expand Up @@ -353,3 +356,15 @@ async def test_endpoint(request: Request):

result = await test_endpoint(mock_request)
assert result == ClientType.KODU

@pytest.mark.asyncio
async def test_copilot_detection_in_detect_client(self, mock_request):
detect_client = DetectClient()
mock_request.headers = Headers({"user-agent": "Copilot"})

@detect_client
async def test_endpoint(request: Request):
return request.state.detected_client

result = await test_endpoint(mock_request)
assert result == ClientType.COPILOT