mirror of
https://github.com/JamesTheGiblet/BuddAI.git
synced 2026-01-08 21:58:40 +00:00
- 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.
23 lines
1.4 KiB
Python
23 lines
1.4 KiB
Python
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
|