From 012964b60e014bce31afa183dd5f106d52cf2834 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 19 Sep 2026 00:17:44 +1000 Subject: [PATCH] fix(workintake): match namespaced forge labels when routing by kind labelKinds is keyed on bare strings, and this repo namespaces its labels (type::feature, priority::medium), so KindsForLabels matched nothing and every issue fell through kind routing to Route's triage fallback. Kind routing has therefore never fired here: issue 813, a type::feature that defaultKindWorkflows binds to feasibility, reached implement instead. Labels now resolve to the value after the last '::'. The namespace is not checked: bug/feature/bootstrap is specific enough that a label ending in one means that kind whatever the tracker files it under. Closes archie-core-tjoc --- internal/domain/workflow/routing_test.go | 27 +++++++++++++++++++++ internal/domain/workintake/subjects.go | 22 ++++++++++++++++- internal/domain/workintake/subjects_test.go | 7 ++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/internal/domain/workflow/routing_test.go b/internal/domain/workflow/routing_test.go index f40a30755..ad1d203ec 100644 --- a/internal/domain/workflow/routing_test.go +++ b/internal/domain/workflow/routing_test.go @@ -51,6 +51,33 @@ func TestRouteLabelMatchStillWinsOverTriage(t *testing.T) { } } +// Forges namespace labels by convention, and a repo that does so was routing +// every issue through triage because no label ever matched a kind. Kind +// routing is the free, reliable signal Route's triage fallback assumes is +// already spent, so it has to survive the namespace. +func TestRouteMatchesNamespacedLabels(t *testing.T) { + reg := Registry{"tdd": TDD(), "feasibility": Feasibility(), "triage": Triage(), "implement": Implement()} + + tests := []struct { + name string + labels string + want string + }{ + {name: "namespaced feature", labels: "type::feature", want: "feasibility"}, + {name: "namespaced bug", labels: "type::bug", want: "tdd"}, + {name: "real issue label set", labels: "status::in_progress,priority::medium,type::feature", want: "feasibility"}, + {name: "bare labels still route", labels: "bug", want: "tdd"}, + {name: "no kind label still triages", labels: "priority::medium", want: "triage"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if wf := Route(&Task{Labels: tt.labels}, reg); wf.Name != tt.want { + t.Fatalf("Route(%q) = %q, want %q", tt.labels, wf.Name, tt.want) + } + }) + } +} + // TestLoadKindWorkflowsYAMLOverridesDefaultBinding is the first slice of // docs/prds/eda-playbook-engine.md: which workflow a Kind prefers becomes // data, not a Go literal. A YAML file rebinding "bug" to "feasibility" diff --git a/internal/domain/workintake/subjects.go b/internal/domain/workintake/subjects.go index ef0b6ba3b..8d99f3e30 100644 --- a/internal/domain/workintake/subjects.go +++ b/internal/domain/workintake/subjects.go @@ -95,9 +95,29 @@ func KindForLabels(labels []string) Kind { func KindsForLabels(labels []string) []Kind { var kinds []Kind for _, label := range labels { - if kind, ok := labelKinds[strings.TrimSpace(label)]; ok { + if kind, ok := labelKinds[labelValue(label)]; ok { kinds = append(kinds, kind) } } return kinds } + +// labelValue reduces a forge label to the value labelKinds is keyed on. +// +// Forges namespace labels by convention ("type::feature", "priority::medium") +// and the namespace is the issue tracker's own taxonomy, not part of the +// routing vocabulary, so the value after the last "::" is what identifies a +// kind. Matching the bare string alone meant a repo that namespaces its +// labels -- which this one does -- never matched any kind, and every task +// fell through kind routing to the content-aware fallback in Route. +// +// The namespace itself is deliberately not checked: a closed three-value +// vocabulary (bug, feature, bootstrap) is specific enough that a label ending +// in one of them means that kind whatever the tracker files it under. +func labelValue(label string) string { + trimmed := strings.TrimSpace(label) + if i := strings.LastIndex(trimmed, "::"); i >= 0 { + return strings.TrimSpace(trimmed[i+len("::"):]) + } + return trimmed +} diff --git a/internal/domain/workintake/subjects_test.go b/internal/domain/workintake/subjects_test.go index 211de1750..1a8486c19 100644 --- a/internal/domain/workintake/subjects_test.go +++ b/internal/domain/workintake/subjects_test.go @@ -69,6 +69,11 @@ func TestKindForLabels(t *testing.T) { {name: "first recognised wins", labels: []string{"feature", "bug"}, want: KindFeature}, {name: "unrecognised then recognised", labels: []string{"wontfix", "bootstrap"}, want: KindBootstrap}, {name: "trims whitespace", labels: []string{" bug "}, want: KindBug}, + {name: "namespaced label", labels: []string{"type::feature"}, want: KindFeature}, + {name: "namespaced, other namespaces ignored", labels: []string{"status::in_progress", "priority::medium", "type::feature"}, want: KindFeature}, + {name: "namespaced and trimmed", labels: []string{" type::bug "}, want: KindBug}, + {name: "namespace alone is not a kind", labels: []string{"type::"}, want: KindDefault}, + {name: "nested namespaces use the last segment", labels: []string{"meta::type::bug"}, want: KindBug}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -90,6 +95,8 @@ func TestKindsForLabels(t *testing.T) { {name: "single", labels: []string{"bug"}, want: []Kind{KindBug}}, {name: "preserves order", labels: []string{"bug", "feature"}, want: []Kind{KindBug, KindFeature}}, {name: "skips unrecognised", labels: []string{"wontfix", "bug", "triage", "feature"}, want: []Kind{KindBug, KindFeature}}, + {name: "namespaced labels", labels: []string{"type::bug", "type::feature"}, want: []Kind{KindBug, KindFeature}}, + {name: "mixed bare and namespaced", labels: []string{"status::open", "bug", "type::feature"}, want: []Kind{KindBug, KindFeature}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {