mirror of
https://github.com/JamesTheGiblet/BuddAI.git
synced 2026-01-08 21:58:40 +00:00
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:
parent
99ef8f5592
commit
d4e09f6d13
43 changed files with 5036 additions and 622 deletions
23
validators/servo_control.py
Normal file
23
validators/servo_control.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import re
|
||||
from . import BaseValidator
|
||||
|
||||
class ServoValidator(BaseValidator):
|
||||
def validate(self, code: str, hardware: str, user_message: str) -> list[dict]:
|
||||
issues = []
|
||||
|
||||
# Check 14: State Machine for Weapons (Combat Protocol)
|
||||
if "weapon" in user_message.lower() or "combat" in user_message.lower() or "state machine" in user_message.lower():
|
||||
if "enum" not in code and "bool isArmed" not in code:
|
||||
issues.append({
|
||||
"severity": "error",
|
||||
"message": "Combat code requires a State Machine (enum State or bool isArmed).",
|
||||
"fix": lambda c: c.replace("void setup", "\n// [AUTO-FIX] State Machine\nenum State { DISARMED, ARMING, ARMED, FIRING };\nState currentState = DISARMED;\nunsigned long stateTimer = 0;\n\nvoid setup") if "void setup" in c else "// [AUTO-FIX] State Machine\nenum State { DISARMED, ARMING, ARMED, FIRING };\nState currentState = DISARMED;\n" + c
|
||||
})
|
||||
|
||||
if "Serial.read" not in code and "Serial.available" not in code:
|
||||
issues.append({
|
||||
"severity": "error",
|
||||
"message": "Missing Serial Command handling (e.g., 'A' to Arm).",
|
||||
"fix": lambda c: c.replace("void loop() {", "void loop() {\n if (Serial.available()) {\n char cmd = Serial.read();\n // Handle commands\n }\n")
|
||||
})
|
||||
return issues
|
||||
Loading…
Add table
Add a link
Reference in a new issue