/** * Unit + in-process integration tests untuk CLI `serve` command. * * Sebelumnya `cli/commands/serve.js` memiliki 0% unit coverage (MEDIUM-3 dari * audit 2026-06): logic-nya hanya teruji secara tidak langsung lewat subprocess * pada test keamanan S-6. Test ini menjalankan `runServe` IN-PROCESS pada port * ephemeral (port 0) lalu melakukan HTTP request nyata ke beberapa route, * sehingga jalur kode utama (routing, compile-on-the-fly, static serve, * directory listing, guard path-traversal) terhitung sebagai unit coverage. */ import { describe, it, expect, beforeAll, afterAll } from 'vitest'; import http from 'node:http'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const { runServe, wrapInHtml, escapeHtml } = require('../src/cli/commands/serve.js'); // ─── Pure helper unit tests ──────────────────────────────────────────────── describe('serve.js — pure helpers', () => { it('escapeHtml meng-escape karakter HTML berbahaya (< > & ")', () => { expect(escapeHtml('