23f7624596
ADR-166 MCP Bridge Security Lock / Static-source security lock (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / Compose default binds loopback + Mongo has auth (push) Failing after 2s
CodeQL Advanced / Analyze (rust) (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / plugin-agent-federation bindHost default (push) Failing after 1s
ADR-166 MCP Bridge Security Lock / Runtime behavior — 401 + terminal gate + fail-closed (push) Failing after 4s
business-pods-smoke / smoke (push) Failing after 1s
all-plugins-smoke / smoke-all (push) Failing after 2s
CI/CD Pipeline / Security & Code Quality (push) Failing after 1s
CI/CD Pipeline / Test Suite (ubuntu-latest) (push) Failing after 1s
CI/CD Pipeline / Build & Package (macos-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (ubuntu-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (windows-latest) (push) Has been skipped
CI/CD Pipeline / Documentation & Examples (push) Failing after 1s
Clone Tracker (14-day rolling) / Snapshot clones for ruflo ecosystem (push) Failing after 1s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
federation-peer-rust / stable-noop (push) Failing after 1s
metaharness-ci / score (push) Failing after 1s
metaharness-ci / router-compat (push) Failing after 0s
metaharness-ci / similarity-tests (push) Failing after 0s
no-agentbbs-smoke / smoke-without-agentbbs (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (windows-latest) (push) Has been skipped
codex-integration-audit / Codex integration audit (push) Failing after 1s
helpers-manifest-guard / guard (push) Failing after 1s
🔗 Cross-Agent Integration Tests / 🤝 Agent Coordination Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🧠 Memory Sharing Integration (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🛡️ Fault Tolerance Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / ⚡ Performance Integration Tests (push) Has been skipped
metaharness-ci / mcp-scan (push) Failing after 1s
metaharness-ci / eject-dryrun (push) Failing after 1s
metaharness-ci / metaharness-real-data (push) Failing after 0s
no-cli-optdep-bloat-2561 / guard (push) Failing after 1s
no-metaharness-smoke / smoke-without-metaharness (push) Failing after 1s
no-phantom-agentic-flow-subpath / guard (push) Failing after 1s
🔄 Automated Rollback Manager / 🚨 Failure Detection (push) Failing after 1s
V3 CI/CD Pipeline / Plugin hooks smoke / ubuntu-latest / Node 22 (push) Failing after 1s
V3 CI/CD Pipeline / ruflo-graph-intelligence build + test smoke (#2044, ADR-123) (push) Failing after 1s
CVE Audit Gate / Audit root (critical-blocking) (push) Failing after 2s
cost-tracker-smoke / smoke (push) Failing after 3s
oia-audit-weekly / audit (push) Failing after 2s
ruflo-agent-smoke / ruflo-agent structural smoke (push) Failing after 1s
📊 Status Badges Update / 📊 Update Status Badges (push) Failing after 1s
V3 CI/CD Pipeline / Static regression guards (#2267 YAML + (push) Failing after 1s
V3 CI/CD Pipeline / Test V3 Packages (push) Failing after 0s
V3 CI/CD Pipeline / agent_execute provider routing smoke (#2042) (push) Failing after 0s
CVE Audit Gate / Audit v3 (critical-blocking) (push) Failing after 1s
federation-peer-rust / stable-native (push) Failing after 2s
🔗 Cross-Agent Integration Tests / 🚀 Integration Test Setup (push) Failing after 2s
neural-trader-smoke / runtime-smoke (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (macos-latest) (push) Has been skipped
V3 CI/CD Pipeline / Build V3 (ubuntu-latest) (push) Has been skipped
V3 CI/CD Pipeline / Type Check V3 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 24 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 22 (push) Failing after 2s
V3 CI/CD Pipeline / browser rvf create flag smoke (#2015) (push) Failing after 0s
V3 CI/CD Pipeline / Dependency review (#2046) (push) Has been skipped
V3 CI/CD Pipeline / Supply-chain audit (#2046) (push) Failing after 0s
V3 CI/CD Pipeline / witness marker drift smoke (#2021) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader portfolio CG smoke (#2068, ADR-126 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader backtest signing smoke (#2068, ADR-126 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / kg-extract type-import classification smoke (#2049) (push) Failing after 0s
V3 CI/CD Pipeline / witness verify precondition smoke (#1880) (push) Failing after 2s
V3 CI/CD Pipeline / neural-trader pipeline risk-gate smoke (#2068, ADR-126 Phase 5) (push) Failing after 0s
V3 CI/CD Pipeline / neural-trader feature attribution smoke (#2068, ADR-126 Phase 6) (push) Failing after 0s
V3 CI/CD Pipeline / plugin-registry signature verification smoke (#1922, CWE-347) (push) Failing after 4s
V3 CI/CD Pipeline / memory stats legacy-DB smoke (#2120) (push) Failing after 4s
V3 CI/CD Pipeline / github deprecated actions smoke (#2089, ADR-127 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / graph query + pathfinder smoke (ADR-130 P2+P5) (push) Has been skipped
V3 CI/CD Pipeline / graph trajectory hooks smoke (ADR-130 P3) (push) Has been skipped
V3 CI/CD Pipeline / graph plugin adapter smoke (ADR-130 P4) (push) Has been skipped
V3 CI/CD Pipeline / graph benchmark (ADR-130 P6) (push) Has been skipped
V3 CI/CD Pipeline / statusline generator delegation smoke (#2195) (push) Failing after 1s
V3 CI/CD Pipeline / wizard init regression guard (#2206 (push) Failing after 1s
V3 CI/CD Pipeline / memory no-stray-db smoke (ADR-125 P7) (push) Failing after 1s
V3 CI/CD Pipeline / github-safe injection smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github actions pin smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github attribution opt-in smoke (#2089, ADR-127 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / pre-bash hook safety smoke (#2017) (push) Failing after 1s
V3 CI/CD Pipeline / Memory import smoke / ubuntu-latest (push) Failing after 0s
V3 CI/CD Pipeline / MCP protocol smoke / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / ruvllm WASM auto-init smoke (#2086) (push) Failing after 4s
V3 CI/CD Pipeline / MCP paired-tool round-trip smoke (#1889) (push) Failing after 1s
V3 CI/CD Pipeline / Plugin package install-safety (#1902/#1903/#1904) (push) Failing after 1s
V3 CI/CD Pipeline / Tool description discoverability (ADR-112) (push) Failing after 3s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (22) (push) Failing after 1s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (24) (push) Failing after 1s
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Vector-index dimension audit (#1947) (push) Failing after 0s
V3 CI/CD Pipeline / Hook-command install safety (#1921) (push) Failing after 1s
V3 CI/CD Pipeline / ToolOutputGuardrail smoke (ADR-131, (push) Failing after 1s
V3 CI/CD Pipeline / init-bundle invariants smoke (#2095, ADR-128 Phase 5) (push) Failing after 1s
V3 CI/CD Pipeline / wasm provider bridge smoke (ADR-129 P1) (push) Failing after 2s
V3 CI/CD Pipeline / wasm gallery CRUD smoke (ADR-129 P3) (push) Failing after 1s
V3 CI/CD Pipeline / wasm plugin bridge smoke (ADR-129 P4) (push) Failing after 0s
V3 CI/CD Pipeline / wasm compose smoke (ADR-129 P2) (push) Failing after 4s
V3 CI/CD Pipeline / graph schema smoke (ADR-130 P1) (push) Failing after 0s
Validate Marketplace / validate (push) Failing after 1s
🔍 Verification Pipeline / 🚀 Setup Verification (push) Failing after 1s
🔍 Verification Pipeline / 🛡️ Security Verification (push) Has been skipped
🔍 Verification Pipeline / 📝 Code Quality (push) Has been skipped
🔍 Verification Pipeline / 🧪 Test Verification (${{ matrix.os }}, Node ${{ matrix.node }}) (push) Has been skipped
🔍 Verification Pipeline / 🏗️ Build Verification (push) Has been skipped
🔍 Verification Pipeline / 📚 Documentation Verification (push) Has been skipped
CVE Audit Gate / High-severity report (warn only) (push) Has been cancelled
🔄 Automated Rollback Manager / 🔄 Execute Rollback (push) Has been cancelled
🔄 Automated Rollback Manager / ✅ Post-Rollback Verification (push) Has been cancelled
🔄 Automated Rollback Manager / 📊 Rollback Monitoring (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / windows-latest (push) Has been cancelled
🔄 Automated Rollback Manager / ⏳ Manual Rollback Approval (push) Has been cancelled
V3 CI/CD Pipeline / MCP protocol smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Memory import smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / ubuntu-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Publish to npm (alpha) (push) Has been cancelled
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / macos-latest / Node 22 (push) Has been cancelled
V3 CI/CD Pipeline / Plugin hooks smoke / macos-latest / Node 22 (push) Has been cancelled
CI/CD Pipeline / Deploy & Release (push) Has been cancelled
CI/CD Pipeline / CI Status (push) Has been cancelled
🔗 Cross-Agent Integration Tests / 📊 Integration Test Report (push) Has been cancelled
🔄 Automated Rollback Manager / 🔍 Pre-Rollback Validation (push) Has been cancelled
🔍 Verification Pipeline / ⚡ Performance Verification (push) Has been cancelled
🔍 Verification Pipeline / 📊 Verification Report (push) Has been cancelled
668 lines
20 KiB
TypeScript
668 lines
20 KiB
TypeScript
/**
|
|
* Code Intelligence Plugin - MCP Tools Tests
|
|
*
|
|
* Tests for MCP tool handlers with mock data
|
|
*/
|
|
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
import {
|
|
semanticSearchTool,
|
|
architectureAnalyzeTool,
|
|
refactorImpactTool,
|
|
splitSuggestTool,
|
|
learnPatternsTool,
|
|
codeIntelligenceTools,
|
|
getTool,
|
|
getToolNames,
|
|
} from '../src/mcp-tools.js';
|
|
|
|
// Mock bridges
|
|
vi.mock('../src/bridges/hnsw-bridge.js', () => ({
|
|
CodeHNSWBridge: vi.fn().mockImplementation(() => ({
|
|
initialized: false,
|
|
initialize: vi.fn().mockResolvedValue(undefined),
|
|
searchSemantic: vi.fn().mockResolvedValue([
|
|
{
|
|
id: 'result-1',
|
|
path: 'src/auth/login.ts',
|
|
content: 'async function login(username, password) { ... }',
|
|
score: 0.92,
|
|
language: 'typescript',
|
|
},
|
|
{
|
|
id: 'result-2',
|
|
path: 'src/auth/session.ts',
|
|
content: 'function createSession(user) { ... }',
|
|
score: 0.85,
|
|
language: 'typescript',
|
|
},
|
|
]),
|
|
count: vi.fn().mockResolvedValue(5000),
|
|
})),
|
|
}));
|
|
|
|
vi.mock('../src/bridges/gnn-bridge.js', () => ({
|
|
CodeGNNBridge: vi.fn().mockImplementation(() => ({
|
|
initialized: false,
|
|
initialize: vi.fn().mockResolvedValue(undefined),
|
|
analyzeArchitecture: vi.fn().mockResolvedValue({
|
|
components: [
|
|
{ name: 'AuthModule', type: 'module', files: 5, dependencies: 3 },
|
|
{ name: 'UserService', type: 'service', files: 3, dependencies: 2 },
|
|
],
|
|
metrics: {
|
|
modularity: 0.72,
|
|
coupling: 0.35,
|
|
cohesion: 0.68,
|
|
},
|
|
issues: [
|
|
{ type: 'circular_dependency', components: ['AuthModule', 'UserService'], severity: 'medium' },
|
|
],
|
|
}),
|
|
analyzeRefactorImpact: vi.fn().mockResolvedValue({
|
|
directImpact: ['src/user.ts', 'src/auth.ts'],
|
|
indirectImpact: ['src/api/routes.ts', 'tests/user.test.ts'],
|
|
riskLevel: 'medium',
|
|
breakingChanges: ['UserService.getById signature changed'],
|
|
}),
|
|
suggestSplit: vi.fn().mockResolvedValue([
|
|
{
|
|
file: 'src/utils.ts',
|
|
reason: 'File exceeds 500 lines with multiple responsibilities',
|
|
suggestedSplits: [
|
|
{ name: 'string-utils.ts', functions: ['capitalize', 'truncate', 'slugify'] },
|
|
{ name: 'date-utils.ts', functions: ['formatDate', 'parseDate', 'addDays'] },
|
|
],
|
|
},
|
|
]),
|
|
learnPatterns: vi.fn().mockResolvedValue({
|
|
patterns: [
|
|
{ name: 'Repository Pattern', occurrences: 12, confidence: 0.88 },
|
|
{ name: 'Factory Pattern', occurrences: 5, confidence: 0.75 },
|
|
],
|
|
antiPatterns: [
|
|
{ name: 'God Object', files: ['src/app.ts'], severity: 'high' },
|
|
],
|
|
}),
|
|
})),
|
|
}));
|
|
|
|
// Mock context for testing
|
|
const createMockContext = (overrides = {}) => ({
|
|
logger: {
|
|
debug: vi.fn(),
|
|
info: vi.fn(),
|
|
warn: vi.fn(),
|
|
error: vi.fn(),
|
|
},
|
|
userId: 'test-user',
|
|
...overrides,
|
|
});
|
|
|
|
describe('Code Intelligence MCP Tools', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
describe('Tool Registry', () => {
|
|
it('should export all 5 tools', () => {
|
|
expect(codeIntelligenceTools).toHaveLength(5);
|
|
});
|
|
|
|
it('should have correct tool names', () => {
|
|
const toolNames = codeIntelligenceTools.map(t => t.name);
|
|
expect(toolNames).toContain('code/semantic-search');
|
|
expect(toolNames).toContain('code/architecture-analyze');
|
|
expect(toolNames).toContain('code/refactor-impact');
|
|
expect(toolNames).toContain('code/split-suggest');
|
|
expect(toolNames).toContain('code/learn-patterns');
|
|
});
|
|
|
|
it('should have category code-intelligence', () => {
|
|
for (const tool of codeIntelligenceTools) {
|
|
expect(tool.category).toBe('code-intelligence');
|
|
}
|
|
});
|
|
|
|
it('should have version 0.1.0', () => {
|
|
for (const tool of codeIntelligenceTools) {
|
|
expect(tool.version).toBe('0.1.0');
|
|
}
|
|
});
|
|
|
|
it('should get tool by name', () => {
|
|
const tool = getTool('code/semantic-search');
|
|
expect(tool).toBeDefined();
|
|
expect(tool?.name).toBe('code/semantic-search');
|
|
});
|
|
|
|
it('should return undefined for unknown tool', () => {
|
|
const tool = getTool('code/unknown');
|
|
expect(tool).toBeUndefined();
|
|
});
|
|
|
|
it('should get all tool names', () => {
|
|
const names = getToolNames();
|
|
expect(names).toHaveLength(5);
|
|
expect(names).toContain('code/semantic-search');
|
|
});
|
|
});
|
|
|
|
describe('code/semantic-search', () => {
|
|
it('should have correct tool definition', () => {
|
|
expect(semanticSearchTool.name).toBe('code/semantic-search');
|
|
expect(semanticSearchTool.inputSchema.required).toContain('query');
|
|
expect(semanticSearchTool.cacheable).toBe(true);
|
|
});
|
|
|
|
it('should handle valid input', async () => {
|
|
const input = {
|
|
query: 'authentication login function',
|
|
topK: 10,
|
|
};
|
|
|
|
const result = await semanticSearchTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
const data = JSON.parse(result.content[0].text!);
|
|
expect(data.results).toBeDefined();
|
|
expect(Array.isArray(data.results)).toBe(true);
|
|
expect(data.searchTime).toBeDefined();
|
|
});
|
|
|
|
it('should handle language filter', async () => {
|
|
const input = {
|
|
query: 'error handling',
|
|
language: 'typescript',
|
|
};
|
|
|
|
const result = await semanticSearchTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
});
|
|
|
|
it('should handle search type filter', async () => {
|
|
const types = ['function', 'class', 'interface', 'type', 'variable', 'comment', 'any'] as const;
|
|
|
|
for (const searchType of types) {
|
|
const input = {
|
|
query: 'user data',
|
|
searchType,
|
|
};
|
|
|
|
const result = await semanticSearchTool.handler(input, createMockContext());
|
|
expect(result.isError).toBeUndefined();
|
|
}
|
|
});
|
|
|
|
it('should handle path filter', async () => {
|
|
const input = {
|
|
query: 'API endpoint',
|
|
pathFilter: 'src/api/',
|
|
};
|
|
|
|
const result = await semanticSearchTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
});
|
|
|
|
it('should reject missing query', async () => {
|
|
const input = {
|
|
topK: 10,
|
|
};
|
|
|
|
const result = await semanticSearchTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
});
|
|
|
|
it('should reject query exceeding max length', async () => {
|
|
const input = {
|
|
query: 'a'.repeat(1001),
|
|
};
|
|
|
|
const result = await semanticSearchTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
});
|
|
|
|
it('should reject topK outside valid range', async () => {
|
|
const input = {
|
|
query: 'test',
|
|
topK: 0, // below min
|
|
};
|
|
|
|
const result = await semanticSearchTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('code/architecture-analyze', () => {
|
|
it('should have correct tool definition', () => {
|
|
expect(architectureAnalyzeTool.name).toBe('code/architecture-analyze');
|
|
expect(architectureAnalyzeTool.inputSchema.required).toContain('targetPath');
|
|
expect(architectureAnalyzeTool.cacheable).toBe(true);
|
|
});
|
|
|
|
it('should handle valid input', async () => {
|
|
const input = {
|
|
targetPath: 'src/',
|
|
analysisTypes: ['dependencies', 'modularity'],
|
|
};
|
|
|
|
const result = await architectureAnalyzeTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
const data = JSON.parse(result.content[0].text!);
|
|
expect(data.components).toBeDefined();
|
|
expect(data.metrics).toBeDefined();
|
|
expect(data.analysisTime).toBeDefined();
|
|
});
|
|
|
|
it('should handle all analysis types', async () => {
|
|
const types = ['dependencies', 'modularity', 'complexity', 'coupling', 'cohesion', 'layers'] as const;
|
|
|
|
const input = {
|
|
targetPath: 'src/',
|
|
analysisTypes: [...types],
|
|
};
|
|
|
|
const result = await architectureAnalyzeTool.handler(input, createMockContext());
|
|
expect(result.isError).toBeUndefined();
|
|
});
|
|
|
|
it('should handle depth option', async () => {
|
|
const input = {
|
|
targetPath: 'src/',
|
|
depth: 5,
|
|
};
|
|
|
|
const result = await architectureAnalyzeTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
});
|
|
|
|
it('should handle exclude patterns', async () => {
|
|
const input = {
|
|
targetPath: 'src/',
|
|
excludePatterns: ['node_modules', '*.test.ts'],
|
|
};
|
|
|
|
const result = await architectureAnalyzeTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
});
|
|
|
|
it('should reject missing targetPath', async () => {
|
|
const input = {
|
|
analysisTypes: ['dependencies'],
|
|
};
|
|
|
|
const result = await architectureAnalyzeTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
});
|
|
|
|
it('should reject targetPath exceeding max length', async () => {
|
|
const input = {
|
|
targetPath: 'a'.repeat(501),
|
|
};
|
|
|
|
const result = await architectureAnalyzeTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('code/refactor-impact', () => {
|
|
it('should have correct tool definition', () => {
|
|
expect(refactorImpactTool.name).toBe('code/refactor-impact');
|
|
expect(refactorImpactTool.inputSchema.required).toContain('targetPath');
|
|
expect(refactorImpactTool.inputSchema.required).toContain('changeType');
|
|
expect(refactorImpactTool.cacheable).toBe(false);
|
|
});
|
|
|
|
it('should handle valid input', async () => {
|
|
const input = {
|
|
targetPath: 'src/services/user.ts',
|
|
changeType: 'rename',
|
|
description: 'Rename UserService to UserRepository',
|
|
};
|
|
|
|
const result = await refactorImpactTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
const data = JSON.parse(result.content[0].text!);
|
|
expect(data.directImpact).toBeDefined();
|
|
expect(data.indirectImpact).toBeDefined();
|
|
expect(data.riskLevel).toBeDefined();
|
|
});
|
|
|
|
it('should handle all change types', async () => {
|
|
const types = ['rename', 'move', 'delete', 'signature_change', 'type_change', 'dependency_change'] as const;
|
|
|
|
for (const changeType of types) {
|
|
const input = {
|
|
targetPath: 'src/test.ts',
|
|
changeType,
|
|
};
|
|
|
|
const result = await refactorImpactTool.handler(input, createMockContext());
|
|
expect(result.isError).toBeUndefined();
|
|
}
|
|
});
|
|
|
|
it('should handle include tests option', async () => {
|
|
const input = {
|
|
targetPath: 'src/service.ts',
|
|
changeType: 'delete',
|
|
includeTests: true,
|
|
};
|
|
|
|
const result = await refactorImpactTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
});
|
|
|
|
it('should handle depth option', async () => {
|
|
const input = {
|
|
targetPath: 'src/core.ts',
|
|
changeType: 'signature_change',
|
|
depth: 3,
|
|
};
|
|
|
|
const result = await refactorImpactTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
});
|
|
|
|
it('should reject missing targetPath', async () => {
|
|
const input = {
|
|
changeType: 'rename',
|
|
};
|
|
|
|
const result = await refactorImpactTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
});
|
|
|
|
it('should reject missing changeType', async () => {
|
|
const input = {
|
|
targetPath: 'src/test.ts',
|
|
};
|
|
|
|
const result = await refactorImpactTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
});
|
|
|
|
it('should reject invalid changeType', async () => {
|
|
const input = {
|
|
targetPath: 'src/test.ts',
|
|
changeType: 'invalid_change',
|
|
};
|
|
|
|
const result = await refactorImpactTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('code/split-suggest', () => {
|
|
it('should have correct tool definition', () => {
|
|
expect(splitSuggestTool.name).toBe('code/split-suggest');
|
|
expect(splitSuggestTool.inputSchema.required).toContain('targetPath');
|
|
expect(splitSuggestTool.cacheable).toBe(true);
|
|
});
|
|
|
|
it('should handle valid input', async () => {
|
|
const input = {
|
|
targetPath: 'src/utils.ts',
|
|
threshold: 300,
|
|
};
|
|
|
|
const result = await splitSuggestTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
const data = JSON.parse(result.content[0].text!);
|
|
expect(data.suggestions).toBeDefined();
|
|
expect(data.analysisTime).toBeDefined();
|
|
});
|
|
|
|
it('should handle all split strategies', async () => {
|
|
const strategies = ['responsibility', 'cohesion', 'size', 'complexity'] as const;
|
|
|
|
for (const strategy of strategies) {
|
|
const input = {
|
|
targetPath: 'src/',
|
|
strategy,
|
|
};
|
|
|
|
const result = await splitSuggestTool.handler(input, createMockContext());
|
|
expect(result.isError).toBeUndefined();
|
|
}
|
|
});
|
|
|
|
it('should use default threshold', async () => {
|
|
const input = {
|
|
targetPath: 'src/',
|
|
};
|
|
|
|
const result = await splitSuggestTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
const data = JSON.parse(result.content[0].text!);
|
|
expect(data.threshold).toBe(500); // default
|
|
});
|
|
|
|
it('should handle include patterns', async () => {
|
|
const input = {
|
|
targetPath: 'src/',
|
|
includePatterns: ['*.ts', '*.tsx'],
|
|
};
|
|
|
|
const result = await splitSuggestTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
});
|
|
|
|
it('should reject missing targetPath', async () => {
|
|
const input = {
|
|
threshold: 300,
|
|
};
|
|
|
|
const result = await splitSuggestTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
});
|
|
|
|
it('should reject threshold outside valid range', async () => {
|
|
const tooLow = {
|
|
targetPath: 'src/',
|
|
threshold: 49, // below min of 50
|
|
};
|
|
|
|
const result = await splitSuggestTool.handler(tooLow, createMockContext());
|
|
expect(result.isError).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('code/learn-patterns', () => {
|
|
it('should have correct tool definition', () => {
|
|
expect(learnPatternsTool.name).toBe('code/learn-patterns');
|
|
expect(learnPatternsTool.inputSchema.required).toContain('targetPath');
|
|
expect(learnPatternsTool.cacheable).toBe(true);
|
|
});
|
|
|
|
it('should handle valid input', async () => {
|
|
const input = {
|
|
targetPath: 'src/',
|
|
patternTypes: ['design_patterns', 'anti_patterns'],
|
|
};
|
|
|
|
const result = await learnPatternsTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
const data = JSON.parse(result.content[0].text!);
|
|
expect(data.patterns).toBeDefined();
|
|
expect(data.antiPatterns).toBeDefined();
|
|
expect(data.analysisTime).toBeDefined();
|
|
});
|
|
|
|
it('should handle all pattern types', async () => {
|
|
const types = ['design_patterns', 'anti_patterns', 'idioms', 'conventions', 'architecture'] as const;
|
|
|
|
const input = {
|
|
targetPath: 'src/',
|
|
patternTypes: [...types],
|
|
};
|
|
|
|
const result = await learnPatternsTool.handler(input, createMockContext());
|
|
expect(result.isError).toBeUndefined();
|
|
});
|
|
|
|
it('should handle language filter', async () => {
|
|
const input = {
|
|
targetPath: 'src/',
|
|
language: 'typescript',
|
|
};
|
|
|
|
const result = await learnPatternsTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
});
|
|
|
|
it('should handle min confidence threshold', async () => {
|
|
const input = {
|
|
targetPath: 'src/',
|
|
minConfidence: 0.8,
|
|
};
|
|
|
|
const result = await learnPatternsTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
});
|
|
|
|
it('should reject missing targetPath', async () => {
|
|
const input = {
|
|
patternTypes: ['design_patterns'],
|
|
};
|
|
|
|
const result = await learnPatternsTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
});
|
|
|
|
it('should reject minConfidence outside valid range', async () => {
|
|
const input = {
|
|
targetPath: 'src/',
|
|
minConfidence: 1.5, // above max of 1.0
|
|
};
|
|
|
|
const result = await learnPatternsTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('Security - Secret Masking', () => {
|
|
it('should mask secrets in search results', async () => {
|
|
// This tests that the tool doesn't expose secrets
|
|
const input = {
|
|
query: 'api key configuration',
|
|
};
|
|
|
|
const result = await semanticSearchTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
const data = JSON.parse(result.content[0].text!);
|
|
|
|
// Results should not contain unmasked secrets
|
|
for (const r of data.results) {
|
|
expect(r.content).not.toMatch(/sk-[a-zA-Z0-9]{48}/); // OpenAI key pattern
|
|
expect(r.content).not.toMatch(/AKIA[0-9A-Z]{16}/); // AWS key pattern
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('Error Handling', () => {
|
|
it('should handle validation errors gracefully', async () => {
|
|
const input = {
|
|
query: '', // Invalid empty query
|
|
};
|
|
|
|
const result = await semanticSearchTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
const data = JSON.parse(result.content[0].text!);
|
|
expect(data.error).toBe(true);
|
|
expect(data.message).toBeDefined();
|
|
});
|
|
|
|
it('should include timestamp in error response', async () => {
|
|
const input = {
|
|
targetPath: '', // Invalid
|
|
};
|
|
|
|
const result = await architectureAnalyzeTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBe(true);
|
|
const data = JSON.parse(result.content[0].text!);
|
|
expect(data.timestamp).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Performance Logging', () => {
|
|
it('should log duration on success', async () => {
|
|
const mockLogger = {
|
|
debug: vi.fn(),
|
|
info: vi.fn(),
|
|
warn: vi.fn(),
|
|
error: vi.fn(),
|
|
};
|
|
|
|
const input = { query: 'test function' };
|
|
await semanticSearchTool.handler(input, { logger: mockLogger });
|
|
|
|
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
expect.stringContaining('completed'),
|
|
expect.objectContaining({ durationMs: expect.any(String) })
|
|
);
|
|
});
|
|
|
|
it('should include analysis time in results', async () => {
|
|
const input = {
|
|
targetPath: 'src/',
|
|
};
|
|
|
|
const result = await architectureAnalyzeTool.handler(input, createMockContext());
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
const data = JSON.parse(result.content[0].text!);
|
|
expect(data.analysisTime).toBeDefined();
|
|
expect(typeof data.analysisTime).toBe('number');
|
|
});
|
|
});
|
|
|
|
describe('Output Format', () => {
|
|
it('should support different output formats', async () => {
|
|
const formats = ['json', 'markdown', 'summary'] as const;
|
|
|
|
for (const outputFormat of formats) {
|
|
const input = {
|
|
targetPath: 'src/',
|
|
outputFormat,
|
|
};
|
|
|
|
const result = await architectureAnalyzeTool.handler(input, createMockContext());
|
|
expect(result.isError).toBeUndefined();
|
|
}
|
|
});
|
|
});
|
|
});
|