Files
mcp/test/config/configuration.test.ts
zeekay ee27c12905 shell: a long command is read on a stack its depth fits; npx and uvx take approve
The walk recurses with a command's nesting, and a flat chain nests as
deep as it is long, so a hostile command overflowed the caller's stack
and aborted the server (the classifier's own deep-nesting test died
under a debug build). A command over 64 bytes is now read on a thread
with a 256 MiB stack, reserved and not committed, and one over 64 KiB
is refused unread as unparsed.

npx and uvx run through exec, whose classifier asks before a package is
fetched, and they had no way to pass the approval: since the merge
neither could run at all. They take approve as exec does.

The hostile-text bound is 3 s for an optimized build and 15 s for an
unoptimized one on a loaded host; it catches a quadratic read, which
takes minutes. The unified surface lists the kai tool beside the eight
purpose-built ones.
2026-10-14 17:24:56 -07:00

228 lines
7.7 KiB
TypeScript

import { describe, test, expect } from '@jest/globals';
import { getConfiguredTools, ToolConfig } from '../../src/tools/index.js';
import { createMCPServer } from '../../src/index.js';
// HIP-0300 unified tool surface
const UNIFIED_TOOLSET = [
'fs', 'exec', 'code', 'git', 'fetch', 'workspace', 'ui', // core
'think', 'llm', 'memory', 'hanzo', 'plan', 'tasks', 'mode', 'gimp', 'browser', 'cdp', 'npx', 'uvx', 'jq', 'kai_compact', // optional
'code_search', 'code_context', 'code_ask', 'code_index', // code intelligence
'tracker_boards', 'tracker_issues', 'tracker_create', 'tracker_update', // work items
'kai_decide', 'kai_choice', 'kai_score', 'kai_noul', // decisions
'kai', // Kai Actions
'kai_tool_select', 'kai_next_action', 'kai_command_guard', 'kai_injection_screen', 'kai_extract', 'kai_log_triage', 'kai_recover', // 7 purpose-built
'kai_agent_step', // agent step
];
describe('Configuration System', () => {
describe('getConfiguredTools', () => {
test('returns HIP-0300 unified surface by default', () => {
const tools = getConfiguredTools();
const names = tools.map((t) => t.name);
expect(names).toHaveLength(UNIFIED_TOOLSET.length);
expect(new Set(names).size).toBe(names.length);
for (const name of UNIFIED_TOOLSET) {
expect(names).toContain(name);
}
});
test('supports full-surface with UI extensions enabled', () => {
const tools = getConfiguredTools({
enableUI: true,
enableAutoGUI: true,
enableOrchestration: true,
enableUIRegistry: true,
enableGitHubUI: true,
enableDesktop: true,
dedupeTools: true,
});
const names = tools.map((t) => t.name);
// Unified core + UI extensions
expect(names.length).toBeGreaterThan(UNIFIED_TOOLSET.length);
for (const name of UNIFIED_TOOLSET) {
expect(names).toContain(name);
}
expect(names).toContain('spawn_agent');
expect(names).toContain('autogui_click');
expect(names).toContain('hanzo_desktop');
expect(names).toContain('playwright_control');
expect(new Set(names).size).toBe(names.length);
});
test('supports category filtering in legacy mode', () => {
const tools = getConfiguredTools({
unified: false,
enableLegacy: true,
enableCore: true,
enabledCategories: ['files'],
enableAI: false,
enableAST: false,
enableVector: false,
enableTodo: false,
enableModes: false,
enableCloud: false,
enableVCS: false,
enableRefactor: false,
enableMemory: false,
enablePlan: false,
});
const names = tools.map((t) => t.name);
expect(names).toContain('read');
expect(names).toContain('write');
expect(names).toContain('list');
expect(names).toContain('info');
expect(names).toContain('tree');
expect(names).not.toContain('grep');
expect(names).not.toContain('bash');
expect(names).not.toContain('edit');
});
test('disables specific unified tools', () => {
const tools = getConfiguredTools({
disabledTools: ['fetch', 'hanzo'],
});
const names = tools.map((t) => t.name);
expect(names).not.toContain('fetch');
expect(names).not.toContain('hanzo');
expect(names).toContain('fs');
expect(names).toContain('exec');
expect(names).toContain('code');
});
test('supports custom tools with minimal config', () => {
const customTool = {
name: 'custom_test_tool',
description: 'A custom tool for testing',
inputSchema: {
type: 'object' as const,
properties: { test: { type: 'string' } },
required: ['test'],
},
handler: async () => ({
content: [{ type: 'text' as const, text: 'Custom tool executed' }],
}),
};
const tools = getConfiguredTools({
unified: false,
enableLegacy: true,
enableCore: false,
enableAI: false,
enableAST: false,
enableVector: false,
enableTodo: false,
enableModes: false,
enableCloud: false,
enableVCS: false,
enableRefactor: false,
enableMemory: false,
enablePlan: false,
customTools: [customTool],
});
expect(tools).toHaveLength(1);
expect(tools[0].name).toBe('custom_test_tool');
});
});
describe('createMCPServer configuration', () => {
test('creates server with HIP-0300 unified surface by default', async () => {
const server = await createMCPServer();
const names = server.tools.map((t) => t.name);
// All unified tools present
for (const name of UNIFIED_TOOLSET) {
expect(names).toContain(name);
}
expect(names).toHaveLength(UNIFIED_TOOLSET.length);
});
test('supports full-surface server configuration', async () => {
const server = await createMCPServer({
toolConfig: {
enableUI: true,
enableAutoGUI: true,
enableOrchestration: true,
enableUIRegistry: true,
enableGitHubUI: true,
dedupeTools: true,
},
});
const names = server.tools.map((t) => t.name);
expect(names).toContain('fs');
expect(names).toContain('exec');
expect(names).toContain('spawn_agent');
expect(names).toContain('autogui_status');
});
test('supports dynamic add/remove tool lifecycle', async () => {
const server = await createMCPServer();
const initialCount = server.tools.length;
const testTool = {
name: 'dynamic_test_tool',
description: 'Dynamic test tool',
inputSchema: { type: 'object' as const, properties: {}, required: [] },
handler: async () => ({
content: [{ type: 'text' as const, text: 'Dynamic tool' }],
}),
};
server.addTool(testTool);
expect(server.tools.length).toBe(initialCount + 1);
expect(server.tools.some((t) => t.name === 'dynamic_test_tool')).toBe(true);
server.removeTool('dynamic_test_tool');
expect(server.tools.length).toBe(initialCount);
expect(server.tools.some((t) => t.name === 'dynamic_test_tool')).toBe(false);
});
});
describe('Tool validation', () => {
test('validates tool schema structure and uniqueness', () => {
const tools = getConfiguredTools({
enableUI: true,
enableAutoGUI: true,
enableOrchestration: true,
enableUIRegistry: true,
enableGitHubUI: true,
});
const names = tools.map((t) => t.name);
expect(new Set(names).size).toBe(names.length);
tools.forEach((tool) => {
expect(typeof tool.name).toBe('string');
expect(typeof tool.description).toBe('string');
expect(typeof tool.handler).toBe('function');
expect(tool.inputSchema.type).toBe('object');
expect(tool.inputSchema).toHaveProperty('properties');
});
});
test('handles invalid category/disabled tool names gracefully', () => {
// Category filtering is a legacy concept
const withBadCategory = getConfiguredTools({
unified: false,
enableLegacy: true,
enableCore: true,
enabledCategories: ['invalid-category', 'files'],
});
expect(withBadCategory.some((t) => t.name === 'read')).toBe(true);
// Disabled tools work on unified surface
const withBadDisabled = getConfiguredTools({
disabledTools: ['invalid-tool', 'exec'],
});
expect(withBadDisabled.some((t) => t.name === 'exec')).toBe(false);
expect(withBadDisabled.some((t) => t.name === 'fs')).toBe(true);
});
});
});