From 3aabb940f5b66aaed340d20bf4decfa6c40330cc Mon Sep 17 00:00:00 2001 From: Preston Holmes Date: Fri, 27 Jun 2025 08:46:27 -0700 Subject: [PATCH] Add the current auth method and GCP Project config to the about message (#2112) --- packages/cli/src/ui/components/AboutBox.tsx | 28 +++++++ .../ui/components/HistoryItemDisplay.test.tsx | 2 + .../src/ui/components/HistoryItemDisplay.tsx | 2 + .../ui/hooks/slashCommandProcessor.test.ts | 83 +++++++++++++++++++ .../cli/src/ui/hooks/slashCommandProcessor.ts | 7 ++ packages/cli/src/ui/types.ts | 4 + 6 files changed, 126 insertions(+) diff --git a/packages/cli/src/ui/components/AboutBox.tsx b/packages/cli/src/ui/components/AboutBox.tsx index 0744beff..71afbdd4 100644 --- a/packages/cli/src/ui/components/AboutBox.tsx +++ b/packages/cli/src/ui/components/AboutBox.tsx @@ -14,6 +14,8 @@ interface AboutBoxProps { osVersion: string; sandboxEnv: string; modelVersion: string; + selectedAuthType: string; + gcpProject: string; } export const AboutBox: React.FC = ({ @@ -21,6 +23,8 @@ export const AboutBox: React.FC = ({ osVersion, sandboxEnv, modelVersion, + selectedAuthType, + gcpProject, }) => ( = ({ {osVersion} + + + + Auth Method + + + + + {selectedAuthType.startsWith('oauth') ? 'OAuth' : selectedAuthType} + + + + {gcpProject && ( + + + + GCP Project + + + + {gcpProject} + + + )} ); diff --git a/packages/cli/src/ui/components/HistoryItemDisplay.test.tsx b/packages/cli/src/ui/components/HistoryItemDisplay.test.tsx index 464647b0..5816f7b4 100644 --- a/packages/cli/src/ui/components/HistoryItemDisplay.test.tsx +++ b/packages/cli/src/ui/components/HistoryItemDisplay.test.tsx @@ -67,6 +67,8 @@ describe('', () => { osVersion: 'test-os', sandboxEnv: 'test-env', modelVersion: 'test-model', + selectedAuthType: 'test-auth', + gcpProject: 'test-project', }; const { lastFrame } = render( , diff --git a/packages/cli/src/ui/components/HistoryItemDisplay.tsx b/packages/cli/src/ui/components/HistoryItemDisplay.tsx index dbbb5938..76b6ba6e 100644 --- a/packages/cli/src/ui/components/HistoryItemDisplay.tsx +++ b/packages/cli/src/ui/components/HistoryItemDisplay.tsx @@ -65,6 +65,8 @@ export const HistoryItemDisplay: React.FC = ({ osVersion={item.osVersion} sandboxEnv={item.sandboxEnv} modelVersion={item.modelVersion} + selectedAuthType={item.selectedAuthType} + gcpProject={item.gcpProject} /> )} {item.type === 'stats' && ( diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts index 09d2acab..01954670 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts @@ -336,6 +336,89 @@ describe('useSlashCommandProcessor', () => { }); }); + describe('/about command', () => { + it('should show the about box with all details including auth and project', async () => { + // Arrange + mockGetCliVersionFn.mockResolvedValue('test-version'); + process.env.SANDBOX = 'gemini-sandbox'; + process.env.GOOGLE_CLOUD_PROJECT = 'test-gcp-project'; + vi.mocked(mockConfig.getModel).mockReturnValue('test-model-from-config'); + + const settings = { + merged: { + selectedAuthType: 'test-auth-type', + contextFileName: 'GEMINI.md', + }, + } as LoadedSettings; + + const { result } = renderHook(() => + useSlashCommandProcessor( + mockConfig, + settings, + [], + mockAddItem, + mockClearItems, + mockLoadHistory, + mockRefreshStatic, + mockSetShowHelp, + mockOnDebugMessage, + mockOpenThemeDialog, + mockOpenAuthDialog, + mockOpenEditorDialog, + mockPerformMemoryRefresh, + mockCorgiMode, + false, + mockSetQuittingMessages, + ), + ); + + // Act + await act(async () => { + await result.current.handleSlashCommand('/about'); + }); + + // Assert + expect(mockAddItem).toHaveBeenCalledTimes(2); // user message + about message + expect(mockAddItem).toHaveBeenNthCalledWith( + 2, + expect.objectContaining({ + type: 'about', + cliVersion: 'test-version', + osVersion: 'test-platform', + sandboxEnv: 'gemini-sandbox', + modelVersion: 'test-model-from-config', + selectedAuthType: 'test-auth-type', + gcpProject: 'test-gcp-project', + }), + expect.any(Number), + ); + }); + + it('should show sandbox-exec profile when applicable', async () => { + // Arrange + mockGetCliVersionFn.mockResolvedValue('test-version'); + process.env.SANDBOX = 'sandbox-exec'; + process.env.SEATBELT_PROFILE = 'test-profile'; + vi.mocked(mockConfig.getModel).mockReturnValue('test-model-from-config'); + + const { result } = getProcessorHook(); + + // Act + await act(async () => { + await result.current.handleSlashCommand('/about'); + }); + + // Assert + expect(mockAddItem).toHaveBeenNthCalledWith( + 2, + expect.objectContaining({ + sandboxEnv: 'sandbox-exec (test-profile)', + }), + expect.any(Number), + ); + }); + }); + describe('Other commands', () => { it('/help should open help and return true', async () => { const { handleSlashCommand } = getProcessor(); diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index 52e8effc..bd0e38b8 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -103,6 +103,8 @@ export const useSlashCommandProcessor = ( osVersion: message.osVersion, sandboxEnv: message.sandboxEnv, modelVersion: message.modelVersion, + selectedAuthType: message.selectedAuthType, + gcpProject: message.gcpProject, }; } else if (message.type === MessageType.STATS) { historyItemContent = { @@ -596,6 +598,8 @@ export const useSlashCommandProcessor = ( } const modelVersion = config?.getModel() || 'Unknown'; const cliVersion = await getCliVersion(); + const selectedAuthType = settings.merged.selectedAuthType || ''; + const gcpProject = process.env.GOOGLE_CLOUD_PROJECT || ''; addMessage({ type: MessageType.ABOUT, timestamp: new Date(), @@ -603,6 +607,8 @@ export const useSlashCommandProcessor = ( osVersion, sandboxEnv, modelVersion, + selectedAuthType, + gcpProject, }); }, }, @@ -1007,6 +1013,7 @@ export const useSlashCommandProcessor = ( toggleCorgiMode, savedChatTags, config, + settings, showToolDescriptions, session, gitService, diff --git a/packages/cli/src/ui/types.ts b/packages/cli/src/ui/types.ts index 1bddfc32..66a465ba 100644 --- a/packages/cli/src/ui/types.ts +++ b/packages/cli/src/ui/types.ts @@ -94,6 +94,8 @@ export type HistoryItemAbout = HistoryItemBase & { osVersion: string; sandboxEnv: string; modelVersion: string; + selectedAuthType: string; + gcpProject: string; }; export type HistoryItemStats = HistoryItemBase & { @@ -169,6 +171,8 @@ export type Message = osVersion: string; sandboxEnv: string; modelVersion: string; + selectedAuthType: string; + gcpProject: string; content?: string; // Optional content, not really used for ABOUT } | {