const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const test = require('node:test'); const root = path.join(__dirname, '..'); function read(relativePath) { return fs.readFileSync(path.join(root, relativePath), 'utf8'); } test('dashboard starts live polling and exposes required controls', () => { const html = read('frontend/index.html'); const dashboard = read('frontend/dashboard.js'); assert.match(html, /id="history-interval"/); assert.match(html, /name="enabled-sensor"/); assert.match(html, /id="api-token-input"/); assert.match(html, /id="history-retention-days"/); assert.match(html, /id="alarm-history-list"/); assert.match(html, /id="alarm-threshold-controls"/); assert.match(dashboard, /updateDashboard\(\);/); assert.match(dashboard, /updateEnabledSensors/); assert.match(dashboard, /\/api\/config\/runtime/); assert.match(dashboard, /\/api\/alarms/); assert.match(dashboard, /saveAlarmThresholds/); assert.match(dashboard, /\/api\/config\/alarms/); assert.match(dashboard, /updateHistoryRetention/); assert.match(dashboard, /getApiHeaders/); assert.match( dashboard, /setInterval\(updateDashboard,\s*POLLING_INTERVAL_MS\)/ ); }); test('api protects critical endpoints with token and rate limiting hooks', () => { const server = read('api/server.js'); const notifications = read('api/notification-service.js'); assert.match(server, /API_RATE_LIMIT_WINDOW_MS/); assert.match(server, /API_RATE_LIMIT_MAX/); assert.match(server, /rateLimitCriticalApi/); assert.match(server, /Retry-After/); assert.match(server, /timingSafeEqual/); assert.match(server, /\/api\/config\/notifications/); assert.match(notifications, /redactNotificationConfig/); assert.match(notifications, /sendTelegramNotification/); assert.match(notifications, /sendWebhookNotification/); }); test('dashboard HTML has balanced structural containers', () => { const html = read('frontend/index.html'); const openDivs = (html.match(/