Add unit tests for analytics, fallback client, and refactored validators

- Implemented comprehensive unit tests for the BuddAI Analytics module, covering fallback statistics calculations.
- Created tests for the FallbackClient to ensure proper escalation to various AI models and handling of missing API keys.
- Developed unit tests for the refactored validator system, validating various hardware and coding standards.
- Established a base validator interface and implemented specific validators for ESP32, Arduino, motor control, memory safety, and more.
- Enhanced the validator registry to auto-discover and manage validators effectively.
- Included detailed validation logic for common issues in embedded systems programming, such as unused variables, safety timeouts, and coding style violations.
This commit is contained in:
JamesTheGiblet 2026-01-08 17:43:11 +00:00
parent 99ef8f5592
commit d4e09f6d13
43 changed files with 5036 additions and 622 deletions

View file

@ -35,6 +35,10 @@ class TestFallbackPrompts(unittest.TestCase):
self.ai.shadow_engine = MagicMock()
self.ai.shadow_engine.get_all_suggestions.return_value = []
# Mock FallbackClient
self.ai.fallback_client = MagicMock()
self.ai.fallback_client.is_available.return_value = True
# Setup default mocks
self.ai.validator.validate.return_value = (True, [])
self.ai.hardware_profile.detect_hardware.return_value = "ESP32"
@ -61,6 +65,15 @@ class TestFallbackPrompts(unittest.TestCase):
# Mock LLM
self.ai.llm.query.return_value = "Code: ```cpp\nvoid setup() {}\n```"
# Mock escalate to return the expected prompt string based on model
def escalate_side_effect(model, prompt, *args, **kwargs):
if model == "claude":
return "Claude Prompt: fix the motor"
if model == "gpt4":
return "GPT4 Prompt: fix the motor"
return "Fallback"
self.ai.fallback_client.escalate.side_effect = escalate_side_effect
# Run
user_msg = "fix the motor"
response = self.ai.chat(user_msg)