import { describe, expect, it } from "vitest"; import { sourceRCONChatRequest, sourceRCONRawCommandRequest } from "./sourceRcon"; describe("Source RCON browser request schemas", () => { it("builds a bounded typed chat request without connection material", () => { expect(sourceRCONChatRequest("server-1", { chatType: 4, message: "hello", targetSteamId: "76561198000000001" }, 12)).toEqual({ kind: "chat", chatType: 4, message: "hello", targetSteamId: "76561198000000001", idempotencyKey: "web:source-rcon:chat:server-1:12" }); }); it("rejects framed text and formats raw commands without chat fields", () => { expect(() => sourceRCONChatRequest("server-1", { chatType: 2, message: "line one\nline two" }, 13)).toThrow("受限的单行文本"); expect(() => sourceRCONChatRequest("server-1", { chatType: 8, message: "hello" }, 13)).toThrow("聊天类型"); expect(sourceRCONRawCommandRequest("server-1", " SetTime 12 ", 14)).toEqual({ kind: "command", command: "SetTime 12", idempotencyKey: "web:source-rcon:command:server-1:14" }); }); });