mirror of
https://github.com/JamesTheGiblet/BuddAI.git
synced 2026-01-08 21:58:40 +00:00
- Implemented tests for confidence scoring logic in `test_buddai_confidence.py` and `test_confidence.py`, covering high and low confidence scenarios, escalation thresholds, and validation scoring penalties. - Created tests for fallback logging functionality in `test_fallback_logging.py`, ensuring fallback prompts are logged correctly and the `/logs` command retrieves log content. - Developed tests for fallback prompts in `test_fallback_prompts.py`, verifying that specific prompts are used for different models based on confidence levels. - Generated detailed test reports for multiple test runs, confirming all tests passed successfully.
45 lines
No EOL
1.6 KiB
Python
45 lines
No EOL
1.6 KiB
Python
import unittest
|
|
from unittest.mock import MagicMock, patch
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
|
|
# Setup path
|
|
REPO_ROOT = Path(__file__).parent.parent
|
|
if str(REPO_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(REPO_ROOT))
|
|
|
|
from core.buddai_fallback import FallbackClient
|
|
|
|
class TestFallbackClient(unittest.TestCase):
|
|
@patch('core.buddai_fallback.genai')
|
|
def test_escalate_success(self, mock_genai):
|
|
"""Test successful escalation to Gemini"""
|
|
# Setup mocks
|
|
mock_model = MagicMock()
|
|
mock_response = MagicMock()
|
|
mock_response.text = "Fixed Code"
|
|
mock_model.generate_content.return_value = mock_response
|
|
mock_genai.GenerativeModel.return_value = mock_model
|
|
|
|
# Force HAS_GEMINI to True for this test
|
|
with patch('core.buddai_fallback.HAS_GEMINI', True):
|
|
with patch.dict('os.environ', {'GEMINI_API_KEY': 'fake_key'}):
|
|
client = FallbackClient()
|
|
# Inject mock client since __init__ might fail if real genai not installed
|
|
client.client = mock_model
|
|
|
|
result = client.escalate_to_gemini("prompt", "bad code", 50)
|
|
|
|
self.assertIn("Gemini Fallback", result)
|
|
self.assertIn("Fixed Code", result)
|
|
|
|
def test_escalate_no_key(self):
|
|
"""Test behavior when API key is missing"""
|
|
with patch.dict('os.environ', {}, clear=True):
|
|
client = FallbackClient()
|
|
result = client.escalate_to_gemini("prompt", "bad code", 50)
|
|
self.assertIn("Fallback unavailable", result)
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main() |