import test from 'node:test'; import assert from 'node:assert/strict'; import { fetchJson } from '../src/operator-dashboard/static/lib/api.js'; test('dashboard fetch helper reports empty upstream 500 responses', async (t) => { const originalFetch = globalThis.fetch; t.after(() => { globalThis.fetch = originalFetch; }); globalThis.fetch = async () => new Response('', { status: 500 }); await assert.rejects( fetchJson('/api/session', { timeoutMs: 0 }), /HTTP 500/, ); }); test('dashboard fetch helper times out stale port-forward requests', async (t) => { const originalFetch = globalThis.fetch; t.after(() => { globalThis.fetch = originalFetch; }); globalThis.fetch = async (_url, options = {}) => new Promise((_resolve, reject) => { options.signal?.addEventListener('abort', () => { reject(Object.assign(new Error('aborted'), { name: 'AbortError' })); }); }); await assert.rejects( fetchJson('/api/bootstrap', { timeoutMs: 1 }), /Request timed out after 1ms/, ); });