Skip to content
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

[KS-136] Disallow non-trigger steps with no dependents #12742

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/services/workflows/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions core/services/workflows/models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package workflows

import (
"errors"
"fmt"

"github.com/dominikbraun/graph"
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions core/services/workflows/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
bolekk marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand Down
Loading