atlas/home-voice-agent/safety/confirmations/test_confirmations.py
ilia bdbf09a9ac feat: Implement voice I/O services (TICKET-006, TICKET-010, TICKET-014)
 TICKET-006: Wake-word Detection Service
- Implemented wake-word detection using openWakeWord
- HTTP/WebSocket server on port 8002
- Real-time detection with configurable threshold
- Event emission for ASR integration
- Location: home-voice-agent/wake-word/

 TICKET-010: ASR Service
- Implemented ASR using faster-whisper
- HTTP endpoint for file transcription
- WebSocket endpoint for streaming transcription
- Support for multiple audio formats
- Auto language detection
- GPU acceleration support
- Location: home-voice-agent/asr/

 TICKET-014: TTS Service
- Implemented TTS using Piper
- HTTP endpoint for text-to-speech synthesis
- Low-latency processing (< 500ms)
- Multiple voice support
- WAV audio output
- Location: home-voice-agent/tts/

 TICKET-047: Updated Hardware Purchases
- Marked Pi5 kit, SSD, microphone, and speakers as purchased
- Updated progress log with purchase status

📚 Documentation:
- Added VOICE_SERVICES_README.md with complete testing guide
- Each service includes README.md with usage instructions
- All services ready for Pi5 deployment

🧪 Testing:
- Created test files for each service
- All imports validated
- FastAPI apps created successfully
- Code passes syntax validation

🚀 Ready for:
- Pi5 deployment
- End-to-end voice flow testing
- Integration with MCP server

Files Added:
- wake-word/detector.py
- wake-word/server.py
- wake-word/requirements.txt
- wake-word/README.md
- wake-word/test_detector.py
- asr/service.py
- asr/server.py
- asr/requirements.txt
- asr/README.md
- asr/test_service.py
- tts/service.py
- tts/server.py
- tts/requirements.txt
- tts/README.md
- tts/test_service.py
- VOICE_SERVICES_README.md

Files Modified:
- tickets/done/TICKET-047_hardware-purchases.md

Files Moved:
- tickets/backlog/TICKET-006_prototype-wake-word-node.md → tickets/done/
- tickets/backlog/TICKET-010_streaming-asr-service.md → tickets/done/
- tickets/backlog/TICKET-014_tts-service.md → tickets/done/
2026-01-12 22:22:38 -05:00

101 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""
Test script for confirmation flows.
"""
import sys
from pathlib import Path
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from safety.confirmations.flow import get_flow
from safety.confirmations.risk import RiskLevel
def test_confirmations():
"""Test confirmation flow."""
print("=" * 60)
print("Confirmation Flow Test")
print("=" * 60)
flow = get_flow()
# Test low-risk tool (no confirmation)
print("\n1. Testing low-risk tool...")
requires, message = flow.check_confirmation_required("get_current_time")
print(f" ✅ get_current_time requires confirmation: {requires} (should be False)")
# Test high-risk tool (confirmation required)
print("\n2. Testing high-risk tool...")
requires, message = flow.check_confirmation_required(
"send_email",
to="user@example.com",
subject="Test"
)
print(f" ✅ send_email requires confirmation: {requires} (should be True)")
if message:
print(f" Message: {message}")
# Test confirmation request
print("\n3. Testing confirmation request...")
response = flow.process_confirmation_request(
tool_name="send_email",
parameters={
"to": "user@example.com",
"subject": "Test Email",
"body": "This is a test"
},
session_id="test-session",
user_id="test-user"
)
print(f" ✅ Confirmation required: {response['confirmation_required']}")
print(f" Risk level: {response['risk_level']}")
if response.get("token"):
print(f" Token generated: {response['token'][:50]}...")
# Test token validation
print("\n4. Testing token validation...")
if response.get("token"):
test_parameters = {
"to": "user@example.com",
"subject": "Test Email",
"body": "This is a test"
}
is_valid, error = flow.validate_confirmation(
token=response["token"],
tool_name="send_email",
parameters=test_parameters
)
print(f" ✅ Token validation: {is_valid} (should be True)")
# Test invalid token
is_valid, error = flow.validate_confirmation(
token="invalid_token",
tool_name="send_email",
parameters=test_parameters
)
print(f" ✅ Invalid token validation: {is_valid} (should be False)")
if error:
print(f" Error: {error}")
# Test risk classification
print("\n5. Testing risk classification...")
from safety.confirmations.risk import get_classifier
classifier = get_classifier()
risk = classifier.classify_risk("get_current_time")
print(f" ✅ get_current_time risk: {risk.value} (should be low)")
risk = classifier.classify_risk("send_email")
print(f" ✅ send_email risk: {risk.value} (should be critical)")
risk = classifier.classify_risk("update_task_status", status="done")
print(f" ✅ update_task_status (done) risk: {risk.value}")
print("\n" + "=" * 60)
print("✅ Confirmation flow tests complete!")
print("=" * 60)
if __name__ == "__main__":
test_confirmations()