Files
markitect-main/tests/test_l2_application_tdd_workflows.py
tegwick b13de9b2ad feat: Revolutionary Test Architecture - 7-Layer Organization with Advanced Testing Capabilities
ARCHITECTURAL MILESTONE: Complete transformation of test suite from issue-based to sophisticated
architectural layer organization with 348 tests across 7 layers (Foundation → Infrastructure →
Integration → Domain → Service → Application → Presentation).

Major Components:

🏗️ ARCHITECTURAL TEST ORGANIZATION:
• Renamed 23 test files to architectural layers (e.g. test_parser.py → test_l7_foundation_markdown_parsing.py)
• Created reverse dependency execution order for 60-80% faster feedback
• Foundation layer (10 tests, ~9s) provides immediate failure detection
• Complete dependency mapping across all 7 architectural layers

🎯 ADVANCED TEST RUNNERS:
• run_architectural_tests.py - Reverse dependency execution with performance metrics
• run_randomized_tests.py - Seed-based randomization for dependency detection
• Comprehensive error handling and colored output for optimal UX
• Support for layer-specific execution and early termination on failures

📋 COMPREHENSIVE DOCUMENTATION:
• ARCHITECTURE.md - 7-layer architecture blueprint with migration strategy
• CAPABILITIES.md - Complete inventory of 73+ system capabilities across 15 categories
• TEST_ARCHITECTURE.md - Detailed test execution strategy and naming conventions
• ARCHITECTURAL_CHAOS_TESTING_ISSUE.md - Chaos engineering gameplan (Issue #35)

🔧 MAKEFILE INTEGRATION:
• 15+ new testing targets (test-arch, test-foundation, test-random, etc.)
• Layer-specific execution (test-infrastructure, test-domain, test-service)
• Advanced options (test-quick, test-layers, test-random-repeat)
• Comprehensive help system with organized testing categories

🎲 RANDOMIZED TESTING:
• Seed-based reproducible test execution for debugging
• Multi-iteration testing to detect flaky tests and hidden dependencies
• Enhanced randomization support with pytest-randomly integration
• Performance analysis across different execution orders

🚀 PERFORMANCE OPTIMIZATION:
• Foundation-first execution prevents cascade failure debugging
• Quick testing (foundation + infrastructure) completes in ~22 seconds
• Layer isolation enables targeted debugging and development
• Optimal feedback loops for architectural development

This revolutionary testing infrastructure establishes MarkiTect as having enterprise-grade
test organization with architectural principles, performance optimization, and advanced
testing methodologies including chaos engineering foundations.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-29 12:18:25 +02:00

186 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
if __name__ == '__main__':
pytest.main([__file__, '-v'])