Files
Netcatty/components/sftp/sftpFollowTerminalCwd.test.ts
T
陈大猫andCursor b1f930a995 feat(sftp): 侧栏 SFTP 增加追随终端目录模式 (#1266) (#1310)
* feat(sftp): add follow terminal directory mode for sidebar (#1266)

Add a toolbar toggle that keeps the side-panel SFTP browser synced with the linked SSH terminal cwd, inspired by MobaXterm's follow-folder behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(sftp): probe pwd after commands when follow mode lacks OSC 7

Add a deferred getSessionPwd fallback after terminal commands when follow-terminal-cwd is enabled and the shell did not report OSC 7, and fix settings sync hook dependencies.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(sftp): repair follow toggle UI and backend cwd sync fallback

Fix SftpPaneView memo skipping follow prop updates, probe fresh pwd when OSC 7 is missing, and broaden linked terminal session resolution for sidebar follow mode.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(sftp): harden follow sync after review findings

Reuse shouldFollowTerminalCwdNavigate in production path, re-read connection
after async cwd probe, skip redundant navigate on toggle, and only probe pwd
when the SFTP side panel is open.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-08 19:28:30 +08:00

36 lines
1.2 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { shouldFollowTerminalCwdNavigate } from "./sftpFollowTerminalCwd";
const base = {
followEnabled: true,
isVisible: true,
terminalCwd: "/home/user/project",
currentPath: "/home/user",
hasActiveWork: false,
isConnected: true,
};
test("shouldFollowTerminalCwdNavigate returns true when follow is on and paths differ", () => {
assert.equal(shouldFollowTerminalCwdNavigate(base), true);
});
test("shouldFollowTerminalCwdNavigate returns false when paths already match", () => {
assert.equal(
shouldFollowTerminalCwdNavigate({ ...base, currentPath: "/home/user/project" }),
false,
);
});
test("shouldFollowTerminalCwdNavigate returns false when follow is disabled", () => {
assert.equal(shouldFollowTerminalCwdNavigate({ ...base, followEnabled: false }), false);
});
test("shouldFollowTerminalCwdNavigate returns false while interactive work is active", () => {
assert.equal(shouldFollowTerminalCwdNavigate({ ...base, hasActiveWork: true }), false);
});
test("shouldFollowTerminalCwdNavigate returns false without a known terminal cwd", () => {
assert.equal(shouldFollowTerminalCwdNavigate({ ...base, terminalCwd: null }), false);
});