Second half of the extraction. cmd/bd/list_filter.go is gone; the direct path (list.go), the proxied path (list_proxied_server.go), and the four other consumers the file had grown (search, search_proxied_server, count, count_proxied_server, graph_apply) call workapi.BuildListFilter / LoadStoreListConfig / LoadUOWListConfig / ApplyStatusFilter / ValidStatusList instead. listInput now embeds workapi.ListParams rather than copying into it. A 50-field flags -> params mapping would be a silent-swap hazard the compiler cannot see; embedding makes cmd/bd fill the shared struct directly, so there is one definition of a list query and nothing to keep in sync. The CLI-only fields (output format, pager, tree/deps rendering, effectiveLimit, --repo) stay in listInput, which is why ListParams is a subset and not the whole thing. applyStatusFilter and validStatusList are exported rather than kept unexported as the design sketch had them: search.go, search_proxied_server.go and graph_apply.go already called them, and leaving them behind in cmd/bd would have forked the status-parsing rules. The --limit flag now registers workapi.DefaultListLimit. internal/config's list.limit viper default keeps its own literal 50 - internal/config cannot import workapi, because workapi imports internal/config for GetCustomTypesFromYAML. Boundary enforcement lands with the package, per the design: a workapi-frontend-boundary depguard rule denying cobra and net/http under internal/workapi, and a pr-policy.sh grep for the symbol-level half depguard cannot express (config.GetDirectoryLabels, os.Getenv). Both were verified to fail on a deliberate violation and then reverted. Gates: protocol corpus unchanged (whole cmd/bd/protocol package green with BEADS_PROTOCOL_REQUIRE_DOLT=1, no testdata diff); TestBuildListFilterGolden 35/35 against the filters recorded from the old builder; TestEmbeddedList 52 subtests and TestProxiedServerList 65 subtests green; count, search and graph-apply suites green; golangci-lint clean on cmd/bd and internal/workapi apart from the two pre-existing main.go gosec baselines. Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of CI Bot
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package workapi
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
func TestApplyStatusFilter(t *testing.T) {
|
|
t.Run("single built-in trims spaces", func(t *testing.T) {
|
|
var filter types.IssueFilter
|
|
if err := ApplyStatusFilter(&filter, " open ", nil); err != nil {
|
|
t.Fatalf("ApplyStatusFilter: %v", err)
|
|
}
|
|
if filter.Status == nil || *filter.Status != types.StatusOpen {
|
|
t.Fatalf("Status = %v, want %q", filter.Status, types.StatusOpen)
|
|
}
|
|
})
|
|
|
|
t.Run("multiple statuses use OR filter", func(t *testing.T) {
|
|
var filter types.IssueFilter
|
|
if err := ApplyStatusFilter(&filter, "open, closed", nil); err != nil {
|
|
t.Fatalf("ApplyStatusFilter: %v", err)
|
|
}
|
|
want := []types.Status{types.StatusOpen, types.StatusClosed}
|
|
if !reflect.DeepEqual(filter.Statuses, want) {
|
|
t.Fatalf("Statuses = %v, want %v", filter.Statuses, want)
|
|
}
|
|
})
|
|
|
|
t.Run("configured custom status", func(t *testing.T) {
|
|
var filter types.IssueFilter
|
|
if err := ApplyStatusFilter(&filter, "in_review", []string{"in_review"}); err != nil {
|
|
t.Fatalf("ApplyStatusFilter: %v", err)
|
|
}
|
|
if filter.Status == nil || *filter.Status != types.Status("in_review") {
|
|
t.Fatalf("Status = %v, want %q", filter.Status, "in_review")
|
|
}
|
|
})
|
|
|
|
t.Run("invalid status errors", func(t *testing.T) {
|
|
var filter types.IssueFilter
|
|
err := ApplyStatusFilter(&filter, "open,not-a-status", nil)
|
|
if err == nil {
|
|
t.Fatal("ApplyStatusFilter unexpectedly succeeded")
|
|
}
|
|
if !strings.Contains(err.Error(), "invalid status") || !strings.Contains(err.Error(), "not-a-status") {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
})
|
|
}
|