Private
Public Access
0
0
Files
manual_slop/tests/test_ai_client_tool_loop_builder.py
T
ed 81d8bce419 refactor(ai_client): merge vendor_capabilities into ai_client; git rm src/vendor_capabilities.py
Per spec FR2 + Phase 2.1: VendorCapabilities + register + get_capabilities +
list_models_for_vendor + the ~40 vendor registrations move into ai_client.py
as a region block. Renamed internal _REGISTRY to _VENDOR_REGISTRY to avoid
collision with mcp_tool_specs._REGISTRY.

Importers (in src/) updated:
- src/ai_client.py: removed top-level import; removed 4 local imports of
  list_models_for_vendor/get_capabilities (symbol now in module namespace)
- src/app_controller.py: 2 sites updated to 'from src.ai_client import get_capabilities'
- src/gui_2.py: 1 site updated to 'from src.ai_client import VendorCapabilities, get_capabilities'

Tests updated:
- 8 test_*.py files: changed 'from src.vendor_capabilities import' to
  'from src.ai_client import'
- tests/test_vendor_capabilities.py: _clean_registry fixture updated to
  reference src.ai_client._VENDOR_REGISTRY (was src.vendor_capabilities._REGISTRY)

Verification: 157 tests pass across the affected files (vendor_capabilities,
ai_client_tool_loop variants, openai_compatible, command_palette,
diff_viewer, patch_modal, app_controller_result, app_controller_sigint,
handle_reset_session, ai_loop_regressions, grok/llama/minimax provider tests).
2026-06-26 07:07:12 -04:00

43 lines
2.0 KiB
Python

"""Verify run_with_tool_loop supports a per-round request_builder callback.
Vendors that mutate their history list (e.g. MiniMax) need to rebuild
the messages on each round so the API sees the latest tool results.
run_with_tool_loop accepts a callable as the 2nd arg to enable this.
"""
from __future__ import annotations
from typing import Any
from unittest.mock import MagicMock, patch
from src.openai_compatible import NormalizedResponse, OpenAICompatibleRequest
from src.openai_schemas import UsageStats
from src.ai_client import run_with_tool_loop
from src.result_types import Result
from src.ai_client import VendorCapabilities
def _make_normalized_response(text: str = "ok", tool_calls: list[dict[str, Any]] | None = None) -> NormalizedResponse:
return NormalizedResponse(
text=text, tool_calls=tool_calls or [],
usage=UsageStats(input_tokens=10, output_tokens=5, cache_read_tokens=0, cache_creation_tokens=0),
raw_response=None,
)
def test_run_with_tool_loop_calls_request_builder_each_round() -> None:
caps = VendorCapabilities(vendor="test", model="test-model", tool_calling=True, context_window=8192)
client = MagicMock()
tool_response = _make_normalized_response(
"first", tool_calls=[{"id": "c1", "type": "function", "function": {"name": "noop", "arguments": "{}"}}]
)
final = _make_normalized_response("done")
builder_calls: list[int] = []
def builder(round_idx: int) -> OpenAICompatibleRequest:
builder_calls.append(round_idx)
return OpenAICompatibleRequest(messages=[{"role": "user", "content": f"round={round_idx}"}], model="m")
with patch("src.openai_compatible.send_openai_compatible", side_effect=[Result(data=tool_response), Result(data=final)]), \
patch("src.ai_client._execute_tool_calls_concurrently", return_value=[("noop", "c1", "r", "")]):
result = run_with_tool_loop(
client, builder, capabilities=caps,
pre_tool_callback=None, qa_callback=None, patch_callback=None,
base_dir=".", vendor_name="test", history_lock=None, history=None,
)
assert result == "done"
assert len(builder_calls) >= 2