// Local synthetic fixtures only. No production proxy or credentials. // Run: PORT=4173 node scripts/preview-errors.js, then open /admin/errors. // Add ?scenario=empty|offline|loading|history to any page to see the other states. const express = require('express'); const fs = require('node:fs'); const { setTimeout } = require('node:timers'); const path = require('node:path'); const { errorFixture, issuesResponse, correlationResponse, historyEntries } = require('./fixtures/error-issues'); const app = express(); const root = path.resolve(__dirname, '../public'); const port = Number(process.env.PORT) || 4173; const oid = n => '65f0c0de' + String(n).padStart(16, '0'); const repos = ['neurips-2026-a91f', 'icse27-replication', 'anon-7c2e0b', 'eval-harness-3d1c']; const users = [oid(1), oid(2)]; const names = { users: { [oid(1)]: 'alice-l', [oid(2)]: 'tmorris' }, repos: {} }; repos.forEach((repoId, i) => { names.repos[repoId] = { ownerId: users[i % 2], owner: names.users[users[i % 2]], source: ['acme-lab/diffusion-bench', 'tmorris/flaky-tests', 'acme-lab/eval-harness', 'tmorris/eval'][i], status: 'ready' }; }); const fixture = errorFixture({ repos, users, owners: Object.fromEntries(repos.map((repoId, i) => [repoId, users[i % 2]])) }); let historyCleared = false; app.use('/api', async (req, res) => { const scenario = new URL(req.headers.referer || 'http://localhost').searchParams.get('scenario') || ''; if (scenario === 'loading') await new Promise(resolve => setTimeout(resolve, 20000)); const now = new Date().toISOString(); if (req.path === '/user') return res.json({ username: 'Synthetic preview', isAdmin: true, status: 'ready' }); if (req.path === '/user/default') return res.json({ options: {}, terms: [] }); if (scenario === 'offline' && req.path.startsWith('/admin/errors')) return res.status(503).json({}); if (req.path === '/admin/errors/issues') return res.json(issuesResponse(fixture, req.query, { scenario, names })); if (req.path === '/admin/errors/correlation') return res.json(correlationResponse(fixture, req.query)); if (req.path === '/admin/errors/investigation') return res.json({ state: 'ready', window: req.query.window || '1h', groups: [], telemetry: { missing: [], instances: [{ service: 'api', instance: 'synthetic-api', last: now, dropped: 0 }], collector: { state: 'reachable', dropped: 0 } } }); if (req.path === '/admin/errors/stats') return res.json({ available: true, last24h: 34, prev24h: 20, severity: { error: 29, warn: 5, info: 0 }, unique: { error: 3, warn: 1, info: 0 }, buckets: [], dropped: 0 }); if (req.path === '/admin/errors' && req.method === 'DELETE') { historyCleared = true; return res.json({ ok: true }); } if (req.path === '/admin/errors') { const entries = historyCleared ? [] : historyEntries(fixture); return res.json({ available: true, redisCollecting: true, total: entries.length, max: 5000, entries }); } return res.json([]); }); app.use((req, res, next) => { req.url = req.url.replace(/\.[a-f0-9]{10}\.min\./, '.min.'); next(); }); app.use(express.static(root, { index: false })); app.get('/{*path}', (req, res) => res.type('html').send(fs.readFileSync(path.join(root, 'index.html'), 'utf8').replace(/__([A-Z]+)_JS__/g, (_, name) => `${name.toLowerCase()}.min.js`).replace('__ALL_CSS__', 'all.min.css').replace('Synthetic preview · generated fixtures only · no production connection
console.log(`Synthetic Errors preview: http://localhost:${port}/admin/errors`));