fix(api): keep unconfigured services running and preserve Docker onboarding
This commit is contained in:
1 parent
e20737a509
commit
de8fbc3ad2
13 files changed
+133
-63
No files matched your search
@@ -70,4 +70,4 @@ def test_failed_write_does_not_leave_an_existing_config(tmp_path):
|
||||
with pytest.raises(PermissionError, match="read-only mount"):
|
||||
initialize_config(path)
|
||||
assert not path.exists()
|
||||
assert list(tmp_path.iterdir()) == []
|
||||
assert not list(tmp_path.glob("*.tmp"))
|
||||
@@ -20,6 +20,7 @@ from nanobot.api.server import (
|
||||
handle_chat_completions,
|
||||
)
|
||||
from nanobot.providers.base import LLMUsage
|
||||
from nanobot.providers.unconfigured_provider import UnconfiguredProvider
|
||||
|
||||
try:
|
||||
from aiohttp.test_utils import TestClient, TestServer
|
||||
@@ -76,6 +77,29 @@ def test_error_json() -> None:
|
||||
assert body["error"]["code"] == 400
|
||||
|
||||
|
||||
@pytest.mark.parametrize("stream", [False, True])
|
||||
@pytest.mark.asyncio
|
||||
async def test_unconfigured_model_returns_503_before_execution(aiohttp_client, mock_agent, stream):
|
||||
mock_agent.provider = UnconfiguredProvider("not-configured")
|
||||
prepare = AsyncMock()
|
||||
app = create_app(mock_agent, api_key=API_KEY, prepare_agent=prepare)
|
||||
client = await aiohttp_client(app)
|
||||
|
||||
assert (await client.get("/health")).status == 200
|
||||
denied = await client.post("/v1/chat/completions", json={"messages": []})
|
||||
assert denied.status == 401
|
||||
response = await client.post(
|
||||
"/v1/chat/completions", headers=AUTH_HEADERS,
|
||||
json={"messages": [{"role": "user", "content": "hello"}], "stream": stream},
|
||||
)
|
||||
assert response.status == 503
|
||||
error = (await response.json())["error"]
|
||||
assert error["type"] == "configuration_error"
|
||||
assert "Model is not configured" in error["message"]
|
||||
mock_agent.process_direct.assert_not_called()
|
||||
prepare.assert_not_called()
|
||||
|
||||
|
||||
def test_chat_completion_response() -> None:
|
||||
result = _chat_completion_response("hello world", "test-model")
|
||||
assert result["object"] == "chat.completion"
|
||||
|
||||
Reference in new issue
Block a user