Files
Netcatty/components/terminal/extractRootPaths.test.ts
T
陈大猫 443202ba4e fix(sftp): instant folder-drop scan UI and drop full-tree pre-scan (#2782)
* fix(sftp): instant folder-drop scan UI and drop full-tree pre-scan

Restore interleaved folder transfers as the only non-compressed path, remove
the folder pre-scan setting, and make local folder drops show a scanning task
with live discovered counts via native listLocalTree (with cancel + progress).

UI shows "done · found" instead of a fake grand-total percentage while
discovery is still growing.

* fix(sftp): make folder scan cancellation bridge-safe

* fix(sftp): preserve path-only terminal drops

* fix(terminal): accept native folder drop paths

* fix(sftp): keep scan task cancellable during setup

* fix(sftp): preserve scan failure state during setup errors

* fix(sftp): keep folder scan task across retries

* fix(sftp): cancel scan task immediately

* fix(sftp): keep cancellation active through session setup

* fix(sftp): settle failed drop upload retry

* fix(sftp): preserve cancellation in final scan cleanup

* fix(sftp): harden folder scan cancellation and conflicts

* fix(sftp): finish Codex follow-ups on folder scan cancel UX

- Abort sibling listLocalTree walks when one multi-root scan fails
- Prefer ERR_*_CANCELLED over matching "cancel" in error text
- Clear scanning phase on settle; only label live rows as Scanning
- Omit directory metadata sizes from drop entries used for totals

* fix(sftp): stream folder discovery into concurrent uploads

Local path-backed folder drops now edge-scan and edge-transfer: listLocalTree
streams entry batches while upload workers consume them, so the first files
start before a 100k-file walk finishes. Cancel aborts the walk, clears the
queue, and stops creating child tasks. Compressed uploads still materialize
fully then pack.

* fix(sftp): harden progressive folder UX, retry, and size-based uploads

Align the SFTP panel with transfer-center progress, keep nested tree batches
until tree-end, honor pause during progressive enqueue, add low-cost retry for
external drag-drop files, and drop whole-file upload digests for industry
size-based resume (download live-log prefix checks unchanged).

* fix(sftp): address multi-agent review on progressive upload and retry

Gate progressive drops to path-backed folders only, prefer pool sessions on
drag-drop retry with in-flight and cancel guards, soft-check upload mtime
without fail-open contentVerifiedSeparately, skip multi-root pause HOL,
and fail closed when the local tree stream misses tree-end.

* fix(sftp): finish multi-root pause HOL and parent rollup guards

Race-wait on all latched parents so resuming a non-head folder can proceed,
and only roll progressive parents to completed after terminal failed status.

* fix(sftp): address Codex progressive conflict and hang findings

Add root-level conflict preflight to progressive folder uploads, wake all
backpressure waiters, preserve cancel listeners across uploadEntriesDirect,
and surface empty-directory mkdir failures.
2026-08-07 02:01:18 +08:00

127 lines
3.7 KiB
TypeScript

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { extractRootPathsFromDropEntries } from './terminalHelpers.ts';
// Inline copy of extractRootPathsFromClipboardFiles for standalone test
function extractRootPathsFromClipboardFiles(
files: Array<{ path: string; name: string; isDirectory: boolean; size?: number }>,
): string[] {
const paths: string[] = [];
const seenPaths = new Set<string>();
for (const file of files) {
const fullPath = file.path;
if (!fullPath || seenPaths.has(fullPath)) continue;
paths.push(fullPath.includes(' ') ? `"${fullPath}"` : fullPath);
seenPaths.add(fullPath);
}
return paths;
}
describe('extractRootPathsFromClipboardFiles', () => {
it('single file path', () => {
assert.deepEqual(
extractRootPathsFromClipboardFiles([{
path: '/home/user/file.txt', name: 'file.txt', isDirectory: false, size: 100,
}]),
['/home/user/file.txt'],
);
});
it('multiple files', () => {
assert.deepEqual(
extractRootPathsFromClipboardFiles([
{ path: '/home/a.txt', name: 'a.txt', isDirectory: false, size: 10 },
{ path: '/home/b.txt', name: 'b.txt', isDirectory: false, size: 20 },
]),
['/home/a.txt', '/home/b.txt'],
);
});
it('quotes paths with spaces', () => {
assert.deepEqual(
extractRootPathsFromClipboardFiles([{
path: '/home/user/my file.txt', name: 'my file.txt', isDirectory: false, size: 100,
}]),
['"/home/user/my file.txt"'],
);
});
it('deduplicates', () => {
assert.deepEqual(
extractRootPathsFromClipboardFiles([
{ path: '/home/file.txt', name: 'file.txt', isDirectory: false, size: 10 },
{ path: '/home/file.txt', name: 'file.txt', isDirectory: false, size: 10 },
]),
['/home/file.txt'],
);
});
it('handles directory entries', () => {
assert.deepEqual(
extractRootPathsFromClipboardFiles([{
path: '/home/myfolder', name: 'myfolder', isDirectory: true, size: 0,
}]),
['/home/myfolder'],
);
});
it('filters out empty paths', () => {
assert.deepEqual(
extractRootPathsFromClipboardFiles([{
path: '', name: 'empty', isDirectory: false,
}]),
[],
);
});
it('Windows-style paths', () => {
assert.deepEqual(
extractRootPathsFromClipboardFiles([{
path: 'C:\\Users\\test\\file.txt', name: 'file.txt', isDirectory: false, size: 100,
}]),
['C:\\Users\\test\\file.txt'],
);
});
it('empty list', () => {
assert.deepEqual(extractRootPathsFromClipboardFiles([]), []);
});
it('multiple spaced paths', () => {
assert.deepEqual(
extractRootPathsFromClipboardFiles([
{ path: '/home/user/a b.txt', name: 'a b.txt', isDirectory: false, size: 10 },
{ path: '/home/user/c d.txt', name: 'c d.txt', isDirectory: false, size: 20 },
]),
['"/home/user/a b.txt"', '"/home/user/c d.txt"'],
);
});
});
describe('extractRootPathsFromDropEntries', () => {
it('uses a reconstructed DropEntry local path when File.path is unavailable', () => {
const fileWithoutPath = { name: 'child.txt' } as File;
assert.deepEqual(
extractRootPathsFromDropEntries([{
file: fileWithoutPath,
localPath: '/home/user/folder/child.txt',
relativePath: 'folder/child.txt',
isDirectory: false,
}]),
['/home/user/folder'],
);
});
it('uses native path-only entries from a folder scan', () => {
assert.deepEqual(
extractRootPathsFromDropEntries([{
file: null,
localPath: '/home/user/folder/src/main.ts',
relativePath: 'folder/src/main.ts',
isDirectory: false,
}]),
['/home/user/folder'],
);
});
});