1+ import os
2+ import pytest
3+
4+
15def test_api_chat_echo (client ):
26 # First message
37 resp1 = client .post ('/api/chat' , json = {'message' : 'Hello' })
@@ -11,3 +15,72 @@ def test_api_chat_echo(client):
1115 resp2 = client .post ('/api/chat' , json = {'message' : 'How are you?' })
1216 data2 = resp2 .get_json ()
1317 assert len (data2 ['history' ]) == 4
18+
19+
20+ def test_api_chat_missing_message (client ):
21+ resp = client .post ('/api/chat' , json = {})
22+ assert resp .status_code == 400
23+ data = resp .get_json ()
24+ assert data ['status' ] == 'error'
25+ assert 'message required' in data ['error' ]
26+
27+
28+ def test_api_chat_history (client ):
29+ # Post a message first
30+ client .post ('/api/chat' , json = {'message' : 'Test' })
31+
32+ # Get history
33+ resp = client .get ('/api/chat/history' )
34+ assert resp .status_code == 200
35+ data = resp .get_json ()
36+ assert data ['status' ] == 'ok'
37+ assert 'history' in data
38+ assert len (data ['history' ]) >= 2
39+
40+
41+ def test_api_chat_capabilities (client ):
42+ resp = client .get ('/api/chat/capabilities' )
43+ assert resp .status_code == 200
44+ data = resp .get_json ()
45+ assert 'graphrag' in data
46+ assert 'enabled' in data ['graphrag' ]
47+ assert 'llm_provider' in data ['graphrag' ]
48+ assert 'model' in data ['graphrag' ]
49+
50+
51+ def test_api_chat_graphrag_disabled_by_default (client ):
52+ # GraphRAG should be disabled without SCIDK_GRAPHRAG_ENABLED
53+ resp = client .post ('/api/chat/graphrag' , json = {'message' : 'Test query' })
54+ assert resp .status_code == 501
55+ data = resp .get_json ()
56+ assert data ['status' ] == 'disabled'
57+ assert 'SCIDK_GRAPHRAG_ENABLED' in data .get ('hint' , '' )
58+
59+
60+ def test_api_chat_graphrag_missing_message (client , monkeypatch ):
61+ monkeypatch .setenv ('SCIDK_GRAPHRAG_ENABLED' , '1' )
62+ resp = client .post ('/api/chat/graphrag' , json = {})
63+ assert resp .status_code == 400
64+ data = resp .get_json ()
65+ assert data ['status' ] == 'error'
66+ assert 'message required' in data ['error' ]
67+
68+
69+ def test_api_chat_context_refresh_disabled (client ):
70+ resp = client .post ('/api/chat/context/refresh' )
71+ assert resp .status_code == 501
72+ data = resp .get_json ()
73+ assert data ['status' ] == 'disabled'
74+
75+
76+ def test_api_chat_observability_graphrag (client ):
77+ resp = client .get ('/api/chat/observability/graphrag' )
78+ assert resp .status_code == 200
79+ data = resp .get_json ()
80+ assert data ['status' ] == 'ok'
81+ assert 'enabled' in data
82+ assert 'llm_provider' in data
83+ assert 'model' in data
84+ assert 'schema' in data
85+ assert 'audit' in data
86+ assert isinstance (data ['audit' ], list )
0 commit comments