File tree Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ from pathlib import Path
4+ from types import SimpleNamespace
5+ from unittest .mock import AsyncMock , MagicMock , patch
6+
7+ import pytest
8+
9+ from ccproxy .config .settings import Settings
10+ from ccproxy .plugins .claude_api .detection_service import ClaudeAPIDetectionService
11+
12+
13+ @pytest .mark .asyncio
14+ async def test_claude_detection_falls_back_when_cli_missing (tmp_path : Path ) -> None :
15+ settings = MagicMock (spec = Settings )
16+ cli_service = MagicMock ()
17+ cli_service .get_cli_info .return_value = {"is_available" : False , "command" : None }
18+ cli_service .detect_cli = AsyncMock (
19+ return_value = SimpleNamespace (is_available = False , version = None )
20+ )
21+
22+ service = ClaudeAPIDetectionService (settings = settings , cli_service = cli_service )
23+ service .cache_dir = tmp_path
24+
25+ with (
26+ patch .object (
27+ service ,
28+ "_get_claude_version" ,
29+ AsyncMock (side_effect = FileNotFoundError ("missing cli" )),
30+ ),
31+ patch .object (
32+ service ,
33+ "_detect_claude_headers" ,
34+ AsyncMock (side_effect = RuntimeError ("should not run" )),
35+ ),
36+ ):
37+ result = await service .initialize_detection ()
38+
39+ assert result == service ._get_fallback_data ()
40+ assert service .get_cached_data () == result
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ from pathlib import Path
4+ from types import SimpleNamespace
5+ from unittest .mock import AsyncMock , MagicMock , patch
6+
7+ import pytest
8+
9+ from ccproxy .config .settings import Settings
10+ from ccproxy .plugins .codex .detection_service import CodexDetectionService
11+
12+
13+ @pytest .mark .asyncio
14+ async def test_codex_detection_falls_back_when_cli_missing (tmp_path : Path ) -> None :
15+ settings = MagicMock (spec = Settings )
16+ cli_service = MagicMock ()
17+ cli_service .get_cli_info .return_value = {"is_available" : False , "command" : None }
18+ cli_service .detect_cli = AsyncMock (
19+ return_value = SimpleNamespace (is_available = False , version = None )
20+ )
21+
22+ service = CodexDetectionService (settings = settings , cli_service = cli_service )
23+ service .cache_dir = tmp_path
24+
25+ with (
26+ patch .object (
27+ service ,
28+ "_get_codex_version" ,
29+ AsyncMock (side_effect = FileNotFoundError ("missing cli" )),
30+ ),
31+ patch .object (
32+ service ,
33+ "_detect_codex_headers" ,
34+ AsyncMock (side_effect = RuntimeError ("should not run" )),
35+ ),
36+ ):
37+ result = await service .initialize_detection ()
38+
39+ assert result == service ._get_fallback_data ()
40+ assert service .get_cached_data () == result
You can’t perform that action at this time.
0 commit comments