Files
czlonkowski--n8n-mcp/scripts/test-helpers-validation.ts
wehub-resource-sync 409e92d6ae
Build and Push Docker Images / Build Docker Image (push) Has been cancelled
Build and Push Docker Images / Build Railway Docker Image (push) Has been cancelled
Build and Publish n8n Docker Image / test-image (push) Has been cancelled
Dependency Compatibility Check / Fresh Install Dependency Check (push) Has been cancelled
Build and Publish n8n Docker Image / build-and-push (push) Has been cancelled
Build and Publish n8n Docker Image / create-release (push) Has been cancelled
Automated Release / Detect Version Change (push) Has been cancelled
Automated Release / Generate Release Notes (push) Has been cancelled
Automated Release / Create GitHub Release (push) Has been cancelled
Automated Release / Package MCPB Bundle (push) Has been cancelled
Automated Release / Build and Verify (push) Has been cancelled
Automated Release / Publish to NPM (push) Has been cancelled
Automated Release / Build and Push Docker Images (push) Has been cancelled
Automated Release / Update Documentation (push) Has been cancelled
Automated Release / Notify Release Completion (push) Has been cancelled
Secret Scan / secretlint (push) Has been cancelled
Test Suite / test (push) Has been cancelled
Test Suite / cjs-runtime (push) Has been cancelled
Test Suite / publish-results (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:41:06 +08:00

93 lines
2.3 KiB
TypeScript

#!/usr/bin/env npx tsx
import { EnhancedConfigValidator } from '../src/services/enhanced-config-validator.js';
console.log('🧪 Testing $helpers Validation\n');
const testCases = [
{
name: 'Incorrect $helpers.getWorkflowStaticData',
config: {
language: 'javaScript',
jsCode: `const data = $helpers.getWorkflowStaticData('global');
data.counter = 1;
return [{json: {counter: data.counter}}];`
}
},
{
name: 'Correct $getWorkflowStaticData',
config: {
language: 'javaScript',
jsCode: `const data = $getWorkflowStaticData('global');
data.counter = 1;
return [{json: {counter: data.counter}}];`
}
},
{
name: '$helpers without check',
config: {
language: 'javaScript',
jsCode: `const response = await $helpers.httpRequest({
method: 'GET',
url: 'https://api.example.com'
});
return [{json: response}];`
}
},
{
name: '$helpers with proper check',
config: {
language: 'javaScript',
jsCode: `if (typeof $helpers !== 'undefined' && $helpers.httpRequest) {
const response = await $helpers.httpRequest({
method: 'GET',
url: 'https://api.example.com'
});
return [{json: response}];
}
return [{json: {error: 'HTTP not available'}}];`
}
},
{
name: 'Crypto without require',
config: {
language: 'javaScript',
jsCode: `const token = crypto.randomBytes(32).toString('hex');
return [{json: {token}}];`
}
},
{
name: 'Crypto with require',
config: {
language: 'javaScript',
jsCode: `const crypto = require('crypto');
const token = crypto.randomBytes(32).toString('hex');
return [{json: {token}}];`
}
}
];
for (const test of testCases) {
console.log(`Test: ${test.name}`);
const result = EnhancedConfigValidator.validateWithMode(
'nodes-base.code',
test.config,
[
{ name: 'language', type: 'options', options: ['javaScript', 'python'] },
{ name: 'jsCode', type: 'string' }
],
'operation',
'ai-friendly'
);
console.log(` Valid: ${result.valid}`);
if (result.errors.length > 0) {
console.log(` Errors: ${result.errors.map(e => e.message).join(', ')}`);
}
if (result.warnings.length > 0) {
console.log(` Warnings: ${result.warnings.map(w => w.message).join(', ')}`);
}
console.log();
}
console.log('✅ $helpers validation tests completed!');