Initial project import
This commit is contained in:
@@ -562,7 +562,7 @@ def test_adapter_live_methods_require_base_id(onec_agent_server: dict[str, str])
|
||||
assert status == 400
|
||||
assert is_error
|
||||
assert turn_data["error"]["code"] == "adapter_error"
|
||||
assert "requires params.base_id" in turn_data["error"]["message"]
|
||||
assert "forbidden technical fields: table" in turn_data["error"]["message"]
|
||||
|
||||
audit_root = Path(onec_agent_server["audit_root"])
|
||||
turn_files = sorted((audit_root / "turn_audit").glob("*.jsonl"))
|
||||
@@ -572,10 +572,89 @@ def test_adapter_live_methods_require_base_id(onec_agent_server: dict[str, str])
|
||||
record["outcome"] == "failure"
|
||||
and record["failure_type"] == "adapter_error"
|
||||
and record["error_code"] == "adapter_error"
|
||||
and "requires params.base_id" in str(record["error_message"])
|
||||
and "forbidden technical fields: table" in str(record["error_message"])
|
||||
for record in turn_records
|
||||
)
|
||||
|
||||
|
||||
def test_agent_adapter_policy_uses_effective_view_and_blocks_storage_selectors(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
prepared = onec_agent.prepare_agent_adapter_call(
|
||||
"metadata.object.full",
|
||||
{"base_id": "upo_test", "name": "Отчет.Продажи"},
|
||||
)
|
||||
assert prepared["configuration_view"] == "effective_working"
|
||||
assert prepared["source_state"] == "working"
|
||||
|
||||
with pytest.raises(ValueError, match="forbidden technical fields: table"):
|
||||
onec_agent.prepare_agent_adapter_call(
|
||||
"metadata.saved_state.forms.search",
|
||||
{"base_id": "upo_test", "table": "ConfigSave"},
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="forbidden technical fields: module_ref"):
|
||||
onec_agent.prepare_agent_adapter_call(
|
||||
"code.read",
|
||||
{"base_id": "upo_test", "selector": {"module_ref": "private"}},
|
||||
)
|
||||
|
||||
monkeypatch.setenv("ONEC_AGENT_ALLOW_DIAGNOSTIC", "true")
|
||||
assert onec_agent.prepare_agent_adapter_call(
|
||||
"metadata.saved_state.forms.search",
|
||||
{"base_id": "upo_test", "table": "ConfigSave"},
|
||||
)["table"] == "ConfigSave"
|
||||
|
||||
|
||||
def test_agent_calls_adapter_through_mcp(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
requests: list[tuple[dict[str, Any], dict[str, str], str]] = []
|
||||
|
||||
class FakeResponse:
|
||||
def __init__(self, body: dict[str, Any], headers: dict[str, str] | None = None) -> None:
|
||||
self._body = json.dumps(body).encode("utf-8")
|
||||
self.headers = headers or {}
|
||||
|
||||
def read(self) -> bytes:
|
||||
return self._body
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *_args: object) -> None:
|
||||
return None
|
||||
|
||||
def fake_urlopen(request: Request, timeout: float):
|
||||
body = json.loads(request.data.decode("utf-8"))
|
||||
requests.append((body, dict(request.headers), request.full_url))
|
||||
if body["method"] == "initialize":
|
||||
return FakeResponse({"jsonrpc": "2.0", "id": body["id"], "result": {}}, {"Mcp-Session-Id": "test-session"})
|
||||
return FakeResponse(
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": body["id"],
|
||||
"result": {"content": [{"type": "text", "text": json.dumps({"status": "ok"})}]},
|
||||
}
|
||||
)
|
||||
|
||||
monkeypatch.setattr(onec_agent, "urlopen", fake_urlopen)
|
||||
result = onec_agent.call_adapter("metadata.object.forms", {"base_id": "upo_test", "ref": "Report.Тест"})
|
||||
|
||||
assert result == {"status": "ok"}
|
||||
assert len(requests) == 2
|
||||
assert requests[0][0]["method"] == "initialize"
|
||||
assert requests[1][0]["method"] == "tools/call"
|
||||
assert requests[1][0]["params"]["name"] == "onec_request"
|
||||
assert requests[1][0]["params"]["arguments"]["payload"]["source_state"] == "working"
|
||||
assert requests[1][2] == "http://docker.cin.su:8021/mcp"
|
||||
|
||||
|
||||
def test_agent_system_prompt_requires_mcp_name_first_navigation() -> None:
|
||||
prompt = onec_agent.DEFAULT_SYSTEM_PROMPT_PATH.read_text(encoding="utf-8")
|
||||
assert "только инструментом MCP `onec_request`" in prompt
|
||||
assert "source_state=working" in prompt
|
||||
assert "Не проси и не подставляй GUID либо `module_ref`" in prompt
|
||||
|
||||
|
||||
def test_get_chat_runtime(onec_agent_server: dict[str, str]) -> None:
|
||||
url = onec_agent_server["url"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user