feat(reporter): persist drift metrics and last heal result in state snapshot

This commit is contained in:
patrick committed 2026-03-05 20:35:18 -05:00
1 parent c698d01c40
commit b34ac69ac1
5 files changed
+160 -14

No files matched your search

+23 -7
View File
@@ -10,8 +10,15 @@ class FakeReporter:
def __init__(self):
self.update_calls = []
def update_status(self, is_synced, ban_count, last_error=None):
self.update_calls.append((is_synced, ban_count, last_error))
def update_status(self, is_synced, ban_count, last_error=None, **kwargs):
self.update_calls.append(
{
"is_synced": is_synced,
"ban_count": ban_count,
"last_error": last_error,
**kwargs,
}
)
class FakeAuditor:
@@ -91,7 +98,11 @@ class PostHealVerificationTests(unittest.TestCase):
self.assertEqual("success", heal_result)
self.assertEqual(post_drift, returned_post_drift)
self.assertEqual([(True, 12, None)], reporter.update_calls)
self.assertEqual(1, len(reporter.update_calls))
self.assertTrue(reporter.update_calls[0]["is_synced"])
self.assertEqual(12, reporter.update_calls[0]["ban_count"])
self.assertEqual("success", reporter.update_calls[0]["last_heal_result"])
self.assertEqual("", reporter.update_calls[0]["last_drift_fingerprint"])
self.assertEqual({"fingerprint": "pre123"}, auditor.last_heal_drift)
@patch("healing.time.sleep", return_value=None)
@@ -109,7 +120,11 @@ class PostHealVerificationTests(unittest.TestCase):
self.assertEqual("restart_failed", heal_result)
self.assertEqual("not_verified", returned_post_drift["reason"])
self.assertEqual([(False, 7, "Bouncer restart failed")], reporter.update_calls)
self.assertEqual(1, len(reporter.update_calls))
self.assertFalse(reporter.update_calls[0]["is_synced"])
self.assertEqual(7, reporter.update_calls[0]["ban_count"])
self.assertEqual("Bouncer restart failed", reporter.update_calls[0]["last_error"])
self.assertEqual("restart_failed", reporter.update_calls[0]["last_heal_result"])
@patch("healing.time.sleep", return_value=None)
def test_execute_heal_and_verify_verify_exception(self, _sleep):
@@ -127,9 +142,10 @@ class PostHealVerificationTests(unittest.TestCase):
self.assertEqual("verify_error", heal_result)
self.assertEqual("verify_error", returned_post_drift["reason"])
self.assertEqual(1, len(reporter.update_calls))
self.assertFalse(reporter.update_calls[0][0])
self.assertEqual(7, reporter.update_calls[0][1])
self.assertIn("Post-heal verify error: boom", reporter.update_calls[0][2])
self.assertFalse(reporter.update_calls[0]["is_synced"])
self.assertEqual(7, reporter.update_calls[0]["ban_count"])
self.assertIn("Post-heal verify error: boom", reporter.update_calls[0]["last_error"])
self.assertEqual("verify_error", reporter.update_calls[0]["last_heal_result"])
if __name__ == "__main__":