test: caminhos-base de lib, hooks e services
This commit is contained in:
1 parent
9d911603f7
commit
adc37e1921
18 files changed
+2961
-142
No files matched your search
@@ -0,0 +1,68 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { useMcpTools, type McpToolInfo } from './use-mcp-tools';
|
||||
|
||||
// Servidores MCP reais não são iniciados: o comando Tauri devolve lista vazia.
|
||||
const invokeMock = vi.hoisted(() => vi.fn(async () => []));
|
||||
vi.mock('@tauri-apps/api/core', () => ({ invoke: invokeMock }));
|
||||
|
||||
const tool = (server_name: string, name: string, input_schema?: unknown): McpToolInfo => ({
|
||||
server_name,
|
||||
tool: { name, description: `desc ${name}`, input_schema },
|
||||
});
|
||||
|
||||
function generate(tools: McpToolInfo[], selected?: string[]) {
|
||||
const { result } = renderHook(() => useMcpTools());
|
||||
return result.current.generateToolsContext(tools, selected);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
describe('generateToolsContext', () => {
|
||||
it('sem ferramentas: string vazia', () => {
|
||||
expect(generate([])).toBe('');
|
||||
});
|
||||
|
||||
it('servidores selecionados sem ferramentas correspondentes: string vazia', () => {
|
||||
expect(generate([tool('fs', 'read')], ['web'])).toBe('');
|
||||
});
|
||||
|
||||
it('sem seleção: cabeçalho genérico e todas as ferramentas', () => {
|
||||
const ctx = generate([tool('fs', 'read'), tool('web', 'search')]);
|
||||
expect(ctx).toContain('Você tem acesso aos servidores MCP listados abaixo.');
|
||||
expect(ctx).toContain('### Servidor: fs');
|
||||
expect(ctx).toContain('### Servidor: web');
|
||||
});
|
||||
|
||||
it('seleção vazia: comporta-se como sem seleção', () => {
|
||||
const ctx = generate([tool('fs', 'read')], []);
|
||||
expect(ctx).toContain('Você tem acesso aos servidores MCP listados abaixo.');
|
||||
expect(ctx).toContain('- **read**: desc read');
|
||||
});
|
||||
|
||||
it('com seleção: cita os servidores e omite os demais', () => {
|
||||
const ctx = generate([tool('fs', 'read'), tool('web', 'search'), tool('db', 'query')], ['web', 'db']);
|
||||
expect(ctx).toContain('servidores MCP selecionados: web, db.');
|
||||
expect(ctx).not.toContain('### Servidor: fs');
|
||||
expect(ctx).toContain('- **search**');
|
||||
expect(ctx).toContain('- **query**');
|
||||
});
|
||||
|
||||
it('duas ferramentas do mesmo servidor: um único cabeçalho de servidor', () => {
|
||||
const ctx = generate([tool('fs', 'read'), tool('fs', 'write')]);
|
||||
expect(ctx.match(/### Servidor: fs/g)).toHaveLength(1);
|
||||
expect(ctx.indexOf('- **read**')).toBeLessThan(ctx.indexOf('- **write**'));
|
||||
});
|
||||
|
||||
it('schema com propriedades: lista parâmetros e usa "any" quando falta o tipo', () => {
|
||||
const ctx = generate([tool('fs', 'read', { properties: { path: { type: 'string' }, flags: {} } })]);
|
||||
expect(ctx).toContain(' - Parâmetros: path (string), flags (any)\n');
|
||||
});
|
||||
|
||||
it('schema sem properties: não lista parâmetros', () => {
|
||||
const ctx = generate([tool('fs', 'read', { type: 'object' })]);
|
||||
expect(ctx).not.toContain('Parâmetros');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user