|
| 1 | +"""MAP-9 on the complete path (changes/2026-09-07-complete-tool-call-no-guess.md): |
| 2 | +a non-streaming reply whose tool call has no name is refused with |
| 3 | +ProviderError; lm15 never substitutes a name.""" |
| 4 | + |
| 5 | +import json |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +from lm15 import Message, ProviderError, Request |
| 10 | +from lm15.providers.base import HttpResponse |
| 11 | +from lm15.vet import adapter_for_provider |
| 12 | + |
| 13 | + |
| 14 | +def _lm(provider: str): |
| 15 | + return adapter_for_provider(provider, "test-key") |
| 16 | + |
| 17 | + |
| 18 | +def _http(body: dict) -> HttpResponse: |
| 19 | + return HttpResponse(status=200, reason="OK", headers=[], body=json.dumps(body).encode()) |
| 20 | + |
| 21 | + |
| 22 | +REQUEST = Request(model="m", messages=[Message.user("hi")]) |
| 23 | + |
| 24 | +BODIES = { |
| 25 | + "openai": {"output": [{"type": "function_call", "call_id": "c", "arguments": "{}"}]}, |
| 26 | + "openai_chat": {"choices": [{"message": {"tool_calls": [{"id": "c", "function": {"arguments": "{}"}}]}}]}, |
| 27 | + "anthropic": {"content": [{"type": "tool_use", "id": "t", "input": {}}]}, |
| 28 | + "gemini": {"candidates": [{"content": {"parts": [{"functionCall": {"args": {}}}]}}]}, |
| 29 | +} |
| 30 | + |
| 31 | + |
| 32 | +@pytest.mark.parametrize("provider", sorted(BODIES)) |
| 33 | +def test_nameless_tool_call_is_refused(provider: str) -> None: |
| 34 | + with pytest.raises(ProviderError) as info: |
| 35 | + _lm(provider).parse_response(REQUEST, _http(BODIES[provider])) |
| 36 | + assert info.value.code == "provider" |
| 37 | + assert "no name" in str(info.value) |
| 38 | + |
| 39 | + |
| 40 | +def test_empty_name_is_no_name() -> None: |
| 41 | + body = {"content": [{"type": "tool_use", "id": "t", "name": "", "input": {}}]} |
| 42 | + with pytest.raises(ProviderError): |
| 43 | + _lm("anthropic").parse_response(REQUEST, _http(body)) |
| 44 | + |
| 45 | + |
| 46 | +def test_named_calls_still_parse() -> None: |
| 47 | + body = {"content": [{"type": "tool_use", "id": "t", "name": "get_weather", "input": {"city": "x"}}]} |
| 48 | + response = _lm("anthropic").parse_response(REQUEST, _http(body)) |
| 49 | + assert response.tool_calls[0].name == "get_weather" |
0 commit comments