diff --git a/packages/cli/src/ui/components/DebugProfiler.test.tsx b/packages/cli/src/ui/components/DebugProfiler.test.tsx index b60419be8a..6ccb9fdea6 100644 --- a/packages/cli/src/ui/components/DebugProfiler.test.tsx +++ b/packages/cli/src/ui/components/DebugProfiler.test.tsx @@ -6,6 +6,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { appEvents, AppEvent } from '../../utils/events.js'; +import { coreEvents } from '@google/gemini-cli-core'; import { profiler, DebugProfiler, @@ -16,6 +17,7 @@ import { render } from '../../test-utils/render.js'; import { useUIState, type UIState } from '../contexts/UIStateContext.js'; import { FixedDeque } from 'mnemonist'; import { debugState } from '../debug.js'; +import { act } from 'react'; vi.mock('../contexts/UIStateContext.js', () => ({ useUIState: vi.fn(), @@ -266,4 +268,40 @@ describe('DebugProfiler Component', () => { expect(output).toContain('5 (idle)'); expect(output).toContain('2 (flicker)'); }); + + it('should report an action when a CoreEvent is emitted', async () => { + vi.mocked(useUIState).mockReturnValue({ + showDebugProfiler: true, + constrainHeight: false, + } as unknown as UIState); + + const reportActionSpy = vi.spyOn(profiler, 'reportAction'); + + const { unmount } = render(); + + act(() => { + coreEvents.emitModelChanged('new-model'); + }); + + expect(reportActionSpy).toHaveBeenCalled(); + unmount(); + }); + + it('should report an action when an AppEvent is emitted', async () => { + vi.mocked(useUIState).mockReturnValue({ + showDebugProfiler: true, + constrainHeight: false, + } as unknown as UIState); + + const reportActionSpy = vi.spyOn(profiler, 'reportAction'); + + const { unmount } = render(); + + act(() => { + appEvents.emit(AppEvent.SelectionWarning); + }); + + expect(reportActionSpy).toHaveBeenCalled(); + unmount(); + }); }); diff --git a/packages/cli/src/ui/components/DebugProfiler.tsx b/packages/cli/src/ui/components/DebugProfiler.tsx index 16eb8d69f9..e68b3018dd 100644 --- a/packages/cli/src/ui/components/DebugProfiler.tsx +++ b/packages/cli/src/ui/components/DebugProfiler.tsx @@ -11,7 +11,7 @@ import { theme } from '../semantic-colors.js'; import { useUIState } from '../contexts/UIStateContext.js'; import { debugState } from '../debug.js'; import { appEvents, AppEvent } from '../../utils/events.js'; -import { debugLogger } from '@google/gemini-cli-core'; +import { coreEvents, CoreEvent, debugLogger } from '@google/gemini-cli-core'; // Frames that render at least this far before or after an action are considered // idle frames. @@ -160,9 +160,29 @@ export const DebugProfiler = () => { stdin.on('data', handler); stdout.on('resize', handler); + // Register handlers for all core and app events to ensure they are + // considered "actions" and don't trigger spurious idle frame warnings. + // These events are expected to trigger UI renders. + for (const eventName of Object.values(CoreEvent)) { + coreEvents.on(eventName, handler); + } + + for (const eventName of Object.values(AppEvent)) { + appEvents.on(eventName, handler); + } + return () => { stdin.off('data', handler); stdout.off('resize', handler); + + for (const eventName of Object.values(CoreEvent)) { + coreEvents.off(eventName, handler); + } + + for (const eventName of Object.values(AppEvent)) { + appEvents.off(eventName, handler); + } + profiler.profilersActive--; }; }, []);