bug(core): Strip thoughts when loading history. (#7167)

This commit is contained in:
joshualitt
2025-08-28 10:25:13 -07:00
committed by GitHub
parent c35aebe109
commit 600151cc2c
2 changed files with 40 additions and 2 deletions

View File

@@ -417,6 +417,44 @@ describe('useSlashCommandProcessor', () => {
);
});
it('should strip thoughts when handling "load_history" action', async () => {
const mockSetHistory = vi.fn();
const mockGeminiClient = {
setHistory: mockSetHistory,
};
vi.spyOn(mockConfig, 'getGeminiClient').mockReturnValue(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
mockGeminiClient as any,
);
const historyWithThoughts = [
{
role: 'model',
parts: [{ text: 'response', thoughtSignature: 'CikB...' }],
},
];
const command = createTestCommand({
name: 'loadwiththoughts',
action: vi.fn().mockResolvedValue({
type: 'load_history',
history: [{ type: MessageType.MODEL, text: 'response' }],
clientHistory: historyWithThoughts,
}),
});
const result = setupProcessorHook([command]);
await waitFor(() => expect(result.current.slashCommands).toHaveLength(1));
await act(async () => {
await result.current.handleSlashCommand('/loadwiththoughts');
});
expect(mockSetHistory).toHaveBeenCalledTimes(1);
expect(mockSetHistory).toHaveBeenCalledWith(historyWithThoughts, {
stripThoughts: true,
});
});
describe('with fake timers', () => {
// This test needs to let the async `waitFor` complete with REAL timers
// before switching to FAKE timers to test setTimeout.

View File

@@ -393,9 +393,9 @@ export const useSlashCommandProcessor = (
}
}
case 'load_history': {
await config
config
?.getGeminiClient()
?.setHistory(result.clientHistory);
?.setHistory(result.clientHistory, { stripThoughts: true });
fullCommandContext.ui.clear();
result.history.forEach((item, index) => {
fullCommandContext.ui.addItem(item, index);