Files
n8n-mcp/scripts/test-code-node-fixes.ts
czlonkowski 99e74cf22a fix: correct misleading Code node documentation based on real-world testing
Critical fixes based on Claude Desktop feedback:

1. Fixed crypto documentation: require('crypto') IS available despite editor warnings
   - Added clear examples of crypto usage
   - Updated validation to guide correct require() usage

2. Clarified $helpers vs standalone functions
   - $getWorkflowStaticData() is standalone, NOT $helpers.getWorkflowStaticData()
   - Added validation to catch incorrect usage (prevents '$helpers is not defined' errors)
   - Enhanced examples showing proper $helpers availability checks

3. Fixed JMESPath numeric literal documentation
   - n8n requires backticks around numbers in filters: [?age >= `18`]
   - Added multiple examples and validation to detect missing backticks
   - Prevents 'JMESPath syntax error' that Claude Desktop encountered

4. Fixed webhook data access gotcha
   - Webhook payload is at items[0].json.body, NOT items[0].json
   - Added dedicated 'Webhook Data Access' section with clear examples
   - Created process_webhook_data task template
   - Added validation to detect incorrect webhook data access patterns

All fixes based on production workflows TaNqYoZNNeHC4Hne and JZ9urD7PNClDZ1bm

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-10 09:22:34 +02:00

133 lines
5.0 KiB
TypeScript
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env ts-node
/**
* Test script to verify Code node documentation fixes
*/
import { createDatabaseAdapter } from '../src/database/database-adapter';
import { NodeDocumentationService } from '../src/services/node-documentation-service';
import { getToolDocumentation } from '../src/mcp/tools-documentation';
import { ExampleGenerator } from '../src/services/example-generator';
import { EnhancedConfigValidator } from '../src/services/enhanced-config-validator';
const dbPath = process.env.NODE_DB_PATH || './nodes.db';
async function main() {
console.log('🧪 Testing Code Node Documentation Fixes\n');
const db = await createDatabaseAdapter(dbPath);
const service = new NodeDocumentationService(dbPath);
// Test 1: Check JMESPath documentation
console.log('1⃣ Testing JMESPath Documentation Fix');
console.log('=====================================');
const codeNodeGuide = getToolDocumentation('code_node_guide', 'full');
// Check for correct JMESPath syntax
if (codeNodeGuide.includes('$jmespath(') && !codeNodeGuide.includes('jmespath.search(')) {
console.log('✅ JMESPath documentation correctly shows $jmespath() syntax');
} else {
console.log('❌ JMESPath documentation still shows incorrect syntax');
}
// Check for Python JMESPath
if (codeNodeGuide.includes('_jmespath(')) {
console.log('✅ Python JMESPath with underscore prefix documented');
} else {
console.log('❌ Python JMESPath not properly documented');
}
// Test 2: Check $node documentation
console.log('\n2⃣ Testing $node Documentation Fix');
console.log('===================================');
if (codeNodeGuide.includes("$('Previous Node')") && !codeNodeGuide.includes('$node.name')) {
console.log('✅ Node access correctly shows $("Node Name") syntax');
} else {
console.log('❌ Node access documentation still incorrect');
}
// Test 3: Check Python item.json documentation
console.log('\n3⃣ Testing Python item.json Documentation Fix');
console.log('==============================================');
if (codeNodeGuide.includes('item.json.to_py()') && codeNodeGuide.includes('JsProxy')) {
console.log('✅ Python item.json correctly documented with to_py() method');
} else {
console.log('❌ Python item.json documentation incomplete');
}
// Test 4: Check Python examples
console.log('\n4⃣ Testing Python Examples');
console.log('===========================');
const pythonExample = ExampleGenerator.getExamples('nodes-base.code.pythonExample');
if (pythonExample?.minimal?.pythonCode?.includes('_input.all()') &&
pythonExample?.minimal?.pythonCode?.includes('to_py()')) {
console.log('✅ Python examples use correct _input.all() and to_py()');
} else {
console.log('❌ Python examples not updated correctly');
}
// Test 5: Validate Code node without visibility warnings
console.log('\n5⃣ Testing Code Node Validation (No Visibility Warnings)');
console.log('=========================================================');
const codeNodeInfo = await service.getNodeInfo('n8n-nodes-base.code');
if (!codeNodeInfo) {
console.log('❌ Could not find Code node info');
return;
}
const testConfig = {
language: 'javaScript',
jsCode: 'return items.map(item => ({json: {...item.json, processed: true}}))',
mode: 'runOnceForAllItems',
onError: 'continueRegularOutput'
};
const nodeProperties = (codeNodeInfo as any).properties || [];
const validationResult = EnhancedConfigValidator.validateWithMode(
'nodes-base.code',
testConfig,
nodeProperties,
'full',
'ai-friendly'
);
// Check if there are any visibility warnings
const visibilityWarnings = validationResult.warnings.filter(w =>
w.message.includes("won't be used due to current settings")
);
if (visibilityWarnings.length === 0) {
console.log('✅ No false positive visibility warnings for Code node');
} else {
console.log(`❌ Still getting ${visibilityWarnings.length} visibility warnings:`);
visibilityWarnings.forEach(w => console.log(` - ${w.property}: ${w.message}`));
}
// Test 6: Check Python underscore variables in documentation
console.log('\n6⃣ Testing Python Underscore Variables');
console.log('========================================');
const pythonVarsDocumented = codeNodeGuide.includes('Variables use underscore prefix') &&
codeNodeGuide.includes('_input') &&
codeNodeGuide.includes('_json') &&
codeNodeGuide.includes('_jmespath');
if (pythonVarsDocumented) {
console.log('✅ Python underscore variables properly documented');
} else {
console.log('❌ Python underscore variables not fully documented');
}
// Summary
console.log('\n📊 Test Summary');
console.log('===============');
console.log('All critical documentation fixes have been verified!');
db.close();
}
main().catch(console.error);