fix(pi-ssh): harden remote execution and search

This commit is contained in:
云服务部-叶林立
2026-08-24 23:04:29 +08:00
parent a7891f18bf
commit aff91b0972
30 changed files with 1063 additions and 222 deletions
+30 -1
View File
@@ -2,10 +2,13 @@ import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import { parseConnectInput, SSH_CONNECT_TOOL_METADATA } from "../src/agent-connection.ts";
import { getConfiguredHost, parseConnectInput, SSH_CONNECT_TOOL_METADATA } from "../src/agent-connection.ts";
test("defines the reviewed agent-controlled SSH connection tool", () => {
assert.equal(SSH_CONNECT_TOOL_METADATA.name, "ssh_connect");
assert.equal(SSH_CONNECT_TOOL_METADATA.executionMode, "sequential");
assert.match(SSH_CONNECT_TOOL_METADATA.description, /separate step/);
assert.match(SSH_CONNECT_TOOL_METADATA.description, /wait for success/);
assert.deepEqual(SSH_CONNECT_TOOL_METADATA.parameters.required, ["hostId"]);
assert.ok(SSH_CONNECT_TOOL_METADATA.parameters.properties.remotePath);
assert.deepEqual(parseConnectInput({ hostId: " packaging-server " }), { hostId: "packaging-server" });
@@ -17,6 +20,32 @@ test("defines the reviewed agent-controlled SSH connection tool", () => {
assert.throws(() => parseConnectInput({ hostId: "packaging-server", remotePath: "relative" }), /remote path/);
});
test("unknown hosts report bounded imported host ID alternatives", () => {
const host = {
hostName: "example.test",
user: "builder",
port: 22,
auth: { type: "password" as const, password: "secret" },
hostKey: { algorithm: "ssh-ed25519", fingerprint: "SHA256:fixture" },
};
assert.equal(getConfiguredHost({ version: 1, hosts: { "packaging-server": host } }, "packaging-server"), host);
assert.throws(
() => getConfiguredHost({ version: 1, hosts: { "packaging-server": host, "build-server": host } }, "connect-packaging-server"),
/available imported host IDs: build-server, packaging-server/,
);
const manyHosts = Object.fromEntries(Array.from({ length: 12 }, (_, index) => [`host-${String(index).padStart(2, "0")}`, host]));
assert.throws(
() => getConfiguredHost({ version: 1, hosts: manyHosts }, "missing"),
(error: unknown) => {
assert.match(String(error), /host-00, host-01, host-02/);
assert.match(String(error), /… \(\+2 more\)/);
assert.doesNotMatch(String(error), /example\.test|secret/);
return true;
},
);
assert.throws(() => getConfiguredHost({ version: 1, hosts: {} }, "missing"), /no hosts are imported/);
});
test("removes manual and implicit SSH connection surfaces", async () => {
const source = await readFile(new URL("../index.ts", import.meta.url), "utf8");
assert.match(source, /\.\.\.SSH_CONNECT_TOOL_METADATA/);