mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 09:29:38 +02:00
saving
This commit is contained in:
parent
9e9307a2aa
commit
e26caa0b12
123 changed files with 3478 additions and 10078 deletions
54
tests/unit/test_gateway/test_graph_rag_request_translator.py
Normal file
54
tests/unit/test_gateway/test_graph_rag_request_translator.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
from trustgraph.messaging.translators.retrieval import GraphRagRequestTranslator
|
||||
|
||||
|
||||
class TestGraphRagRequestTranslator:
|
||||
def test_accepts_hyphenated_keys(self):
|
||||
translator = GraphRagRequestTranslator()
|
||||
|
||||
result = translator.to_pulsar(
|
||||
{
|
||||
"query": "q",
|
||||
"user": "u",
|
||||
"collection": "c",
|
||||
"entity-limit": 8,
|
||||
"triple-limit": 16,
|
||||
"max-subgraph-size": 24,
|
||||
"max-path-length": 2,
|
||||
"edge-score-limit": 12,
|
||||
"edge-limit": 6,
|
||||
}
|
||||
)
|
||||
|
||||
assert result.entity_limit == 8
|
||||
assert result.triple_limit == 16
|
||||
assert result.max_subgraph_size == 24
|
||||
assert result.max_path_length == 2
|
||||
assert result.edge_score_limit == 12
|
||||
assert result.edge_limit == 6
|
||||
|
||||
def test_accepts_snake_case_aliases_and_uses_aligned_default(self):
|
||||
translator = GraphRagRequestTranslator()
|
||||
|
||||
result = translator.to_pulsar(
|
||||
{
|
||||
"query": "q",
|
||||
"user": "u",
|
||||
"collection": "c",
|
||||
"entity_limit": 5,
|
||||
"triple_limit": 7,
|
||||
"max_subgraph_size": 9,
|
||||
"max_path_length": 1,
|
||||
"edge_score_limit": 11,
|
||||
"edge_limit": 3,
|
||||
}
|
||||
)
|
||||
|
||||
assert result.entity_limit == 5
|
||||
assert result.triple_limit == 7
|
||||
assert result.max_subgraph_size == 9
|
||||
assert result.max_path_length == 1
|
||||
assert result.edge_score_limit == 11
|
||||
assert result.edge_limit == 3
|
||||
|
||||
defaulted = translator.to_pulsar({"query": "q"})
|
||||
assert defaulted.max_subgraph_size == 150
|
||||
49
tests/unit/test_mcp/test_load_document.py
Normal file
49
tests/unit/test_mcp/test_load_document.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
import base64
|
||||
|
||||
import pytest
|
||||
|
||||
from trustgraph.mcp_server.mcp import McpServer, encode_document_content
|
||||
|
||||
|
||||
class TestEncodeDocumentContent:
|
||||
def test_encodes_text_payloads(self):
|
||||
encoded = encode_document_content("hello world", "text/plain")
|
||||
assert encoded == base64.b64encode(b"hello world").decode("utf-8")
|
||||
|
||||
def test_passes_through_binary_payloads(self):
|
||||
pdf_payload = "JVBERi0xLjQKJcTl8uXrpA=="
|
||||
assert encode_document_content(pdf_payload, "application/pdf") == pdf_payload
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestLoadDocument:
|
||||
@patch("trustgraph.mcp_server.mcp.get_socket_manager")
|
||||
async def test_load_document_base64_encodes_text_content(self, mock_get_socket_manager):
|
||||
server = McpServer()
|
||||
|
||||
manager = MagicMock()
|
||||
manager.request.return_value = self._single_response()
|
||||
mock_get_socket_manager.return_value = manager
|
||||
|
||||
ctx = SimpleNamespace(
|
||||
request_id="req-123",
|
||||
session=SimpleNamespace(send_log_message=AsyncMock()),
|
||||
)
|
||||
|
||||
await server.load_document(
|
||||
document="plain text body",
|
||||
document_id="doc-1",
|
||||
mime_type="text/plain",
|
||||
title="Example",
|
||||
user="trustgraph",
|
||||
ctx=ctx,
|
||||
)
|
||||
|
||||
manager.request.assert_called_once()
|
||||
_, request_data, _ = manager.request.call_args.args
|
||||
assert request_data["content"] == base64.b64encode(b"plain text body").decode("utf-8")
|
||||
|
||||
async def _single_response(self):
|
||||
yield {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue