// tools/generate-tests/generators/concurrency-test-generator/go-templates.ts — SPEC-034
// Go concurrency test scaffolds (goroutines + race detector)
import { sanitizeGoName } from './utils.js';
export function generateGoConcurrencyTest(title) {
    return [
        `// Concurrency tests for: ${title}`,
        '// Run with: go test -race -timeout 30s',
        '// Generated by Planu SDD MCP Server (SPEC-034)',
        '',
        'package concurrency_test',
        '',
        'import (',
        '\t"sync"',
        '\t"sync/atomic"',
        '\t"testing"',
        '\t"time"',
        ')',
        '',
        `func Test${sanitizeGoName(title)}_RaceCondition(t *testing.T) {`,
        '\t// Arrange: N goroutines will increment a shared counter',
        '\tconst N = 100',
        '\tvar counter int64',
        '\tvar wg sync.WaitGroup',
        '',
        '\t// Act: start N goroutines that increment atomically',
        '\tfor i := 0; i < N; i++ {',
        '\t\twg.Add(1)',
        '\t\tgo func() {',
        '\t\t\tdefer wg.Done()',
        '\t\t\tatomic.AddInt64(&counter, 1)',
        '\t\t\t// TODO: replace with your actual concurrent operation',
        '\t\t}()',
        '\t}',
        '\twg.Wait()',
        '',
        '\t// Assert: all increments were applied (no lost updates)',
        '\tif got := atomic.LoadInt64(&counter); got != N {',
        '\t\tt.Errorf("expected %d, got %d (lost updates detected)", N, got)',
        '\t}',
        '}',
        '',
        `func Test${sanitizeGoName(title)}_DeadlockTimeout(t *testing.T) {`,
        '\t// Test that lock acquisition does not deadlock — timeout after 5 seconds',
        '\tdone := make(chan struct{})',
        '',
        '\tgo func() {',
        '\t\t// TODO: perform the operation that could deadlock',
        '\t\t// mu.Lock(); defer mu.Unlock(); doWork()',
        '\t\tclose(done)',
        '\t}()',
        '',
        '\tselect {',
        '\tcase <-done:',
        '\t\t// OK: operation completed without deadlock',
        '\tcase <-time.After(5 * time.Second):',
        '\t\tt.Fatal("deadlock detected: operation did not complete within 5 seconds")',
        '\t}',
        '}',
        '',
    ].join('\n');
}
//# sourceMappingURL=go-templates.js.map