Spaces:
Sleeping
Sleeping
| """ | |
| Test basic guardrails system functionality. | |
| """ | |
| from src.guardrails import GuardrailsSystem | |
| def test_guardrails_system_initialization(): | |
| """Test that guardrails system initializes properly.""" | |
| system = GuardrailsSystem() | |
| assert system is not None | |
| assert system.response_validator is not None | |
| assert system.content_filter is not None | |
| assert system.quality_metrics is not None | |
| assert system.source_attributor is not None | |
| assert system.error_handler is not None | |
| def test_guardrails_system_basic_validation(): | |
| """Test basic response validation through guardrails system.""" | |
| system = GuardrailsSystem() | |
| # Test data | |
| response = "According to our employee handbook, remote work is allowed " "with manager approval." | |
| query = "What is our remote work policy?" | |
| sources = [ | |
| { | |
| "content": "Remote work is permitted with proper approval and guidelines.", | |
| "metadata": {"filename": "employee_handbook.md", "section": "Remote Work"}, | |
| "relevance_score": 0.9, | |
| } | |
| ] | |
| # Validate response | |
| result = system.validate_response(response, query, sources) | |
| # Basic assertions | |
| assert result is not None | |
| assert hasattr(result, "is_approved") | |
| assert hasattr(result, "confidence_score") | |
| assert hasattr(result, "validation_result") | |
| assert hasattr(result, "safety_result") | |
| assert hasattr(result, "quality_score") | |
| assert hasattr(result, "citations") | |
| # Should have processed successfully | |
| assert result.processing_time > 0 | |
| assert len(result.components_used) > 0 | |
| def test_guardrails_system_health(): | |
| """Test guardrails system health check.""" | |
| system = GuardrailsSystem() | |
| health = system.get_system_health() | |
| assert health is not None | |
| assert "status" in health | |
| assert "components" in health | |
| assert "error_statistics" in health | |
| assert "configuration" in health | |
| if __name__ == "__main__": | |
| # Run basic tests | |
| test_guardrails_system_initialization() | |
| test_guardrails_system_basic_validation() | |
| test_guardrails_system_health() | |
| print("All basic guardrails tests passed!") | |