|
|
@@ -5,6 +5,7 @@ from unittest.mock import Mock
|
|
|
from public_server import PublicMcpHttpHandler, create_http_handler, extract_client_ip
|
|
|
from services.diagnostic_event import RequestDiagnosticEmitter
|
|
|
from utils.rate_limiter import SimpleRateLimiter
|
|
|
+from constants import DEVICE_INVALID_MESSAGE
|
|
|
|
|
|
|
|
|
class FakeContext:
|
|
|
@@ -247,6 +248,34 @@ class PublicMcpHttpHandlerTest(unittest.TestCase):
|
|
|
self.assertEqual('Gateway request failed. Please try again later.', response['error']['message'])
|
|
|
self.assertNotIn('password', json.dumps(response))
|
|
|
|
|
|
+ def test_tools_list_redis_miss_returns_device_invalid(self):
|
|
|
+ class MissingSessionGateway(FakeGateway):
|
|
|
+ def list_tools(self, gateway_session_id, request_id=''):
|
|
|
+ raise RuntimeError(DEVICE_INVALID_MESSAGE)
|
|
|
+
|
|
|
+ reporter = RecordingReporter()
|
|
|
+ handler = PublicMcpHttpHandler(
|
|
|
+ MissingSessionGateway(),
|
|
|
+ context_parser=FakeParser(),
|
|
|
+ reporter=reporter,
|
|
|
+ )
|
|
|
+ with self.assertLogs('public_server', level='WARNING') as logs:
|
|
|
+ response = handler.handle_json_rpc(
|
|
|
+ headers={'X-Gateway-Session': 'GWS_A'},
|
|
|
+ message={'jsonrpc': '2.0', 'id': 32, 'method': 'tools/list', 'params': {}},
|
|
|
+ client_ip='10.0.0.5',
|
|
|
+ )
|
|
|
+
|
|
|
+ self.assertEqual(-32001, response['error']['code'])
|
|
|
+ self.assertEqual(DEVICE_INVALID_MESSAGE, response['error']['message'])
|
|
|
+ self.assertTrue(response['error']['data']['request_id'].startswith('rq_http_'))
|
|
|
+ event = next(item for item in reporter.events if item['stage'] == 'gateway_session')
|
|
|
+ self.assertEqual('failed', event['status'])
|
|
|
+ self.assertEqual('GATEWAY_SESSION_NOT_FOUND', event['event_code'])
|
|
|
+ record = logs.records[0]
|
|
|
+ self.assertEqual(-32001, record.protocol_code)
|
|
|
+ self.assertEqual('GATEWAY_SESSION_NOT_FOUND', record.diagnostic_reason)
|
|
|
+
|
|
|
def test_handle_tools_call_passes_gateway_session_to_public_gateway(self):
|
|
|
gateway = FakeGateway()
|
|
|
handler = PublicMcpHttpHandler(gateway, context_parser=FakeParser())
|