mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-08-28 08:35:57 +00:00
feat(pi-ssh): add reviewed agent connection flow
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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";
|
||||
|
||||
test("defines the reviewed agent-controlled SSH connection tool", () => {
|
||||
assert.equal(SSH_CONNECT_TOOL_METADATA.name, "ssh_connect");
|
||||
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" });
|
||||
assert.deepEqual(parseConnectInput({ hostId: "packaging-server", remotePath: "~/api" }), {
|
||||
hostId: "packaging-server",
|
||||
remotePath: "~/api",
|
||||
});
|
||||
assert.throws(() => parseConnectInput({ hostId: "user@host" }), /invalid pi-ssh host id/);
|
||||
assert.throws(() => parseConnectInput({ hostId: "packaging-server", remotePath: "relative" }), /remote path/);
|
||||
});
|
||||
|
||||
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/);
|
||||
assert.doesNotMatch(source, /registerCommand\(["']ssh["']/);
|
||||
assert.doesNotMatch(source, /registerFlag\(["']ssh["']/);
|
||||
assert.doesNotMatch(source, /getFlag\(["']ssh["']/);
|
||||
assert.doesNotMatch(source, /appendEntry\(["']pi-ssh-config["']/);
|
||||
assert.doesNotMatch(source, /pi\.on\(["']user_bash["']/);
|
||||
});
|
||||
@@ -45,6 +45,17 @@ const connection: SshPermissionConnection = {
|
||||
remoteCwd: "/srv/build",
|
||||
};
|
||||
|
||||
test("formats reviewed connection requests without exposing credentials", () => {
|
||||
assert.equal(
|
||||
formatSshPermissionInput("ssh_connect", { hostId: "packaging-server", remotePath: "/srv/build" }, connection),
|
||||
"SSH target 'packaging-server:2222' in remote cwd '/srv/build'; establish a persistent SSH2 connection",
|
||||
);
|
||||
assert.equal(
|
||||
formatSshPermissionInput("ssh_connect", { hostId: "unknown" }, null),
|
||||
"requested imported SSH host 'unknown'; establish a persistent SSH2 connection",
|
||||
);
|
||||
});
|
||||
|
||||
test("formats the SSH target and bounded operation details", () => {
|
||||
assert.equal(
|
||||
formatSshPermissionInput("ssh_read", { path: "src/main.ts", offset: 5, limit: 20 }, connection),
|
||||
@@ -66,14 +77,19 @@ test("registers previews and disables local path extraction for remote file tool
|
||||
const dispose = installSshPermissionIntegration(
|
||||
pi.api as never,
|
||||
() => connection,
|
||||
{ getPermissionsService: () => service, permissionsReadyChannel: "permissions:ready" },
|
||||
{
|
||||
getPermissionsService: () => service,
|
||||
permissionsReadyChannel: "permissions:ready",
|
||||
getConnectTarget: () => connection,
|
||||
},
|
||||
);
|
||||
|
||||
assert.deepEqual([...formatters.keys()], ["ssh_read", "ssh_write", "ssh_edit", "ssh_find", "ssh_grep", "ssh_bash"]);
|
||||
assert.deepEqual([...formatters.keys()], ["ssh_connect", "ssh_read", "ssh_write", "ssh_edit", "ssh_find", "ssh_grep", "ssh_bash"]);
|
||||
assert.deepEqual([...extractors.keys()], ["ssh_read", "ssh_write", "ssh_edit", "ssh_find", "ssh_grep"]);
|
||||
assert.equal(extractors.get("ssh_read")?.({ path: "/remote/secret" }), undefined);
|
||||
assert.equal(extractors.get("ssh_grep")?.({ path: "/remote/src" }), undefined);
|
||||
assert.match(formatters.get("ssh_bash")?.({ command: "git push" }) ?? "", /packaging-server:2222/);
|
||||
assert.match(formatters.get("ssh_connect")?.({ hostId: "packaging-server" }) ?? "", /establish a persistent SSH2 connection/);
|
||||
|
||||
dispose();
|
||||
assert.equal(formatters.size, 0);
|
||||
@@ -92,7 +108,7 @@ test("registers when the permission service becomes ready and cleans up on shutd
|
||||
|
||||
published = service;
|
||||
pi.emitEvent("permissions:ready");
|
||||
assert.equal(formatters.size, 6);
|
||||
assert.equal(formatters.size, 7);
|
||||
assert.equal(extractors.size, 5);
|
||||
|
||||
pi.emit("session_shutdown");
|
||||
|
||||
Reference in New Issue
Block a user