feat: route profiled ops runs through Glas
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a02b6f-7db1-7222-918b-e813a6bda38d
This commit is contained in:
parent
68ab94581a
commit
0f01c3e421
17 changed files with 895 additions and 11 deletions
|
|
@ -169,6 +169,8 @@ def test_llm_connect_client_complete(monkeypatch) -> None:
|
|||
import rein_aharness.llm_connect_client as mod
|
||||
|
||||
class FakeResp:
|
||||
status_code = 200
|
||||
|
||||
def raise_for_status(self) -> None:
|
||||
return None
|
||||
|
||||
|
|
@ -187,6 +189,68 @@ def test_llm_connect_client_complete(monkeypatch) -> None:
|
|||
assert client.last_response_metadata.get("model") == "test-model"
|
||||
|
||||
|
||||
class _ErrorResp:
|
||||
def __init__(self, status_code: int, body) -> None:
|
||||
self.status_code = status_code
|
||||
self._body = body
|
||||
|
||||
def json(self):
|
||||
if isinstance(self._body, Exception):
|
||||
raise self._body
|
||||
return self._body
|
||||
|
||||
|
||||
def test_llm_connect_error_preserves_safe_provider_cause(monkeypatch) -> None:
|
||||
import rein_aharness.llm_connect_client as mod
|
||||
|
||||
response = _ErrorResp(
|
||||
502,
|
||||
{
|
||||
"error": "provider_api_error",
|
||||
"provider_status": 401,
|
||||
"provider": "openrouter",
|
||||
"model": "model-1",
|
||||
"message": "No auth credentials found",
|
||||
"api_key": "sk-must-not-appear",
|
||||
"raw_response": {"authorization": "Bearer secret"},
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(mod.httpx, "post", lambda *args, **kwargs: response)
|
||||
|
||||
with pytest.raises(LLMConnectError) as excinfo:
|
||||
LLMConnectClient("http://llm.test").complete("hi")
|
||||
|
||||
text = str(excinfo.value)
|
||||
assert "HTTP 502" in text
|
||||
assert "error=provider_api_error" in text
|
||||
assert "provider_status=401" in text
|
||||
assert "provider=openrouter" in text
|
||||
assert "model=model-1" in text
|
||||
assert "message=No auth credentials found" in text
|
||||
assert "sk-must-not-appear" not in text
|
||||
assert "authorization" not in text
|
||||
|
||||
|
||||
def test_llm_connect_error_message_is_bounded(monkeypatch) -> None:
|
||||
import rein_aharness.llm_connect_client as mod
|
||||
|
||||
response = _ErrorResp(502, {"error": "provider_api_error", "message": "x" * 5000})
|
||||
monkeypatch.setattr(mod.httpx, "post", lambda *args, **kwargs: response)
|
||||
with pytest.raises(LLMConnectError) as excinfo:
|
||||
LLMConnectClient("http://llm.test").complete("hi")
|
||||
assert len(str(excinfo.value)) < 600
|
||||
|
||||
|
||||
@pytest.mark.parametrize("body", [ValueError("not json"), ["unexpected"]])
|
||||
def test_llm_connect_error_without_usable_body_reports_status(monkeypatch, body) -> None:
|
||||
import rein_aharness.llm_connect_client as mod
|
||||
|
||||
response = _ErrorResp(504, body)
|
||||
monkeypatch.setattr(mod.httpx, "post", lambda *args, **kwargs: response)
|
||||
with pytest.raises(LLMConnectError, match="llm-connect returned HTTP 504"):
|
||||
LLMConnectClient("http://llm.test").complete("hi")
|
||||
|
||||
|
||||
def test_get_client_requires_env(monkeypatch) -> None:
|
||||
monkeypatch.delenv("LLM_CONNECT_URL", raising=False)
|
||||
with pytest.raises(LLMConnectError, match="LLM_CONNECT_URL"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue