Skip to content

Commit b42f234

Browse files
committed
test(plugins): strengthen detection service fallback tests and remove obsolete TODO comments
1 parent e864452 commit b42f234

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

ccproxy/core/async_utils.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -633,13 +633,8 @@ def generate_json_schema() -> dict[str, Any]:
633633
Returns:
634634
JSON Schema dictionary
635635
636-
Raises:
637-
ImportError: If required dependencies are not available
638636
"""
639-
try:
640-
from ccproxy.config.settings import Settings
641-
except ImportError as e:
642-
raise ImportError(f"Required dependencies not available: {e}") from e
637+
from ccproxy.config.settings import Settings
643638

644639
schema = Settings.model_json_schema()
645640

ccproxy/plugins/claude_api/detection_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ async def initialize_detection(self) -> ClaudeCacheData:
102102
cached=cached,
103103
)
104104

105-
# TODO: add proper testing without claude cli installed
106105
if detected_data is None:
107106
raise ValueError("Claude detection failed")
108107
return detected_data

ccproxy/plugins/codex/detection_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ async def initialize_detection(self) -> CodexCacheData:
109109
cached=cached,
110110
)
111111

112-
# TODO: add proper testing without codex cli installed
113112
if detected_data is None:
114113
raise ValueError("Codex detection failed")
115114
return detected_data

tests/unit/plugins/test_claude_detection.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,29 @@ async def test_claude_detection_falls_back_when_cli_missing(tmp_path: Path) -> N
2222
service = ClaudeAPIDetectionService(settings=settings, cli_service=cli_service)
2323
service.cache_dir = tmp_path
2424

25+
expected_fallback = service._get_fallback_data()
26+
2527
with (
2628
patch.object(
2729
service,
28-
"_get_claude_version",
29-
AsyncMock(side_effect=FileNotFoundError("missing cli")),
30+
"_get_fallback_data",
31+
MagicMock(return_value=expected_fallback),
3032
),
3133
patch.object(
3234
service,
3335
"_detect_claude_headers",
34-
AsyncMock(side_effect=RuntimeError("should not run")),
35-
),
36+
AsyncMock(
37+
side_effect=FileNotFoundError(
38+
"Claude CLI not found for header detection"
39+
)
40+
),
41+
) as mock_detect,
42+
patch.object(service, "_save_to_cache", MagicMock()) as mock_save,
3643
):
3744
result = await service.initialize_detection()
3845

39-
assert result == service._get_fallback_data()
40-
assert service.get_cached_data() == result
46+
assert cli_service.detect_cli.await_count == 1
47+
mock_detect.assert_awaited_once_with("unknown")
48+
mock_save.assert_not_called()
49+
assert result is expected_fallback
50+
assert service.get_cached_data() is expected_fallback

tests/unit/plugins/test_codex_detection.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,29 @@ async def test_codex_detection_falls_back_when_cli_missing(tmp_path: Path) -> No
2222
service = CodexDetectionService(settings=settings, cli_service=cli_service)
2323
service.cache_dir = tmp_path
2424

25+
expected_fallback = service._get_fallback_data()
26+
2527
with (
2628
patch.object(
2729
service,
28-
"_get_codex_version",
29-
AsyncMock(side_effect=FileNotFoundError("missing cli")),
30+
"_get_fallback_data",
31+
MagicMock(return_value=expected_fallback),
3032
),
3133
patch.object(
3234
service,
3335
"_detect_codex_headers",
34-
AsyncMock(side_effect=RuntimeError("should not run")),
35-
),
36+
AsyncMock(
37+
side_effect=FileNotFoundError(
38+
"Codex CLI not found for header detection"
39+
)
40+
),
41+
) as mock_detect,
42+
patch.object(service, "_save_to_cache", MagicMock()) as mock_save,
3643
):
3744
result = await service.initialize_detection()
3845

39-
assert result == service._get_fallback_data()
40-
assert service.get_cached_data() == result
46+
assert cli_service.detect_cli.await_count == 1
47+
mock_detect.assert_awaited_once_with("unknown")
48+
mock_save.assert_not_called()
49+
assert result is expected_fallback
50+
assert service.get_cached_data() is expected_fallback

0 commit comments

Comments
 (0)