feat(admin): implement admin controls polling and restart prompt (#16627)

This commit is contained in:
Shreya Keshive
2026-01-16 15:24:53 -05:00
committed by GitHub
parent 93224e1813
commit d8d4d87e29
20 changed files with 689 additions and 26 deletions
+17
View File
@@ -186,6 +186,7 @@ export const AppContainer = (props: AppContainerProps) => {
);
const [copyModeEnabled, setCopyModeEnabled] = useState(false);
const [pendingRestorePrompt, setPendingRestorePrompt] = useState(false);
const [adminSettingsChanged, setAdminSettingsChanged] = useState(false);
const [shellModeActive, setShellModeActive] = useState(false);
const [modelSwitchedFromQuotaError, setModelSwitchedFromQuotaError] =
@@ -364,9 +365,18 @@ export const AppContainer = (props: AppContainerProps) => {
setSettingsNonce((prev) => prev + 1);
};
const handleAdminSettingsChanged = () => {
setAdminSettingsChanged(true);
};
coreEvents.on(CoreEvent.SettingsChanged, handleSettingsChanged);
coreEvents.on(CoreEvent.AdminSettingsChanged, handleAdminSettingsChanged);
return () => {
coreEvents.off(CoreEvent.SettingsChanged, handleSettingsChanged);
coreEvents.off(
CoreEvent.AdminSettingsChanged,
handleAdminSettingsChanged,
);
};
}, []);
@@ -1452,6 +1462,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
const dialogsVisible =
shouldShowIdePrompt ||
isFolderTrustDialogOpen ||
adminSettingsChanged ||
!!shellConfirmationRequest ||
!!confirmationRequest ||
!!customDialog ||
@@ -1616,6 +1627,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
bannerVisible,
terminalBackgroundColor: config.getTerminalBackground(),
settingsNonce,
adminSettingsChanged,
}),
[
isThemeDialogOpen,
@@ -1710,6 +1722,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
bannerVisible,
config,
settingsNonce,
adminSettingsChanged,
],
);
@@ -1754,6 +1767,10 @@ Logging in with Google... Restarting Gemini CLI to continue.
setBannerVisible,
setEmbeddedShellFocused,
setAuthContext,
handleRestart: async () => {
await runExitCleanup();
process.exit(RELAUNCH_EXIT_CODE);
},
}),
[
handleThemeSelect,
@@ -0,0 +1,51 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { renderWithProviders } from '../../test-utils/render.js';
import { describe, it, expect, vi, afterEach } from 'vitest';
import { act } from 'react';
import { AdminSettingsChangedDialog } from './AdminSettingsChangedDialog.js';
const handleRestartMock = vi.fn();
describe('AdminSettingsChangedDialog', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('renders correctly', () => {
const { lastFrame } = renderWithProviders(<AdminSettingsChangedDialog />);
expect(lastFrame()).toMatchSnapshot();
});
it('restarts on "r" key press', async () => {
const { stdin } = renderWithProviders(<AdminSettingsChangedDialog />, {
uiActions: {
handleRestart: handleRestartMock,
},
});
act(() => {
stdin.write('r');
});
expect(handleRestartMock).toHaveBeenCalled();
});
it.each(['r', 'R'])('restarts on "%s" key press', async (key) => {
const { stdin } = renderWithProviders(<AdminSettingsChangedDialog />, {
uiActions: {
handleRestart: handleRestartMock,
},
});
act(() => {
stdin.write(key);
});
expect(handleRestartMock).toHaveBeenCalled();
});
});
@@ -0,0 +1,36 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { Box, Text } from 'ink';
import { theme } from '../semantic-colors.js';
import { useKeypress } from '../hooks/useKeypress.js';
import { useUIActions } from '../contexts/UIActionsContext.js';
import { Command, keyMatchers } from '../keyMatchers.js';
export const AdminSettingsChangedDialog = () => {
const { handleRestart } = useUIActions();
useKeypress(
(key) => {
if (keyMatchers[Command.RESTART_APP](key)) {
handleRestart();
}
},
{ isActive: true },
);
const message =
'Admin settings have changed. Please restart the session to apply new settings.';
return (
<Box borderStyle="round" borderColor={theme.status.warning} paddingX={1}>
<Text color={theme.status.warning}>
{message} Press &apos;r&apos; to restart, or &apos;Ctrl+C&apos; twice to
exit.
</Text>
</Box>
);
};
@@ -30,6 +30,7 @@ import { useConfig } from '../contexts/ConfigContext.js';
import { useSettings } from '../contexts/SettingsContext.js';
import process from 'node:process';
import { type UseHistoryManagerReturn } from '../hooks/useHistoryManager.js';
import { AdminSettingsChangedDialog } from './AdminSettingsChangedDialog.js';
import { IdeTrustChangeDialog } from './IdeTrustChangeDialog.js';
interface DialogManagerProps {
@@ -50,6 +51,9 @@ export const DialogManager = ({
const { constrainHeight, terminalHeight, staticExtraHeight, mainAreaWidth } =
uiState;
if (uiState.adminSettingsChanged) {
return <AdminSettingsChangedDialog />;
}
if (uiState.showIdeRestartPrompt) {
return <IdeTrustChangeDialog reason={uiState.ideTrustRestartReason} />;
}
@@ -0,0 +1,8 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`AdminSettingsChangedDialog > renders correctly 1`] = `
"╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Admin settings have changed. Please restart the session to apply new settings. Press 'r' to restart, or 'Ctrl+C' │
│ twice to exit. │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯"
`;
@@ -57,6 +57,7 @@ export interface UIActions {
setBannerVisible: (visible: boolean) => void;
setEmbeddedShellFocused: (value: boolean) => void;
setAuthContext: (context: { requiresRestart?: boolean }) => void;
handleRestart: () => void;
}
export const UIActionsContext = createContext<UIActions | null>(null);
@@ -141,6 +141,7 @@ export interface UIState {
customDialog: React.ReactNode | null;
terminalBackgroundColor: TerminalBackgroundColor;
settingsNonce: number;
adminSettingsChanged: boolean;
}
export const UIStateContext = createContext<UIState | null>(null);