Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(file-browser): 本地 watcher 预过滤不再吞恒真忽略目录自身的事件

Zhang Yunjine5508f902b32
diff --git a/apps/desktop/src/main/file-browser/__tests__/watcher.test.ts b/apps/desktop/src/main/file-browser/__tests__/watcher.test.ts
index 64cfc3c9d7..0f1b602742 100644
--- a/apps/desktop/src/main/file-browser/__tests__/watcher.test.ts
+++ b/apps/desktop/src/main/file-browser/__tests__/watcher.test.ts
@@ -184,10 +184,17 @@ describe('WatcherManager stop 宽限期', () => {
const workdir = path.join(path.sep, 'no-such-workdir-reveal');
await manager.start(makeWindow(), workdir, { showIgnoredDirs: true }, vi.fn());
expect(calls[0].ignore).toEqual(
- expect.arrayContaining(['**/node_modules/**', '**/Library/**', '**/.git/**']),
+ expect.arrayContaining([
+ '**/node_modules/*',
+ '**/node_modules/**/*',
+ '**/Library/*',
+ '**/Library/**/*',
+ '**/.git/*',
+ '**/.git/**/*',
+ ]),
);
// 开关打开时 REVEALABLE 不预过滤 —— 它们本来就该推事件。
- expect(calls[0].ignore).not.toContain('**/dist/**');
+ expect(calls[0].ignore).not.toContain('**/dist/*');
});
it('开关关闭时同样无条件带上 ALWAYS(目录稍后才出现也不漏)', async () => {
@@ -196,27 +203,35 @@ describe('WatcherManager stop 宽限期', () => {
await manager.start(makeWindow(), workdir, { showIgnoredDirs: false }, vi.fn());
expect(calls[0].ignore).toEqual(
expect.arrayContaining([
- '**/node_modules/**',
- '**/Library/**',
- '**/dist/**',
+ '**/node_modules/*',
+ '**/node_modules/**/*',
+ '**/Library/*',
+ '**/Library/**/*',
+ '**/dist/*',
+ '**/dist/**/*',
]),
);
});
/**
- * 预过滤名单的「层级」回归:名单必须发 glob,不能发根级绝对路径。
- * @parcel/watcher 对非 glob 项走 `ignorePaths` 前缀比较 ——
- * `nested/node_modules/x` 不是 `/workdir/node_modules` 的后代,monorepo
- * (`packages/foo/node_modules`)与嵌套 Unity 工程(`client/Library`)会整目录
- * 漏过去,开关打开时每个生成文件都是一条事件推过 watcher-host + IPC。
- * glob 形态与层级无关,这里锁住这个形态(实测 2.5.6/win32:前缀形态零命中,
- * `**\/<name>/**` 全层级命中)。
+ * 预过滤名单的形态回归:两个约束必须同时成立。
+ * 1. 层级:必须发 glob,不能发根级绝对路径 —— @parcel/watcher 对非 glob 项
+ * 走 `ignorePaths` 前缀比较,`nested/node_modules/x` 不是
+ * `/workdir/node_modules` 的后代,monorepo / 嵌套 Unity 工程整目录漏过去。
+ * 2. 自身:`**\/<name>/**` 会把**目录自身**的事件也吞掉(探针实测 2.5.6/win32:
+ * mkdir node_modules 一条事件都没有),开关打开时新建 / 删除 / 改名都看不到。
+ * 拆成一级内容与深层内容两条形态(目录自身不匹配)后,事件保留、
+ * 两级内容仍都忽略。
*/
- it('预过滤用 glob 覆盖任意层级(不是根级绝对路径)', async () => {
+ it('预过滤用 glob 覆盖任意层级,且不吞目录自身事件', async () => {
const { manager, calls } = setup();
await manager.start(makeWindow(), 'D:/repo', { showIgnoredDirs: false }, vi.fn());
- expect(calls[0].ignore).toContain('**/node_modules/**');
- expect(calls[0].ignore).toContain('**/Library/**');
+ expect(calls[0].ignore).toContain('**/node_modules/*');
+ expect(calls[0].ignore).toContain('**/node_modules/**/*');
+ expect(calls[0].ignore).toContain('**/Library/*');
+ expect(calls[0].ignore).toContain('**/Library/**/*');
+ // 旧形态(吞目录自身事件)不得回潮。
+ expect(calls[0].ignore).not.toContain('**/node_modules/**');
expect(calls[0].ignore).not.toContain(path.join('D:/repo', 'node_modules'));
});
diff --git a/apps/desktop/src/main/file-browser/watcher.ts b/apps/desktop/src/main/file-browser/watcher.ts
index 3210927ad7..a524e071d4 100644
--- a/apps/desktop/src/main/file-browser/watcher.ts
+++ b/apps/desktop/src/main/file-browser/watcher.ts
@@ -154,13 +154,20 @@ const PREFILTER_REVEALABLE = [
* 只认“工作区根下直接命中”—— 实测(2.5.6, win32)`nested/node_modules/x` 不是
* `/workdir/node_modules` 的后代,一条事件都拦不住,monorepo
* (`packages/foo/node_modules`)与嵌套 Unity 工程(`client/Library`)全量漏过去。
- * 所以统一发 glob:`**\/<name>/**` 覆盖任意层级。
+ * 所以统一发 glob。
*
- * 末尾的 `/**` 不能省:目录名要连内部条目一起匹配,`**\/<name>` 只匹配目录自身
- * (实测)。将来名单里若出现文件项(如 .DS_Store),要另用不带后缀的形态。
+ * 每个目录发**两条**`**\/<name>/*` 与 `**\/<name>/**\/*`,而不是一条
+ * `**\/<name>/**` —— 后者把**目录自身**的事件也吞掉(实测:mkdir node_modules
+ * 一条事件都没有),于是开关打开时新建 / 删除 / 改名 node_modules / Library 都
+ * 不会让 renderer refetch 父目录,那一行缺失或陈旧到手动刷新(评审 P1;daemon
+ * 侧同一裁决见 watch.ts 的 isInsideAlwaysIgnoredDir)。两条形态下:目录自身不
+ * 匹配 → 事件保留;一级与深层内容都匹配 → 仍不监听(也不会进入子目录)。
+ *
+ * 将来名单里若出现**文件**项(如 .DS_Store),要另发不带后缀的 `**\/<name>`
+ * —— 文件没有“内部”,套用同一对形态会让它自己漏出去。
*/
const ignoreGlobsForDirs = (names: readonly string[]): string[] =>
- names.map((name) => `**/${name}/**`);
+ names.flatMap((name) => [`**/${name}/*`, `**/${name}/**/*`]);
function buildIgnoreList(opts: { showIgnoredDirs: boolean }): string[] {
// ALWAYS 名单**无条件注册**,不做存在性探测:parcel 的 ignore 只在