mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-02 01:11:24 -07:00
fix: shorten tool call IDs and fix duplicate tool name in truncated output filenames (#18600)
This commit is contained in:
@@ -1110,7 +1110,7 @@ describe('fileUtils', () => {
|
||||
it('should save content to a file with safe name', async () => {
|
||||
const content = 'some content';
|
||||
const toolName = 'shell';
|
||||
const id = '123';
|
||||
const id = 'shell_123';
|
||||
|
||||
const result = await saveTruncatedToolOutput(
|
||||
content,
|
||||
@@ -1154,6 +1154,26 @@ describe('fileUtils', () => {
|
||||
expect(result.outputFile).toBe(expectedOutputFile);
|
||||
});
|
||||
|
||||
it('should not duplicate tool name when id already starts with it', async () => {
|
||||
const content = 'content';
|
||||
const toolName = 'run_shell_command';
|
||||
const id = 'run_shell_command_1707400000000_0';
|
||||
|
||||
const result = await saveTruncatedToolOutput(
|
||||
content,
|
||||
toolName,
|
||||
id,
|
||||
tempRootDir,
|
||||
);
|
||||
|
||||
const expectedOutputFile = path.join(
|
||||
tempRootDir,
|
||||
'tool-outputs',
|
||||
'run_shell_command_1707400000000_0.txt',
|
||||
);
|
||||
expect(result.outputFile).toBe(expectedOutputFile);
|
||||
});
|
||||
|
||||
it('should sanitize id in filename', async () => {
|
||||
const content = 'content';
|
||||
const toolName = 'shell';
|
||||
@@ -1178,7 +1198,7 @@ describe('fileUtils', () => {
|
||||
it('should sanitize sessionId in filename/path', async () => {
|
||||
const content = 'content';
|
||||
const toolName = 'shell';
|
||||
const id = '1';
|
||||
const id = 'shell_1';
|
||||
const sessionId = '../../etc/passwd';
|
||||
|
||||
const result = await saveTruncatedToolOutput(
|
||||
|
||||
@@ -617,7 +617,9 @@ export async function saveTruncatedToolOutput(
|
||||
): Promise<{ outputFile: string }> {
|
||||
const safeToolName = sanitizeFilenamePart(toolName).toLowerCase();
|
||||
const safeId = sanitizeFilenamePart(id.toString()).toLowerCase();
|
||||
const fileName = `${safeToolName}_${safeId}.txt`;
|
||||
const fileName = safeId.startsWith(safeToolName)
|
||||
? `${safeId}.txt`
|
||||
: `${safeToolName}_${safeId}.txt`;
|
||||
|
||||
let toolOutputDir = path.join(projectTempDir, TOOL_OUTPUTS_DIR);
|
||||
if (sessionId) {
|
||||
|
||||
Reference in New Issue
Block a user