Files
archie/internal/domain/workflow/routing_test.go
T
sam b147a288ae feat(workflow): dynamic triage instead of defaulting every task to implement
Route() had no content-aware fallback: any task with no explicit
workflow and no label match ran the full "implement" pipeline
regardless of content. Confirmed in production (task 6): a
chat-spawned task whose entire content was "this is just a test,
close it when you receive it" burned 669,421 tokens finding that out
the expensive way -- baseline, plan, and build all ran before the
plan stage's own conclusion (nothing needed to change) arrived too
late to save anything.

Adds a "triage" workflow: one cheap, read-only classification turn
(mirrors feasibility.go's decide-tool pattern) that either closes a
task needing no code change immediately, or sets Task.Workflow and
requeues under whichever workflow fits. Route()'s fallback now
prefers a registered "triage" over "implement", unchanged when
triage isn't registered. Labeled tasks are untouched -- a label is
already a free, reliable signal, so triage never fires there.

See docs/prds/dynamic-workflow-triage.md for the full design.
2026-09-02 21:40:06 +10:00

50 lines
1.8 KiB
Go

package workflow
import (
"testing"
"github.com/samcharles93/archie-core/internal/store"
)
func TestRouteDoesNotSilentlyReplaceAnAdmittedWorkflow(t *testing.T) {
task := &store.Task{Workflow: "skill-review"}
wf := Route(task, Registry{"implement": Implement()})
if wf.Name != "none" || len(wf.Stages) != 1 || wf.Stages[0].Name != "fail" {
t.Fatalf("Route() = %#v, want explicit failure workflow", wf)
}
}
// TestRoutePrefersTriageOverImplementWhenNoLabelMatches is the regression
// case for archie-core-enfj: an unlabeled task (the common shape for a
// chat-spawned task) with no explicit workflow must reach triage, not the
// heaviest workflow, when triage is registered.
func TestRoutePrefersTriageOverImplementWhenNoLabelMatches(t *testing.T) {
task := &store.Task{}
wf := Route(task, Registry{"implement": Implement(), "triage": Triage()})
if wf.Name != "triage" {
t.Fatalf("Route() = %q, want %q", wf.Name, "triage")
}
}
// TestRouteFallsBackToImplementWhenTriageIsNotRegistered pins backward
// compatibility: a registry without a "triage" entry must behave exactly
// as it did before triage existed.
func TestRouteFallsBackToImplementWhenTriageIsNotRegistered(t *testing.T) {
task := &store.Task{}
wf := Route(task, Registry{"implement": Implement()})
if wf.Name != "implement" {
t.Fatalf("Route() = %q, want %q", wf.Name, "implement")
}
}
// TestRouteLabelMatchStillWinsOverTriage confirms labels remain the
// preferred, free signal: a labeled task never pays for a triage
// classification call even when triage is registered.
func TestRouteLabelMatchStillWinsOverTriage(t *testing.T) {
task := &store.Task{Labels: "bug"}
wf := Route(task, Registry{"tdd": TDD(), "triage": Triage(), "implement": Implement()})
if wf.Name != "tdd" {
t.Fatalf("Route() = %q, want %q", wf.Name, "tdd")
}
}