Label to workflow rules and a default workflow are the intake-routes resource: ordered, case-insensitive, first rule wins, seeded with bug to tdd, feature to feasibility, default triage. A write naming an undefined workflow or an empty label is refused. The daemon reads it through the workflow definitions client when pinning a task and at intake. The kind indirection only carried this routing, so it is removed: the per-kind NATS subjects (every consumer already bound archie.task.>) are one subject, the envelope and playbook triggers lose their kind, and x-intake-routes is dropped. The dashboard gets an Issue routing page under Automation; the trigger card reads the same setting.
53 lines
1.8 KiB
Go
53 lines
1.8 KiB
Go
package workflow
|
|
|
|
import "testing"
|
|
|
|
// Guards the label to workflow contract: a label matches without regard to
|
|
// case, the first rule in list order wins when an issue carries several
|
|
// labels, and an issue no rule matches runs the default.
|
|
func TestResolveWorkflowIDByLabel(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
routes := IntakeRoutes{
|
|
Rules: []IntakeRule{
|
|
{Label: "Security", Workflow: "audit"},
|
|
{Label: "bug", Workflow: "tdd"},
|
|
{Label: "feature", Workflow: "feasibility"},
|
|
},
|
|
Default: "triage",
|
|
}
|
|
available := map[string]struct{}{"audit": {}, "tdd": {}, "feasibility": {}, "triage": {}}
|
|
|
|
tests := []struct {
|
|
name string
|
|
labels string
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{name: "label matches without regard to case", labels: "BUG", want: "tdd"},
|
|
{name: "rule label case does not matter either", labels: "security", want: "audit"},
|
|
{name: "scoped label matches its value", labels: "kind::feature", want: "feasibility"},
|
|
{name: "first rule in list order wins over label order", labels: "feature,bug", want: "tdd"},
|
|
{name: "a rule earlier in the list beats a later one", labels: "bug,security", want: "audit"},
|
|
{name: "no match runs the default", labels: "priority::high", want: "triage"},
|
|
{name: "no labels runs the default", labels: "", want: "triage"},
|
|
{name: "a route to an undefined workflow is an error", labels: "bug", want: "", wantErr: true},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
avail := available
|
|
if tt.wantErr {
|
|
avail = map[string]struct{}{"triage": {}}
|
|
}
|
|
got, err := ResolveWorkflowID(&Task{Labels: tt.labels}, routes, avail)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Fatalf("err = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
if got != tt.want {
|
|
t.Errorf("routed to %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|