"use strict";
/**
 * E2E Smoke Test: File Generation
 *
 * This test verifies that the code generation process actually writes files to disk.
 * It catches bugs like the v0.4.1 issue where generators returned relative paths
 * and files weren't being written.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const generation_orchestrator_1 = require("../generators/generation-orchestrator");
describe('E2E: File Generation Smoke Test', () => {
    const testOutputDir = path.join(__dirname, '../../.e2e-output/file-generation-smoke');
    let orchestrator;
    beforeEach(() => {
        // Clean up test directory before each test
        if (fs.existsSync(testOutputDir)) {
            fs.rmSync(testOutputDir, { recursive: true, force: true });
        }
        orchestrator = new generation_orchestrator_1.GenerationOrchestrator();
    });
    afterEach(() => {
        // Clean up test directory after each test
        if (fs.existsSync(testOutputDir)) {
            fs.rmSync(testOutputDir, { recursive: true, force: true });
        }
    });
    it('should actually write files to disk with absolute paths', async () => {
        // Create a minimal workflow for testing
        const minimalWorkflow = {
            workflow: {
                id: 'e2e-smoke-test',
                version: '1.0.0',
                name: 'E2E Smoke Test',
                description: 'Minimal workflow for E2E testing',
            },
            stack: {
                api: {
                    type: 'backend',
                    technology: 'typescript/express',
                    config: { port: 3000 },
                },
            },
            stages: {
                local: {
                    infrastructure: {
                        databases: {},
                        services: {},
                    },
                },
            },
        };
        // Generate code
        const result = await orchestrator.generate(minimalWorkflow, {
            outputDirectory: testOutputDir,
            dryRun: false,
            verbose: false,
        });
        // Verify files were actually generated
        expect(result.files.length).toBeGreaterThan(0);
        // Verify all returned paths are absolute
        result.files.forEach(file => {
            expect(path.isAbsolute(file.path)).toBe(true);
        });
        // Verify files actually exist on disk
        const filesOnDisk = [];
        result.files.forEach(file => {
            if (fs.existsSync(file.path)) {
                filesOnDisk.push(file.path);
            }
        });
        // At least some files should exist (this catches the v0.4.1 bug)
        expect(filesOnDisk.length).toBeGreaterThan(0);
        // Verify the files are in the correct directory
        filesOnDisk.forEach(filePath => {
            expect(filePath.startsWith(testOutputDir)).toBe(true);
        });
        // Verify files written count matches
        expect(result.written.length).toBeGreaterThan(0);
    });
    it('should write files with content matching returned data', async () => {
        const workflow = {
            workflow: {
                id: 'content-test',
                version: '1.0.0',
                name: 'Content Test',
            },
            stack: {
                api: {
                    type: 'backend',
                    technology: 'typescript/express',
                    config: { port: 3000 },
                },
            },
            stages: {
                local: {
                    infrastructure: {
                        databases: {},
                        services: {},
                    },
                },
            },
        };
        const result = await orchestrator.generate(workflow, {
            outputDirectory: testOutputDir,
            dryRun: false,
            verbose: false,
        });
        // Verify at least one file was written
        expect(result.written.length).toBeGreaterThan(0);
        // Pick the first file and verify content matches
        const firstFile = result.files[0];
        if (fs.existsSync(firstFile.path)) {
            const fileContent = fs.readFileSync(firstFile.path, 'utf-8');
            expect(fileContent).toBe(firstFile.content);
        }
    });
});
//# sourceMappingURL=file-generation-smoke.test.js.map