-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix: enable workflow validation before deployment (was hardcoded to false) #3579
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
base: main
Are you sure you want to change the base?
Changes from all commits
1376793
70dd04d
30c68ae
d646ee1
945b207
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| 'use client' | ||
|
|
||
| import { memo, useCallback, useEffect, useRef, useState } from 'react' | ||
| import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react' | ||
| import { createLogger } from '@sim/logger' | ||
| import { ArrowUp, Lock, Square, Unlock } from 'lucide-react' | ||
| import { useParams, useRouter } from 'next/navigation' | ||
|
|
@@ -26,6 +26,7 @@ import { | |
| } from '@/components/emcn' | ||
| import { VariableIcon } from '@/components/icons' | ||
| import { generateWorkflowJson } from '@/lib/workflows/operations/import-export' | ||
| import { validateWorkflowState } from '@/lib/workflows/sanitization/validation' | ||
| import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider' | ||
| import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider' | ||
| import { createCommands } from '@/app/workspace/[workspaceId]/utils/commands-utils' | ||
|
|
@@ -356,7 +357,25 @@ export const Panel = memo(function Panel() { | |
| // Compute run button state | ||
| const canRun = userPermissions.canRead // Running only requires read permissions | ||
| const isLoadingPermissions = userPermissions.isLoading | ||
| const hasValidationErrors = false // TODO: Add validation logic if needed | ||
| // Memoize workflow structure to avoid re-validating on every store change | ||
| // (e.g. block dragging at 60fps, text input, etc.) | ||
| const blocks = useWorkflowStore((state) => state.blocks) | ||
| const edges = useWorkflowStore((state) => state.edges) | ||
| const loops = useWorkflowStore((state) => state.loops) | ||
| const parallels = useWorkflowStore((state) => state.parallels) | ||
|
|
||
| const hasValidationErrors = useMemo(() => { | ||
| if (Object.keys(blocks).length === 0) return false | ||
| // Pass shallow copies to validateWorkflowState to prevent any | ||
| // internal mutation from affecting Zustand store state | ||
| const result = validateWorkflowState({ | ||
| blocks: { ...blocks }, | ||
| edges: [...edges], | ||
| loops: { ...(loops || {}) }, | ||
| parallels: { ...(parallels || {}) }, | ||
| }) | ||
| return !result.valid | ||
| }, [blocks, edges, loops, parallels]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deploy button not disabled when validation errors existMedium Severity The new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keyboard shortcut bypasses validation-disabled Run buttonMedium Severity The Additional Locations (1) |
||
| const isWorkflowBlocked = isExecuting || hasValidationErrors | ||
| const isButtonDisabled = !isExecuting && (isWorkflowBlocked || (!canRun && !isLoadingPermissions)) | ||
|
|
||
|
|
||


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.
Missing
loopsandparallelsblocks valid workflow deploymentsnormalizedDataalready containsloopsandparallels(used in theGEThandler on lines 83–86 of this same file), but they are omitted from thevalidateWorkflowStatecall here. The validation function usesworkflowState.loops || {}andworkflowState.parallels || {}, so passingundefinedmeans every edge whose source or target is a loop/parallel container will be flagged as referencing a non-existent block — causing the deployment to be rejected with a 400 even for a perfectly valid workflow.