// engine/test-scaffold-generator/unit-scaffold.ts — Unit test scaffold generators
// SPEC-018
import { generateMockCode, criteriaContainsMockKeyword } from '../test-mocks-generator.js';
import { toPascal, toSnake, getFrameworkExt, getFrameworkRunCommand } from './helpers.js';
// === Unit test scaffold ===
/**
 * Generate a unit test scaffold for a given spec title and framework.
 */
export function generateUnitTestScaffold(specTitle, specCriteria, framework) {
    const content = buildUnitContent(specTitle, specCriteria, framework);
    const ext = getFrameworkExt(framework);
    const runCommand = getFrameworkRunCommand(framework);
    return {
        filepath: `tests/unit/${toSnake(specTitle)}.test.${ext}`,
        content,
        framework,
        testType: 'unit',
        runCommand,
    };
}
function buildUnitContent(title, criteria, framework) {
    const base = buildBaseUnitContent(title, criteria, framework);
    if (!criteriaContainsMockKeyword(criteria)) {
        return base;
    }
    const mockExample = generateMockCode(framework, [`${title.replace(/\s+/g, '')}Service`], title);
    return `${base}\n// === Mock example for this spec ===\n${mockExample}`;
}
function buildBaseUnitContent(title, criteria, framework) {
    if (framework === 'pytest') {
        return buildPytestUnit(title, criteria);
    }
    if (framework === 'junit') {
        return buildJunitUnit(title, criteria);
    }
    return buildJsUnit(title, criteria, framework);
}
function buildJsUnit(title, criteria, framework) {
    const importLine = framework === 'vitest'
        ? "import { describe, it } from 'vitest';"
        : "import { describe, it } from '@jest/globals';";
    const tests = criteria
        .map((c) => `  it.skip('${c}', () => {\n    throw new Error('Bind this criterion to implementation evidence before enabling.');\n  });`)
        .join('\n\n');
    return `${importLine}\n\ndescribe('${title}', () => {\n${tests}\n});\n`;
}
function buildPytestUnit(title, criteria) {
    const cls = toPascal(title);
    const methods = criteria
        .map((c) => `    @pytest.mark.skip(reason="Bind this criterion to implementation evidence before enabling.")\n    def test_${toSnake(c)}(self):\n        """${c}"""\n        raise AssertionError("Bind this criterion to implementation evidence before enabling.")`)
        .join('\n\n');
    return `import pytest\n\n\nclass Test${cls}:\n    """Unit tests for ${title}."""\n\n${methods}\n`;
}
function buildJunitUnit(title, criteria) {
    const cls = toPascal(title);
    const methods = criteria
        .map((c) => `    @Test\n    @Disabled("Bind this criterion to implementation evidence before enabling.")\n    void ${toSnake(c).replace(/_([a-z])/g, (_, l) => l.toUpperCase())}() {\n        fail("Bind this criterion to implementation evidence before enabling: ${c}");\n    }`)
        .join('\n\n');
    return `import org.junit.jupiter.api.Disabled;\nimport org.junit.jupiter.api.Test;\nimport static org.junit.jupiter.api.Assertions.*;\n\nclass ${cls}Test {\n\n${methods}\n}\n`;
}
// === Integration test scaffold ===
/**
 * Generate an integration test scaffold.
 */
export function generateIntegrationTestScaffold(specTitle, framework) {
    const ext = getFrameworkExt(framework);
    const runCommand = getFrameworkRunCommand(framework);
    const content = buildIntegrationContent(specTitle, framework);
    return {
        filepath: `tests/integration/${toSnake(specTitle)}.integration.test.${ext}`,
        content,
        framework,
        testType: 'integration',
        runCommand,
    };
}
function buildIntegrationContent(title, framework) {
    if (framework === 'pytest') {
        const cls = toPascal(title);
        return `import pytest\n\n\nclass Test${cls}Integration:\n    """Integration tests for ${title}."""\n\n    @pytest.mark.skip(reason="Bind integration boundaries before enabling.")\n    def test_declared_integration_boundary(self):\n        raise AssertionError("Bind integration boundaries before enabling.")\n`;
    }
    const importLine = framework === 'vitest'
        ? "import { describe, it } from 'vitest';"
        : "import { describe, it } from '@jest/globals';";
    return `${importLine}\n\ndescribe('${title} — Integration', () => {\n  it.skip('declared integration boundary is verified', async () => {\n    throw new Error('Bind integration boundaries before enabling.');\n  });\n});\n`;
}
//# sourceMappingURL=unit-scaffold.js.map