fix(skill): simplify n8n action router

This commit is contained in:
zap
2026-03-12 07:32:40 +00:00
parent e0a3694430
commit 9b8b744cb1
3 changed files with 43 additions and 330 deletions

View File

@@ -5,26 +5,14 @@ from pathlib import Path
REQUIRED_NODE_NAMES = {
'Webhook',
'normalize-request',
'route-action',
'append-log-response',
'respond-append-log',
'notify-response',
'respond-notify',
'unknown-action-response',
'respond-unknown-action',
'Respond to Webhook',
}
EXPECTED_DIRECT_TYPES = {
'Webhook': 'n8n-nodes-base.webhook',
'normalize-request': 'n8n-nodes-base.set',
'route-action': 'n8n-nodes-base.switch',
'append-log-response': 'n8n-nodes-base.set',
'respond-append-log': 'n8n-nodes-base.respondToWebhook',
'notify-response': 'n8n-nodes-base.set',
'respond-notify': 'n8n-nodes-base.respondToWebhook',
'unknown-action-response': 'n8n-nodes-base.set',
'respond-unknown-action': 'n8n-nodes-base.respondToWebhook',
'route-action': 'n8n-nodes-base.code',
'Respond to Webhook': 'n8n-nodes-base.respondToWebhook',
}
@@ -81,30 +69,25 @@ def main():
if webhook_params.get('responseMode') != 'responseNode':
fail('Webhook.responseMode must be responseNode')
normalize = by_name['normalize-request'].get('parameters', {})
normalize_assignments = normalize.get('assignments', {}).get('assignments', [])
normalize_fields = {a.get('name') for a in normalize_assignments if isinstance(a, dict)}
for field in ('action', 'args', 'request_id'):
if field not in normalize_fields:
fail(f'normalize-request must assign {field!r}')
route = by_name['route-action'].get('parameters', {})
rule_values = route.get('rules', {}).get('values', [])
if len(rule_values) < 2:
fail('route-action must define at least two routing rules')
rule_names = {rule.get('outputKey') for rule in rule_values if isinstance(rule, dict)}
for action in ('append_log', 'notify'):
if action not in rule_names:
fail(f'route-action must have a routing rule for {action!r}')
router = by_name['route-action'].get('parameters', {})
if router.get('mode') != 'runOnceForEachItem':
fail('route-action code node must use runOnceForEachItem mode')
if router.get('language') != 'javaScript':
fail('route-action code node must use javaScript language')
js_code = router.get('jsCode', '')
for snippet in ("append_log", "notify", "unknown_action", "invalid_request", "status_code", "response_body"):
if snippet not in js_code:
fail(f'route-action jsCode missing expected snippet: {snippet!r}')
route_outputs = connections.get('route-action', {}).get('main', [])
if len(route_outputs) < 3:
fail('route-action must expose append_log, notify, and fallback outputs')
if len(route_outputs) < 1:
fail('route-action must connect to Respond to Webhook')
for responder_name in ('respond-append-log', 'respond-notify', 'respond-unknown-action'):
params = by_name[responder_name].get('parameters', {})
if params.get('respondWith') != 'json':
fail(f'{responder_name} must respondWith json')
responder = by_name['Respond to Webhook'].get('parameters', {})
if responder.get('respondWith') != 'json':
fail('Respond to Webhook must respondWith json')
if responder.get('responseBody') != '={{$json.response_body}}':
fail('Respond to Webhook must use $json.response_body as responseBody')
sample_paths = [
path.parent / 'test-append-log.json',
@@ -120,7 +103,7 @@ def main():
print('OK: workflow asset structure looks consistent')
print(f'- workflow: {path}')
print(f'- nodes: {len(nodes)}')
print(f'- rules: {len(rule_values)} + fallback')
print('- router: code node with append_log + notify + fallback')
print('- samples: test-append-log.json, test-notify.json')