mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-02 16:04:38 -07:00
refactor: simplify tool output truncation to single config (#18446)
This commit is contained in:
@@ -44,7 +44,6 @@ describe('ToolExecutor', () => {
|
||||
// Default mock implementation
|
||||
vi.mocked(fileUtils.saveTruncatedToolOutput).mockResolvedValue({
|
||||
outputFile: '/tmp/truncated_output.txt',
|
||||
totalLines: 100,
|
||||
});
|
||||
vi.mocked(fileUtils.formatTruncatedToolOutput).mockReturnValue(
|
||||
'TruncatedContent...',
|
||||
@@ -180,9 +179,7 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should truncate large shell output', async () => {
|
||||
// 1. Setup Config for Truncation
|
||||
vi.spyOn(config, 'getEnableToolOutputTruncation').mockReturnValue(true);
|
||||
vi.spyOn(config, 'getTruncateToolOutputThreshold').mockReturnValue(10);
|
||||
vi.spyOn(config, 'getTruncateToolOutputLines').mockReturnValue(5);
|
||||
|
||||
const mockTool = new MockTool({ name: SHELL_TOOL_NAME });
|
||||
const invocation = mockTool.build({});
|
||||
@@ -227,7 +224,7 @@ describe('ToolExecutor', () => {
|
||||
expect(fileUtils.formatTruncatedToolOutput).toHaveBeenCalledWith(
|
||||
longOutput,
|
||||
'/tmp/truncated_output.txt',
|
||||
5, // lines
|
||||
10, // threshold (maxChars)
|
||||
);
|
||||
|
||||
expect(result.status).toBe('success');
|
||||
|
||||
@@ -204,18 +204,11 @@ export class ToolExecutor {
|
||||
const toolName = call.request.name;
|
||||
const callId = call.request.callId;
|
||||
|
||||
if (
|
||||
typeof content === 'string' &&
|
||||
toolName === SHELL_TOOL_NAME &&
|
||||
this.config.getEnableToolOutputTruncation() &&
|
||||
this.config.getTruncateToolOutputThreshold() > 0 &&
|
||||
this.config.getTruncateToolOutputLines() > 0
|
||||
) {
|
||||
const originalContentLength = content.length;
|
||||
if (typeof content === 'string' && toolName === SHELL_TOOL_NAME) {
|
||||
const threshold = this.config.getTruncateToolOutputThreshold();
|
||||
const lines = this.config.getTruncateToolOutputLines();
|
||||
|
||||
if (content.length > threshold) {
|
||||
if (threshold > 0 && content.length > threshold) {
|
||||
const originalContentLength = content.length;
|
||||
const { outputFile: savedPath } = await saveTruncatedToolOutput(
|
||||
content,
|
||||
toolName,
|
||||
@@ -224,7 +217,7 @@ export class ToolExecutor {
|
||||
this.config.getSessionId(),
|
||||
);
|
||||
outputFile = savedPath;
|
||||
content = formatTruncatedToolOutput(content, outputFile, lines);
|
||||
content = formatTruncatedToolOutput(content, outputFile, threshold);
|
||||
|
||||
logToolOutputTruncated(
|
||||
this.config,
|
||||
@@ -233,7 +226,6 @@ export class ToolExecutor {
|
||||
originalContentLength,
|
||||
truncatedContentLength: content.length,
|
||||
threshold,
|
||||
lines,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user