import test from 'node:test'; import assert from 'node:assert/strict'; import { airshipLog, clearAirshipLogs, getAirshipLogs, } from '../src/diagnostics.js'; test('diagnostics records structured entries and returns copies', () => { clearAirshipLogs(); const originalLog = console.log; console.log = () => {}; try { airshipLog('test:event', { value: 42 }); } finally { console.log = originalLog; } const logs = getAirshipLogs(); assert.equal(logs.length, 1); assert.equal(logs[0].event, 'test:event'); assert.equal(logs[0].value, 42); assert.equal(logs[0].level, 'info'); assert.match(logs[0].ts, /^\d{4}-\d{2}-\d{2}T/); logs[0].value = 99; assert.equal(getAirshipLogs()[0].value, 42); }); test('diagnostics ring buffer is capped at 300 entries', () => { clearAirshipLogs(); const originalLog = console.log; console.log = () => {}; try { for (let i = 0; i < 305; i += 1) { airshipLog('test:ring', { i }); } } finally { console.log = originalLog; } const logs = getAirshipLogs(); assert.equal(logs.length, 300); assert.equal(logs[0].i, 5); assert.equal(logs.at(-1).i, 304); });