// The control channel of the scripted Daemon, which the App's tests run against (daemon/test/scripted-daemon.ts). // A test connects to the control port and scripts a Daemon of its own: what it holds, when it stops and starts, which events it sends. // That Daemon speaks the real protocol (index.ts) to the App, with the real server and its token check. // No imports, so Node and NSH both load this file as it is. /** The port of the control channel, on 127.0.0.1. */ export const SCRIPTED_CONTROL_PORT = 47199; /** What a test asks, as JSON text. Each request gets one reply. * start: the Daemon starts with this snapshot (a protocol Snapshot), on the port it had before if it ran already. * stop: the Daemon closes every connection and stops listening, as when it crashes. * send: the Daemon sends this event (a protocol DaemonEvent) to every connected App. * hang: the Daemon stops, and its port accepts WebSocket connections but never sends a snapshot, as a Daemon that is stuck. * commands: gives the commands the App sent since the last time the test asked (protocol AppCommands), oldest first. * answer: how the Daemon answers the App's next command, as the real Daemon does: it sends these events (protocol DaemonEvents), * then its reply with this error, or null when it is done, and the id of what the command created, if any. * Answers queue up, one for each command. A command with no answer queued gets a reply that it is done, and no event. */ export type ControlRequest = | { do: "start"; snapshot: unknown } | { do: "stop" } | { do: "send"; event: unknown } | { do: "hang" } | { do: "commands" } | { do: "answer"; events: unknown[]; error: string | null; created?: string }; /** The reply: start gives the Daemon's address (a protocol DaemonAddress), commands the commands. */ export type ControlReply = { ok: true; address?: { port: number; token: string }; commands?: unknown[] } | { ok: false; error: string };