292 lines
10 KiB
Python
292 lines
10 KiB
Python
#!/usr/bin/env python3
|
|||
|
|
"""
|
||
|
|
Basic functionality validation test.
|
||
|
|
Tests core components that can be imported and validated.
|
||
|
|
"""
|
||
|
|
|
||
|
|
import asyncio
|
||
|
|
import json
|
||
|
|
import logging
|
||
|
|
import os
|
||
|
|
import sys
|
||
|
|
import tempfile
|
||
|
|
import traceback
|
||
|
|
from pathlib import Path
|
||
|
|
from typing import Dict, Any, List, Tuple
|
||
|
|
|
||
|
|
# Configure logging
|
||
|
|
logging.basicConfig(
|
||
|
|
level=logging.INFO,
|
||
|
|
format="%(asctime)s - %(levelname)s - %(message)s"
|
||
|
|
)
|
||
|
|
logger = logging.getLogger("BasicFunctionality")
|
||
|
|
|
||
|
|
|
||
|
|
class BasicFunctionalityTest:
|
||
|
|
"""Test basic functionality of core components"""
|
||
|
|
|
||
|
|
def __init__(self):
|
||
|
|
self.test_results: List[Tuple[str, bool, str]] = []
|
||
|
|
|
||
|
|
def test_dependency_manager(self) -> Tuple[str, bool, str]:
|
||
|
|
"""Test dependency manager functionality"""
|
||
|
|
test_name = "Dependency Manager Test"
|
||
|
|
|
||
|
|
try:
|
||
|
|
import dependency_manager
|
||
|
|
|
||
|
|
# Test getting dependency manager
|
||
|
|
dep_manager = dependency_manager.get_dependency_manager()
|
||
|
|
assert dep_manager is not None, "Dependency manager should not be None"
|
||
|
|
|
||
|
|
# Test status report
|
||
|
|
status_report = dep_manager.get_dependency_status_report()
|
||
|
|
assert isinstance(status_report, str), "Status report should be a string"
|
||
|
|
assert len(status_report) > 0, "Status report should not be empty"
|
||
|
|
|
||
|
|
# Test missing dependencies
|
||
|
|
missing_deps = dep_manager.get_missing_dependencies()
|
||
|
|
assert isinstance(missing_deps, list), "Missing deps should be a list"
|
||
|
|
|
||
|
|
return test_name, True, f"Dependency manager works (missing: {len(missing_deps)} deps)"
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
return test_name, False, f"Dependency manager failed: {str(e)}"
|
||
|
|
|
||
|
|
def test_error_handling(self) -> Tuple[str, bool, str]:
|
||
|
|
"""Test error handling framework"""
|
||
|
|
test_name = "Error Handling Framework Test"
|
||
|
|
|
||
|
|
try:
|
||
|
|
import error_handling
|
||
|
|
|
||
|
|
# Test custom exceptions
|
||
|
|
exc1 = error_handling.JournalOrganizerError("test")
|
||
|
|
exc2 = error_handling.ConfigurationError("config error")
|
||
|
|
exc3 = error_handling.APIError("api error")
|
||
|
|
exc4 = error_handling.ValidationError("validation error")
|
||
|
|
|
||
|
|
assert all(isinstance(exc, Exception) for exc in [exc1, exc2, exc3, exc4])
|
||
|
|
|
||
|
|
# Test ErrorHandler
|
||
|
|
import logging
|
||
|
|
logger = logging.getLogger("test")
|
||
|
|
error_handler = error_handling.ErrorHandler(logger)
|
||
|
|
|
||
|
|
assert hasattr(error_handler, 'handle_api_error')
|
||
|
|
assert hasattr(error_handler, 'handle_validation_error')
|
||
|
|
|
||
|
|
return test_name, True, "Error handling framework works correctly"
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
return test_name, False, f"Error handling test failed: {str(e)}"
|
||
|
|
|
||
|
|
def test_configuration_validation(self) -> Tuple[str, bool, str]:
|
||
|
|
"""Test configuration validation"""
|
||
|
|
test_name = "Configuration Validation Test"
|
||
|
|
|
||
|
|
try:
|
||
|
|
import config_validation
|
||
|
|
|
||
|
|
# Test configuration models exist
|
||
|
|
assert hasattr(config_validation, 'ObsidianConfig')
|
||
|
|
assert hasattr(config_validation, 'ClaudeConfig')
|
||
|
|
assert hasattr(config_validation, 'SystemConfig')
|
||
|
|
|
||
|
|
# Test validation functions
|
||
|
|
assert hasattr(config_validation, 'validate_obsidian_config')
|
||
|
|
assert hasattr(config_validation, 'validate_claude_config')
|
||
|
|
|
||
|
|
return test_name, True, "Configuration validation works"
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
return test_name, False, f"Configuration validation failed: {str(e)}"
|
||
|
|
|
||
|
|
def test_input_validation(self) -> Tuple[str, bool, str]:
|
||
|
|
"""Test input validation"""
|
||
|
|
test_name = "Input Validation Test"
|
||
|
|
|
||
|
|
try:
|
||
|
|
import input_validation
|
||
|
|
|
||
|
|
# Test validation functions exist
|
||
|
|
assert hasattr(input_validation, 'command_input_validator')
|
||
|
|
assert hasattr(input_validation, 'validate_user_input')
|
||
|
|
|
||
|
|
# Test basic validation
|
||
|
|
validator = input_validation.command_input_validator
|
||
|
|
assert hasattr(validator, 'validate_organize_command_input'), "Validator should have organize command validation method"
|
||
|
|
|
||
|
|
return test_name, True, "Input validation works"
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
return test_name, False, f"Input validation failed: {str(e)}"
|
||
|
|
|
||
|
|
def test_date_validation(self) -> Tuple[str, bool, str]:
|
||
|
|
"""Test date validation"""
|
||
|
|
test_name = "Date Validation Test"
|
||
|
|
|
||
|
|
try:
|
||
|
|
import date_validation
|
||
|
|
|
||
|
|
# Test validation function exists
|
||
|
|
assert hasattr(date_validation, 'validate_date_input')
|
||
|
|
|
||
|
|
# Test basic date validation
|
||
|
|
result = date_validation.validate_date_input("2025-12-31")
|
||
|
|
assert result is not None, "Valid date should return result"
|
||
|
|
|
||
|
|
return test_name, True, "Date validation works"
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
return test_name, False, f"Date validation failed: {str(e)}"
|
||
|
|
|
||
|
|
def test_path_security(self) -> Tuple[str, bool, str]:
|
||
|
|
"""Test path security"""
|
||
|
|
test_name = "Path Security Test"
|
||
|
|
|
||
|
|
try:
|
||
|
|
import path_security
|
||
|
|
|
||
|
|
# Test security functions exist
|
||
|
|
assert hasattr(path_security, 'validate_path_safety')
|
||
|
|
assert hasattr(path_security, 'sanitize_path')
|
||
|
|
|
||
|
|
# Test basic path validation
|
||
|
|
safe_path = "/tmp/test.txt"
|
||
|
|
result = path_security.validate_path_safety(safe_path)
|
||
|
|
assert isinstance(result, bool), "Path validation should return boolean"
|
||
|
|
|
||
|
|
return test_name, True, "Path security works"
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
return test_name, False, f"Path security failed: {str(e)}"
|
||
|
|
|
||
|
|
def test_api_response_validation(self) -> Tuple[str, bool, str]:
|
||
|
|
"""Test API response validation"""
|
||
|
|
test_name = "API Response Validation Test"
|
||
|
|
|
||
|
|
try:
|
||
|
|
import api_response_validation
|
||
|
|
|
||
|
|
# Test validation functions exist
|
||
|
|
assert hasattr(api_response_validation, 'validate_claude_response')
|
||
|
|
assert hasattr(api_response_validation, 'validate_obsidian_response')
|
||
|
|
|
||
|
|
# Test basic response validation
|
||
|
|
test_response = {"status": "success", "data": {}}
|
||
|
|
result = api_response_validation.validate_obsidian_response(test_response)
|
||
|
|
assert isinstance(result, bool), "Response validation should return boolean"
|
||
|
|
|
||
|
|
return test_name, True, "API response validation works"
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
return test_name, False, f"API response validation failed: {str(e)}"
|
||
|
|
|
||
|
|
def test_agent_core_classes(self) -> Tuple[str, bool, str]:
|
||
|
|
"""Test agent core classes can be imported"""
|
||
|
|
test_name = "Agent Core Classes Test"
|
||
|
|
|
||
|
|
try:
|
||
|
|
import agent_core
|
||
|
|
|
||
|
|
# Test core classes exist
|
||
|
|
assert hasattr(agent_core, 'Agent')
|
||
|
|
assert hasattr(agent_core, 'Command')
|
||
|
|
assert hasattr(agent_core, 'Skill')
|
||
|
|
assert hasattr(agent_core, 'SkillResult')
|
||
|
|
assert hasattr(agent_core, 'CommandContext')
|
||
|
|
|
||
|
|
# Test SkillResult can be instantiated
|
||
|
|
result = agent_core.SkillResult(success=True, message="test")
|
||
|
|
assert result.success is True
|
||
|
|
assert result.message == "test"
|
||
|
|
|
||
|
|
return test_name, True, "Agent core classes work"
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
return test_name, False, f"Agent core classes failed: {str(e)}"
|
||
|
|
|
||
|
|
def run_all_tests(self) -> List[Tuple[str, bool, str]]:
|
||
|
|
"""Run all basic functionality tests"""
|
||
|
|
logger.info("🚀 Starting basic functionality tests...")
|
||
|
|
|
||
|
|
test_methods = [
|
||
|
|
self.test_dependency_manager,
|
||
|
|
self.test_error_handling,
|
||
|
|
self.test_configuration_validation,
|
||
|
|
self.test_input_validation,
|
||
|
|
self.test_date_validation,
|
||
|
|
self.test_path_security,
|
||
|
|
self.test_api_response_validation,
|
||
|
|
self.test_agent_core_classes
|
||
|
|
]
|
||
|
|
|
||
|
|
for test_method in test_methods:
|
||
|
|
try:
|
||
|
|
logger.info(f"Running {test_method.__name__}...")
|
||
|
|
result = test_method()
|
||
|
|
self.test_results.append(result)
|
||
|
|
|
||
|
|
status = "✅ PASS" if result[1] else "❌ FAIL"
|
||
|
|
logger.info(f"{status} {result[0]}: {result[2]}")
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
error_result = (test_method.__name__, False, f"Test execution failed: {str(e)}")
|
||
|
|
self.test_results.append(error_result)
|
||
|
|
logger.error(f"❌ FAIL {error_result[0]}: {error_result[2]}")
|
||
|
|
|
||
|
|
return self.test_results
|
||
|
|
|
||
|
|
def generate_report(self) -> str:
|
||
|
|
"""Generate test report"""
|
||
|
|
total_tests = len(self.test_results)
|
||
|
|
passed_tests = sum(1 for _, success, _ in self.test_results if success)
|
||
|
|
failed_tests = total_tests - passed_tests
|
||
|
|
|
||
|
|
report = f"""
|
||
|
|
{'='*60}
|
||
|
|
BASIC FUNCTIONALITY TEST REPORT
|
||
|
|
{'='*60}
|
||
|
|
|
||
|
|
Summary:
|
||
|
|
Total Tests: {total_tests}
|
||
|
|
Passed: {passed_tests}
|
||
|
|
Failed: {failed_tests}
|
||
|
|
Success Rate: {(passed_tests/total_tests*100):.1f}%
|
||
|
|
|
||
|
|
Test Results:
|
||
|
|
"""
|
||
|
|
|
||
|
|
for test_name, success, message in self.test_results:
|
||
|
|
status = "✅ PASS" if success else "❌ FAIL"
|
||
|
|
report += f"\n{status} {test_name}: {message}"
|
||
|
|
|
||
|
|
report += f"\n\n{'='*60}\n"
|
||
|
|
|
||
|
|
return report
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
"""Main test function"""
|
||
|
|
tester = BasicFunctionalityTest()
|
||
|
|
|
||
|
|
try:
|
||
|
|
results = tester.run_all_tests()
|
||
|
|
report = tester.generate_report()
|
||
|
|
|
||
|
|
print(report)
|
||
|
|
|
||
|
|
# Return appropriate exit code
|
||
|
|
failed_count = sum(1 for _, success, _ in results if not success)
|
||
|
|
return 0 if failed_count == 0 else 1
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
logger.error(f"Test execution failed: {str(e)}")
|
||
|
|
traceback.print_exc()
|
||
|
|
return 1
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
exit_code = main()
|
||
|
|
sys.exit(exit_code)
|