fix: clean up /clear and /resume (#22007)

This commit is contained in:
Jack Wotherspoon
2026-03-11 16:23:23 +01:00
committed by GitHub
parent 99bbbc2170
commit b804fe9662
9 changed files with 282 additions and 22 deletions
@@ -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