Replace spawn with execFile for memory-safe command execution (#1068)

This commit is contained in:
tanzhenxin
2025-11-20 15:04:00 +08:00
committed by GitHub
parent a15b84e2a1
commit 442a9aed58
20 changed files with 620 additions and 969 deletions

View File

@@ -1085,7 +1085,7 @@ describe('setApprovalMode with folder trust', () => {
expect.any(RipgrepFallbackEvent),
);
const event = (logRipgrepFallback as Mock).mock.calls[0][1];
expect(event.error).toContain('Ripgrep is not available');
expect(event.error).toContain('ripgrep is not available');
});
it('should fall back to GrepTool and log error when useRipgrep is true and builtin ripgrep is not available', async () => {
@@ -1109,7 +1109,7 @@ describe('setApprovalMode with folder trust', () => {
expect.any(RipgrepFallbackEvent),
);
const event = (logRipgrepFallback as Mock).mock.calls[0][1];
expect(event.error).toContain('Ripgrep is not available');
expect(event.error).toContain('ripgrep is not available');
});
it('should fall back to GrepTool and log error when canUseRipgrep throws an error', async () => {
@@ -1133,7 +1133,7 @@ describe('setApprovalMode with folder trust', () => {
expect.any(RipgrepFallbackEvent),
);
const event = (logRipgrepFallback as Mock).mock.calls[0][1];
expect(event.error).toBe(String(error));
expect(event.error).toBe(`ripGrep check failed`);
});
it('should register GrepTool when useRipgrep is false', async () => {

View File

@@ -82,6 +82,7 @@ import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
import { FileExclusions } from '../utils/ignorePatterns.js';
import { WorkspaceContext } from '../utils/workspaceContext.js';
import { isToolEnabled, type ToolName } from '../utils/tool-utils.js';
import { getErrorMessage } from '../utils/errors.js';
// Local config modules
import type { FileFilteringOptions } from './constants.js';
@@ -1147,17 +1148,20 @@ export class Config {
try {
useRipgrep = await canUseRipgrep(this.getUseBuiltinRipgrep());
} catch (error: unknown) {
errorString = String(error);
errorString = getErrorMessage(error);
}
if (useRipgrep) {
registerCoreTool(RipGrepTool, this);
} else {
errorString =
errorString ||
'Ripgrep is not available. Please install ripgrep globally.';
// Log for telemetry
logRipgrepFallback(this, new RipgrepFallbackEvent(errorString));
logRipgrepFallback(
this,
new RipgrepFallbackEvent(
this.getUseRipgrep(),
this.getUseBuiltinRipgrep(),
errorString || 'ripgrep is not available',
),
);
registerCoreTool(GrepTool, this);
}
} else {