Build Basalt 0.3.3 candidate and integrate media and response controls

This commit is contained in:
Mikei386 committed 2026-11-13 12:53:49 +01:00
1 parent 584a884cc9
commit 34e711721a
44 files changed
+2290 -166

No files matched your search

+24 -1
View File
@@ -144,7 +144,7 @@ class Tests(unittest.TestCase):
def test_chat_test_routes_are_admin_only(self):
self.assertIsNone(self.request('chat-tests')['job'])
for path,method,body in [('chat-tests','GET',None),('chat-tests/start','POST',b'{}'),('auto-tests','GET',None),('auto-tests/start','POST',b'{}'),('auto-tests/save','POST',b'{}')]:
for path,method,body in [('chat-tests','GET',None),('chat-tests/start','POST',b'{}'),('chat-tests/capabilities?profile_id=test','GET',None),('chat-tests/answer-now','POST',b'{}'),('auto-tests','GET',None),('auto-tests/start','POST',b'{}'),('auto-tests/save','POST',b'{}')]:
req=urllib.request.Request(self.url+'/api/v1/'+path,method=method,data=body,headers={'Authorization':'Bearer '+self.api_token,'X-Athena-Deck':'1','Content-Type':'application/json'})
with self.assertRaises(urllib.error.HTTPError) as exc:urllib.request.urlopen(req)
self.assertEqual(exc.exception.code,401);exc.exception.close()
@@ -154,6 +154,29 @@ class Tests(unittest.TestCase):
with urllib.request.urlopen(req) as r:self.assertEqual(json.load(r)['state'],'running')
start.assert_called_once_with(data)
def test_chat_control_requires_csrf_and_current_job_id(self):
with patch.object(self.server.chat_tests,'answer_now',return_value={'state':'thinking'}) as control:
for headers,expected in [({'Cookie':self.cookie},403),({'Cookie':self.cookie,'X-Athena-Deck':'1'},200)]:
req=urllib.request.Request(self.url+'/api/v1/chat-tests/answer-now',data=b'{"job_id":"fixture"}',headers={'Content-Type':'application/json',**headers})
try:
with urllib.request.urlopen(req) as result:self.assertEqual(result.status,expected)
except urllib.error.HTTPError as error:self.assertEqual(error.code,expected);error.close()
control.assert_called_once_with({'job_id':'fixture'})
with patch.object(self.server.chat_tests,'stop',return_value={'cancellation_requested':True}) as stop:
req=urllib.request.Request(self.url+'/api/v1/chat-tests/cancel',data=b'{"job_id":"fixture"}',headers={'Content-Type':'application/json','Cookie':self.cookie,'X-Athena-Deck':'1'})
with urllib.request.urlopen(req) as result:self.assertEqual(result.status,200)
stop.assert_called_once_with('fixture')
def test_chat_media_upload_has_own_limit_not_global_config_limit(self):
with patch.object(self.server.chat_tests,'start',return_value={'state':'running'}) as start:
data={'profile_id':'test','messages':[{'role':'user','content':'x'*40000}],'max_tokens':8}
req=urllib.request.Request(self.url+'/api/v1/chat-tests/start',data=json.dumps(data).encode(),headers={'Cookie':self.cookie,'X-Athena-Deck':'1','Content-Type':'application/json'})
with urllib.request.urlopen(req) as result:self.assertEqual(result.status,200)
start.assert_called_once_with(data)
req=urllib.request.Request(self.url+'/api/v1/endpoint/config',data=json.dumps({'padding':'x'*40000}).encode(),headers={'Cookie':self.cookie,'X-Athena-Deck':'1','Content-Type':'application/json'})
with self.assertRaises(urllib.error.HTTPError) as error:urllib.request.urlopen(req)
self.assertEqual(error.exception.code,400);error.exception.close()
def test_control_guard(self):
for headers in ({},{'X-Athena-Deck':'1','Origin':'http://evil.invalid'}):
with self.assertRaises(urllib.error.HTTPError) as e:self.request('demo/start','POST',headers)