mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-29 07:21:27 -07:00
feat(cli): consolidate shell inactivity and redirection monitoring (#17086)
This commit is contained in:
103
packages/cli/src/ui/hooks/useShellInactivityStatus.test.ts
Normal file
103
packages/cli/src/ui/hooks/useShellInactivityStatus.test.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { act } from 'react';
|
||||
import { renderHook } from '../../test-utils/render.js';
|
||||
import { useShellInactivityStatus } from './useShellInactivityStatus.js';
|
||||
import { useTurnActivityMonitor } from './useTurnActivityMonitor.js';
|
||||
import { StreamingState } from '../types.js';
|
||||
|
||||
vi.mock('./useTurnActivityMonitor.js', () => ({
|
||||
useTurnActivityMonitor: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('useShellInactivityStatus', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
vi.mocked(useTurnActivityMonitor).mockReturnValue({
|
||||
operationStartTime: 1000,
|
||||
isRedirectionActive: false,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
const defaultProps = {
|
||||
activePtyId: 'pty-1',
|
||||
lastOutputTime: 1001,
|
||||
streamingState: StreamingState.Responding,
|
||||
pendingToolCalls: [],
|
||||
embeddedShellFocused: false,
|
||||
isInteractiveShellEnabled: true,
|
||||
};
|
||||
|
||||
it('should show action_required status after 30s when output has been produced', async () => {
|
||||
const { result } = renderHook(() => useShellInactivityStatus(defaultProps));
|
||||
|
||||
expect(result.current.inactivityStatus).toBe('none');
|
||||
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(30000);
|
||||
});
|
||||
expect(result.current.inactivityStatus).toBe('action_required');
|
||||
});
|
||||
|
||||
it('should show silent_working status after 60s when no output has been produced (silent)', async () => {
|
||||
const { result } = renderHook(() =>
|
||||
useShellInactivityStatus({ ...defaultProps, lastOutputTime: 500 }),
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(30000);
|
||||
});
|
||||
expect(result.current.inactivityStatus).toBe('none');
|
||||
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(30000);
|
||||
});
|
||||
expect(result.current.inactivityStatus).toBe('silent_working');
|
||||
});
|
||||
|
||||
it('should show silent_working status after 2 mins for redirected commands', async () => {
|
||||
vi.mocked(useTurnActivityMonitor).mockReturnValue({
|
||||
operationStartTime: 1000,
|
||||
isRedirectionActive: true,
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useShellInactivityStatus(defaultProps));
|
||||
|
||||
// Should NOT show action_required even after 60s
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(60000);
|
||||
});
|
||||
expect(result.current.inactivityStatus).toBe('none');
|
||||
|
||||
// Should show silent_working after 2 mins (120000ms)
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(60000);
|
||||
});
|
||||
expect(result.current.inactivityStatus).toBe('silent_working');
|
||||
});
|
||||
|
||||
it('should suppress focus hint when redirected', async () => {
|
||||
vi.mocked(useTurnActivityMonitor).mockReturnValue({
|
||||
operationStartTime: 1000,
|
||||
isRedirectionActive: true,
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useShellInactivityStatus(defaultProps));
|
||||
|
||||
// Even after delay, focus hint should be suppressed
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(20000);
|
||||
});
|
||||
expect(result.current.shouldShowFocusHint).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user