Spaces:
Sleeping
Sleeping
| """ | |
| Tests for orchestrator component | |
| """ | |
| import pytest | |
| from app.core.orchestrator import Orchestrator | |
| from app.models.schemas import TaskType, Language | |
| async def orchestrator(): | |
| """Create and initialize orchestrator for testing""" | |
| orch = Orchestrator() | |
| await orch.initialize() | |
| return orch | |
| async def test_orchestrator_format_via_automata(orchestrator, unformatted_python_code): | |
| """Test orchestrator uses automata for format task""" | |
| result = await orchestrator.process( | |
| task=TaskType.FORMAT, | |
| code=unformatted_python_code, | |
| language=Language.PYTHON | |
| ) | |
| assert result["success"] is True | |
| assert result["used_automata"] is True | |
| assert result["used_slm"] is False | |
| assert "def messy_function(x, y, z):" in result["result"] | |
| async def test_orchestrator_fix_via_automata(orchestrator, buggy_python_code): | |
| """Test orchestrator uses automata for simple fix""" | |
| result = await orchestrator.process( | |
| task=TaskType.FIX, | |
| code=buggy_python_code, | |
| language=Language.PYTHON | |
| ) | |
| assert result["success"] is True | |
| assert result["used_automata"] is True | |
| # Should have fixed at least one colon | |
| assert ":" in result["result"] | |
| async def test_orchestrator_pipeline_tracking(orchestrator, sample_python_code): | |
| """Test orchestrator tracks execution pipeline""" | |
| result = await orchestrator.process( | |
| task=TaskType.FORMAT, | |
| code=sample_python_code, | |
| language=Language.PYTHON | |
| ) | |
| assert "pipeline" in result | |
| assert len(result["pipeline"]) > 0 | |
| # Check pipeline steps have required fields | |
| for step in result["pipeline"]: | |
| assert "step_type" in step | |
| assert "component" in step | |
| assert "duration_ms" in step | |
| async def test_orchestrator_valid_code_no_changes(orchestrator, sample_python_code): | |
| """Test orchestrator with already valid code""" | |
| result = await orchestrator.process( | |
| task=TaskType.FIX, | |
| code=sample_python_code, | |
| language=Language.PYTHON | |
| ) | |
| assert result["success"] is True | |
| assert "No syntax errors" in result.get("explanation", "") | |
| async def test_orchestrator_performance(orchestrator, sample_python_code): | |
| """Test orchestrator performance is within limits""" | |
| result = await orchestrator.process( | |
| task=TaskType.FORMAT, | |
| code=sample_python_code, | |
| language=Language.PYTHON | |
| ) | |
| # Automata should be fast (<100ms for simple tasks) | |
| assert result["total_duration_ms"] < 100 | |
| assert result["used_automata"] is True | |