Jelajahi Sumber

fix: GET/POST/PUT trigger nodes read context.triggerData, which the engine never sets

The runner hands a trigger node's payload to `input`, not `context` -
`context` only carries executionId/nodeId/workflowId. All three nodes read
`context.triggerData || {}`, so every field (method, path, query, headers,
body) fell through to its default on every real webhook call, and the
`|| {}` made the failure look like a plausible empty request instead of an
error. Fixed by reading from `input`, following the same fix already applied
to form-trigger.js and database-change.js on this branch.

Added tests/nodes/post-trigger-body-passthrough.json and
tests/nodes/get-trigger-query-passthrough.json, which send a value through
the webhook and assert it comes back out through a respond-to-webhook node -
the existing webhook tests only asserted on the HTTP response shape and never
on what the trigger node actually emitted, so they passed before this fix
just as they do after it.
fszontagh 1 bulan lalu
induk
melakukan
705b995a10

+ 5 - 2
nodes/triggers/get-trigger.js

@@ -78,8 +78,11 @@ const outputSchema = {
 async function execute(config, input, context) {
   smartbotic.log.info('GET trigger activated');
 
-  // The trigger data comes from the webhook controller
-  const triggerData = context.triggerData || {};
+  // The runner hands the trigger node's payload to `input`, not `context` -
+  // `context` only carries executionId/nodeId/workflowId. Executed directly
+  // from the editor's Run button there is no request, so the defaults below
+  // (method GET, empty path/query/headers/clientIp) are the honest answer.
+  const triggerData = input || {};
 
   return {
     method: triggerData.method || 'GET',

+ 5 - 2
nodes/triggers/post-trigger.js

@@ -107,8 +107,11 @@ const outputSchema = {
 async function execute(config, input, context) {
   smartbotic.log.info('POST trigger activated');
 
-  // The trigger data comes from the webhook controller
-  const triggerData = context.triggerData || {};
+  // The runner hands the trigger node's payload to `input`, not `context` -
+  // `context` only carries executionId/nodeId/workflowId. Executed directly
+  // from the editor's Run button there is no request, so the defaults below
+  // (method POST, empty path/query/headers/body/clientIp) are the honest answer.
+  const triggerData = input || {};
 
   return {
     method: triggerData.method || 'POST',

+ 5 - 2
nodes/triggers/put-trigger.js

@@ -107,8 +107,11 @@ const outputSchema = {
 async function execute(config, input, context) {
   smartbotic.log.info('PUT trigger activated');
 
-  // The trigger data comes from the webhook controller
-  const triggerData = context.triggerData || {};
+  // The runner hands the trigger node's payload to `input`, not `context` -
+  // `context` only carries executionId/nodeId/workflowId. Executed directly
+  // from the editor's Run button there is no request, so the defaults below
+  // (method PUT, empty path/query/headers/body/clientIp) are the honest answer.
+  const triggerData = input || {};
 
   return {
     method: triggerData.method || 'PUT',

+ 17 - 0
tests/nodes/get-trigger-query-passthrough.json

@@ -0,0 +1,17 @@
+{
+  "name": "get-trigger-query-passthrough",
+  "nodes": [
+    {"id": "n1", "name": "Webhook", "type": "get-trigger", "position": {"x": 0, "y": 0}, "config": {}},
+    {"id": "n2", "name": "Respond", "type": "respond-to-webhook", "position": {"x": 0, "y": 100},
+     "config": {"status": 200, "bodySource": "input", "bodyField": "data.query"}}
+  ],
+  "connections": [
+    {"sourceNodeId": "n1", "sourceOutput": "main", "targetNodeId": "n2", "targetInput": "data"}
+  ],
+  "http": {
+    "method": "GET",
+    "path": "/webhook/{workflowId}?probe=query-from-test",
+    "expectStatus": 200,
+    "expectBodyContains": ["\"probe\":\"query-from-test\""]
+  }
+}

+ 18 - 0
tests/nodes/post-trigger-body-passthrough.json

@@ -0,0 +1,18 @@
+{
+  "name": "post-trigger-body-passthrough",
+  "nodes": [
+    {"id": "n1", "name": "Webhook", "type": "post-trigger", "position": {"x": 0, "y": 0}, "config": {}},
+    {"id": "n2", "name": "Respond", "type": "respond-to-webhook", "position": {"x": 0, "y": 100},
+     "config": {"status": 200, "bodySource": "input", "bodyField": "data.body"}}
+  ],
+  "connections": [
+    {"sourceNodeId": "n1", "sourceOutput": "main", "targetNodeId": "n2", "targetInput": "data"}
+  ],
+  "http": {
+    "method": "POST",
+    "path": "/webhook/{workflowId}",
+    "body": {"greeting": "hello-from-test"},
+    "expectStatus": 200,
+    "expectBodyContains": ["\"greeting\":\"hello-from-test\""]
+  }
+}