import { describe, expect, it, vi } from "vitest"; vi.mock("../src/server/env", () => ({ env: { mcContainer: "mc" } })); vi.mock("../src/server/network-config", () => ({ readNetwork: () => ({ profiles: [{ id: "horror", name: "Horror" }] }), profileById: (config: { profiles: Array<{ id: string }> }, id: string) => { const p = config.profiles.find(p => p.id === id); if (!p) throw new Error("Unknown server"); return p; }, })); import { createDemuxer } from "../src/server/docker"; import { consoleTarget } from "../src/server/console-target"; const frame = (payload: Buffer) => { const header = Buffer.alloc(8); header[0] = 1; header.writeUInt32BE(payload.length, 4); return Buffer.concat([header, payload]); }; describe("console transport", () => { it("keeps UTF-8 characters split across Docker frames and flushes output without a newline", () => { const lines: string[] = []; const demux = createDemuxer(s => lines.push(s)); const bytes = Buffer.from("hello 🌫️\nDone"); const data = Buffer.concat([frame(bytes.subarray(0, 8)), frame(bytes.subarray(8))]); for (const byte of data) demux(Buffer.from([byte])); demux.end(); expect(lines).toEqual(["hello 🌫️", "Done"]); }); it("shows short raw TTY output", () => { const lines: string[] = []; const demux = createDemuxer(s => lines.push(s)); demux(Buffer.from("OK")); demux.end(); expect(lines).toEqual(["OK"]); }); it("allows only primary or registered profile IDs", () => { expect(consoleTarget(null)).toBe("mc"); expect(consoleTarget("horror")).toBe("craftdeck-horror"); expect(() => consoleTarget("komodo-core")).toThrow(); expect(() => consoleTarget("../escape")).toThrow(); }); });