diff --git a/core/services/workflows/engine.go b/core/services/workflows/engine.go index dfc2fb347ae..8198152fb14 100644 --- a/core/services/workflows/engine.go +++ b/core/services/workflows/engine.go @@ -564,6 +564,7 @@ func NewEngine(cfg Config) (engine *Engine, err error) { // - that there are no step `ref` called `trigger` as this is reserved for any triggers // - that there are no duplicate `ref`s // - that the `ref` for any triggers is empty -- and filled in with `trigger` + // - that the resulting graph is strongly connected (i.e. no disjointed subgraphs exist) // - etc. workflow, err := Parse(cfg.Spec) diff --git a/core/services/workflows/models.go b/core/services/workflows/models.go index 3c15c1bc778..9c1c56d6054 100644 --- a/core/services/workflows/models.go +++ b/core/services/workflows/models.go @@ -1,6 +1,7 @@ package workflows import ( + "errors" "fmt" "github.com/dominikbraun/graph" @@ -182,6 +183,10 @@ func Parse(yamlWorkflow string) (*workflow, error) { } step.dependencies = refs + if stepRef != keywordTrigger && len(refs) == 0 { + return nil, errors.New("all non-trigger steps must have a dependent ref") + } + for _, r := range refs { innerErr = g.AddEdge(r, step.Ref) if innerErr != nil { diff --git a/core/services/workflows/models_test.go b/core/services/workflows/models_test.go index 93b5bf64f56..61aced2ed19 100644 --- a/core/services/workflows/models_test.go +++ b/core/services/workflows/models_test.go @@ -186,6 +186,31 @@ targets: "a-target": {}, }, }, + { + name: "non-trigger step with no dependent refs", + yaml: ` +triggers: + - type: "a-trigger" + - type: "a-second-trigger" +actions: + - type: "an-action" + ref: "an-action" + inputs: + hello: "world" +consensus: + - type: "a-consensus" + ref: "a-consensus" + inputs: + trigger_output: $(trigger.outputs) + action_output: $(an-action.outputs) +targets: + - type: "a-target" + ref: "a-target" + inputs: + consensus_output: $(a-consensus.outputs) +`, + errMsg: "all non-trigger steps must have a dependent ref", + }, } for _, tc := range testCases {