Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions packages/core/src/utils/filesearch/crawler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,80 @@ describe('crawler', () => {
);
});

it('should preserve non-ASCII tracked filenames', async () => {
tmpDir = await createTmpDir({
'设计文档.txt': '',
});
await initGitRepo(tmpDir);
await runExecFile('git', ['config', 'core.quotePath', 'true'], tmpDir);

const ignore = loadIgnoreRules({
projectRoot: tmpDir,
useGitignore: false,
useQwenignore: false,
ignoreDirs: [],
});

const results = await crawl({
crawlDirectory: tmpDir,
cwd: tmpDir,
ignore,
cache: false,
cacheTtl: 0,
});

expect(results).toContain('设计文档.txt');
expect(results.some((entry) => entry.includes('\\346'))).toBe(false);
});

it('should disable Git path quoting for crawler commands', async () => {
tmpDir = await createTmpDir({ 'tracked.js': '' });
const gitArgsSeen: string[][] = [];

__setCommandRunnerForTests(async (command, args) => {
if (command !== 'git') {
return { success: false, lines: [] };
}

gitArgsSeen.push(args);
const quotePathArgIndex = args.indexOf('core.quotePath=false');
expect(quotePathArgIndex).toBeGreaterThan(0);
expect(args[quotePathArgIndex - 1]).toBe('-c');

if (args.includes('rev-parse') && args.includes('--show-toplevel')) {
return { success: true, lines: [tmpDir] };
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] expect.arrayContaining(['-c', 'core.quotePath=false']) checks that both strings exist somewhere in the args array but does not verify they are adjacent. Since withSafeGitConfig already produces multiple -c entries, the '-c' match is trivially satisfied by an unrelated entry. A bug that placed core.quotePath=false without a preceding -c would go undetected.

Consider verifying adjacency:

const idx = args.indexOf('core.quotePath=false');
expect(idx).toBeGreaterThan(0);
expect(args[idx - 1]).toBe('-c');

Note: the integration test above (real git, real non-ASCII file) would catch a positional regression, so this is low-risk in practice.

— qwen3.7-max via Qwen Code /review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good point. Updated the mock assertion to verify that core.quotePath=false is immediately preceded by -c, while keeping the real Git regression test for the end-to-end behavior. Verified locally with cd packages/core && npx vitest run src/utils/filesearch/crawler.test.ts (46 tests passed).

if (args.includes('ls-files') && args.includes('--others')) {
return { success: true, lines: [] };
}
if (args.includes('ls-files') && args.includes('--deleted')) {
return { success: true, lines: [] };
}
if (args.includes('ls-files') && args.includes('--cached')) {
return { success: true, lines: ['H tracked.js'] };
}
return { success: false, lines: [] };
});

const ignore = loadIgnoreRules({
projectRoot: tmpDir,
useGitignore: false,
useQwenignore: false,
ignoreDirs: [],
});

const results = await crawl({
crawlDirectory: tmpDir,
cwd: tmpDir,
ignore,
cache: false,
cacheTtl: 0,
});

expect(results).toContain('tracked.js');
expect(gitArgsSeen.length).toBeGreaterThan(0);
});

it('should resolve the git root from a subdirectory crawl', async () => {
tmpDir = await createTmpDir({
src: ['file2.js'],
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/utils/filesearch/crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ function logCommandProblem(

function withSafeGitConfig(args: string[]): string[] {
return [
'-c',
'core.quotePath=false',
'-c',
'core.fsmonitor=false',
'-c',
Expand Down
Loading