import { readFileSync } from 'node:fs'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const root = dirname(dirname(fileURLToPath(import.meta.url))); const read = rel => readFileSync(join(root, rel), 'utf8'); const failures = []; const expect = (text, marker, label = marker) => { if (!text.includes(marker)) failures.push(`Fehlt: ${label}`); }; const pkg = JSON.parse(read('package.json')); const server = read('server.mjs'); const fluxJobs = read('lib/ai-flux-prompt-jobs.mjs'); const fluxModule = read('app/modules/flux-studio/index.mjs'); const ci = read('.github/workflows/ci.yml'); const release = read('.github/workflows/release.yml'); if (pkg.version !== '1.43.0') failures.push(`package.json-Version ist ${pkg.version}`); expect(server, 'startFluxPromptJobLoop, stopFluxPromptJobLoop', 'Server importiert Start- und Stop-Funktion'); expect(server, 'configureFluxStudioModule({ start: startFluxPromptJobLoop, stop: stopFluxPromptJobLoop })', 'FLUX-Lifecycle ist vollständig verdrahtet'); expect(fluxJobs, 'export function stopFluxPromptJobLoop()', 'fehlender Stop-Export'); expect(fluxJobs, 'if (loopTimer) clearInterval(loopTimer);', 'Intervall wird beim Stoppen beendet'); expect(fluxJobs, 'loopTimer = null;', 'Loop-Zustand wird zurückgesetzt'); expect(fluxJobs, 'export function startFluxPromptJobLoop()', 'Start-Export bleibt vorhanden'); expect(fluxJobs, 'if (loopTimer) return;', 'Start bleibt idempotent'); expect(fluxModule, 'async stop() { runtime?.stop(); started = false; }', 'Modul-Lifecycle ruft Stop auf'); expect(ci, 'npm run verify:esm-exports', 'CI prüft ESM-Exportverträge'); expect(ci, 'npm run verify:flux-loop', 'CI prüft FLUX-Hotfix'); expect(release, 'npm run verify:esm-exports', 'Release prüft ESM-Exportverträge'); expect(release, 'npm run verify:flux-loop', 'Release prüft FLUX-Hotfix'); if (failures.length) { console.error(`FLUX-Loop-Hotfix-Gate 1.43.0 fehlgeschlagen (${failures.length}):`); failures.forEach(item => console.error(`- ${item}`)); process.exit(1); } console.log('FLUX-Loop-Hotfix-Gate 1.43.0 erfolgreich: Stop-Export, Lifecycle-Verdrahtung und CI-Verträge geprüft.');