Skip to content

Commit 4a340d3

Browse files
committed
test(plugins): add detection service fallback tests for claude and codex
1 parent 00ad62c commit 4a340d3

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

0 commit comments

Comments
 (0)