Skip to content

Commit fec7d0f

Browse files
minipuftclaude
andcommitted
fix: restore missing test infrastructure for comprehensive testing
Add essential test scripts that were missing from the branch separation: - tests/scripts/server-integration.js: Core server functionality testing - tests/scripts/cageerf-framework.js: CAGEERF framework comprehensive tests - tests/scripts/mcp-tools.js: MCP tools and integration testing - tests/scripts/performance-memory.js: Performance benchmarking and memory leak detection These scripts are referenced by npm scripts but were missing from the clean MCP server enhancements branch, preventing full test coverage. This fix ensures comprehensive testing capability while maintaining the focused approach of enhanced server diagnostics and CI-aware logging. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b45f0b6 commit fec7d0f

4 files changed

Lines changed: 503 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env node
2+
/**
3+
* CAGEERF Framework Comprehensive Tests
4+
* Replaces complex inline scripts from GitHub Actions with proper test script
5+
*/
6+
7+
async function comprehensiveFrameworkTests() {
8+
try {
9+
console.log('🧪 Running comprehensive CAGEERF framework tests...');
10+
11+
const { CAGEERFAnalyzer } = await import('../../dist/utils/cageerf-analyzer.js');
12+
const { TemplateGenerator } = await import('../../dist/utils/template-generator.js');
13+
const { TemplateRepositoryBuilder } = await import('../../dist/utils/template-repository.js');
14+
const { SemanticAnalyzer } = await import('../../dist/utils/semanticAnalyzer.js');
15+
const { MockLogger } = await import('../../dist/utils/index.js');
16+
17+
console.log('🔍 Test 1: CAGEERF Analyzer edge cases');
18+
19+
const analyzer = new CAGEERFAnalyzer();
20+
21+
const testCases = [
22+
'Simple prompt',
23+
'Context analysis goals execution evaluation refinement framework methodology',
24+
'A'.repeat(1000), // Long input
25+
'🚀 Analyze 📊 the data with systematic approach! 🎯' // With emojis
26+
];
27+
28+
for (let i = 0; i < testCases.length; i++) {
29+
const analysis = analyzer.analyzeText(testCases[i]);
30+
if (!analysis.compliance || analysis.frameworkScore === undefined || analysis.overallCompliance === undefined) {
31+
throw new Error(`Invalid analysis structure for test case ${i + 1}`);
32+
}
33+
if (analysis.frameworkScore < 0 || analysis.frameworkScore > 1) {
34+
throw new Error(`Invalid framework score: ${analysis.frameworkScore}`);
35+
}
36+
console.log(`✅ Test case ${i + 1} passed (score: ${analysis.frameworkScore.toFixed(3)})`);
37+
}
38+
39+
console.log('🔍 Test 2: Template Generator validation');
40+
const generator = new TemplateGenerator();
41+
const complexities = ['simple', 'intermediate', 'advanced'];
42+
const styles = ['structured', 'conversational', 'professional'];
43+
44+
for (const complexity of complexities) {
45+
for (const style of styles) {
46+
const template = await generator.generateTemplate({
47+
useCase: `Test ${complexity} ${style}`,
48+
domain: 'Testing',
49+
complexity: complexity,
50+
frameworkEmphasis: {
51+
context: true, analysis: true, goals: true,
52+
execution: true, evaluation: true, refinement: true, framework: true
53+
},
54+
templateStyle: style,
55+
includePlaceholders: true
56+
});
57+
58+
if (!template.userMessageTemplate || typeof template.userMessageTemplate !== 'string') {
59+
throw new Error('Invalid template content');
60+
}
61+
if (!template.qualityScore || template.qualityScore < 0 || template.qualityScore > 1) {
62+
throw new Error(`Invalid CAGEERF score: ${template.qualityScore}`);
63+
}
64+
console.log(`✅ Template ${complexity}/${style} passed (score: ${template.qualityScore.toFixed(3)})`);
65+
}
66+
}
67+
68+
console.log('🔍 Test 3: Template Repository validation');
69+
const repository = TemplateRepositoryBuilder.buildRepository();
70+
if (!repository.templates || !Array.isArray(repository.templates)) {
71+
throw new Error('Invalid templates array');
72+
}
73+
console.log(`✅ Repository validation passed: ${repository.templates.length} templates`);
74+
75+
console.log('🔍 Test 4: Semantic Analyzer enhanced functionality');
76+
const semanticAnalyzer = new SemanticAnalyzer(new MockLogger());
77+
const testPrompt = {
78+
id: 'test-prompt-001',
79+
name: 'Test Analysis Prompt',
80+
userMessageTemplate: 'Analyze the context, set goals, execute systematic evaluation',
81+
description: 'Test prompt for semantic analysis',
82+
category: 'test',
83+
arguments: [],
84+
systemMessage: 'Test system message'
85+
};
86+
87+
const classification = semanticAnalyzer.classifyPrompt(testPrompt);
88+
if (!classification.executionType || classification.confidence === undefined) {
89+
throw new Error('Invalid classification structure');
90+
}
91+
if (!classification.cageerfAnalysis || classification.frameworkCompliance === undefined) {
92+
throw new Error('Missing CAGEERF integration');
93+
}
94+
console.log(`✅ Semantic analysis passed: ${classification.executionType} (confidence: ${classification.confidence.toFixed(3)})`);
95+
96+
console.log('🎉 Comprehensive CAGEERF framework tests completed successfully');
97+
process.exit(0);
98+
99+
} catch (error) {
100+
console.error('❌ CAGEERF framework tests failed:', error.message);
101+
process.exit(1);
102+
}
103+
}
104+
105+
comprehensiveFrameworkTests();

server/tests/scripts/mcp-tools.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env node
2+
/**
3+
* MCP Tools Comprehensive Tests
4+
* Replaces complex inline scripts from GitHub Actions with proper test script
5+
*/
6+
7+
async function comprehensiveMcpToolsTests() {
8+
try {
9+
console.log('🧪 Running comprehensive MCP tools tests...');
10+
11+
const { McpToolsManager } = await import('../../dist/mcp-tools/index.js');
12+
const { TemplateGenerationTools } = await import('../../dist/mcp-tools/template-generation-tools.js');
13+
const { MockLogger } = await import('../../dist/utils/index.js');
14+
15+
console.log('🔍 Test 1: MCP Tools Manager functionality');
16+
17+
const toolCalls = [];
18+
const mockMcpServer = {
19+
tool: function(name, description, schema) {
20+
toolCalls.push({ name, description, schema });
21+
return {
22+
name,
23+
handler: async (args) => {
24+
return {
25+
content: [{ type: 'text', text: `Mock response for ${name}` }]
26+
};
27+
}
28+
};
29+
}
30+
};
31+
32+
const logger = new MockLogger();
33+
const toolsManager = new McpToolsManager(logger, mockMcpServer, {});
34+
35+
const testPromptsData = [
36+
{
37+
id: 'test-1',
38+
name: 'Test Prompt 1',
39+
content: 'Test content with context and analysis components',
40+
description: 'Test prompt description'
41+
}
42+
];
43+
44+
const testConvertedPrompts = [
45+
{
46+
id: 'test-1',
47+
name: 'Test Prompt 1',
48+
content: 'Test content',
49+
description: 'Test description',
50+
category: 'test',
51+
executionMode: 'template'
52+
}
53+
];
54+
55+
const testCategories = [
56+
{ name: 'test', description: 'Test category' }
57+
];
58+
59+
toolsManager.updateData(testPromptsData, testConvertedPrompts, testCategories);
60+
toolsManager.registerAllTools();
61+
62+
if (toolCalls.length === 0) {
63+
throw new Error('No tools were registered');
64+
}
65+
console.log(`✅ MCP Tools Manager registered ${toolCalls.length} tools`);
66+
67+
const registeredNames = toolCalls.map(t => t.name);
68+
const essentialTools = ['update_prompt', 'list_prompts', 'execute_prompt'];
69+
70+
for (const tool of essentialTools) {
71+
if (!registeredNames.includes(tool)) {
72+
console.log(`⚠️ Essential tool missing: ${tool}`);
73+
} else {
74+
console.log(`✅ Essential tool found: ${tool}`);
75+
}
76+
}
77+
78+
console.log('🔍 Test 2: Template Generation Tools validation');
79+
const templateTools = new TemplateGenerationTools(logger, mockMcpServer);
80+
const beforeCount = toolCalls.length;
81+
82+
templateTools.registerAllTools();
83+
const templateToolsCount = toolCalls.length - beforeCount;
84+
85+
if (templateToolsCount === 0) {
86+
throw new Error('No template generation tools were registered');
87+
}
88+
console.log(`✅ Template Generation Tools registered ${templateToolsCount} additional tools`);
89+
90+
console.log('🎉 Comprehensive MCP tools tests completed successfully');
91+
process.exit(0);
92+
93+
} catch (error) {
94+
console.error('❌ MCP tools tests failed:', error.message);
95+
process.exit(1);
96+
}
97+
}
98+
99+
comprehensiveMcpToolsTests();
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Performance and Memory Tests
4+
* Replaces complex inline scripts from GitHub Actions with proper test script
5+
*/
6+
7+
async function performanceTests() {
8+
try {
9+
console.log('🧪 Running performance and memory tests...');
10+
11+
const { CAGEERFAnalyzer } = await import('../../dist/utils/cageerf-analyzer.js');
12+
const { TemplateGenerator } = await import('../../dist/utils/template-generator.js');
13+
14+
console.log('⏱️ Starting performance tests...');
15+
16+
const analyzer = new CAGEERFAnalyzer();
17+
const generator = new TemplateGenerator();
18+
19+
// Performance benchmark
20+
const testPrompts = [
21+
'Simple analysis task',
22+
'Complex multi-faceted analysis requiring comprehensive context evaluation, systematic goal setting, detailed execution planning, thorough evaluation criteria, and iterative refinement processes',
23+
'Medium complexity prompt with CAGEERF elements'
24+
];
25+
26+
console.log('📊 Analysis Performance:');
27+
for (let i = 0; i < testPrompts.length; i++) {
28+
const start = Date.now();
29+
const analysis = analyzer.analyzeText(testPrompts[i]);
30+
const duration = Date.now() - start;
31+
console.log(` Prompt ${i + 1}: ${duration}ms (score: ${analysis.frameworkScore.toFixed(3)})`);
32+
33+
if (duration > 1000) {
34+
console.log(`⚠️ Warning: Analysis took ${duration}ms (threshold: 1000ms)`);
35+
}
36+
}
37+
38+
// Template generation performance
39+
console.log('📊 Template Generation Performance:');
40+
const complexities = ['simple', 'intermediate', 'advanced'];
41+
42+
for (const complexity of complexities) {
43+
const start = Date.now();
44+
const template = await generator.generateTemplate({
45+
useCase: 'Performance Test',
46+
domain: 'Testing',
47+
complexity: complexity,
48+
frameworkEmphasis: {
49+
context: true, analysis: true, goals: true,
50+
execution: true, evaluation: true, refinement: true, framework: true
51+
},
52+
templateStyle: 'structured'
53+
});
54+
const duration = Date.now() - start;
55+
console.log(` ${complexity}: ${duration}ms (length: ${template.userMessageTemplate.length}, score: ${template.qualityScore.toFixed(3)})`);
56+
57+
if (duration > 2000) {
58+
console.log(`⚠️ Warning: Template generation took ${duration}ms (threshold: 2000ms)`);
59+
}
60+
}
61+
62+
// Memory usage test
63+
console.log('💾 Memory Usage Test:');
64+
const initialMemory = process.memoryUsage().heapUsed;
65+
console.log(`Initial memory: ${Math.round(initialMemory / 1024 / 1024)}MB heap`);
66+
67+
for (let i = 0; i < 50; i++) {
68+
analyzer.analyzeText(`Memory test prompt ${i} with comprehensive analysis components`);
69+
await generator.generateTemplate({
70+
useCase: `Memory Test ${i}`,
71+
domain: 'Testing',
72+
complexity: 'simple',
73+
frameworkEmphasis: {
74+
context: true, analysis: true, goals: true,
75+
execution: true, evaluation: true, refinement: true, framework: true
76+
},
77+
templateStyle: 'structured'
78+
});
79+
}
80+
81+
// Force garbage collection if available
82+
if (global.gc) {
83+
global.gc();
84+
}
85+
86+
// Wait a bit for cleanup
87+
await new Promise(resolve => setTimeout(resolve, 1000));
88+
89+
const finalMemory = process.memoryUsage().heapUsed;
90+
const memoryIncrease = finalMemory - initialMemory;
91+
92+
console.log(`Final memory: ${Math.round(finalMemory / 1024 / 1024)}MB heap`);
93+
console.log(`Memory increase: ${Math.round(memoryIncrease / 1024 / 1024)}MB for 50 operations`);
94+
95+
if (memoryIncrease > 25 * 1024 * 1024) {
96+
console.log(`⚠️ Potential memory leak: ${Math.round(memoryIncrease / 1024 / 1024)}MB increase`);
97+
} else {
98+
console.log(`✅ Memory usage acceptable: ${Math.round(memoryIncrease / 1024 / 1024)}MB increase for 50 operations`);
99+
}
100+
101+
// Memory stability test
102+
console.log('📊 Memory Stability Test:');
103+
const measurements = [];
104+
105+
for (let i = 0; i < 10; i++) {
106+
// Perform batch of operations
107+
for (let j = 0; j < 10; j++) {
108+
analyzer.analyzeText(`Load test prompt ${i}-${j} with analysis framework components`);
109+
}
110+
111+
// Force garbage collection if available
112+
if (global.gc) {
113+
global.gc();
114+
}
115+
116+
// Measure memory
117+
const memory = process.memoryUsage().heapUsed;
118+
measurements.push(memory);
119+
120+
// Brief pause between batches
121+
await new Promise(resolve => setTimeout(resolve, 100));
122+
}
123+
124+
// Analyze memory stability
125+
const maxMemory = Math.max(...measurements);
126+
const minMemory = Math.min(...measurements);
127+
const memoryRange = maxMemory - minMemory;
128+
const averageMemory = measurements.reduce((a, b) => a + b, 0) / measurements.length;
129+
130+
console.log(`Memory range: ${Math.round(minMemory / 1024 / 1024)} - ${Math.round(maxMemory / 1024 / 1024)}MB (range: ${Math.round(memoryRange / 1024 / 1024)}MB)`);
131+
console.log(`Average memory: ${Math.round(averageMemory / 1024 / 1024)}MB`);
132+
133+
// Memory should remain relatively stable (range < 50MB)
134+
if (memoryRange > 50 * 1024 * 1024) {
135+
console.log(`⚠️ Memory instability detected: ${Math.round(memoryRange / 1024 / 1024)}MB range`);
136+
} else {
137+
console.log(`✅ Memory stability acceptable: ${Math.round(memoryRange / 1024 / 1024)}MB range`);
138+
}
139+
140+
console.log('✅ Performance and memory tests completed successfully');
141+
process.exit(0);
142+
143+
} catch (error) {
144+
console.error('❌ Performance tests failed:', error.message);
145+
process.exit(1);
146+
}
147+
}
148+
149+
performanceTests();

0 commit comments

Comments
 (0)