Add slot context history to dashboard

This commit is contained in:
Mikei386
2026-09-15 23:05:00 +02:00
parent 724e20fec0
commit 54b9daae91
4 changed files with 131 additions and 6 deletions
+34
View File
@@ -118,6 +118,40 @@ class DashboardModeTests(unittest.TestCase):
self.assertEqual(backups[0]["sha256"], "a" * 64)
self.assertTrue(backups[0]["download_url"].startswith("/api/backups/download/"))
def test_slot_context_history_is_recorded_and_exposed(self):
with tempfile.TemporaryDirectory() as tempdir:
store = self.dashboard.HistoryStore(Path(tempdir) / "slots.sqlite3")
store.record({
"timestamp": 1_789_000_000,
"router": {
"current_profile": "medium",
"upstream": {"model": "qwen"},
"llama_telemetry": {
"slots": [{
"id": 0,
"context_used": 40_000,
"n_ctx": 160_000,
"processing": True,
}],
},
},
"llama_runtime": {"pid": 123, "model_file": "qwen.gguf"},
"gpus": [],
})
result = store.query("all")
store._db.close()
self.assertEqual(len(result["slot_points"]), 1)
self.assertEqual(result["slot_points"][0]["slot_id"], 0)
self.assertEqual(result["slot_points"][0]["context_percent"], 25.0)
self.assertEqual(result["slot_points"][0]["busy_ratio"], 1.0)
def test_dashboard_renders_slot_context_history_controls(self):
self.assertIn('id="slotHistoryChart"', self.dashboard.HTML)
self.assertIn('id="slotHistoryRanges"', self.dashboard.HTML)
self.assertIn("drawSlotHistory(d.slot_points||[])", self.dashboard.HISTORY_JS)
if __name__ == "__main__":
unittest.main()