This document describes the testing approach and quality assurance mechanisms used in the Sim platform. It covers Vitest setup, execution engine verification, mocking patterns, and testing best practices for both backend logic and frontend state.
The Sim platform employs a multi-layered testing strategy centered around Vitest. The suite covers core workflow execution logic, block handlers, utility functions, and complex React hooks. Testing is integrated into the CI/CD pipeline to ensure that changes to the DAG executor or block registry do not introduce regressions.
The testing infrastructure is built around:
Sources: apps/sim/executor/handlers/workflow/workflow-handler.test.ts1-10 apps/sim/vitest.setup.ts1-10
The DAGExecutor and BlockExecutor are the most critical components of the system. Testing these requires verifying the flow of BlockLog and BlockState updates across a Directed Acyclic Graph (DAG).
The BlockExecutor is tested by mocking the BlockHandler interface and verifying that inputs are resolved correctly before execution and outputs are persisted afterward.
Key Verification Points:
resolver.resolveInputs correctly handles variable references apps/sim/executor/execution/block-executor.ts111-115handleBlockError captures stack traces and updates the block log with failure details apps/sim/executor/execution/block-executor.ts208-220handleStreamingExecution to ensure real-time logs are dispatched apps/sim/executor/execution/block-executor.ts145-153Sources: apps/sim/executor/execution/block-executor.ts51-135 apps/sim/executor/execution/block-executor.ts208-220
Testing complex workflows requires sophisticated mocking of the execution context and external triggers.
Webhooks are tested by simulating NextRequest objects and verifying the WebhookProcessor logic, including signature validation and fan-out behavior.
| Mock Component | Implementation Detail | File Reference |
|---|---|---|
| Request Body | parseWebhookBody handles JSON and URL-encoded forms | apps/sim/lib/webhooks/processor.ts106-156 |
| Auth Verification | verifyProviderAuth mocks HMAC and OAuth signatures | apps/sim/app/api/webhooks/trigger/[path]/route.ts:107-113 |
| Trigger Payloads | extractTriggerMockPayload provides default data for testing | apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts:9-12 |
When testing WorkflowBlockHandler, the ExecutionContext must be mocked to support nested executions (child workflows).
Sources: apps/sim/executor/handlers/workflow/workflow-handler.ts38-87 apps/sim/lib/execution/call-chain.ts2-29
Frontend testing focuses on the orchestration of workflow execution and the synchronization of the terminal console.
This hook is the primary interface for running workflows from the UI. Tests verify:
createBlockEventHandlers apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/workflow-execution-utils.ts:132-151.setIsExecuting correctly updates the ExecutionStore and consolePersistence apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts:134-145.The TerminalConsoleStore is tested for high-performance log ingestion and indexing.
indexWorkflowEntries is verified to ensure logs are correctly mapped to their respective blocks and execution IDs apps/sim/stores/terminal/console/store.ts144-160appendWorkflowEntry to ensure that duplicate or stale logs are filtered out apps/sim/stores/terminal/console/store.ts195-210Sources: apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts:104-150, apps/sim/stores/terminal/console/store.ts144-210
Sim uses Trigger.dev for background tasks like scheduled executions and webhook processing. Testing these involves:
buildWebhookCorrelation and buildScheduleCorrelation generate consistent IDs for log aggregation apps/sim/background/webhook-execution.ts32-48 apps/sim/background/schedule-execution.ts46-61webhookIdempotency.executeWithIdempotency prevents duplicate executions for the same provider event apps/sim/background/webhook-execution.ts160-164createTimeoutAbortController to ensure long-running background jobs are terminated based on workspace limits apps/sim/background/schedule-execution.ts214-225Sources: apps/sim/background/webhook-execution.ts32-164 apps/sim/background/schedule-execution.ts46-225
ExecutionContext for logging and state updates rather than direct database calls apps/sim/executor/execution/block-executor.ts182-184buildTraceSpans produces a valid tree of spans for the execution timeline apps/sim/lib/workflows/executor/execution-core.ts178-180filterOutputForLog is used to prevent sensitive data or massive blobs from entering the console apps/sim/executor/execution/block-executor.ts189-191validateCallChain is called to prevent infinite recursion apps/sim/executor/handlers/workflow/workflow-handler.ts87-93Sources: apps/sim/executor/execution/block-executor.ts182-191 apps/sim/executor/handlers/workflow/workflow-handler.ts87-93 apps/sim/lib/workflows/executor/execution-core.ts178-180
Refresh this wiki