refactor(core): consolidate into Triad-Pattern (Status, Usage, History) for SLM reliability

This commit is contained in:
vai committed 2026-06-27 09:46:02 +00:00
1 parent 70d46c64dd
commit e60c74c182
2 files changed
+113 -173

No files matched your search

+26 -36
View File
@@ -1,13 +1,11 @@
import unittest
import os
import sys
from litellm_dashboard import Tools
# Note: Integration key is NOT stored in repo. It is read from /tmp at runtime.
INTEGRATION_KEY_PATH = "/tmp/litellm-integration-testing-key.txt"
LIVE_URL = "http://mon-serv1.captcouch.xyz:4001"
class TestLiteLLMTool(unittest.TestCase):
class TestLiteLLMToolConsolidated(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.tools = Tools()
@@ -15,49 +13,41 @@ class TestLiteLLMTool(unittest.TestCase):
if os.path.exists(INTEGRATION_KEY_PATH):
with open(INTEGRATION_KEY_PATH, 'r') as f:
cls.tools.valves.litellm_master_key = f.read().strip()
else:
print("Warning: Integration key not found. Some tests will fail.")
def test_litellm_status_integration(self):
"""Test lean status snapshot against live instance."""
def test_litellm_status(self):
"""Test consolidated infrastructure + model health check."""
output = self.tools.litellm_status()
print("\n--- Status Output ---")
print(output)
self.assertIn("LiteLLM Status Snapshot", output)
self.assertIn("Infrastructure Status", output)
self.assertIn("Proxy: ✅", output)
if self.tools.valves.litellm_master_key:
self.assertIn("Lifetime Spend:", output)
self.assertIn("healthy", output.lower())
def test_litellm_health_integration(self):
"""Test health check against live instance."""
output = self.tools.litellm_health()
self.assertIn("LiteLLM Health Check", output)
self.assertIn("Healthy:", output)
def test_litellm_cost_visualization_integration(self):
"""Test cost report and sparkline logic."""
output = self.tools.litellm_cost(start_date="3 days ago", end_date="today")
print("\n--- Cost Output ---")
def test_litellm_usage_summary(self):
"""Test token-efficient usage snapshot."""
output = self.tools.litellm_usage(detail_level="summary")
print("\n--- Usage Summary ---")
print(output)
self.assertIn("Total Spend:", output)
self.assertIn("[", output) # Part of sparkline check
self.assertIn("]", output)
self.assertIn("Spend Summary", output)
self.assertIn("Total Lifetime Spend", output)
def test_litellm_history_audit_integration(self):
"""Test request history and Dynamic Audit Engine."""
output = self.tools.litellm_history(limit=5)
def test_litellm_usage_full(self):
"""Test detailed fiscal report with sparklines."""
output = self.tools.litellm_usage(start_date="7 days ago", detail_level="full")
print("\n--- Usage Full ---")
print(output)
self.assertIn("Usage Report", output)
self.assertIn("Breakdown by Endpoint", output)
def test_litellm_history_filtered(self):
"""Test filtered request history."""
output = self.tools.litellm_history(limit=5, filter_model="gemini")
print("\n--- History Output ---")
print(output)
self.assertIn("LiteLLM History", output)
# Check if audit engine is firing (either calc ok or mismatch)
self.assertTrue("calc:" in output or "History" in output)
def test_date_resolution(self):
"""Unit test for date resolver."""
d1 = self.tools._resolve_date("today")
d2 = self.tools._resolve_date("yesterday")
self.assertNotEqual(d1, d2)
self.assertEqual(len(d1), 10) # YYYY-MM-DD
self.assertIn("History", output)
# Verify filtering if logs exist
if "gemini" in output.lower():
self.assertTrue(True)
if __name__ == "__main__":
unittest.main()