mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-06-01 06:21:17 +00:00
test: cover missing tool-call arguments normalization
Lock the strict-provider sanitization path so assistant tool calls without function.arguments are normalized to {} instead of being forwarded as missing values.
Made-with: Cursor
This commit is contained in:
parent
f293ff7f18
commit
b60e8dc0ba
@ -632,6 +632,30 @@ def test_openai_compat_repairs_non_json_tool_arguments_string() -> None:
|
|||||||
assert sanitized[1]["tool_calls"][0]["function"]["arguments"] == '{"cmd": "pwd"}'
|
assert sanitized[1]["tool_calls"][0]["function"]["arguments"] == '{"cmd": "pwd"}'
|
||||||
|
|
||||||
|
|
||||||
|
def test_openai_compat_defaults_missing_tool_arguments_to_empty_object() -> None:
|
||||||
|
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"):
|
||||||
|
provider = OpenAICompatProvider()
|
||||||
|
|
||||||
|
sanitized = provider._sanitize_messages([
|
||||||
|
{"role": "user", "content": "hi"},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "",
|
||||||
|
"tool_calls": [
|
||||||
|
{
|
||||||
|
"id": "call_1",
|
||||||
|
"type": "function",
|
||||||
|
"function": {"name": "exec"},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{"role": "tool", "tool_call_id": "call_1", "name": "exec", "content": "ok"},
|
||||||
|
{"role": "user", "content": "done"},
|
||||||
|
])
|
||||||
|
|
||||||
|
assert sanitized[1]["tool_calls"][0]["function"]["arguments"] == "{}"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_openai_compat_stream_watchdog_returns_error_on_stall(monkeypatch) -> None:
|
async def test_openai_compat_stream_watchdog_returns_error_on_stall(monkeypatch) -> None:
|
||||||
monkeypatch.setenv("NANOBOT_STREAM_IDLE_TIMEOUT_S", "0")
|
monkeypatch.setenv("NANOBOT_STREAM_IDLE_TIMEOUT_S", "0")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user