'use strict'; // Isolated browser QA. Never reads production user data or contacts image sources. const fs = require('fs'), os = require('os'), path = require('path'), { spawn } = require('child_process'); const { Canvas } = require('../tools/png'); const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'mc-ui-')), data = path.join(dir, 'data'), library = path.join(dir, 'library'); fs.mkdirSync(path.join(data, 'scraper'), { recursive: true }); fs.writeFileSync(path.join(data, 'scraper', 'queue.json'), JSON.stringify({ paused: true, queue: [], settings: { autoUpdateEnabled: false } })); for (const [index, name] of ['Moon Garden', 'Moon Garden Before the Rain', 'Iron Harbor'].entries()) { const folder = path.join(library, name, 'v01', 'c001 The Beginning'); fs.mkdirSync(folder, { recursive: true }); const png = new Canvas(180, 270, [50 + index * 40, 60, 120]).png(); fs.writeFileSync(path.join(folder, '001.png'), png); fs.writeFileSync(path.join(library, name, 'cover.png'), png); fs.writeFileSync(path.join(library, name, 'manga.json'), JSON.stringify({ title: name, status: index ? 'completed' : 'ongoing', tags: ['Fantasy', 'Demo'] })); } const env = { ...process.env, DATA: data, LIBRARY: library, PORT: '8180', SCRAPER_PORT: '8191', SENTINEL_PORT: '8192', READER_URL: 'http://127.0.0.1:8180', SCRAPER_URL: 'http://127.0.0.1:8191', SENTINEL_URL: 'http://127.0.0.1:8192', SCRAPER_DATA: path.join(data, 'scraper'), SENTINEL_DATA: path.join(data, 'sentinel'), COOKIE_SECURE: '0', SCAN_INTERVAL: '0', SCRAPER_TOKEN: 'fixture', SCRAPER_TOKEN_FILE: '' }; const child = spawn(process.execPath, ['tools/start-all.js'], { cwd: path.resolve(__dirname, '..'), env, stdio: 'inherit', windowsHide: true }); console.log('Isolated UI fixture at http://127.0.0.1:8180 ยท first account is test admin'); for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => child.kill('SIGTERM')); child.once('exit', code => { fs.rmSync(dir, { recursive: true, force: true }); process.exit(code || 0); });