fix: 双击文件夹条目读取失败清空该侧面板修复名不符实对比残留、枚举改手写BFS凑满即停修复超大目录枚举耗时(0.6.2)

This commit is contained in:
2026-08-18 15:29:21 +08:00
parent 946f6b2f6a
commit 74d52ec0b0
9 changed files with 128 additions and 23 deletions
+26
View File
@@ -136,6 +136,32 @@ describe('scanFolders - 边界与选项', () => {
}
})
it('截断后不再深入子目录(凑满即停,total 为已遍历下限)', async () => {
const l = await mkdtemp(join(tmpdir(), 'difflens-stop-l-'))
const r = await mkdtemp(join(tmpdir(), 'difflens-stop-r-'))
try {
// 根目录 3 个文件 + 子目录 1 个文件,maxFiles=2:凑满后子目录不被遍历
// (readdir 目录内条目顺序不保证,但 3 个根文件计入 total 与顺序无关)
for (let i = 0; i < 3; i++) {
await writeFile(join(l, `f${i}.txt`), String(i))
await writeFile(join(r, `f${i}.txt`), String(i))
}
await mkdir(join(l, 'sub'), { recursive: true })
await mkdir(join(r, 'sub'), { recursive: true })
await writeFile(join(l, 'sub', 'inner.txt'), 'x')
await writeFile(join(r, 'sub', 'inner.txt'), 'x')
const res = await scanFolders(l, r, { maxFiles: 2 })
expect(res.truncated).toBe(true)
// 根目录 3 文件全部计入(当前目录统计完整),sub 未被深入
expect(res.total).toBe(3)
expect(res.entries.some((e) => e.rel.startsWith('sub/'))).toBe(false)
expect(res.entries.length).toBeLessThanOrEqual(2)
} finally {
await rm(l, { recursive: true, force: true })
await rm(r, { recursive: true, force: true })
}
})
it('超过 maxContentBytes 的同大小文件:头部采样一致判 same 且带 approximate 标注', async () => {
const l = await mkdtemp(join(tmpdir(), 'difflens-big-l-'))
const r = await mkdtemp(join(tmpdir(), 'difflens-big-r-'))