Files
markitect-main/tests/test_l2_application_tdd_workflows.py
tegwick 1358ca17ec
Some checks failed
Test Suite / unit-tests (3.11) (push) Has been cancelled
Test Suite / unit-tests (3.12) (push) Has been cancelled
Test Suite / integration-tests (push) Has been cancelled
Test Suite / e2e-tests (push) Has been cancelled
Test Suite / performance-tests (push) Has been cancelled
Test Suite / code-quality (push) Has been cancelled
Test Suite / security-scan (push) Has been cancelled
Test Suite / test-summary (push) Has been cancelled
refactor: Remove circular test dependencies and meta-testing anti-patterns
Clean up test infrastructure by removing problematic tests that create
circular dependencies and execute the test suite from within tests.

Key removals:
- Delete test_issue_57_test_efficiency_improvements.py entirely (12 tests)
  - Contained tests that ran `make test-tdd`, `make test-status` etc.
  - Created circular dependencies where tests execute the entire test suite
  - Violated separation of concerns between testing and test infrastructure

- Remove self-execution blocks from 11 test files
  - Eliminated `if __name__ == '__main__': pytest.main([__file__, '-v'])` patterns
  - Prevents confusion and potential circular execution paths
  - Test files should be run via pytest, not as standalone scripts

Test Infrastructure Improvements:
- Reduced test count from 701 to 689 tests (removed 12 problematic tests)
- Eliminated subprocess calls to `make test-*` commands from within tests
- Removed `pytest.main()` calls that could cause circular execution
- Maintained clean separation between test infrastructure and actual tests

Impact:
- No more tests testing tests (circular dependency elimination)
- Cleaner test execution without subprocess complexity
- Proper test isolation and independence
- Faster and more reliable test runs

The proper way to test infrastructure is to test the underlying functions
directly, not to execute the entire test suite from within a test.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-01 21:05:36 +02:00

185 lines
6.6 KiB
Python

"""
Test TDD workflow integration for Issue #11: Setup TDD workspace infrastructure
This test validates the complete TDD workflow from workspace creation through
test generation to completion and cleanup.
Issue Reference: #11 - Setup TDD workspace infrastructure
"""
import pytest
import os
import subprocess
import tempfile
import shutil
from pathlib import Path
from unittest.mock import patch, MagicMock
from tddai.config import TddaiConfig
from tddai.workspace import WorkspaceStatus
class TestTDDWorkflowIntegration:
"""Test complete TDD workflow integration."""
def setup_method(self):
"""Set up test environment."""
self.original_cwd = os.getcwd()
self.test_dir = tempfile.mkdtemp()
os.chdir(self.test_dir)
def teardown_method(self):
"""Clean up test environment."""
os.chdir(self.original_cwd)
if os.path.exists(self.test_dir):
shutil.rmtree(self.test_dir)
@patch('tddai.IssueFetcher.fetch_issue')
def test_complete_tdd_workflow_cycle(self, mock_fetch):
"""Test the complete TDD workflow from start to finish."""
# Arrange
mock_fetch.return_value = {
'number': 11,
'title': 'Setup TDD workspace infrastructure',
'body': 'Complete workflow test',
'state': 'open'
}
# Simulate the make commands workflow
from tddai import WorkspaceManager
config = TddaiConfig(workspace_dir=Path('.markitect_workspace'))
workspace_manager = WorkspaceManager(config)
# Act & Assert - Workspace Creation
issue_data = mock_fetch.return_value
workspace = workspace_manager.create_workspace(issue_data)
assert workspace.issue_dir.exists()
# Act & Assert - Status Check
status = workspace_manager.get_workspace_status()
assert status == WorkspaceStatus.ACTIVE
# Act & Assert - Test Generation (simulate multiple tests)
test_files = [
'test_issue_11_basic.py',
'test_issue_11_advanced.py'
]
for test_file in test_files:
workspace_manager.add_test_to_workspace(test_file, f'# Test file: {test_file}\ndef test_example(): pass')
# Verify tests are created
status = workspace_manager.get_workspace_status()
assert status == WorkspaceStatus.ACTIVE
# Act & Assert - Workspace Completion
main_tests_dir = Path('tests')
main_tests_dir.mkdir(exist_ok=True)
workspace_manager.finish_workspace()
# Verify tests moved to main
for test_file in test_files:
main_test_path = main_tests_dir / test_file
assert main_test_path.exists()
# Verify workspace cleaned up
final_status = workspace_manager.get_workspace_status()
assert final_status == WorkspaceStatus.CLEAN
def test_workspace_git_exclusion(self):
"""Test that workspace files are properly excluded from git."""
# Arrange
gitignore_path = Path('.gitignore')
gitignore_content = """
# MarkiTect issue workspace (temporary development files)
.markitect_workspace/
"""
gitignore_path.write_text(gitignore_content)
# Create workspace directory
workspace_dir = Path('.markitect_workspace')
workspace_dir.mkdir()
test_file = workspace_dir / 'test_file.py'
test_file.write_text('# Test content')
# Act - Check git status would ignore workspace files
# This simulates what git status would show
gitignore_patterns = ['.markitect_workspace/']
# Assert
assert any(str(test_file).startswith(pattern.rstrip('/')) for pattern in gitignore_patterns)
@patch('subprocess.run')
def test_makefile_integration_commands(self, mock_run):
"""Test that Makefile commands integrate properly with workspace system."""
# Arrange
mock_run.return_value = MagicMock(returncode=0, stdout='Success', stderr='')
# Act & Assert - Test make tdd-start command integration
from tddai_cli import main as cli_main
# Simulate CLI call for tdd-start
with patch('sys.argv', ['tddai_cli.py', 'start-issue', '11']):
with patch('tddai.IssueFetcher.fetch_issue') as mock_fetch:
mock_fetch.return_value = {
'number': 11,
'title': 'Setup TDD workspace infrastructure',
'body': 'Makefile integration test',
'state': 'open'
}
# This would normally create workspace
# Just verify the CLI interface works
assert callable(cli_main)
def test_error_handling_invalid_workflow_states(self):
"""Test error handling for invalid workflow states."""
from tddai import WorkspaceManager, WorkspaceError
config = TddaiConfig(workspace_dir=Path('.markitect_workspace'))
workspace_manager = WorkspaceManager(config)
# Test adding test without workspace
with pytest.raises(WorkspaceError, match="No active workspace"):
workspace_manager.add_test_to_workspace("test_file.py", "test content")
# Test finishing workspace without workspace (should return None, not raise)
result = workspace_manager.finish_workspace()
assert result is None
# Test getting status without workspace
status = workspace_manager.get_workspace_status()
assert status == WorkspaceStatus.CLEAN
def test_workspace_status_monitoring_accuracy(self):
"""Test that workspace status monitoring provides accurate information."""
# Arrange
from tddai import WorkspaceManager
config = TddaiConfig(workspace_dir=Path('.markitect_workspace'))
workspace_manager = WorkspaceManager(config)
issue_data = {
'number': 11,
'title': 'Setup TDD workspace infrastructure',
'body': 'Status monitoring test',
'state': 'open'
}
# Act
workspace = workspace_manager.create_workspace(issue_data)
# Add some test files using the WorkspaceManager method
test_files = ['test_a.py', 'test_b.py', 'test_c.py']
for test_file in test_files:
workspace_manager.add_test_to_workspace(test_file, f'# {test_file}')
status = workspace_manager.get_workspace_status()
# Assert
assert status == WorkspaceStatus.ACTIVE
# Check that test files were actually created
assert workspace.tests_dir.exists()
created_files = list(workspace.tests_dir.glob("*.py"))
assert len(created_files) == 3