fix: Resolve failing tests after CLI and error handling refactoring

Fix all test failures introduced by recent architectural changes:

• Issue Creator Tests:
  - Fixed mock API responses to include required fields (created_at, updated_at, html_url)
  - Added input validation for empty titles back to issue creator
  - Updated test expectations to match new error handling patterns
  - Created helper function for complete mock responses

• Issue Fetcher Test:
  - Updated mock target from tddai.issue_fetcher.subprocess to gitea.http_client.subprocess
  - Fixed test assertions to match new error handling with specific exception chaining
  - Test now properly validates API error translation

• Makefile Integration Test:
  - Implemented lazy initialization in tddai_cli.py to prevent import-time configuration errors
  - Replaced eager CLI framework initialization with _get_cli() lazy pattern
  - Preserves normal CLI functionality while fixing test environment compatibility

• Result: All 171 tests now pass (169 passed, 2 skipped)
• Maintains backward compatibility of CLI interface
• Validates that refactored error handling works correctly

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-26 17:15:36 +02:00
parent 235e6831ed
commit 6713768ea6
4 changed files with 71 additions and 33 deletions

View File

@@ -25,6 +25,18 @@ class TestIssueCreator:
repo_name="test_repo"
)
def _get_complete_mock_response(self, number: int, title: str = "Test Issue", body: str = "Test description"):
"""Get a complete mock API response with all required fields."""
return {
"number": number,
"title": title,
"body": body,
"state": "open",
"created_at": "2025-09-26T10:00:00Z",
"updated_at": "2025-09-26T10:00:00Z",
"html_url": f"http://gitea.example.com/repo/issues/{number}"
}
def test_init_with_auth_token(self):
"""Test IssueCreator initialization with auth token."""
config = self._get_test_config()
@@ -62,7 +74,10 @@ class TestIssueCreator:
"number": 123,
"title": "Test Issue",
"body": "Test description",
"state": "open"
"state": "open",
"created_at": "2025-09-26T10:00:00Z",
"updated_at": "2025-09-26T10:00:00Z",
"html_url": "http://gitea.example.com/repo/issues/123"
}
mock_run.return_value = MagicMock(
@@ -73,7 +88,19 @@ class TestIssueCreator:
result = creator.create_issue("Test Issue", "Test description")
assert result == mock_response
# Verify the result has the expected structure (transformed by issue creator)
expected_result = {
'number': 123,
'title': "Test Issue",
'body': "Test description",
'state': "open",
'html_url': "http://gitea.example.com/repo/issues/123",
'created_at': "2025-09-26T10:00:00", # ISO format from datetime parsing
'updated_at': "2025-09-26T10:00:00",
'assignee': None,
'labels': []
}
assert result == expected_result
mock_run.assert_called_once()
# Check curl command structure
@@ -144,7 +171,7 @@ class TestIssueCreator:
stderr=""
)
with pytest.raises(IssueError, match="Failed to parse response data"):
with pytest.raises(IssueError, match="Failed to create issue.*parse.*response"):
creator.create_issue("Test Issue", "Test description")
@patch('subprocess.run')
@@ -153,7 +180,7 @@ class TestIssueCreator:
config = self._get_test_config()
creator = IssueCreator(config=config, auth_token="test-token")
mock_response = {"number": 124}
mock_response = self._get_complete_mock_response(124)
mock_run.return_value = MagicMock(
returncode=0,
stdout=json.dumps(mock_response),
@@ -183,7 +210,7 @@ class TestIssueCreator:
config = self._get_test_config()
creator = IssueCreator(config=config, auth_token="test-token")
mock_response = {"number": 125}
mock_response = self._get_complete_mock_response(125)
mock_run.return_value = MagicMock(
returncode=0,
stdout=json.dumps(mock_response),
@@ -218,7 +245,7 @@ class TestIssueCreator:
config = self._get_test_config()
creator = IssueCreator(config=config, auth_token="test-token")
mock_response = {"number": 126}
mock_response = self._get_complete_mock_response(126)
mock_run.return_value = MagicMock(
returncode=0,
stdout=json.dumps(mock_response),
@@ -255,7 +282,7 @@ class TestIssueCreator:
config = self._get_test_config()
creator = IssueCreator(config=config, auth_token="test-token")
mock_response = {"number": 127}
mock_response = self._get_complete_mock_response(127)
mock_run.return_value = MagicMock(
returncode=0,
stdout=json.dumps(mock_response),