n8n-bookstack-agent-tool
Version:
Comprehensive BookStack API integration tool for n8n AI Agent with MCP framework compatibility
166 lines ⢠8.4 kB
JavaScript
;
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