Skip to content

fix: give a plugin process's SFTP session the events ssh2's has - #1961

Open
ZacharyZcR wants to merge 1 commit into
Termix-SSH:dev-26.11.4from
ZacharyZcR:fix/sftp-proxy-events
Open

ZacharyZcR wants to merge 1 commit into
Termix-SSH:dev-26.11.4from
ZacharyZcR:fix/sftp-proxy-events

Conversation

@ZacharyZcR

Copy link
Copy Markdown
Member

Fixes Termix-SSH/Plugin-File-Manager#63

In a plugin process, client.sftp() on a connection from ctx.ssh.connect hands back sftpProxy(...), a plain object with the SFTP calls on it. ssh2's SFTPWrapper is an EventEmitter, and plugins written against it listen on it straight away. File Manager does sftp.on("error", ...) and sftp.on("close", ...) when it opens one (getSessionSftp, openDedicatedSftp). So every cross-host "Copy to host..." on 26.11.2 and later failed in about a second with sftp.on is not a function, because its dedicated transfer connection comes from ctx.ssh.connect.

Change

  • sftpProxy and its helpers (SFTP_METHODS, withStats) move from child/runtime.ts to child/sftp-proxy.ts, the same way socket.ts and request-body.ts sit beside it. The endpoint is passed in, so it can be tested without a plugin process.
  • The proxy is now an EventEmitter. It emits close once, when it ends or when its SSH connection closes, so a plugin that caches its SFTP session (File Manager does) drops it as it would with ssh2.
  • The calls themselves (sftp.call, sftp.read, sftp.write, sftp.end) are unchanged.

Testing

  • src/backend/tests/plugins/sandbox/child/sftp-proxy.test.ts checks that:
    • the proxy is an EventEmitter and on works;
    • calls go to sftp.call and stats come back with isFile();
    • close fires once, from either the connection closing or end(), and the listener on the connection is removed.
  • supervisor.test.ts spawns real plugin processes: 25 of 29 pass, the same as on dev-26.11.4 without this change. The other 4 are timing tests that fail the same way here.
  • lint and tsc -p tsconfig.node.json are clean.

@termix-triage-bot

Copy link
Copy Markdown

AI review | Looks safe to merge

Refactors the SFTP proxy into a dedicated module and adds EventEmitter support to fix plugin compatibility errors. The change is safe, follows repository standards, and includes appropriate tests.

Reviewed 0b5f913. AI can be wrong, a maintainer still decides. Comment /termix review to run it again.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Open PRs

Development

Successfully merging this pull request may close these issues.

1 participant