import { describe, expect, test } from 'bun:test'; import type { JournalReport } from '../../services/module-journal'; import { formatJournalReport } from './module-journal'; const system = (over: Partial = {}) => ({ system: 'signal', hostname: 'signal', ipv4Address: '10.0.20.40', unit: 'signal*', ok: true, lines: [] as string[], ...over, }); describe('formatJournalReport', () => { test('renders the journal lines under their host', () => { const { message, allOk } = formatJournalReport({ moduleId: 'signal', systems: [system({ lines: ['Received sync sent message'] })], }); expect(allOk).toBe(true); expect(message).toContain('signal (10.0.20.40)'); expect(message).toContain('Received sync sent message'); }); // The defect class of #501: unreadable must not present as quiet. test('an unreadable host and an empty journal do not look the same', () => { const empty = formatJournalReport({ moduleId: 'signal', systems: [system()] }); const broken = formatJournalReport({ moduleId: 'signal', systems: [system({ ok: false, error: 'Connection timed out' })], }); expect(empty.allOk).toBe(true); expect(broken.allOk).toBe(false); expect(broken.message).not.toBe(empty.message); expect(broken.message).toContain('UNREADABLE'); }); test('one unreadable host among several fails the whole read', () => { const { allOk } = formatJournalReport({ moduleId: 'forgejo', systems: [system({ lines: ['ok'] }), system({ ok: false, error: 'no route to host' })], }); expect(allOk).toBe(false); }); });