Some checks failed
social-bot integration tests / Lint (flake8 + pep257) (pull_request) Failing after 29s
social-bot integration tests / Core integration tests (mock sensors, no GPU) (pull_request) Has been skipped
social-bot integration tests / Latency profiling (GPU, Orin) (pull_request) Has been cancelled
- SQLite database at /home/seb/saltybot-data/social_memory.db - Tables: persons (name, embeddings, relationship_tier, notes), encounters (person_id, timestamp, transcript, mood) - ROS2 services: /saltybot/social_memory/lookup, /update, /encounter, /stats - Automatic tier promotion by encounter count (5→regular, 20→favorite) - Quality-based promotion: 80%+ positive interactions required - Custom greetings per relationship tier (stranger/regular/favorite) - Encounter tracking: transcript, mood, engagement_score, positive_interaction flag - Face embedding storage support for face recognition integration - Relationship score computation from interaction history - Thread-safe concurrent service calls - Periodic stats publishing on /saltybot/social_memory/stats_update - Backup/restore functionality with gzip compression - Full database statistics: person counts by tier, total encounters, database size - Configurable via social_memory.yaml: thresholds, backup dir, publish interval Two packages: - saltybot_social_memory: Service definitions (CMake, ROS2 services) - saltybot_social_memory_node: Python service server with SQLite backend Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
100 lines
3.2 KiB
Python
100 lines
3.2 KiB
Python
"""Unit tests for diagnostics system."""
|
|
|
|
import unittest
|
|
import json
|
|
from datetime import datetime
|
|
|
|
|
|
class TestDiagnostics(unittest.TestCase):
|
|
"""Test cases for diagnostics node."""
|
|
|
|
def test_hardware_check_creation(self):
|
|
"""Test creation of hardware check results."""
|
|
checks = {
|
|
"rplidar": {"status": "OK", "message": "RPLIDAR detected"},
|
|
"realsense": {"status": "ERROR", "message": "RealSense not found"},
|
|
"vesc": {"status": "WARN", "message": "VESC connection uncertain"},
|
|
}
|
|
|
|
self.assertEqual(len(checks), 3)
|
|
self.assertEqual(checks["rplidar"]["status"], "OK")
|
|
self.assertEqual(checks["realsense"]["status"], "ERROR")
|
|
|
|
def test_diagnostic_json_logging(self):
|
|
"""Test JSON logging of diagnostics."""
|
|
log_data = {
|
|
"timestamp": datetime.now().isoformat(),
|
|
"check_type": "startup_checks",
|
|
"hardware_checks": {
|
|
"rplidar": {
|
|
"status": "OK",
|
|
"message": "Device OK",
|
|
"details": {"port": "/dev/ttyUSB0"},
|
|
},
|
|
"realsense": {
|
|
"status": "ERROR",
|
|
"message": "Device not found",
|
|
"details": {},
|
|
},
|
|
},
|
|
"runtime_metrics": {
|
|
"gpu_temp": {"status": "OK", "temperature_c": 65.0},
|
|
"network_latency": {"status": "WARN", "latency_ms": 150},
|
|
},
|
|
}
|
|
|
|
# Should be JSON serializable
|
|
json_str = json.dumps(log_data)
|
|
parsed = json.loads(json_str)
|
|
|
|
self.assertIn("timestamp", parsed)
|
|
self.assertEqual(len(parsed["hardware_checks"]), 2)
|
|
self.assertEqual(parsed["hardware_checks"]["rplidar"]["status"], "OK")
|
|
|
|
def test_temperature_threshold_detection(self):
|
|
"""Test temperature threshold detection."""
|
|
thresholds = {
|
|
"gpu_temp": {"warn": 80, "error": 85},
|
|
"vesc_temp": {"warn": 60, "error": 70},
|
|
}
|
|
|
|
test_temps = [
|
|
(65, "OK"),
|
|
(82, "WARN"),
|
|
(88, "ERROR"),
|
|
]
|
|
|
|
for temp, expected_status in test_temps:
|
|
if temp < thresholds["gpu_temp"]["warn"]:
|
|
status = "OK"
|
|
elif temp < thresholds["gpu_temp"]["error"]:
|
|
status = "WARN"
|
|
else:
|
|
status = "ERROR"
|
|
|
|
self.assertEqual(status, expected_status)
|
|
|
|
def test_diagnostic_aggregation(self):
|
|
"""Test aggregation of multiple diagnostics."""
|
|
hardware_checks = {
|
|
"rplidar": "OK",
|
|
"realsense": "OK",
|
|
"vesc": "ERROR",
|
|
"wifi": "OK",
|
|
"gps": "WARN",
|
|
}
|
|
|
|
errors = [name for name, status in hardware_checks.items() if status == "ERROR"]
|
|
warnings = [name for name, status in hardware_checks.items() if status == "WARN"]
|
|
ok_items = [name for name, status in hardware_checks.items() if status == "OK"]
|
|
|
|
self.assertEqual(len(errors), 1)
|
|
self.assertEqual(len(warnings), 1)
|
|
self.assertEqual(len(ok_items), 3)
|
|
self.assertIn("vesc", errors)
|
|
self.assertIn("gps", warnings)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|