c683f6e739
Docker / build (push) Has been cancelled
Build / build (push) Has been cancelled
Lint / ruff (push) Has been cancelled
Test / pytest (ubuntu-latest, 3.11) (push) Has been cancelled
Test / pytest (ubuntu-latest, 3.12) (push) Has been cancelled
Test / pytest (windows-latest, 3.11) (push) Has been cancelled
Test / pytest (windows-latest, 3.12) (push) Has been cancelled
Add bounded document ingestion, controlled web search, recoverable session support, subagent timeouts, and the native sandbox runtime contract. Unify package versioning and add release-focused regression coverage.
91 lines
2.6 KiB
Python
91 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from EvoScientist.llm.contracts import EvoRuntimeError
|
|
from EvoScientist.middleware import recoverable_tools
|
|
|
|
|
|
def test_tool_effect_context_prefers_dedicated_grant(monkeypatch):
|
|
monkeypatch.setattr(
|
|
"langgraph.config.get_config",
|
|
lambda: {
|
|
"configurable": {
|
|
"ai4sci_model_proxy": {
|
|
"gateway_url": "http://gateway",
|
|
"run_id": "model-run",
|
|
"envelope_signature": "model-signature",
|
|
},
|
|
"ai4sci_tool_effect": {
|
|
"gateway_url": "http://gateway",
|
|
"run_id": "tool-run",
|
|
"envelope_signature": "tool-signature",
|
|
},
|
|
},
|
|
"metadata": {},
|
|
},
|
|
)
|
|
|
|
proxy, _ = recoverable_tools._context()
|
|
|
|
assert proxy == {
|
|
"gateway_url": "http://gateway",
|
|
"run_id": "tool-run",
|
|
"envelope_signature": "tool-signature",
|
|
}
|
|
|
|
|
|
def test_evomemory_never_falls_back_to_parent_model_proxy(monkeypatch):
|
|
monkeypatch.setattr(
|
|
"langgraph.config.get_config",
|
|
lambda: {
|
|
"configurable": {
|
|
"ai4sci_model_proxy": {
|
|
"gateway_url": "http://gateway",
|
|
"run_id": "parent-run",
|
|
"envelope_signature": "parent-signature",
|
|
},
|
|
},
|
|
"metadata": {"run_kind": "evomemory_turn_worker"},
|
|
},
|
|
)
|
|
|
|
proxy, metadata = recoverable_tools._context()
|
|
|
|
assert proxy is None
|
|
assert metadata["run_kind"] == "evomemory_turn_worker"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_tool_effect_gateway_error_preserves_machine_code(monkeypatch):
|
|
class Client:
|
|
async def __aenter__(self):
|
|
return self
|
|
|
|
async def __aexit__(self, *_):
|
|
return None
|
|
|
|
async def post(self, url, json):
|
|
return httpx.Response(
|
|
409,
|
|
json={"detail": {"code": "RUN_FENCE_LOST"}},
|
|
request=httpx.Request("POST", url),
|
|
)
|
|
|
|
monkeypatch.setattr(recoverable_tools.httpx, "AsyncClient", lambda **_: Client())
|
|
|
|
with pytest.raises(EvoRuntimeError) as exc_info:
|
|
await recoverable_tools._post(
|
|
{
|
|
"gateway_url": "http://gateway",
|
|
"run_id": "run-1",
|
|
"envelope_signature": "signature",
|
|
},
|
|
"prepare",
|
|
{},
|
|
)
|
|
|
|
assert exc_info.value.code == "RUN_FENCE_LOST"
|
|
assert repr(exc_info.value) == "EvoRuntimeError(code='RUN_FENCE_LOST')"
|