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
This commit is contained in:
sam committed 2026-09-19 00:17:44 +10:00
1 parent d7aa6b6ac6
commit 012964b60e
3 files changed
+55 -1

No files matched your search

+27
View File
@@ -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"
+21 -1
View File
@@ -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
}
@@ -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) {