-
Notifications
You must be signed in to change notification settings - Fork 3.1k
improvement(execution): trigger manual execution using mock payloads #1863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This PR enables manual execution of all trigger types (including external webhooks and integrations) by generating mock payloads from trigger output definitions.
Key Changes:
- Added mock payload generation system that dynamically creates test data from trigger
outputsschema usinggenerateMockPayloadFromOutputsDefinition() - Implemented multi-trigger support with path-based grouping via
selectBestTrigger()to handle workflows with multiple disjoint execution paths - Added
EXTERNAL_TRIGGERto manual execution priorities, allowing webhooks/integrations to run manually - Removed hardcoded sample payloads from 60+ trigger files - now auto-generated from outputs at runtime via
getTrigger() - Removed
filterEdgesFromTriggerBlocks()utility as trigger-to-trigger edge prevention now happens at creation time
Architecture:
The system determines if a trigger needs mock data using triggerNeedsMockPayload() (true for webhooks/integrations, false for schedules/manual triggers). For external triggers, it extracts the trigger ID from block metadata and generates structured mock data matching the trigger's output schema. The mock payload generator recursively processes nested output structures to create realistic test data.
Impact:
Significantly improves developer experience by allowing testing of webhook-triggered workflows without external events. Mock payloads maintain type consistency with actual webhook data since they're generated from the same output definitions.
Confidence Score: 4/5
- This PR is mostly safe to merge with one logical issue requiring attention
- The implementation is well-structured with comprehensive mock payload generation and multi-trigger support. However, there's a critical issue in
processOutputFieldat apps/sim/lib/workflows/trigger-utils.ts:50 that could cause infinite recursion if trigger outputs contain circular references. While unlikely in practice (since outputs are typically defined as plain objects), this should be fixed before merge. - apps/sim/lib/workflows/trigger-utils.ts requires fixing the circular reference protection in
processOutputField
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/lib/workflows/trigger-utils.ts | 4/5 | Added comprehensive mock payload generation logic from trigger outputs, plus trigger selection and grouping by execution paths |
| apps/sim/lib/workflows/triggers.ts | 5/5 | Added EXTERNAL_TRIGGER to manual execution priorities and improved block classification with registry fallback |
| apps/sim/lib/workflows/executor/execution-core.ts | 5/5 | Removed edge filtering logic since trigger-to-trigger edges are prevented at creation time |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts | 4/5 | Implemented multi-trigger support with path-based grouping, mock payload generation for external triggers, and improved error handling |
| apps/sim/triggers/index.ts | 4/5 | Auto-generates and injects samplePayload subblocks dynamically from trigger outputs definition |
Sequence Diagram
sequenceDiagram
participant User
participant UI as Workflow UI
participant Hook as useWorkflowExecution
participant Utils as TriggerUtils
participant API as /api/workflows/[id]/execute
participant Core as ExecutionCore
participant Executor
User->>UI: Click "Run Workflow" button
UI->>Hook: executeWorkflow()
Note over Hook: Resolve start candidates
Hook->>Utils: resolveStartCandidates(blocks, 'manual')
Utils-->>Hook: Array of trigger candidates
Note over Hook: Select best trigger per path
Hook->>Utils: selectBestTrigger(candidates, edges)
Utils->>Utils: groupTriggersByPath()
Utils->>Utils: selectBestFromGroup()
Utils-->>Hook: Selected trigger(s)
alt External Trigger (webhook/integration)
Hook->>Utils: triggerNeedsMockPayload(trigger)
Utils-->>Hook: true
Hook->>Utils: extractTriggerMockPayload(trigger)
Utils->>Utils: getTrigger(triggerId)
Utils->>Utils: generateMockPayloadFromOutputsDefinition()
Utils-->>Hook: Mock payload data
else Manual/API/Input Trigger
Hook->>Hook: Use test values from inputFormat
end
Hook->>API: POST with input & startBlockId
API->>Core: executeWorkflowCore()
alt No startBlockId provided
Core->>Utils: findStartBlock(blocks, executionKind)
Utils-->>Core: Resolved trigger block
end
Core->>Executor: execute(workflow, input)
Executor-->>Core: Execution result
Core-->>API: Result
API-->>Hook: Response
Hook-->>UI: Update execution state
UI-->>User: Show execution results
61 files reviewed, 1 comment
…1863) * fix(err-message): manual run message * make external triggers start workflow manually too * improvement(execution): trigger manual execution using mock payloads * remove redundant code and update generate mock value func * cleanup code, add to docs * fix multi trigger injection * address greptile comments
…1863) * fix(err-message): manual run message * make external triggers start workflow manually too * improvement(execution): trigger manual execution using mock payloads * remove redundant code and update generate mock value func * cleanup code, add to docs * fix multi trigger injection * address greptile comments
Summary
Can trigger all triggers manually. Will run with a mock payload for integration triggers.
Type of Change
Testing
Tested manually
Checklist