// Live smoke test against a running RconDataBridge server. Not a unit test // suite -- exercises real ops over a real RCON connection, against the // built package output, and fails loudly if anything doesn't round-trip. // Run via `npm run smoke`. import { z } from "zod"; import { RconDataBridgeClient, RconDataBridgeError, RconDataBridgeSchemaMismatchError } from "../dist/index.js"; async function main() { const client = await RconDataBridgeClient.connect({ host: process.env["RDB_HOST"] ?? "127.0.0.1", port: Number(process.env["RDB_PORT"] ?? 27015), password: process.env["RDB_PASSWORD"] ?? "rdbtestpw123", }); try { console.log("== getProtocolVersion (direct option read, no round trip) =="); console.log(await client.getProtocolVersion()); console.log("== call get_bridge_status =="); const status = await client.call("get_bridge_status"); console.log(status); if (status.version !== 2) { throw new Error(`expected protocol version 2, got ${status.version}`); } console.log("== batch: get_world_stats + list_players + get_queue_status + list_ops =="); const [worldStats, players, queueStatus, ops] = await client.batch([ { op: "get_world_stats" }, { op: "list_players" }, { op: "get_queue_status" }, { op: "list_ops" }, ]); console.log({ worldStats, players, queueStatus, ops }); console.log("== call get_player with an unknown id (expect PLAYER_NOT_FOUND) =="); try { await client.call("get_player", { id: "definitely-not-a-real-player" }); throw new Error("expected RconDataBridgeError, got a success response"); } catch (err) { if (!(err instanceof RconDataBridgeError) || err.code !== "PLAYER_NOT_FOUND") { throw err; } console.log(`got expected error: ${err.message}`); } console.log("== call unchecked path for an op this client has no schema for =="); try { await client.call("definitely_not_a_real_op"); throw new Error("expected RconDataBridgeError, got a success response"); } catch (err) { if (!(err instanceof RconDataBridgeError) || err.code !== "OP_NOT_ALLOWED") { throw err; } console.log(`unchecked call correctly reached the server and got: ${err.message}`); } console.log("== with(schema).call, matching shape =="); const looseWorldStats = await client.with(z.object({}).passthrough()).call("get_world_stats"); if (typeof looseWorldStats.worldAgeDays !== "number") { throw new Error("expected ad-hoc-schema call to still return real world stats data"); } console.log("ad-hoc schema call passed through real data:", looseWorldStats.worldAgeDays); console.log("== with(schema).call, deliberately wrong shape (expect RconDataBridgeSchemaMismatchError) =="); try { await client.with(z.object({ thisFieldWillNeverExist: z.string() })).call("get_world_stats"); throw new Error("expected RconDataBridgeSchemaMismatchError, got a success response"); } catch (err) { if (!(err instanceof RconDataBridgeSchemaMismatchError)) { throw err; } console.log(`ad-hoc schema mismatch correctly caught: ${err.message}`); } console.log("\nAll smoke checks passed."); } finally { client.close(); } } main().catch((err) => { console.error("Smoke test FAILED:", err); process.exitCode = 1; });