feat: route desktop control to authorized devices
This commit is contained in:
70
tests/ssh-computer-use-smoke.test.mjs
Normal file
70
tests/ssh-computer-use-smoke.test.mjs
Normal file
@@ -0,0 +1,70 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { spawn } from "node:child_process";
|
||||
import path from "node:path";
|
||||
|
||||
const repoRoot = path.resolve(import.meta.dirname, "..");
|
||||
|
||||
function runRuntime(payload, env = {}) {
|
||||
return new Promise((resolve) => {
|
||||
const child = spawn(process.execPath, ["scripts/ssh-computer-use-smoke.mjs"], {
|
||||
cwd: repoRoot,
|
||||
env: {
|
||||
...process.env,
|
||||
...env,
|
||||
},
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
});
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
child.stdout.setEncoding("utf8");
|
||||
child.stderr.setEncoding("utf8");
|
||||
child.stdout.on("data", (chunk) => {
|
||||
stdout += chunk;
|
||||
});
|
||||
child.stderr.on("data", (chunk) => {
|
||||
stderr += chunk;
|
||||
});
|
||||
child.on("close", (status) => {
|
||||
resolve({ status, stdout, stderr });
|
||||
});
|
||||
child.stdin.end(JSON.stringify(payload));
|
||||
});
|
||||
}
|
||||
|
||||
test("ssh computer use runtime returns a dry-run desktop control summary", async () => {
|
||||
const result = await runRuntime(
|
||||
{
|
||||
requestKind: "desktop_control",
|
||||
requestId: "ssh-dry-run-1",
|
||||
objective: "打开 Chrome 输入“Boss 远程控制测试”",
|
||||
},
|
||||
{
|
||||
BOSS_SSH_CONTROL_HOST: "192.168.31.114",
|
||||
BOSS_SSH_CONTROL_USER: "jas",
|
||||
BOSS_SSH_CONTROL_DRY_RUN: "true",
|
||||
},
|
||||
);
|
||||
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
const payload = JSON.parse(result.stdout);
|
||||
assert.equal(payload.status, "completed");
|
||||
assert.equal(payload.requestId, "ssh-dry-run-1");
|
||||
assert.equal(payload.targetApp, "Chrome");
|
||||
assert.equal(payload.typedText, "Boss 远程控制测试");
|
||||
assert.match(payload.replyBody, /SSH 桌面控制已完成/);
|
||||
});
|
||||
|
||||
test("ssh computer use runtime fails closed when host is missing", async () => {
|
||||
const result = await runRuntime({
|
||||
requestKind: "desktop_control",
|
||||
requestId: "ssh-missing-host",
|
||||
objective: "打开 Finder",
|
||||
});
|
||||
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
const payload = JSON.parse(result.stdout);
|
||||
assert.equal(payload.status, "failed");
|
||||
assert.equal(payload.requestId, "ssh-missing-host");
|
||||
assert.equal(payload.error, "SSH_CONTROL_HOST_REQUIRED");
|
||||
});
|
||||
Reference in New Issue
Block a user