Files
Athena-Deck/test_upstream_diagnostics.py
T

29 lines
2.4 KiB
Python

import json
import unittest
from endpoint import chat_upstream_error
class DiagnosticsTests(unittest.TestCase):
def error(self,msg,status=400):return chat_upstream_error(status,json.dumps({'error':{'message':msg}}).encode(),'strata')
def test_real_reservation_overflow(self):
e=self.error('request exceeds the context window: prompt (100462 tokens) + max tokens (32000) exceeds the context (131072); requests are never truncated. Send a smaller max_tokens (at most 30602 here), or SECRET')
self.assertEqual(e.code,'context_length_exceeded')
for value in ('Strata','100.462','32.000','131.072','30.602'):self.assertIn(value,str(e))
self.assertNotIn('SECRET',str(e))
def test_prompt_overflow(self):
e=self.error('request exceeds the context window: prompt (131100 tokens) leaves no room to answer in the context (131072); requests are never truncated')
self.assertEqual(e.code,'context_length_exceeded');self.assertIn('kein Platz',str(e))
def test_limits(self):
e=self.error('request exceeds the context window: prompt (99999999999 tokens) + max tokens (32000) exceeds the context (131072)')
self.assertEqual(e.code,'upstream_error');self.assertNotIn('99999999999',str(e))
def test_known_errors(self):
cases={'structured response_format with tools/MCP is not supported':'unsupported_parameter_combination','unknown reasoning effort SECRET':'invalid_reasoning_effort','this server was started without the vision encoder SECRET':'vision_unavailable','the prompt and its images do not match':'image_prompt_mismatch','tools must be a list of tool objects SECRET':'invalid_tool_schema','stop takes at most 4 strings SECRET':'invalid_stop_parameter','CUDA out of memory SECRET':'gpu_memory_exhausted'}
for msg,code in cases.items():
with self.subTest(code=code):
e=self.error(msg);self.assertEqual(e.code,code);self.assertNotIn('SECRET',str(e))
def test_status_and_privacy(self):
for status in (400,401,403,404,409,422,429,500,502,503,504):
with self.subTest(status=status):
e=self.error('PRIVATE PASSWORD PROMPT',status);self.assertEqual(e.status,status);self.assertIn(str(status),str(e));self.assertNotIn('PRIVATE',str(e))
for raw in (b'private non JSON',b'[]',b'{"error":null}'):
self.assertEqual(chat_upstream_error(400,raw).code,'upstream_error')
def test_no_embedded_match(self):self.assertEqual(self.error('User said: CUDA out of memory').code,'upstream_error')