From 22516437b77e03d17fc12a66b05fdd55373577f2 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 18 Dec 2025 01:17:17 +0000 Subject: [PATCH] Protocol: switch node.invoke screen.* to canvas.* --- src/cli/nodes-cli.ts | 2 +- src/cli/program.test.ts | 6 +-- src/gateway/server.test.ts | 79 +++++++-------------------------- src/gateway/server.ts | 5 +-- src/infra/bridge/server.test.ts | 4 +- 5 files changed, 22 insertions(+), 74 deletions(-) diff --git a/src/cli/nodes-cli.ts b/src/cli/nodes-cli.ts index 7766cd27f..8306cb465 100644 --- a/src/cli/nodes-cli.ts +++ b/src/cli/nodes-cli.ts @@ -347,7 +347,7 @@ export function registerNodesCli(program: Command) { .requiredOption("--node ", "Node id, name, or IP") .requiredOption( "--command ", - "Command (e.g. screen.eval or canvas.eval)", + "Command (e.g. canvas.eval)", ) .option("--params ", "JSON object string for params", "{}") .option( diff --git a/src/cli/program.test.ts b/src/cli/program.test.ts index 214e9c583..aae37e730 100644 --- a/src/cli/program.test.ts +++ b/src/cli/program.test.ts @@ -126,7 +126,7 @@ describe("cli program", () => { .mockResolvedValueOnce({ ok: true, nodeId: "ios-node", - command: "screen.eval", + command: "canvas.eval", payload: { result: "ok" }, }); @@ -139,7 +139,7 @@ describe("cli program", () => { "--node", "ios-node", "--command", - "screen.eval", + "canvas.eval", "--params", '{"javaScript":"1+1"}', ], @@ -156,7 +156,7 @@ describe("cli program", () => { method: "node.invoke", params: { nodeId: "ios-node", - command: "screen.eval", + command: "canvas.eval", params: { javaScript: "1+1" }, timeoutMs: 15000, idempotencyKey: "idem-test", diff --git a/src/gateway/server.test.ts b/src/gateway/server.test.ts index e2e7d3eca..ccd8c78df 100644 --- a/src/gateway/server.test.ts +++ b/src/gateway/server.test.ts @@ -543,72 +543,23 @@ describe("gateway server", () => { try { await connectOk(ws); - const res = await rpcReq(ws, "node.invoke", { - nodeId: "ios-node", - command: "screen.eval", - params: { javaScript: "2+2" }, - timeoutMs: 123, - idempotencyKey: "idem-1", - }); + const res = await rpcReq(ws, "node.invoke", { + nodeId: "ios-node", + command: "canvas.eval", + params: { javaScript: "2+2" }, + timeoutMs: 123, + idempotencyKey: "idem-1", + }); expect(res.ok).toBe(true); - expect(bridgeInvoke).toHaveBeenCalledWith( - expect.objectContaining({ - nodeId: "ios-node", - command: "screen.eval", - paramsJSON: JSON.stringify({ javaScript: "2+2" }), - 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, - }), - ); + expect(bridgeInvoke).toHaveBeenCalledWith( + expect.objectContaining({ + nodeId: "ios-node", + command: "canvas.eval", + paramsJSON: JSON.stringify({ javaScript: "2+2" }), + timeoutMs: 123, + }), + ); } finally { ws.close(); await server.close(); diff --git a/src/gateway/server.ts b/src/gateway/server.ts index 501f8f389..3033d0320 100644 --- a/src/gateway/server.ts +++ b/src/gateway/server.ts @@ -3019,10 +3019,7 @@ export async function startGatewayServer(port = 18789): Promise { idempotencyKey: string; }; const nodeId = String(p.nodeId ?? "").trim(); - const rawCommand = String(p.command ?? "").trim(); - const command = rawCommand.startsWith("canvas.") - ? `screen.${rawCommand.slice("canvas.".length)}` - : rawCommand; + const command = String(p.command ?? "").trim(); if (!nodeId || !command) { respond( false, diff --git a/src/infra/bridge/server.test.ts b/src/infra/bridge/server.test.ts index 359639ed2..232614416 100644 --- a/src/infra/bridge/server.test.ts +++ b/src/infra/bridge/server.test.ts @@ -388,7 +388,7 @@ describe("node bridge server", () => { const res = await server.invoke({ nodeId: "n5", - command: "screen.eval", + command: "canvas.eval", paramsJSON: JSON.stringify({ javaScript: "1+1" }), timeoutMs: 3000, }); @@ -397,7 +397,7 @@ describe("node bridge server", () => { const payload = JSON.parse(String(res.payloadJSON ?? "null")) as { echo?: string; }; - expect(payload.echo).toBe("screen.eval"); + expect(payload.echo).toBe("canvas.eval"); await responder; socket.destroy();