summaryrefslogtreecommitdiff
path: root/packages/cli/src/commands/mcp/remove.test.ts
diff options
context:
space:
mode:
authorJack Wotherspoon <[email protected]>2025-08-06 11:52:29 -0400
committerGitHub <[email protected]>2025-08-06 15:52:29 +0000
commitca4c745e3b620e3ac4eca24b610cc7b936c0a50d (patch)
treeeb1b9cfb46bd4fa2e7f9631828b0704df1050eb7 /packages/cli/src/commands/mcp/remove.test.ts
parentb38f377c9a2672e88dd15119b38d908c0f00b54a (diff)
feat(mcp): add `gemini mcp` commands for `add`, `remove` and `list` (#5481)
Diffstat (limited to 'packages/cli/src/commands/mcp/remove.test.ts')
-rw-r--r--packages/cli/src/commands/mcp/remove.test.ts69
1 files changed, 69 insertions, 0 deletions
diff --git a/packages/cli/src/commands/mcp/remove.test.ts b/packages/cli/src/commands/mcp/remove.test.ts
new file mode 100644
index 00000000..eb7dedce
--- /dev/null
+++ b/packages/cli/src/commands/mcp/remove.test.ts
@@ -0,0 +1,69 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { vi, describe, it, expect, beforeEach } from 'vitest';
+import yargs from 'yargs';
+import { loadSettings, SettingScope } from '../../config/settings.js';
+import { removeCommand } from './remove.js';
+
+vi.mock('fs/promises', () => ({
+ readFile: vi.fn(),
+ writeFile: vi.fn(),
+}));
+
+vi.mock('../../config/settings.js', async () => {
+ const actual = await vi.importActual('../../config/settings.js');
+ return {
+ ...actual,
+ loadSettings: vi.fn(),
+ };
+});
+
+const mockedLoadSettings = loadSettings as vi.Mock;
+
+describe('mcp remove command', () => {
+ let parser: yargs.Argv;
+ let mockSetValue: vi.Mock;
+ let mockSettings: Record<string, unknown>;
+
+ beforeEach(() => {
+ vi.resetAllMocks();
+ const yargsInstance = yargs([]).command(removeCommand);
+ parser = yargsInstance;
+ mockSetValue = vi.fn();
+ mockSettings = {
+ mcpServers: {
+ 'test-server': {
+ command: 'echo "hello"',
+ },
+ },
+ };
+ mockedLoadSettings.mockReturnValue({
+ forScope: () => ({ settings: mockSettings }),
+ setValue: mockSetValue,
+ });
+ });
+
+ it('should remove a server from project settings', async () => {
+ await parser.parseAsync('remove test-server');
+
+ expect(mockSetValue).toHaveBeenCalledWith(
+ SettingScope.Workspace,
+ 'mcpServers',
+ {},
+ );
+ });
+
+ it('should show a message if server not found', async () => {
+ const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
+ await parser.parseAsync('remove non-existent-server');
+
+ expect(mockSetValue).not.toHaveBeenCalled();
+ expect(consoleSpy).toHaveBeenCalledWith(
+ 'Server "non-existent-server" not found in project settings.',
+ );
+ });
+});