const fs = require('fs'); const path = require('path'); const { spawnSync } = require('child_process'); const sqliteDb = process.env.SQLITE_RESULTS_DB || 'results/uat_vapt_results.sqlite'; const outPath = 'results/merged-results.json'; function exportFromSqliteIfAvailable() { if (!fs.existsSync(sqliteDb)) return false; const result = spawnSync('python3', ['scripts/sqlite_db.py', '--db', sqliteDb, '--output', outPath, 'export-json'], { cwd: process.cwd(), encoding: 'utf8', env: process.env, }); if (result.status === 0) { console.log((result.stdout || '').trim()); console.log(`Wrote ${outPath} from SQLite database ${sqliteDb}`); return true; } console.warn('SQLite export failed, falling back to Playwright JSON:', result.stderr || result.stdout); return false; } if (exportFromSqliteIfAvailable()) process.exit(0); const matrix = JSON.parse(fs.readFileSync('data/generated-test-matrix.json','utf8')); const resultPath = 'results/playwright-results.json'; let results = {}; if (fs.existsSync(resultPath)) { const raw = JSON.parse(fs.readFileSync(resultPath,'utf8')); function walk(suite) { for (const spec of suite.specs || []) { for (const test of spec.tests || []) { const title = spec.title; const m = title.match(/\[([^\]]+)\]/); if (m) results[m[1]] = test.outcome || test.status || 'unknown'; } } for (const child of suite.suites || []) walk(child); } for (const s of raw.suites || []) walk(s); } const merged = matrix.map(v => ({...v, result: results[v.variantId] || (v.automation === 'manual' ? 'manual' : 'not_run')})); fs.mkdirSync(path.dirname(outPath), {recursive:true}); fs.writeFileSync(outPath, JSON.stringify(merged,null,2)); console.log(`Wrote ${outPath} from Playwright JSON fallback`);