mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-09 21:00:56 -07:00
fix: clean up /clear and /resume (#22007)
This commit is contained in:
@@ -238,6 +238,34 @@ describe('SessionStatsContext', () => {
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('should update session ID and reset stats when the uiTelemetryService emits a clear event', () => {
|
||||
const contextRef: MutableRefObject<
|
||||
ReturnType<typeof useSessionStats> | undefined
|
||||
> = { current: undefined };
|
||||
|
||||
const { unmount } = render(
|
||||
<SessionStatsProvider>
|
||||
<TestHarness contextRef={contextRef} />
|
||||
</SessionStatsProvider>,
|
||||
);
|
||||
|
||||
const initialStartTime = contextRef.current?.stats.sessionStartTime;
|
||||
const newSessionId = 'new-session-id';
|
||||
|
||||
act(() => {
|
||||
uiTelemetryService.emit('clear', newSessionId);
|
||||
});
|
||||
|
||||
const stats = contextRef.current?.stats;
|
||||
expect(stats?.sessionId).toBe(newSessionId);
|
||||
expect(stats?.promptCount).toBe(0);
|
||||
expect(stats?.sessionStartTime.getTime()).toBeGreaterThanOrEqual(
|
||||
initialStartTime!.getTime(),
|
||||
);
|
||||
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('should throw an error when useSessionStats is used outside of a provider', () => {
|
||||
const onError = vi.fn();
|
||||
// Suppress console.error from React for this test
|
||||
|
||||
@@ -216,7 +216,17 @@ export const SessionStatsProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
});
|
||||
};
|
||||
|
||||
const handleClear = (newSessionId?: string) => {
|
||||
setStats((prevState) => ({
|
||||
...prevState,
|
||||
sessionId: newSessionId || prevState.sessionId,
|
||||
sessionStartTime: new Date(),
|
||||
promptCount: 0,
|
||||
}));
|
||||
};
|
||||
|
||||
uiTelemetryService.on('update', handleUpdate);
|
||||
uiTelemetryService.on('clear', handleClear);
|
||||
// Set initial state
|
||||
handleUpdate({
|
||||
metrics: uiTelemetryService.getMetrics(),
|
||||
@@ -225,6 +235,7 @@ export const SessionStatsProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
|
||||
return () => {
|
||||
uiTelemetryService.off('update', handleUpdate);
|
||||
uiTelemetryService.off('clear', handleClear);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user