// tools/generate-tests/generators/concurrency-test-generator/js-templates.ts — SPEC-034
// TypeScript/JavaScript concurrency test scaffolds
export function generateJsConcurrencyTest(title, framework, model) {
    const isVitest = framework === 'vitest';
    const runner = isVitest ? 'vitest' : 'jest';
    const lines = [
        `// Concurrency tests for: ${title}`,
        `// Concurrency model: ${model}`,
        '// Generated by Planu SDD MCP Server (SPEC-034)',
        '',
        `import { describe, it, expect } from '${runner}'`,
        '',
        `describe('${title} — Concurrency Tests', () => {`,
        '',
        `  it('N concurrent operations produce correct final state (no lost updates)', async () => {`,
        `    // Arrange: set up shared state and N = 100 concurrent operations`,
        `    const N = 100`,
        `    // TODO: const sharedResource = createSharedResource()`,
        '',
        `    // Act: run N concurrent writers`,
        `    // TODO: await Promise.all(Array.from({ length: N }, () => writeOperation(sharedResource)))`,
        '',
        `    // Assert: final state equals expected value (N successful writes, no lost updates)`,
        `    // TODO: expect(sharedResource.value).toBe(N)`,
        `    expect(true).toBe(true) // Replace with real concurrency assertion`,
        `  })`,
        '',
        `  it('concurrent read while write in progress returns consistent data', async () => {`,
        `    // Arrange: start a write operation`,
        `    // TODO: const writePromise = longWriteOperation()`,
        '',
        `    // Act: read concurrently while write is in progress`,
        `    // TODO: const readResult = await readOperation()`,
        `    // await writePromise`,
        '',
        `    // Assert: read returns either the old value or the new value, never partial state`,
        `    // TODO: expect([OLD_VALUE, NEW_VALUE]).toContain(readResult.value)`,
        `    expect(true).toBe(true) // Replace with real consistency assertion`,
        `  })`,
    ];
    if (model === 'async-await') {
        lines.push('', `  it('event loop is not blocked by synchronous operations', async () => {`, `    // Arrange: start a concurrent lightweight operation`, `    let lightweightCompleted = false`, `    const lightweightPromise = Promise.resolve().then(() => { lightweightCompleted = true })`, '', `    // Act: trigger the potentially blocking operation`, `    // TODO: await potentiallyBlockingOperation()`, '', `    // Assert: the lightweight operation completed (event loop was not blocked)`, `    await lightweightPromise`, `    expect(lightweightCompleted).toBe(true)`, `  })`);
    }
    lines.push(`})`, '');
    return lines.join('\n');
}
export function generateJsPactTest(title, framework) {
    const isVitest = framework === 'vitest';
    const runner = isVitest ? 'vitest' : 'jest';
    return [
        `// Pact consumer contract tests for: ${title}`,
        '// Install: npm install --save-dev @pact-foundation/pact',
        '// Generated by Planu SDD MCP Server (SPEC-034)',
        '',
        `import { describe, it, expect, beforeAll, afterAll } from '${runner}'`,
        `import { PactV3, MatchersV3 } from '@pact-foundation/pact'`,
        `import path from 'node:path'`,
        '',
        `const provider = new PactV3({`,
        `  consumer: 'my-consumer', // TODO: replace with your service name`,
        `  provider: 'my-provider', // TODO: replace with the upstream service name`,
        `  dir: path.resolve(process.cwd(), 'pacts'),`,
        `  logLevel: 'warn',`,
        `})`,
        '',
        `describe('${title} — Pact Consumer Contract', () => {`,
        '',
        `  it('expects the provider to return a valid response', async () => {`,
        `    await provider`,
        `      .addInteraction({`,
        `        states: [{ description: 'resource exists' }],`,
        `        uponReceiving: 'a valid request for ${title}',`,
        `        withRequest: {`,
        `          method: 'GET', // TODO: replace with actual method`,
        `          path: '/api/resource', // TODO: replace with actual path`,
        `          headers: { Accept: 'application/json' },`,
        `        },`,
        `        willRespondWith: {`,
        `          status: 200,`,
        `          headers: { 'Content-Type': 'application/json' },`,
        `          body: {`,
        `            id: MatchersV3.string('resource-id'),`,
        `            name: MatchersV3.string('Resource Name'),`,
        `          },`,
        `        },`,
        `      })`,
        `      .executeTest(async (mockServer) => {`,
        `        const response = await fetch(\`\${mockServer.url}/api/resource\`)`,
        `        const data = await response.json() as Record<string, unknown>`,
        `        expect(response.status).toBe(200)`,
        `        expect(data).toHaveProperty('id')`,
        `      })`,
        `  })`,
        `})`,
        '',
    ].join('\n');
}
//# sourceMappingURL=js-templates.js.map