feat(pi-ssh): add reviewed agent connection flow

This commit is contained in:
云服务部-叶林立
2026-08-21 20:52:50 +08:00
parent 0ac50eb581
commit a7891f18bf
20 changed files with 208 additions and 203 deletions
+19 -3
View File
@@ -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");