add chache for last known good in sqlite..

This commit is contained in:
larssand
2026-06-30 10:30:59 +02:00
parent 50463aa4d6
commit 2aaa2e28f3
6 changed files with 91 additions and 2 deletions

View File

@@ -4,7 +4,8 @@ import unittest
from pathlib import Path
from unittest.mock import patch
from fgai.monitor import add_llm_assessment, build_status, write_status
from fgai.history import StatusSnapshotStore
from fgai.monitor import add_llm_assessment, build_status, cached_status_with_error, write_status
class MonitorTests(unittest.TestCase):
@@ -109,6 +110,26 @@ class MonitorTests(unittest.TestCase):
self.assertEqual(advisor["status"], "error")
self.assertIn("timeout", advisor["error"])
def test_cached_status_with_error_keeps_last_good_dashboard_data(self):
with tempfile.TemporaryDirectory() as tmp:
cache_path = str(Path(tmp) / "status-cache.sqlite3")
StatusSnapshotStore(cache_path).save(
"last_good",
{
"summary": {"total": 42},
"capabilities": {"graylog_mcp": {"status": "connected"}},
"cross_source_correlations": [{"entity": "10.0.0.1"}],
},
)
status = cached_status_with_error(cache_path, {"status": "error", "error": "mcp down"})
self.assertIsNotNone(status)
self.assertEqual(status["summary"]["total"], 42)
self.assertTrue(status["stale"])
self.assertEqual(status["capabilities"]["graylog_mcp"]["status"], "error")
self.assertTrue(status["status_cache"]["served_from_cache"])
if __name__ == "__main__":
unittest.main()