test-all-features.mjsโข7.2 kB
#!/usr/bin/env node
/**
* Comprehensive Feature Test for M365 Core MCP Server
* Tests both the enhanced Microsoft API capabilities and extended resources/prompts
*/
import { execSync } from 'child_process';
import fs from 'fs';
console.log('๐งช M365 Core MCP Server - Comprehensive Feature Test');
console.log('===================================================\n');
// Test categories
const tests = {
build: [],
extendedResources: [],
enhancedAPI: [],
prompts: [],
integration: []
};
// 1. Build and Compilation Tests
console.log('๐ฆ 1. Testing Build and Compilation...');
try {
execSync('npm run build', { stdio: 'pipe' });
tests.build.push('โ
TypeScript compilation successful');
} catch (error) {
tests.build.push('โ TypeScript compilation failed');
console.error('Build error:', error.message);
}
// 2. Extended Resources Verification
console.log('๐ 2. Verifying Extended Resources...');
// Check if extended-resources.ts exists and has the right content
const extendedResourcesPath = './src/extended-resources.ts';
if (fs.existsSync(extendedResourcesPath)) {
const content = fs.readFileSync(extendedResourcesPath, 'utf8');
// Check for key resources mentioned in EXTENDED_FEATURES.md
const requiredResources = [
'security_alerts',
'security_incidents',
'conditional_access_policies',
'applications',
'service_principals',
'directory_roles',
'intune_devices_extended',
'teams_list_extended',
'mail_folders_extended',
'calendar_events_extended'
];
requiredResources.forEach(resource => {
if (content.includes(`"${resource}"`)) {
tests.extendedResources.push(`โ
Resource '${resource}' found`);
} else {
tests.extendedResources.push(`โ Resource '${resource}' missing`);
}
});
// Count total resources
const resourceCount = (content.match(/server\.resource\(/g) || []).length;
tests.extendedResources.push(`๐ Total resources defined: ${resourceCount}`);
} else {
tests.extendedResources.push('โ extended-resources.ts file not found');
}
// 3. Enhanced Microsoft API Features Verification
console.log('๐ 3. Verifying Enhanced Microsoft API Features...');
// Check enhanced tool schema
const toolDefinitionsPath = './src/tool-definitions.ts';
if (fs.existsSync(toolDefinitionsPath)) {
const content = fs.readFileSync(toolDefinitionsPath, 'utf8');
const enhancedFeatures = [
'maxRetries',
'retryDelay',
'timeout',
'customHeaders',
'responseFormat',
'selectFields',
'expandFields',
'batchSize'
];
enhancedFeatures.forEach(feature => {
if (content.includes(feature)) {
tests.enhancedAPI.push(`โ
Enhanced feature '${feature}' found in schema`);
} else {
tests.enhancedAPI.push(`โ Enhanced feature '${feature}' missing from schema`);
}
});
} else {
tests.enhancedAPI.push('โ tool-definitions.ts file not found');
}
// Check enhanced handler implementation
const handlersPath = './src/handlers.ts';
if (fs.existsSync(handlersPath)) {
const content = fs.readFileSync(handlersPath, 'utf8');
const handlerFeatures = [
'executeWithRetry',
'TokenCache',
'RateLimiter',
'exponential backoff',
'responseFormat',
'selectFields',
'expandFields'
];
handlerFeatures.forEach(feature => {
if (content.includes(feature)) {
tests.enhancedAPI.push(`โ
Handler feature '${feature}' implemented`);
} else {
tests.enhancedAPI.push(`โ ๏ธ Handler feature '${feature}' not found (may use different naming)`);
}
});
} else {
tests.enhancedAPI.push('โ handlers.ts file not found');
}
// 4. Prompts Verification
console.log('๐ 4. Verifying Comprehensive Prompts...');
if (fs.existsSync(extendedResourcesPath)) {
const content = fs.readFileSync(extendedResourcesPath, 'utf8');
const requiredPrompts = [
'security_assessment',
'compliance_review',
'user_access_review',
'device_compliance_analysis',
'collaboration_governance'
];
requiredPrompts.forEach(prompt => {
if (content.includes(`"${prompt}"`)) {
tests.prompts.push(`โ
Prompt '${prompt}' found`);
} else {
tests.prompts.push(`โ Prompt '${prompt}' missing`);
}
});
// Count total prompts
const promptCount = (content.match(/server\.prompt\(/g) || []).length;
tests.prompts.push(`๐ Total prompts defined: ${promptCount}`);
}
// 5. Integration Tests
console.log('๐ 5. Verifying Integration...');
// Check if server.ts imports and uses extended resources
const serverPath = './src/server.ts';
if (fs.existsSync(serverPath)) {
const content = fs.readFileSync(serverPath, 'utf8');
if (content.includes('setupExtendedResources')) {
tests.integration.push('โ
Extended resources integrated into server');
} else {
tests.integration.push('โ Extended resources not integrated');
}
if (content.includes('TokenCache') || content.includes('RateLimiter')) {
tests.integration.push('โ
Enhanced utility classes integrated');
} else {
tests.integration.push('โ Enhanced utility classes not integrated');
}
if (content.includes('version: \'1.1.0\'')) {
tests.integration.push('โ
Server version updated to reflect enhancements');
} else {
tests.integration.push('โ ๏ธ Server version not updated (may still be 1.0.0)');
}
} else {
tests.integration.push('โ server.ts file not found');
}
// Check if index.ts reflects enhanced version
const indexPath = './src/index.ts';
if (fs.existsSync(indexPath)) {
const content = fs.readFileSync(indexPath, 'utf8');
if (content.includes('1.1.0')) {
tests.integration.push('โ
Index version updated to reflect enhancements');
} else {
tests.integration.push('โ ๏ธ Index version not updated');
}
}
// Display Results
console.log('\n๐ TEST RESULTS SUMMARY');
console.log('=======================\n');
Object.entries(tests).forEach(([category, results]) => {
console.log(`${category.toUpperCase()}:`);
results.forEach(result => console.log(` ${result}`));
console.log('');
});
// Overall Assessment
const allTests = Object.values(tests).flat();
const passedTests = allTests.filter(test => test.includes('โ
')).length;
const failedTests = allTests.filter(test => test.includes('โ')).length;
const warningTests = allTests.filter(test => test.includes('โ ๏ธ')).length;
console.log('OVERALL ASSESSMENT:');
console.log(`โ
Passed: ${passedTests}`);
console.log(`โ Failed: ${failedTests}`);
console.log(`โ ๏ธ Warnings: ${warningTests}`);
console.log(`๐ Total: ${allTests.length}`);
const successRate = (passedTests / allTests.length) * 100;
console.log(`\n๐ฏ Success Rate: ${successRate.toFixed(1)}%`);
if (successRate >= 90) {
console.log('๐ Excellent! All major features are implemented and working.');
} else if (successRate >= 75) {
console.log('๐ Good! Most features are working, some minor issues to address.');
} else if (successRate >= 50) {
console.log('โ ๏ธ Fair! Several features need attention.');
} else {
console.log('๐จ Poor! Major issues need to be resolved.');
}
console.log('\nโจ Feature Test Complete!\n');