// tools/generate-tests/generators/concurrency-test-generator/python-rust-templates.ts — SPEC-034
// Python and Rust concurrency test scaffolds + Python Pact
import { sanitizePythonName } from './utils.js';
export function generatePythonConcurrencyTest(title) {
    return [
        `# Concurrency tests for: ${title}`,
        '# Generated by Planu SDD MCP Server (SPEC-034)',
        '',
        'import asyncio',
        'import pytest',
        '',
        `class Test${sanitizePythonName(title)}Concurrency:`,
        '',
        '    @pytest.mark.asyncio',
        '    async def test_n_concurrent_operations_correct_state(self):',
        '        """N concurrent async operations produce correct final state."""',
        '        N = 100',
        '        results = []',
        '',
        '        async def operation(i: int) -> None:',
        '            # TODO: replace with your actual async operation',
        '            results.append(i)',
        '',
        '        await asyncio.gather(*[operation(i) for i in range(N)])',
        '        assert len(results) == N, f"Expected {N} results, got {len(results)}"',
        '',
        '    @pytest.mark.asyncio',
        '    async def test_event_loop_not_blocked(self):',
        '        """A lightweight coroutine completes even when heavier work runs concurrently."""',
        '        lightweight_done = False',
        '',
        '        async def lightweight() -> None:',
        '            nonlocal lightweight_done',
        '            await asyncio.sleep(0)',
        '            lightweight_done = True',
        '',
        '        await asyncio.gather(',
        '            lightweight(),',
        '            # TODO: add your potentially-blocking operation here',
        '        )',
        '        assert lightweight_done, "Event loop was blocked"',
    ].join('\n');
}
export function generateRustConcurrencyTest(title) {
    return [
        `// Concurrency tests for: ${title}`,
        '// Note: Rust compile-time guarantees prevent data races.',
        '// These tests verify logical correctness and deadlock-free behavior.',
        '// Generated by Planu SDD MCP Server (SPEC-034)',
        '',
        '#[cfg(test)]',
        'mod concurrency_tests {',
        '    use std::sync::{Arc, Mutex};',
        '    use std::thread;',
        `    use tokio::time::{timeout, Duration};`,
        '',
        '    #[test]',
        '    fn n_threads_produce_correct_final_state() {',
        '        let counter = Arc::new(Mutex::new(0i64));',
        '        let mut handles = vec![];',
        '',
        '        for _ in 0..100 {',
        '            let counter = Arc::clone(&counter);',
        '            handles.push(thread::spawn(move || {',
        '                let mut val = counter.lock().unwrap();',
        '                *val += 1;',
        '                // TODO: replace with your actual operation',
        '            }));',
        '        }',
        '',
        '        for h in handles { h.join().unwrap(); }',
        '',
        '        let final_val = *counter.lock().unwrap();',
        '        assert_eq!(final_val, 100, "Lost updates detected");',
        '    }',
        '',
        '    #[tokio::test]',
        '    async fn mutex_acquisition_does_not_deadlock() {',
        '        let mutex = Arc::new(tokio::sync::Mutex::new(0i32));',
        '',
        '        let result = timeout(Duration::from_secs(5), async {',
        '            let mut guard = mutex.lock().await;',
        '            *guard += 1;',
        '            // TODO: replace with your actual async operation',
        '        }).await;',
        '',
        '        assert!(result.is_ok(), "Deadlock detected: mutex not acquired within 5 seconds");',
        '    }',
        '}',
        '',
    ].join('\n');
}
export function generatePythonPactTest(title) {
    return [
        `# Pact consumer contract tests for: ${title}`,
        '# Install: pip install pact-python',
        '# Generated by Planu SDD MCP Server (SPEC-034)',
        '',
        'import pytest',
        'from pact import Consumer, Provider',
        '',
        `PACT_CONSUMER = '${sanitizePythonName(title).toLowerCase()}-consumer'`,
        `PACT_PROVIDER = '${sanitizePythonName(title).toLowerCase()}-provider'`,
        '',
        `@pytest.fixture(scope='module')`,
        'def pact():',
        '    pact = Consumer(PACT_CONSUMER).has_pact_with(',
        '        Provider(PACT_PROVIDER),',
        `        pact_dir='./pacts',`,
        '    )',
        '    pact.start_service()',
        '    yield pact',
        '    pact.stop_service()',
        '',
        `def test_consumer_contract(pact):`,
        `    """Consumer defines what it expects from the provider."""`,
        `    (pact`,
        `        .given('resource exists')`,
        `        .upon_receiving('a valid GET request')`,
        `        .with_request('GET', '/api/resource')`,
        `        .will_respond_with(200, body={'id': '1', 'name': 'Resource'})`,
        `    )`,
        '',
        `    with pact:`,
        `        # TODO: call your client with the pact mock URL`,
        `        pass  # assert response shape here`,
    ].join('\n');
}
//# sourceMappingURL=python-rust-templates.js.map