chore: import upstream snapshot with attribution
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
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
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env npx tsx
|
||||
|
||||
import { EnhancedConfigValidator } from '../src/services/enhanced-config-validator.js';
|
||||
|
||||
console.log('🧪 Testing Webhook Data Access Validation\n');
|
||||
|
||||
const testCases = [
|
||||
{
|
||||
name: 'Direct webhook data access (incorrect)',
|
||||
config: {
|
||||
language: 'javaScript',
|
||||
jsCode: `// Processing data from Webhook node
|
||||
const prevWebhook = $('Webhook').first();
|
||||
const command = items[0].json.testCommand;
|
||||
const data = items[0].json.payload;
|
||||
return [{json: {command, data}}];`
|
||||
},
|
||||
expectWarning: true
|
||||
},
|
||||
{
|
||||
name: 'Correct webhook data access through body',
|
||||
config: {
|
||||
language: 'javaScript',
|
||||
jsCode: `// Processing data from Webhook node
|
||||
const webhookData = items[0].json.body;
|
||||
const command = webhookData.testCommand;
|
||||
const data = webhookData.payload;
|
||||
return [{json: {command, data}}];`
|
||||
},
|
||||
expectWarning: false
|
||||
},
|
||||
{
|
||||
name: 'Common webhook field names without body',
|
||||
config: {
|
||||
language: 'javaScript',
|
||||
jsCode: `// Processing webhook
|
||||
const command = items[0].json.command;
|
||||
const action = items[0].json.action;
|
||||
const payload = items[0].json.payload;
|
||||
return [{json: {command, action, payload}}];`
|
||||
},
|
||||
expectWarning: true
|
||||
},
|
||||
{
|
||||
name: 'Non-webhook data access (should not warn)',
|
||||
config: {
|
||||
language: 'javaScript',
|
||||
jsCode: `// Processing data from HTTP Request node
|
||||
const data = items[0].json.results;
|
||||
const status = items[0].json.status;
|
||||
return [{json: {data, status}}];`
|
||||
},
|
||||
expectWarning: false
|
||||
},
|
||||
{
|
||||
name: 'Mixed correct and incorrect access',
|
||||
config: {
|
||||
language: 'javaScript',
|
||||
jsCode: `// Mixed access patterns
|
||||
const webhookBody = items[0].json.body; // Correct
|
||||
const directAccess = items[0].json.command; // Incorrect if webhook
|
||||
return [{json: {webhookBody, directAccess}}];`
|
||||
},
|
||||
expectWarning: false // If user already uses .body, we assume they know the pattern
|
||||
}
|
||||
];
|
||||
|
||||
let passCount = 0;
|
||||
let failCount = 0;
|
||||
|
||||
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'
|
||||
);
|
||||
|
||||
const hasWebhookWarning = result.warnings.some(w =>
|
||||
w.message.includes('Webhook data is nested under .body') ||
|
||||
w.message.includes('webhook data, remember it\'s nested under .body')
|
||||
);
|
||||
|
||||
const passed = hasWebhookWarning === test.expectWarning;
|
||||
|
||||
console.log(` Expected warning: ${test.expectWarning}`);
|
||||
console.log(` Has webhook warning: ${hasWebhookWarning}`);
|
||||
console.log(` Result: ${passed ? '✅ PASS' : '❌ FAIL'}`);
|
||||
|
||||
if (result.warnings.length > 0) {
|
||||
const relevantWarnings = result.warnings
|
||||
.filter(w => w.message.includes('webhook') || w.message.includes('Webhook'))
|
||||
.map(w => w.message);
|
||||
if (relevantWarnings.length > 0) {
|
||||
console.log(` Webhook warnings: ${relevantWarnings.join(', ')}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (passed) passCount++;
|
||||
else failCount++;
|
||||
|
||||
console.log();
|
||||
}
|
||||
|
||||
console.log(`\n📊 Results: ${passCount} passed, ${failCount} failed`);
|
||||
console.log(failCount === 0 ? '✅ All webhook validation tests passed!' : '❌ Some tests failed');
|
||||
Reference in New Issue
Block a user