from unittest.mock import Mock from pr_review.database import ( DatabasePRWaiter, DatabasePromptBuilder, DatabasePRAnalyzer, ) class TestDatabasePRWaiter: def test_wait_for_analysis_ready_immediate(self): """Test that database waiter returns immediately.""" mock_github_client = Mock() pr_data = { 'diff': [], 'comments': [], 'pr_title': 'Add migration', 'pr_body': 'Test migration', } mock_github_client.get_pr_details.return_value = pr_data waiter = DatabasePRWaiter() result = waiter.wait_for_analysis_ready(mock_github_client, 123, 600) assert result == pr_data mock_github_client.get_pr_details.assert_called_once_with(123) class TestDatabasePromptBuilder: def test_build_prompt(self): """Test building database migration prompt.""" builder = DatabasePromptBuilder() pr_data = { 'pr_title': 'Add user table migration', 'pr_body': 'This PR adds a new user table with Liquibase migration', 'diff': [ { 'filename': 'changelog/001-create-user-table.xml', 'patch': 'added table', } ], 'comments': [ {'body': 'Migration looks good'}, {'body': 'Check rollback strategy'}, ], } result = builder.build_prompt(pr_data) assert 'Add user table migration' in result assert 'This PR adds a new user table with Liquibase migration' in result assert 'Migration looks good' in result assert 'Check rollback strategy' in result assert 'Database Migration Review Prompt' in result assert 'Migration Safety & Data Integrity' in result assert 'Liquibase/Liquigraph Best Practices' in result class TestDatabasePRAnalyzer: def test_post_process_analysis(self): """Test header de-emphasis.""" mock_github_client = Mock() mock_llm_client = Mock() mock_prompt_builder = Mock() mock_pr_waiter = Mock() analyzer = DatabasePRAnalyzer( mock_github_client, mock_llm_client, mock_prompt_builder, mock_pr_waiter ) analysis = '# Header 1\n## Header 2\n### Header 3\n#### Header 4' result = analyzer.post_process_analysis(analysis) expected = '#### Header 1\n#### Header 2\n#### Header 3\n#### Header 4' assert result == expected