Private
Public Access
0
0
Files
manual_slop/tests/test_ai_client_result.py
T
ed ada9617308 test(ai_client): rename send_result to send in 22 remaining test files
Batch rename of 22 test files. 62 references renamed total.

The full test suite is now GREEN again, matching the pre-rename baseline
from Task 1.1. Pure mechanical rename. No behavior change.

Files affected: test_ai_cache_tracking, test_ai_client_cli,
test_ai_client_result, test_api_events, test_context_pruner,
test_deepseek_provider, test_gemini_cli_* (3 files), test_gui2_mcp,
test_headless_* (2 files), test_live_gui_integration_v2,
test_orchestration_logic, test_phase6_engine, test_rag_integration,
test_run_worker_lifecycle_abort, test_spawn_interception_v2,
test_symbol_parsing, test_tier4_interceptor, test_tiered_aggregation,
test_token_usage.

Note: spec estimated 24 files; actual is 22 (test_deprecation_warnings
no longer exists, and 1 fewer file than spec's list).

Refs: conductor/tracks/send_result_to_send_20260616/
2026-06-17 00:38:29 -04:00

54 lines
1.9 KiB
Python

from unittest.mock import MagicMock, patch
import pytest
from src import ai_client
from src.result_types import Result, ErrorInfo, ErrorKind
def test_send_public_api_returns_result() -> None:
with patch.object(ai_client, "set_provider"):
with patch.object(ai_client, "_send_gemini", return_value=Result(data="hello")) as mock_send:
r = ai_client.send("system", "user")
assert isinstance(r, Result)
assert r.ok
assert r.data == "hello"
def test_send_does_not_emit_deprecation() -> None:
import warnings
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
with patch.object(ai_client, "set_provider"):
with patch.object(ai_client, "_send_gemini", return_value=Result(data="hi")):
r = ai_client.send("system", "user")
assert r.ok and r.data == "hi"
assert not any(issubclass(x.category, DeprecationWarning) for x in w)
def test_send_preserves_errors() -> None:
err = ErrorInfo(kind=ErrorKind.RATE_LIMIT, message="slow down", source="test")
with patch.object(ai_client, "set_provider"):
with patch.object(ai_client, "_send_gemini", return_value=Result(data="", errors=[err])):
r = ai_client.send("system", "user")
assert not r.ok
assert r.errors == [err]
def test_send_returns_empty_data_with_error_on_auth_failure() -> None:
err = ErrorInfo(kind=ErrorKind.AUTH, message="bad key", source="test")
with patch.object(ai_client, "set_provider"):
with patch.object(ai_client, "_send_gemini", return_value=Result(data="", errors=[err])):
r = ai_client.send("system", "user")
assert not r.ok
assert r.data == ""
def test_classify_gemini_error_returns_error_info() -> None:
from src.ai_client import _classify_gemini_error
class FakeRateLimitError(Exception): pass
e = FakeRateLimitError("rate limited")
info = _classify_gemini_error(e, source="test.gemini")
assert isinstance(info, ErrorInfo)
assert info.kind == ErrorKind.RATE_LIMIT
assert info.source == "test.gemini"
assert info.original is e