Files
mesh-tools/node-tools/test/console-seats.ts
T
jschoubben 200249a84f Let the TypeScript mesh client take every role's tools from the console on its machine, so it asks the controller for none (issue 1955, ADR 0571 clause 5)
The Go console answers mesh/seats beside MCP's methods from mesh-sdk's seat
definitions and placement's seat-holders. The console test that runs bundles
expects the unread seat-holders line beside ghost.
2026-10-29 23:19:55 +01:00

32 lines
1.5 KiB
TypeScript

/**
* The console on this machine as a client asks it for every role's tools (novox/hq ADR 0571): the method `mesh/seats`
* beside MCP's, answered in the shape the Go console's `seatsAnswer` gives (internal/console/mcp.go). Sets
* MESH_CONSOLE to it, so a client, and a `mesh` it spawns, asks it.
*/
import { createServer } from "node:http";
import type { AddressInfo } from "node:net";
import { SEATS_METHOD } from "../dist/client.js";
export type SeatOfConsole = { seat: string; scope: string; tools: { name: string; description?: string; input?: unknown }[] };
export async function aConsoleWithSeats(seats: SeatOfConsole[]): Promise<{ url: string; close: () => Promise<void> }> {
const local = createServer((req, res) => {
let body = "";
req.on("data", (c) => (body += c));
req.on("end", () => {
const asked = JSON.parse(body) as { id: number; method: string };
res.setHeader("content-type", "application/json");
if (req.url !== "/mcp" || asked.method !== SEATS_METHOD) {
res.end(JSON.stringify({ jsonrpc: "2.0", id: asked.id, error: { code: -32601, message: "no such method" } }));
return;
}
res.end(JSON.stringify({ jsonrpc: "2.0", id: asked.id, result: { seats: seats.map((s) => ({ ...s, holders: [] })) } }));
});
});
await new Promise<void>((done) => local.listen(0, "127.0.0.1", done));
const url = `http://127.0.0.1:${(local.address() as AddressInfo).port}`;
process.env.MESH_CONSOLE = url;
return { url, close: () => new Promise((done) => local.close(() => done())) };
}