Protocol: switch node.invoke screen.* to canvas.*
This commit is contained in:
@@ -347,7 +347,7 @@ export function registerNodesCli(program: Command) {
|
||||
.requiredOption("--node <idOrNameOrIp>", "Node id, name, or IP")
|
||||
.requiredOption(
|
||||
"--command <command>",
|
||||
"Command (e.g. screen.eval or canvas.eval)",
|
||||
"Command (e.g. canvas.eval)",
|
||||
)
|
||||
.option("--params <json>", "JSON object string for params", "{}")
|
||||
.option(
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -3019,10 +3019,7 @@ export async function startGatewayServer(port = 18789): Promise<GatewayServer> {
|
||||
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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user