Protocol: switch node.invoke screen.* to canvas.*

This commit is contained in:
Peter Steinberger
2025-12-18 01:17:17 +00:00
parent ea53f1bec7
commit 22516437b7
5 changed files with 22 additions and 74 deletions

View File

@@ -347,7 +347,7 @@ export function registerNodesCli(program: Command) {
.requiredOption("--node <idOrNameOrIp>", "Node id, name, or IP") .requiredOption("--node <idOrNameOrIp>", "Node id, name, or IP")
.requiredOption( .requiredOption(
"--command <command>", "--command <command>",
"Command (e.g. screen.eval or canvas.eval)", "Command (e.g. canvas.eval)",
) )
.option("--params <json>", "JSON object string for params", "{}") .option("--params <json>", "JSON object string for params", "{}")
.option( .option(

View File

@@ -126,7 +126,7 @@ describe("cli program", () => {
.mockResolvedValueOnce({ .mockResolvedValueOnce({
ok: true, ok: true,
nodeId: "ios-node", nodeId: "ios-node",
command: "screen.eval", command: "canvas.eval",
payload: { result: "ok" }, payload: { result: "ok" },
}); });
@@ -139,7 +139,7 @@ describe("cli program", () => {
"--node", "--node",
"ios-node", "ios-node",
"--command", "--command",
"screen.eval", "canvas.eval",
"--params", "--params",
'{"javaScript":"1+1"}', '{"javaScript":"1+1"}',
], ],
@@ -156,7 +156,7 @@ describe("cli program", () => {
method: "node.invoke", method: "node.invoke",
params: { params: {
nodeId: "ios-node", nodeId: "ios-node",
command: "screen.eval", command: "canvas.eval",
params: { javaScript: "1+1" }, params: { javaScript: "1+1" },
timeoutMs: 15000, timeoutMs: 15000,
idempotencyKey: "idem-test", idempotencyKey: "idem-test",

View File

@@ -543,72 +543,23 @@ describe("gateway server", () => {
try { try {
await connectOk(ws); await connectOk(ws);
const res = await rpcReq(ws, "node.invoke", { const res = await rpcReq(ws, "node.invoke", {
nodeId: "ios-node", nodeId: "ios-node",
command: "screen.eval", command: "canvas.eval",
params: { javaScript: "2+2" }, params: { javaScript: "2+2" },
timeoutMs: 123, timeoutMs: 123,
idempotencyKey: "idem-1", idempotencyKey: "idem-1",
}); });
expect(res.ok).toBe(true); expect(res.ok).toBe(true);
expect(bridgeInvoke).toHaveBeenCalledWith( expect(bridgeInvoke).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
nodeId: "ios-node", nodeId: "ios-node",
command: "screen.eval", command: "canvas.eval",
paramsJSON: JSON.stringify({ javaScript: "2+2" }), paramsJSON: JSON.stringify({ javaScript: "2+2" }),
timeoutMs: 123, timeoutMs: 123,
}), }),
); );
} finally {
ws.close();
await server.close();
}
} finally {
await fs.rm(homeDir, { recursive: true, force: true });
if (prevHome === undefined) {
delete process.env.HOME;
} else {
process.env.HOME = prevHome;
}
}
});
test("maps node.invoke canvas.* to screen.*", async () => {
const homeDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-home-"));
const prevHome = process.env.HOME;
process.env.HOME = homeDir;
try {
bridgeInvoke.mockResolvedValueOnce({
type: "invoke-res",
id: "inv-2",
ok: true,
payloadJSON: JSON.stringify({ result: "ok" }),
error: null,
});
const { server, ws } = await startServerWithClient();
try {
await connectOk(ws);
const res = await rpcReq(ws, "node.invoke", {
nodeId: "android-node",
command: "canvas.eval",
params: { javaScript: "1+1" },
timeoutMs: 123,
idempotencyKey: "idem-2",
});
expect(res.ok).toBe(true);
expect(bridgeInvoke).toHaveBeenCalledWith(
expect.objectContaining({
nodeId: "android-node",
command: "screen.eval",
paramsJSON: JSON.stringify({ javaScript: "1+1" }),
timeoutMs: 123,
}),
);
} finally { } finally {
ws.close(); ws.close();
await server.close(); await server.close();

View File

@@ -3019,10 +3019,7 @@ export async function startGatewayServer(port = 18789): Promise<GatewayServer> {
idempotencyKey: string; idempotencyKey: string;
}; };
const nodeId = String(p.nodeId ?? "").trim(); const nodeId = String(p.nodeId ?? "").trim();
const rawCommand = String(p.command ?? "").trim(); const command = String(p.command ?? "").trim();
const command = rawCommand.startsWith("canvas.")
? `screen.${rawCommand.slice("canvas.".length)}`
: rawCommand;
if (!nodeId || !command) { if (!nodeId || !command) {
respond( respond(
false, false,

View File

@@ -388,7 +388,7 @@ describe("node bridge server", () => {
const res = await server.invoke({ const res = await server.invoke({
nodeId: "n5", nodeId: "n5",
command: "screen.eval", command: "canvas.eval",
paramsJSON: JSON.stringify({ javaScript: "1+1" }), paramsJSON: JSON.stringify({ javaScript: "1+1" }),
timeoutMs: 3000, timeoutMs: 3000,
}); });
@@ -397,7 +397,7 @@ describe("node bridge server", () => {
const payload = JSON.parse(String(res.payloadJSON ?? "null")) as { const payload = JSON.parse(String(res.payloadJSON ?? "null")) as {
echo?: string; echo?: string;
}; };
expect(payload.echo).toBe("screen.eval"); expect(payload.echo).toBe("canvas.eval");
await responder; await responder;
socket.destroy(); socket.destroy();