// @vitest-environment jsdom import { describe, it, expect } from 'vitest' import { readFileSync } from 'fs' import { join } from 'path' // ── esc() ───────────────────────────────────────────────────────────────────── // Mirrors the implementation in ui.js exactly (DOM-based). // Tests the XSS contract — if the implementation changes, these define // what it must still guarantee. function esc(str) { const d = document.createElement('div') d.textContent = (str == null) ? '' : String(str) return d.innerHTML } describe('esc', () => { it('passes through plain strings unchanged', () => { expect(esc('plex')).toBe('plex') expect(esc('postgres-primary')).toBe('postgres-primary') }) it('escapes < and >', () => { expect(esc('')).toBe('</script>') }) it('neutralises a script injection payload', () => { const payload = '' expect(esc(payload)).not.toContain('