Menghuan1918
57fe6e657d
test: 临时目录清理统一走 removeTree(修 Windows 上的 ENOTEMPTY 竞态)
...
CI 在 windows lane 上红在**清理**而不是断言:
`rmSync(scratch, { recursive: true, force: true })` 抛
`ENOTEMPTY: rmdir …archives-pvpAWR`——刚被 kill 的 zip/tar 子进程(以及刚关闭的
fs.watch / 刚结束的 git 子进程)还没被系统释放句柄,删除于是失败在一个**已经通过**
的用例的 afterEach 里(那一次 2466 个用例全过,只有清理挂掉,整个 lane 变红)。
`maxRetries` + `retryDelay` 正是 Node 为这种场景提供的对策,因此新增
`tests/temp-tree.ts` 的 `removeTree()`,把 30 份 spec(175 处 `{ recursive, force }`
写法)统一换过去,并清掉随之不再使用的 `rmSync` 导入。POSIX 上首次即成功、不触发
重试,行为不变。
本地:typecheck / lint 干净,全量 210 文件 / 2524 通过。
2026-10-16 00:51:11 +08:00
NolanHo
6497046c9e
fix(search-engines): settle streamLines on close, propagate fd dirs-run failures ( #883 )
...
streamLines settled its promise on the child's 'exit' event. Node fires
'exit' the moment the process dies, while the stdout pipe may still hold
undrained data — under host load the exit event can win that race and the
promise resolved with a still-empty lines array. fd's second --type d run
was the common victim (both children race, the match run usually drains
first), so the observable signature was matches intact with dirs: [] —
directory hits silently degraded into open-as-file errors, the exact
error surface #801 fixed, now intermittent.
Settlement moves to 'close' (process dead AND stdio drained, so every
readline line event has fired). The truncation kill, the timeout and the
spawn-error paths keep their semantics: whichever finish() ran first
sets the closed flag and the close handler is idempotent. The --version
probe keeps 'exit' — its stdio is 'ignore', the exit code is the only
signal it reads.
The fd branch also no longer swallows the directory run's failure: the
.catch(() => empty dir list) is deleted, so a rejection now reaches
runEngine's existing broken-marking and this one search falls back to
the plain walk — symmetric with the main run, where the old catch
degraded every failure into an invisible "zero directories".
Evidence: on an fd-equipped Linux host the real-engine suite reproduced
7/30 runs on clean dev (signature constant), 0/30 after the one-line
close change; upstream CI never saw it (ubuntu lane has no fd; ci-windows
runs serially). Two deterministic cases now pin the contracts through the
new spawner hook (scripted PassThrough children replay the racy event
order directly); each was verified red by temporarily reverting the
corresponding half of the fix.
2026-10-06 10:50:51 -07:00
Menghuan1918
d51a46075d
fix(search-engines): 目录命中去掉 fd 打印的尾部分隔符(Windows lane 暴露的真实缺陷)
...
fd 的目录命中带尾部分隔符('src/util/'),rg --files 只报文件,所以只有 --type d 那一路带着它。
走查契约没有尾分隔符('src/util'),而一整类消费者会把这些行与走查输出比较(dirs 集合、
kept.has(dir) 子集判定、行标签),所以规范化必须在两条引擎、两次调用共用的这个点上收口。
从未暴露的原因:fd 只存在于 Windows lane(ubuntu 与开发机都没有),而那条真实引擎用例此前
红在 fixture 的非法文件名字符上——修掉 fixture 才让它第一次真正跑到断言。
新增 3 条不依赖真机引擎的判别性用例(旧实现在其上 3/3 红):POSIX 形状、Windows 反斜杠形状、
以及被尾部剥离塌空的裸根。全量 1962 passed。
2026-10-05 03:09:38 +08:00
Menghuan1918
cc4a462408
fix(search-engines,e2e): Windows 路径推导按入参平台、fixture 换合法元字符、展开断言改为预取感知
...
集成批 17556fd 在 CI 上暴露三处红(Ubuntu `ci` 绿、Windows 测试红 2 条、挂载 lane 红 1 条),
逐条根因与修法:
1) tests/search-engines.spec.ts > bundledRgCandidates > walks every node_modules level
above the CLI entry (argv[1])(仅 Windows 红)
CI: AssertionError: expected [ …(8) ] to include '\Applications\Dsh.app\Contents\Resour…'
根因:bundledRgCandidates() 按「传入的 platform」推导候选,内部却用宿主的 sep / dirname / join。
测试传的是 POSIX 路径(/Applications/Dsh.app/…),Windows runner 上 sep === '\\' →
endsWith('<sep>node_modules') 永不成立 → argv[1] 走查一个 root 都产不出,期望项缺失。
修法(修源头,不改测试语义):按 platform 选 node:path 方言
(`const P = platform === 'win32' ? win32 : posix`),walkRoots 与 %APPDATA% / execPath /
profile / 候选拼装一律走 P.dirname / P.join / P.sep。函数自此是入参的纯函数:darwin 在任何
宿主上都产出 '/'-joined 候选,win32 都产出 '\'-joined 候选。
测试同步:darwin 用例期望改用 posix.join、win32 用例改用 win32.join——宿主 join 正是
Windows 上把 POSIX 期望拼成反斜杠、POSIX 上又把 win32 期望拼成混合分隔符的原因;
argv[1] 那条补齐 win32 反向断言(在 macOS 上直接跑出真实反斜杠形状),%APPDATA%、
~/.dsh profile、APPDATA 缺席三条从「结构包含」收紧为精确 pin win32 形状。
2) tests/search-engines.spec.ts > real engines (only when installed) > matches literals,
splits dirs, skips noise when an engine is installed(仅 Windows 红)
CI: Error: ENOENT: no such file or directory, open
'C:\Users\RUNNER~1\AppData\Local\Temp\dsh-sidebar-engine-real-oCa7RG\a*b.ts'
(tests/search-engines.spec.ts:432)
根因:为验证「模式里的元字符按字面处理」而真建了一个叫 a*b.ts 的文件——'*'(连同 ? : " < > |)
是 Windows 非法文件名字符,fixture 自己就 ENOENT,一条断言都没跑到。
修法:按 platform 选一对「两平台都合法、且非字面解读必然命中诱饵」的见证。POSIX 保留
query 'a*b' / literal 'a*b.ts' / decoy 'anb.ts';win32 改用 '[' ']'(Windows 合法文件名
字符)——query 'a[b]' / literal 'a[b].ts' / decoy 'ab.ts'。'a[b]' 是 glob 字符组,漏转义时
匹配的是 'ab.ts' 而不是字面文件(实测 rg 15.2.0:未转义 '*a[b]*' 返回 ab.ts,转义
'*a\[b\]*' 返回 a[b].ts)。刻意不用未闭合的 'a[b':rg 直接拒绝该 glob(unclosed character
class),引擎被判 broken 后回退普通 walk,断言会被兜底意外满足。整条用例不跳过、
「元字符不当通配符」的断言不削弱。
3) tests/e2e/zz-expand-refresh.e2e.ts > a folder toggle re-lists that folder and nothing else
(挂载 lane 红)
CI: Expected: "fs.trees[bravo]" / Received: undefined,同用例 phase dump:
D-expand-bravo: requests: [], domAdded: 1, ...
A-expand-big: requests: ["fs.trees[big]"], domAdded: 41, ...
根因(是预期行为,不是缺陷):src/fs-tree.ts 的 probeCompactRows 明确把「唯一子项是文件」的
目录也标 compact(客户端据此预取并稳定折叠标签),而 bravo 恰好只有一个文件;FileTree.tsx
的 loadLevels(compactLoadTargets(...)) 在**层级缓存变化时**就列了 bravo(根层到货即可触发),
阶段 D 的展开直接命中缓存 → 零请求,但子行确实出现。旧断言
sibling.requests[0] === 'fs.trees[bravo]' 编码的是「展开必然发请求」这条已不成立的前提。
修法:断言改为预取感知——允许 0 或恰好该层级两种取值,且必须同时证明不存在更大范围的
fs.trees 请求(requests.length ≤ 1 且每一条 === 'fs.trees[bravo]'),并要求子行出现
(added ≥ 1);注释写明「零请求是预取命中,不是没展开」以及「预取发生在层级缓存变化时」,
免得后人又把它当 bug 改回去。展开 big(40 子项、非 compact)仍必须恰好发 fs.trees[big]
(防「重列整个可见集」的主守卫保留),tree body 不被替换、socket 不新增、collapse 无
killed rows、拓扑/展开语义等既有守卫一律保留。
门禁(本地,最终状态):
pnpm typecheck → exit 0
pnpm exec vitest run --maxWorkers=3 tests/search-engines.spec.ts tests/fs-search.spec.ts \
tests/fs-tree-compact.spec.ts tests/exclude-patterns.spec.ts → 4 files / 71 tests passed, exit 0
pnpm exec vitest run --maxWorkers=3 → 172 files / 1943 passed | 13 skipped, exit 0
pnpm lint → exit 0
pnpm check:engines → exit 0(本机无 fd:SKIPPED,rg 实跑通过)
未验证:真机 fd(本机未安装,win32 fixture 分支用真实 rg 在同一台机器上端到端验过)与
plugin-mount lane(挂载 lane 需下载真实 DSH + Playwright,未在本地运行,交由 CI 验证)。
Refs #303
Refs #264
2026-10-05 02:58:04 +08:00
Menghuan1918 and Cold Cloud
194099e7f3
feat(search): fs.search 文件名搜索优先用 fd/rg,缺失/失败回退 JS 遍历
...
issue #203:十万级目录下纯 JS 递归遍历是秒级,10 万条访问预算一顶结果
还被静默截断。现在启动后惰性探测一次本机 fd / rg(每个候选 `--version`
500ms 内验证通过才算数,进程内缓存),探到就用引擎输出,探不到或运行失败
整段回退原来的遍历(导出为 `searchFilesPlain`);坏二进制在进程内禁用,
超时只降级本次(树大 ≠ 二进制坏)。
为什么按 dev 现状重写而不是机械解冲突(PR #303 的落点全部复核过):
- **#801 的必填 `dirs` 是语义级冲突,必须扩引擎契约**。dev 的
`FsSearchResult` 多了 `dirs`(`TreePanel` 用它把命中行当目录导航,否则
`fs.read` 报 “is a directory”),而 PR 的引擎侧只产出
`{paths, truncated}`,`searchFilesPlain` 的空查询也还在返回两字段形状;
照搬会让 #801 修的 bug 在引擎路径上静默回退。收口:fd 用第二次
`--type d` 调用取目录子集(fd 自己不做标注),rg 由文件路径倒推匹配的
目录段(`deriveRgMatches`),dispatch 再把 `dirs` 收敛成 `matches` 的
子集。残留差异只有**空目录在 rg 下不可见**(没有文件路径能带上它)。
- **rg 的路径级 glob 补成三个**:PR 的 `**/*<q>*/**` 缺一个直接子文件
(`util/helper.ts` 是最常见形态),只加 `**` 会让这类目录命中在
rg-only 机器上凭空消失;`**/*<q>/*` + `**/*<q>/**` 两条并用(对真实
rg 15 实测:单用任一条都丢结果)。
- **`bundledRgCandidates` 的路径推导按真机布局改写**:npm/pnpm 把
`@vscode/ripgrep-<platform>-<arch>` 提升到 `@deepseek-ai` 的**同级**,
不存在 `<root>/@deepseek-ai/dsh/node_modules/@vscode/...`;候选根改成
「从 CLI 入口(argv[1])向上逐级 `node_modules`」+ 各包管理器全局前缀,
桌面壳那种「自带依赖树 + 外部 node」的布局才探得到捆绑 rg(实测命中)。
- **丢掉 abort 形参**:`src/index.ts` 的生产路径不传 signal(PR 里也只有
测试在用),单为测试保留一条贯穿三层的通道不划算;引擎子进程由 15s
内部超时兜底。
- **文档锚点按 dev 重锚**:README 的 v0.12.3 条目已随发布历史迁到
CHANGELOG(新增 Unreleased 条目),AGENTS §2 的引擎门禁入口挂到现有
ci-windows 段落,指南 §14 参考实现行补 `src/search-engines.ts`。
- 未新增任何依赖:`@vscode/ripgrep` 只作为**路径**探测,不做模块导入。
Windows 侧由既有 ci-windows lane 承载:`choco install fd ripgrep` 把真
二进制放进 PATH,套件后 `pnpm check:engines`(`scripts/win-engine-check.mjs
--assert`,import `src/search-engines.ts` 取插件自己的 argv)断言
`--path-separator /` 的输出不含 `\`/CR、非 ASCII 文件名命中;引擎缺失则
跳过(fd 在 ubuntu lane 与多数开发机上都没有)。
测试:`tests/search-engines.spec.ts`(探测缓存 / 运行失败禁用 / 超时不禁
用 / argv 对称性与噪声目录排除 / `deriveRgMatches` / 捆绑 rg 候选推导 /
真引擎在场时的端到端——缺席即返回),`tests/fs-search.spec.ts` 拆成
「直接钉遍历」+「注入假引擎的 dispatch 组」(引擎优先、`dirs` 透传与
子集收敛、预算透传、运行失败回退并禁用)。真机核对:本仓库上 rg 路径与
JS 遍历对 `locales` / `util` / `client` / `src` / `e2e` 五个查询的
matches 与 dirs **逐项一致**。
Refs #303
Co-authored-by: Cold Cloud <64406210+yanzhaohui1999@users.noreply.github.com >
2026-10-05 02:10:45 +08:00