mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-18 17:20:38 -07:00
Adds executeCommand endpoint with support for /extensions list (#11515)
This commit is contained in:
@@ -130,7 +130,9 @@ export const HistoryItemDisplay: React.FC<HistoryItemDisplayProps> = ({
|
||||
{itemForDisplay.type === 'compression' && (
|
||||
<CompressionMessage compression={itemForDisplay.compression} />
|
||||
)}
|
||||
{itemForDisplay.type === 'extensions_list' && <ExtensionsList />}
|
||||
{itemForDisplay.type === 'extensions_list' && (
|
||||
<ExtensionsList extensions={itemForDisplay.extensions} />
|
||||
)}
|
||||
{itemForDisplay.type === 'tools_list' && (
|
||||
<ToolsList
|
||||
terminalWidth={terminalWidth}
|
||||
|
||||
@@ -5,20 +5,40 @@
|
||||
*/
|
||||
|
||||
import { render } from 'ink-testing-library';
|
||||
import { vi } from 'vitest';
|
||||
import { vi, describe, beforeEach, it, expect } from 'vitest';
|
||||
import { useUIState } from '../../contexts/UIStateContext.js';
|
||||
import { ExtensionUpdateState } from '../../state/extensions.js';
|
||||
import { ExtensionsList } from './ExtensionsList.js';
|
||||
import { createMockCommandContext } from '../../../test-utils/mockCommandContext.js';
|
||||
|
||||
vi.mock('../../contexts/UIStateContext.js');
|
||||
|
||||
const mockUseUIState = vi.mocked(useUIState);
|
||||
|
||||
const mockExtensions = [
|
||||
{ name: 'ext-one', version: '1.0.0', isActive: true },
|
||||
{ name: 'ext-two', version: '2.1.0', isActive: true },
|
||||
{ name: 'ext-disabled', version: '3.0.0', isActive: false },
|
||||
{
|
||||
name: 'ext-one',
|
||||
version: '1.0.0',
|
||||
isActive: true,
|
||||
path: '/path/to/ext-one',
|
||||
contextFiles: [],
|
||||
id: '',
|
||||
},
|
||||
{
|
||||
name: 'ext-two',
|
||||
version: '2.1.0',
|
||||
isActive: true,
|
||||
path: '/path/to/ext-two',
|
||||
contextFiles: [],
|
||||
id: '',
|
||||
},
|
||||
{
|
||||
name: 'ext-disabled',
|
||||
version: '3.0.0',
|
||||
isActive: false,
|
||||
path: '/path/to/ext-disabled',
|
||||
contextFiles: [],
|
||||
id: '',
|
||||
},
|
||||
];
|
||||
|
||||
describe('<ExtensionsList />', () => {
|
||||
@@ -27,31 +47,25 @@ describe('<ExtensionsList />', () => {
|
||||
});
|
||||
|
||||
const mockUIState = (
|
||||
extensions: unknown[],
|
||||
extensionsUpdateState: Map<string, ExtensionUpdateState>,
|
||||
) => {
|
||||
mockUseUIState.mockReturnValue({
|
||||
commandContext: createMockCommandContext({
|
||||
services: {
|
||||
config: {
|
||||
getExtensions: () => extensions,
|
||||
},
|
||||
},
|
||||
}),
|
||||
extensionsUpdateState,
|
||||
// Add other required properties from UIState if needed by the component
|
||||
} as never);
|
||||
};
|
||||
|
||||
it('should render "No extensions installed." if there are no extensions', () => {
|
||||
mockUIState([], new Map());
|
||||
const { lastFrame } = render(<ExtensionsList />);
|
||||
mockUIState(new Map());
|
||||
const { lastFrame } = render(<ExtensionsList extensions={[]} />);
|
||||
expect(lastFrame()).toContain('No extensions installed.');
|
||||
});
|
||||
|
||||
it('should render a list of extensions with their version and status', () => {
|
||||
mockUIState(mockExtensions, new Map());
|
||||
const { lastFrame } = render(<ExtensionsList />);
|
||||
mockUIState(new Map());
|
||||
const { lastFrame } = render(
|
||||
<ExtensionsList extensions={mockExtensions} />,
|
||||
);
|
||||
const output = lastFrame();
|
||||
expect(output).toContain('ext-one (v1.0.0) - active');
|
||||
expect(output).toContain('ext-two (v2.1.0) - active');
|
||||
@@ -59,8 +73,10 @@ describe('<ExtensionsList />', () => {
|
||||
});
|
||||
|
||||
it('should display "unknown state" if an extension has no update state', () => {
|
||||
mockUIState([mockExtensions[0]], new Map());
|
||||
const { lastFrame } = render(<ExtensionsList />);
|
||||
mockUIState(new Map());
|
||||
const { lastFrame } = render(
|
||||
<ExtensionsList extensions={[mockExtensions[0]]} />,
|
||||
);
|
||||
expect(lastFrame()).toContain('(unknown state)');
|
||||
});
|
||||
|
||||
@@ -94,8 +110,10 @@ describe('<ExtensionsList />', () => {
|
||||
for (const { state, expectedText } of stateTestCases) {
|
||||
it(`should correctly display the state: ${state}`, () => {
|
||||
const updateState = new Map([[mockExtensions[0].name, state]]);
|
||||
mockUIState([mockExtensions[0]], updateState);
|
||||
const { lastFrame } = render(<ExtensionsList />);
|
||||
mockUIState(updateState);
|
||||
const { lastFrame } = render(
|
||||
<ExtensionsList extensions={[mockExtensions[0]]} />,
|
||||
);
|
||||
expect(lastFrame()).toContain(expectedText);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,15 +4,20 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type React from 'react';
|
||||
import { Box, Text } from 'ink';
|
||||
import { useUIState } from '../../contexts/UIStateContext.js';
|
||||
import { ExtensionUpdateState } from '../../state/extensions.js';
|
||||
import type { GeminiCLIExtension } from '@google/gemini-cli-core';
|
||||
|
||||
export const ExtensionsList = () => {
|
||||
const { commandContext, extensionsUpdateState } = useUIState();
|
||||
const allExtensions = commandContext.services.config!.getExtensions();
|
||||
interface ExtensionsList {
|
||||
extensions: readonly GeminiCLIExtension[];
|
||||
}
|
||||
|
||||
if (allExtensions.length === 0) {
|
||||
export const ExtensionsList: React.FC<ExtensionsList> = ({ extensions }) => {
|
||||
const { extensionsUpdateState } = useUIState();
|
||||
|
||||
if (extensions.length === 0) {
|
||||
return <Text>No extensions installed.</Text>;
|
||||
}
|
||||
|
||||
@@ -20,7 +25,7 @@ export const ExtensionsList = () => {
|
||||
<Box flexDirection="column" marginTop={1} marginBottom={1}>
|
||||
<Text>Installed extensions:</Text>
|
||||
<Box flexDirection="column" paddingLeft={2}>
|
||||
{allExtensions.map((ext) => {
|
||||
{extensions.map((ext) => {
|
||||
const state = extensionsUpdateState.get(ext.name);
|
||||
const isActive = ext.isActive;
|
||||
const activeString = isActive ? 'active' : 'disabled';
|
||||
|
||||
Reference in New Issue
Block a user