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(search): match Windows directories case-insensitively

Zhao Dengfeng5da6edf431f1
diff --git a/apps/desktop/src/main/localDb/__tests__/conversationSearch.test.ts b/apps/desktop/src/main/localDb/__tests__/conversationSearch.test.ts
index ef4492418a..fcdfc669b6 100644
--- a/apps/desktop/src/main/localDb/__tests__/conversationSearch.test.ts
+++ b/apps/desktop/src/main/localDb/__tests__/conversationSearch.test.ts
@@ -220,6 +220,48 @@ describe('conversationSearch remote project aliases', () => {
});
});
+describe('conversationSearch workingDir filtering', () => {
+ it('retains Windows drive and UNC case variants without merging POSIX paths', async () => {
+ const db = createSearchDb();
+ const client = makeSearchDbClient(db);
+ setCurrentDbClient(client, 'test-user');
+ mocks.searchChatHistoryHybrid.mockResolvedValue({
+ hits: [], sessions: {}, vectorUsed: false, vectorSkipReason: null,
+ nextOffset: null, hasMore: false, poolSize: 0, poolCapped: false,
+ });
+ try {
+ const rows = [
+ ['drive', 'C:/work/repo'],
+ ['unc', '//SERVER/Share/Work/Repo'],
+ ['other', 'C:/work/other'],
+ ['posix-lower', '/work/repo'],
+ ['posix-upper', '/Work/Repo'],
+ ] as const;
+ rows.forEach(([id, workingDir], index) => {
+ insertSearchSession(db, id, index + 1, null);
+ db.prepare('UPDATE sessions SET working_dir = ? WHERE id = ?').run(workingDir, id);
+ });
+
+ const windows = await searchConversations({
+ query: 'needle',
+ semanticMode: 'keyword',
+ filters: { workingDirs: ['c:\\Work\\Repo', '\\\\server\\share\\work\\repo'] },
+ });
+ expect(windows.results.map((item) => item.session.id).sort()).toEqual(['drive', 'unc']);
+
+ const posix = await searchConversations({
+ query: 'needle',
+ semanticMode: 'keyword',
+ filters: { workingDirs: ['/work/repo'] },
+ });
+ expect(posix.results.map((item) => item.session.id)).toEqual(['posix-lower']);
+ } finally {
+ clearCurrentDbClient(client);
+ db.close();
+ }
+ });
+});
+
describe('conversationSearch recent activity SQL filtering', () => {
it('filters the SQLite session candidates before title and content matching', async () => {
const db = createSearchDb();
diff --git a/apps/desktop/src/main/localDb/conversationSearch.ts b/apps/desktop/src/main/localDb/conversationSearch.ts
index 4696a22ab6..596fd598ae 100644
--- a/apps/desktop/src/main/localDb/conversationSearch.ts
+++ b/apps/desktop/src/main/localDb/conversationSearch.ts
@@ -15,7 +15,7 @@ import type {
} from '../../shared/conversationSearch.js';
import { conversationSearchTitle } from '../../shared/conversationSearch.js';
import type { SessionSource } from '../../shared/sessionSource.js';
-import { normalizeWorkingDirForGrouping } from '../../shared/workingDir.js';
+import { normalizeWorkingDirForComparison, normalizeWorkingDirForGrouping } from '../../shared/workingDir.js';
import { getDbClient } from './client/current.js';
import { botProfiles, botSessionLinks, messages, projectAliases, sessions } from './schema.js';
import { searchChatHistoryHybrid } from './chatHistorySearch.js';
@@ -335,9 +335,9 @@ function applyWorkingDirFilter(
workingDirs: string[] | null,
): SessionRow[] {
if (workingDirs == null) return rows;
- const allowed = new Set(workingDirs);
+ const allowed = new Set(workingDirs.map((dir) => normalizeWorkingDirForComparison(dir)));
return rows.filter((row) => {
- const key = normalizeWorkingDirForGrouping(row.workingDir);
+ const key = normalizeWorkingDirForComparison(row.workingDir);
return key != null && allowed.has(key);
});
}
diff --git a/apps/desktop/src/renderer/lib/__tests__/conversationSearchFanout.test.ts b/apps/desktop/src/renderer/lib/__tests__/conversationSearchFanout.test.ts
index 56b0dddd09..7e7bed27d1 100644
--- a/apps/desktop/src/renderer/lib/__tests__/conversationSearchFanout.test.ts
+++ b/apps/desktop/src/renderer/lib/__tests__/conversationSearchFanout.test.ts
@@ -741,6 +741,40 @@ describe('filterResultsByRequestFilters', () => {
expect(page.results.map((item) => item.session.id)).toEqual(['keep']);
});
+ it('matches Windows drive and UNC case variants without folding POSIX paths', () => {
+ const windowsPage = response([
+ result('drive', 1, { workingDir: 'C:/work/repo' }),
+ result('unc', 1, { workingDir: '//SERVER/Share/Work/Repo' }),
+ result('other', 1, { workingDir: 'C:/work/other' }),
+ ]);
+ const windowsRequest = {
+ filters: { workingDirs: ['c:\\Work\\Repo', '\\\\server\\share\\work\\repo'] },
+ };
+ expect(
+ filterResultsByRequestFilters(windowsPage, windowsRequest).results.map(
+ (item) => item.session.id,
+ ),
+ ).toEqual(['drive', 'unc']);
+ expect(
+ remoteIndexedSearchIgnoredWorkingDirs(
+ response(windowsPage.results.slice(0, 2)),
+ windowsRequest.filters.workingDirs,
+ ),
+ ).toBe(false);
+
+ const posixPage = response([
+ result('posix-lower', 1, { workingDir: '/work/repo' }),
+ result('posix-upper', 1, { workingDir: '/Work/Repo' }),
+ ]);
+ const posixRequest = { filters: { workingDirs: ['/work/repo'] } };
+ expect(
+ filterResultsByRequestFilters(posixPage, posixRequest).results.map(
+ (item) => item.session.id,
+ ),
+ ).toEqual(['posix-lower']);
+ expect(remoteIndexedSearchIgnoredWorkingDirs(posixPage, ['/work/repo'])).toBe(true);
+ });
+
it('keeps a remote hit when updatedAt is recent but userSendAt is old', () => {
const page = filterResultsByRequestFilters(
response([
diff --git a/apps/desktop/src/renderer/lib/conversationSearchFanout.ts b/apps/desktop/src/renderer/lib/conversationSearchFanout.ts
index f104078065..5605655496 100644
--- a/apps/desktop/src/renderer/lib/conversationSearchFanout.ts
+++ b/apps/desktop/src/renderer/lib/conversationSearchFanout.ts
@@ -29,7 +29,7 @@ import {
normalizeProjectKey,
projectKeyComparisonKey,
} from '../../shared/projectKeys';
-import { normalizeWorkingDirForGrouping } from '../../shared/workingDir';
+import { normalizeWorkingDirForComparison, normalizeWorkingDirForGrouping } from '../../shared/workingDir';
import { CINDY_MAKE_ENABLED, isCindyMakeSource } from '@cindy/maker-shared/cindy-make-feature';
export interface ConversationSearchDevice {
@@ -510,7 +510,7 @@ function normalizeWorkingDirSet(value: string[] | null | undefined): Set<string>
if (value == null || !Array.isArray(value)) return null;
const out = new Set<string>();
for (const item of value) {
- const normalized = normalizeWorkingDirForGrouping(item);
+ const normalized = normalizeWorkingDirForComparison(item);
if (normalized) out.add(normalized);
}
return out.size > 0 ? out : null;
@@ -521,7 +521,7 @@ function matchesWorkingDirSet(
allowed: Set<string> | null,
): boolean {
if (allowed == null) return true;
- const key = normalizeWorkingDirForGrouping(workingDir);
+ const key = normalizeWorkingDirForComparison(workingDir);
return key != null && allowed.has(key);
}
diff --git a/apps/desktop/src/shared/workingDir.ts b/apps/desktop/src/shared/workingDir.ts
index 0ae8557c56..61eab6271c 100644
--- a/apps/desktop/src/shared/workingDir.ts
+++ b/apps/desktop/src/shared/workingDir.ts
@@ -87,10 +87,15 @@ export function normalizeWorkingDirForProjectSettings(
export function normalizeWorkingDirForGrouping(raw: string | null | undefined): string | null {
const out = normalizeWorkingDirForProjectSettings(raw);
if (out == null) return null;
-
return collapseWorktreeDirForGrouping(out);
}
+/** 搜索比较键:保留分组结果的原始拼写用于展示,只有比较时才折叠 Windows 大小写。 */
+export function normalizeWorkingDirForComparison(raw: string | null | undefined): string | null {
+ const collapsed = normalizeWorkingDirForGrouping(raw);
+ return collapsed && isWindowsPathLike(collapsed) ? collapsed.toLowerCase() : collapsed;
+}
+
export function stripWindowsLongPathPrefix(p: string): string {
if (p.startsWith('\\\\?\\UNC\\')) return `\\\\${p.slice('\\\\?\\UNC\\'.length)}`;
if (p.startsWith('\\\\?\\')) return p.slice('\\\\?\\'.length);
diff --git a/packages/maker-shared/src/__tests__/conversationSearch.test.ts b/packages/maker-shared/src/__tests__/conversationSearch.test.ts
index c4c51cd17a..b282170dc2 100644
--- a/packages/maker-shared/src/__tests__/conversationSearch.test.ts
+++ b/packages/maker-shared/src/__tests__/conversationSearch.test.ts
@@ -166,6 +166,43 @@ describe('filterResultsByWorkingDirs', () => {
);
expect(page.results.map((item) => item.session.id)).toEqual(['keep']);
});
+
+ // 回归价值:两个公开过滤入口必须保留同目录、排除异目录;现有 POSIX 用例未覆盖
+ // Windows 大小写变体被误排除的 bug。最小失败输入为仅盘符/UNC 大小写不同的目录(unit)。
+ it.each([
+ {
+ name: 'drive',
+ selected: 'c:\\Work\\Repo',
+ matching: 'C:/work/repo',
+ different: 'C:/Work/Other',
+ },
+ {
+ name: 'UNC',
+ selected: '\\\\Server\\Share\\Repo',
+ matching: '//server/share/repo',
+ different: '//server/share/other',
+ },
+ ])('keeps Windows $name case variants but drops genuinely different directories', ({ selected, matching, different }) => {
+ const page = filterResultsByWorkingDirs(
+ response([
+ result('keep', 1, { workingDir: matching }),
+ result('drop', 1, { workingDir: different }),
+ ]),
+ [selected],
+ );
+ expect(page.results.map((item) => item.session.id)).toEqual(['keep']);
+ });
+
+ it('keeps POSIX directory matching case-sensitive', () => {
+ const page = filterResultsByWorkingDirs(
+ response([
+ result('keep', 1, { workingDir: '/Work/Repo' }),
+ result('drop', 1, { workingDir: '/work/repo' }),
+ ]),
+ ['/Work/Repo'],
+ );
+ expect(page.results.map((item) => item.session.id)).toEqual(['keep']);
+ });
});
describe('filterResultsByRequestFilters', () => {
@@ -247,4 +284,47 @@ describe('remoteIndexedSearchIgnoredWorkingDirs', () => {
),
).toBe(false);
});
+
+ it.each([
+ {
+ name: 'drive',
+ selected: 'c:\\Work\\Repo',
+ matching: 'C:/work/repo',
+ different: 'C:/Work/Other',
+ },
+ {
+ name: 'UNC',
+ selected: '\\\\Server\\Share\\Repo',
+ matching: '//server/share/repo',
+ different: '//server/share/other',
+ },
+ ])('uses Windows $name case-insensitive matching when detecting ignored filters', ({ selected, matching, different }) => {
+ expect(
+ remoteIndexedSearchIgnoredWorkingDirs(
+ response([result('keep', 1, { workingDir: matching })]),
+ [selected],
+ ),
+ ).toBe(false);
+ expect(
+ remoteIndexedSearchIgnoredWorkingDirs(
+ response([result('drop', 1, { workingDir: different })]),
+ [selected],
+ ),
+ ).toBe(true);
+ });
+
+ it('uses POSIX case-sensitive matching when detecting ignored filters', () => {
+ expect(
+ remoteIndexedSearchIgnoredWorkingDirs(
+ response([result('keep', 1, { workingDir: '/Work/Repo' })]),
+ ['/Work/Repo'],
+ ),
+ ).toBe(false);
+ expect(
+ remoteIndexedSearchIgnoredWorkingDirs(
+ response([result('drop', 1, { workingDir: '/work/repo' })]),
+ ['/Work/Repo'],
+ ),
+ ).toBe(true);
+ });
});
diff --git a/packages/maker-shared/src/conversationSearch.ts b/packages/maker-shared/src/conversationSearch.ts
index ab258b558d..a434521211 100644
--- a/packages/maker-shared/src/conversationSearch.ts
+++ b/packages/maker-shared/src/conversationSearch.ts
@@ -268,7 +268,8 @@ function normalizeWorkingDirForGrouping(raw: string | null | undefined): string
if (/^[A-Za-z]:\/$/.test(out)) break;
out = out.slice(0, -1);
}
- return collapseWorktreeDirForGrouping(out);
+ const collapsed = collapseWorktreeDirForGrouping(out);
+ return isWindowsPathLike(collapsed) ? collapsed.toLowerCase() : collapsed;
}
function stripWindowsLongPathPrefix(value: string): string {