UNPKG

n8n-bookstack-agent-tool

Version:

Comprehensive BookStack API integration tool for n8n AI Agent with MCP framework compatibility

166 lines • 8.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorConsistencyValidator = void 0; const index_js_1 = require("../index.js"); class ErrorConsistencyValidator { constructor() { const config = { baseUrl: 'https://wiki.l7cloud.io', authType: 'bearer', token: 'EnRkbVwqzNSyLaVo7olU8Wx8umGznKuE', tokenSecret: 'TyaJ0JHAenwRIgScmsffrCeSIlon4fZ2', timeout: 30000, retryAttempts: 3, retryDelay: 1000 }; this.tool = new index_js_1.BookStackN8nTool(config); } async runErrorConsistencyTests() { console.log('\nšŸ” ERROR HANDLING CONSISTENCY VALIDATION'); console.log('========================================'); await this.validateErrorTypes(); await this.validateErrorMessages(); await this.validateErrorStructure(); await this.validateRetryBehavior(); console.log('\nāœ… Error handling consistency validation completed'); } async validateErrorTypes() { console.log('\nšŸ·ļø Validating error type consistency...'); const errorScenarios = [ { name: 'Not Found (404)', command: 'getBook', params: { id: 999999 }, expectedType: 'BookStackError' }, { name: 'Validation Error', command: 'createBook', params: { name: '' }, expectedType: 'BookStackError' }, { name: 'Invalid Command', command: 'invalidCommand', params: {}, expectedType: 'Error' } ]; let consistentErrors = 0; const totalErrors = errorScenarios.length; for (const scenario of errorScenarios) { try { console.log(` Testing ${scenario.name}...`); await this.tool.execCommand(scenario.command, scenario.params); console.log(` āš ļø ${scenario.name}: No error thrown`); } catch (error) { const errorType = error.constructor.name; const isExpectedType = errorType === scenario.expectedType || (scenario.expectedType === 'BookStackError' && errorType.includes('BookStack')); if (isExpectedType) { console.log(` āœ… ${scenario.name}: Correct error type (${errorType})`); consistentErrors++; } else { console.log(` āŒ ${scenario.name}: Unexpected error type (${errorType}, expected ${scenario.expectedType})`); } } } console.log(`\n šŸ“Š Error Type Consistency: ${consistentErrors}/${totalErrors} (${(consistentErrors / totalErrors * 100).toFixed(1)}%)`); } async validateErrorMessages() { console.log('\nšŸ’¬ Validating error message consistency...'); const messageTests = [ { name: 'Resource Not Found', command: 'getBook', params: { id: 999999 }, expectedKeywords: ['not found', '404'] }, { name: 'Missing Required Field', command: 'createBook', params: { name: '' }, expectedKeywords: ['required', 'validation'] }, { name: 'Invalid Resource ID', command: 'getPage', params: { id: 'invalid' }, expectedKeywords: ['invalid', 'id'] } ]; let consistentMessages = 0; const totalMessages = messageTests.length; for (const test of messageTests) { try { console.log(` Testing ${test.name}...`); await this.tool.execCommand(test.command, test.params); console.log(` āš ļø ${test.name}: No error thrown`); } catch (error) { const errorMessage = error.message?.toLowerCase() || ''; const hasExpectedKeywords = test.expectedKeywords.some(keyword => errorMessage.includes(keyword.toLowerCase())); if (hasExpectedKeywords) { console.log(` āœ… ${test.name}: Message contains expected keywords`); consistentMessages++; } else { console.log(` āŒ ${test.name}: Message missing expected keywords`); console.log(` Message: ${errorMessage}`); console.log(` Expected: ${test.expectedKeywords.join(', ')}`); } } } console.log(`\n šŸ“Š Error Message Consistency: ${consistentMessages}/${totalMessages} (${(consistentMessages / totalMessages * 100).toFixed(1)}%)`); } async validateErrorStructure() { console.log('\nšŸ—ļø Validating error structure consistency...'); const structureTests = [ { name: 'API Error Structure', command: 'getBook', params: { id: 999999 } }, { name: 'Validation Error Structure', command: 'createBook', params: { name: '' } } ]; let consistentStructures = 0; const totalStructures = structureTests.length; for (const test of structureTests) { try { console.log(` Testing ${test.name}...`); await this.tool.execCommand(test.command, test.params); console.log(` āš ļø ${test.name}: No error thrown`); } catch (error) { const hasMessage = typeof error.message === 'string'; const hasName = typeof error.name === 'string'; const hasStack = typeof error.stack === 'string'; const structureValid = hasMessage && hasName && hasStack; if (structureValid) { console.log(` āœ… ${test.name}: Error structure is consistent`); console.log(` - Message: ${hasMessage ? 'āœ“' : 'āœ—'}`); console.log(` - Name: ${hasName ? 'āœ“' : 'āœ—'}`); console.log(` - Stack: ${hasStack ? 'āœ“' : 'āœ—'}`); consistentStructures++; } else { console.log(` āŒ ${test.name}: Error structure is inconsistent`); console.log(` - Message: ${hasMessage ? 'āœ“' : 'āœ—'}`); console.log(` - Name: ${hasName ? 'āœ“' : 'āœ—'}`); console.log(` - Stack: ${hasStack ? 'āœ“' : 'āœ—'}`); } } } console.log(`\n šŸ“Š Error Structure Consistency: ${consistentStructures}/${totalStructures} (${(consistentStructures / totalStructures * 100).toFixed(1)}%)`); } async validateRetryBehavior() { console.log('\nšŸ”„ Validating retry behavior consistency...'); try { console.log(' Testing retry behavior with network errors...'); const invalidConfig = { baseUrl: 'https://nonexistent-server.invalid', authType: 'bearer', token: 'test', tokenSecret: 'test', timeout: 5000, retryAttempts: 2, retryDelay: 500 }; const retryTool = new index_js_1.BookStackN8nTool(invalidConfig); const startTime = Date.now(); try { await retryTool.execCommand('listBooks', {}); console.log(' āš ļø Retry test: Request succeeded unexpectedly'); } catch (error) { const endTime = Date.now(); const duration = endTime - startTime; const expectedMinDuration = 1000; const retryBehaviorValid = duration >= expectedMinDuration; if (retryBehaviorValid) { console.log(` āœ… Retry behavior: Consistent timing (${duration}ms >= ${expectedMinDuration}ms)`); } else { console.log(` āŒ Retry behavior: Inconsistent timing (${duration}ms < ${expectedMinDuration}ms)`); } } } catch (configError) { console.log(` āœ… Retry test: Configuration validation prevented invalid setup`); } } } exports.ErrorConsistencyValidator = ErrorConsistencyValidator; if (require.main === module) { const validator = new ErrorConsistencyValidator(); validator.runErrorConsistencyTests().catch(console.error); } //# sourceMappingURL=error-consistency-validator.js.map