"""Unit tests for concurrency control."""

import pytest

from mahavishnu.core.app import MahavishnuApp
from mahavishnu.core.config import MahavishnuSettings


@pytest.mark.asyncio
async def test_semaphore_initialization():
    """Test that semaphore is initialized with correct concurrency limit."""
    config = MahavishnuSettings(max_concurrent_workflows=5)
    app = MahavishnuApp(config)

    # Check that the semaphore was initialized with the correct value
    assert app.semaphore._value == 5  # Note: This is implementation-specific


@pytest.mark.asyncio
async def test_concurrent_workflow_limiting():
    """Test that concurrent workflow execution respects the limit."""
    # This test would require mocking the adapter execution to be meaningful
    # For now, we'll just verify the semaphore exists and has the right initial value
    config = MahavishnuSettings(max_concurrent_workflows=3)
    app = MahavishnuApp(config)

    assert app.config.max_concurrent_workflows == 3


@pytest.mark.asyncio
async def test_get_active_workflows():
    """Test retrieving active workflows."""
    config = MahavishnuSettings()
    app = MahavishnuApp(config)

    # Initially, no active workflows
    active_workflows = await app.get_active_workflows()
    assert active_workflows == []

    # Verify it returns a list (even if empty)
    assert isinstance(active_workflows, list)
