mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-15 16:41:11 -07:00
fix: persist and restore workspace directories on session resume (#17454)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
@@ -402,6 +402,77 @@ describe('ChatRecordingService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('recordDirectories', () => {
|
||||
beforeEach(() => {
|
||||
chatRecordingService.initialize();
|
||||
});
|
||||
|
||||
it('should save directories to the conversation', () => {
|
||||
const writeFileSyncSpy = vi
|
||||
.spyOn(fs, 'writeFileSync')
|
||||
.mockImplementation(() => undefined);
|
||||
const initialConversation = {
|
||||
sessionId: 'test-session-id',
|
||||
projectHash: 'test-project-hash',
|
||||
messages: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'user',
|
||||
content: 'Hello',
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
};
|
||||
vi.spyOn(fs, 'readFileSync').mockReturnValue(
|
||||
JSON.stringify(initialConversation),
|
||||
);
|
||||
|
||||
chatRecordingService.recordDirectories([
|
||||
'/path/to/dir1',
|
||||
'/path/to/dir2',
|
||||
]);
|
||||
|
||||
expect(writeFileSyncSpy).toHaveBeenCalled();
|
||||
const conversation = JSON.parse(
|
||||
writeFileSyncSpy.mock.calls[0][1] as string,
|
||||
) as ConversationRecord;
|
||||
expect(conversation.directories).toEqual([
|
||||
'/path/to/dir1',
|
||||
'/path/to/dir2',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should overwrite existing directories', () => {
|
||||
const writeFileSyncSpy = vi
|
||||
.spyOn(fs, 'writeFileSync')
|
||||
.mockImplementation(() => undefined);
|
||||
const initialConversation = {
|
||||
sessionId: 'test-session-id',
|
||||
projectHash: 'test-project-hash',
|
||||
messages: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'user',
|
||||
content: 'Hello',
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
directories: ['/old/dir'],
|
||||
};
|
||||
vi.spyOn(fs, 'readFileSync').mockReturnValue(
|
||||
JSON.stringify(initialConversation),
|
||||
);
|
||||
|
||||
chatRecordingService.recordDirectories(['/new/dir1', '/new/dir2']);
|
||||
|
||||
expect(writeFileSyncSpy).toHaveBeenCalled();
|
||||
const conversation = JSON.parse(
|
||||
writeFileSyncSpy.mock.calls[0][1] as string,
|
||||
) as ConversationRecord;
|
||||
expect(conversation.directories).toEqual(['/new/dir1', '/new/dir2']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('rewindTo', () => {
|
||||
it('should rewind the conversation to a specific message ID', () => {
|
||||
chatRecordingService.initialize();
|
||||
|
||||
@@ -96,6 +96,8 @@ export interface ConversationRecord {
|
||||
lastUpdated: string;
|
||||
messages: MessageRecord[];
|
||||
summary?: string;
|
||||
/** Workspace directories added during the session via /dir add */
|
||||
directories?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -486,6 +488,23 @@ export class ChatRecordingService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Records workspace directories to the session file.
|
||||
* Called when directories are added via /dir add.
|
||||
*/
|
||||
recordDirectories(directories: readonly string[]): void {
|
||||
if (!this.conversationFile) return;
|
||||
|
||||
try {
|
||||
this.updateConversation((conversation) => {
|
||||
conversation.directories = [...directories];
|
||||
});
|
||||
} catch (error) {
|
||||
debugLogger.error('Error saving directories to chat history.', error);
|
||||
// Don't throw - we want graceful degradation
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current conversation data (for summary generation).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user