mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-24 20:14:44 -07:00
refactor: simplify tool output truncation to single config (#18446)
This commit is contained in:
@@ -1125,7 +1125,6 @@ describe('fileUtils', () => {
|
||||
'shell_123.txt',
|
||||
);
|
||||
expect(result.outputFile).toBe(expectedOutputFile);
|
||||
expect(result.totalLines).toBe(1);
|
||||
|
||||
const savedContent = await fsPromises.readFile(
|
||||
expectedOutputFile,
|
||||
@@ -1200,43 +1199,32 @@ describe('fileUtils', () => {
|
||||
expect(result.outputFile).toBe(expectedOutputFile);
|
||||
});
|
||||
|
||||
it('should format multi-line output correctly', () => {
|
||||
const lines = Array.from({ length: 50 }, (_, i) => `line ${i}`);
|
||||
const content = lines.join('\n');
|
||||
it('should truncate showing first 20% and last 80%', () => {
|
||||
const content = 'abcdefghijklmnopqrstuvwxyz'; // 26 chars
|
||||
const outputFile = '/tmp/out.txt';
|
||||
|
||||
// maxChars=10 -> head=2 (20%), tail=8 (80%)
|
||||
const formatted = formatTruncatedToolOutput(content, outputFile, 10);
|
||||
|
||||
expect(formatted).toContain(
|
||||
'Output too large. Showing the last 10 of 50 lines.',
|
||||
);
|
||||
expect(formatted).toContain('Showing first 2 and last 8 characters');
|
||||
expect(formatted).toContain('For full output see: /tmp/out.txt');
|
||||
expect(formatted).toContain('line 49');
|
||||
expect(formatted).not.toContain('line 0');
|
||||
expect(formatted).toContain('ab'); // first 2 chars
|
||||
expect(formatted).toContain('stuvwxyz'); // last 8 chars
|
||||
expect(formatted).toContain('[16 characters omitted]'); // 26 - 2 - 8 = 16
|
||||
});
|
||||
|
||||
it('should truncate "elephant lines" (long single line in multi-line output)', () => {
|
||||
const longLine = 'a'.repeat(2000);
|
||||
const content = `line 1\n${longLine}\nline 3`;
|
||||
const outputFile = '/tmp/out.txt';
|
||||
|
||||
const formatted = formatTruncatedToolOutput(content, outputFile, 3);
|
||||
|
||||
expect(formatted).toContain('(some long lines truncated)');
|
||||
expect(formatted).toContain('... [LINE WIDTH TRUNCATED]');
|
||||
expect(formatted.length).toBeLessThan(longLine.length);
|
||||
});
|
||||
|
||||
it('should handle massive single-line string with character-based truncation', () => {
|
||||
it('should format large content with head/tail truncation', () => {
|
||||
const content = 'a'.repeat(50000);
|
||||
const outputFile = '/tmp/out.txt';
|
||||
|
||||
const formatted = formatTruncatedToolOutput(content, outputFile);
|
||||
// maxChars=4000 -> head=800 (20%), tail=3200 (80%)
|
||||
const formatted = formatTruncatedToolOutput(content, outputFile, 4000);
|
||||
|
||||
expect(formatted).toContain(
|
||||
'Output too large. Showing the last 4,000 characters',
|
||||
'Showing first 800 and last 3,200 characters',
|
||||
);
|
||||
expect(formatted.endsWith(content.slice(-4000))).toBe(true);
|
||||
expect(formatted).toContain('For full output see: /tmp/out.txt');
|
||||
expect(formatted).toContain('[46,000 characters omitted]'); // 50000 - 800 - 3200
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user