CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
mcp.test.ts67 linesDownload Raw Back to commands
1/**2 * @license3 * Copyright 2025 Google LLC4 * SPDX-License-Identifier: Apache-2.05 */6 7import { describe, it, expect, vi } from 'vitest';8import { mcpCommand } from './mcp.js';9import { type Argv } from 'yargs';10import yargs from 'yargs';11 12describe('mcp command', () => {13  it('should have correct command definition', () => {14    expect(mcpCommand.command).toBe('mcp');15    expect(mcpCommand.describe).toBe('Manage MCP servers');16    expect(typeof mcpCommand.builder).toBe('function');17    expect(typeof mcpCommand.handler).toBe('function');18  });19 20  it('should have exactly one option (help flag)', async () => {21    // Test to ensure that the global 'gemini' flags are not added to the mcp command22    const yargsInstance = yargs();23    const builder = mcpCommand.builder;24    if (typeof builder !== 'function') {25      throw new Error('mcp command builder must be a function');26    }27    const builtYargs = await builder(yargsInstance);28    const options = builtYargs.getOptions();29 30    // Should have exactly 1 option (help flag)31    expect(Object.keys(options.key).length).toBe(1);32    expect(options.key).toHaveProperty('help');33  });34 35  it('should register add, remove, and list subcommands', () => {36    const mockYargs = {37      command: vi.fn().mockReturnThis(),38      demandCommand: vi.fn().mockReturnThis(),39      version: vi.fn().mockReturnThis(),40    };41 42    const builder = mcpCommand.builder;43    if (typeof builder !== 'function') {44      throw new Error('mcp command builder must be a function');45    }46    builder(mockYargs as unknown as Argv);47 48    expect(mockYargs.command).toHaveBeenCalledTimes(6);49 50    // Verify that the specific subcommands are registered51    const commandCalls = mockYargs.command.mock.calls;52    const commandNames = commandCalls.map((call) => call[0].command);53 54    expect(commandNames).toContain('add <name> <commandOrUrl> [args...]');55    expect(commandNames).toContain('remove <name>');56    expect(commandNames).toContain('list');57    expect(commandNames).toContain('reconnect [server-name]');58    expect(commandNames).toContain('approve [name]');59    expect(commandNames).toContain('reject [name]');60 61    expect(mockYargs.demandCommand).toHaveBeenCalledWith(62      1,63      'You need at least one command before continuing.',64    );65  });66});67 
basant307/AI_Governance_Project · CoolFace