Reader is Lifecycle's read counterpart, built as its mirror image: a role in the leaf `issueops` package, reached through a capability accessor on the storage seam, implemented at the same six sites. `Storage` gains `IssueReader() (issueops.Reader, error)` beside `IssueLifecycle()`, and the governing rule holds — a new capability got a new role and a new accessor, not four more methods on an existing one. SUBSUME, NOT COMPOSE. Reader takes the whole high-level request and performs filter and default construction INTERNALLY, supplying its own ConfigSource from the store or unit of work it already holds. Under compose both front doors would each build a ConfigSource, load config, call a builder and execute — two callers again, which is the topology that shipped a bare IssueFilter to a viewer and silently served in_progress rows as "ready". Under subsume the ritual is not callable from a front door: handlers and RunE bodies can only say rd.List(ctx, req), so the failure mode is unwritable rather than merely discouraged. The three read endpoints are implemented against the frozen OpenAPI v0 document and consume the accessor; the 501 stubs and their self-deleting exemption list are gone. `bd show --json` reaches the same role through the same accessor, resolving the canonical id first so fuzzy and cross-repo lookup stay CLI-local. The workapi builders are re-typed onto the leaf request types, so there is no second params struct to drift; both recorded goldens replay byte-identical, which is the proof the re-typing changed nothing. Load-bearing details: - `sort` is forwarded EXPLICITLY as priority when absent. The storage layer reads an empty policy as hybrid, which demotes older high-priority work and therefore changes the item SET once a limit truncates — while the document still reads correctly. Pinned by a handler test on the recorded filter and by the parity oracle's order assertion. - The parity oracle compares FULL ITEM JSON, not id sets. An id-set oracle passes while ready ships a bare Issue against the CLI's IssueWithCounts. - internal/workapi no longer imports internal/storage/uow; it names the slice of a unit of work it reads through, so the uow provider can implement the role without closing an import cycle. - internal/utils' cgo store test moves to an external test package for the same reason, with its two unexported-symbol cases split out. Verified: issueops is still a leaf (internal/types + stdlib only); the protocol corpus is unchanged structurally and behaviourally under BEADS_PROTOCOL_REQUIRE_DOLT=1; a real `bd serve` answers all six operations against a real workspace with CLI and HTTP JSON identical field for field.
78 lines
3 KiB
Go
78 lines
3 KiB
Go
package workapi
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// TestBuildReadyFilterPropagatesLabelPatternAndRegex moved here from cmd/bd's
|
|
// ready_input_test.go with the builder it covers (bd-ehi).
|
|
func TestBuildReadyFilterPropagatesLabelPatternAndRegex(t *testing.T) {
|
|
filter, err := BuildReadyFilter(issueops.ReadyRequest{
|
|
LabelPattern: "tech-*",
|
|
LabelRegex: "^tech-(debt|legacy)$",
|
|
Sort: "priority",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("BuildReadyFilter() error = %v", err)
|
|
}
|
|
if got, want := filter.LabelPattern, "tech-*"; got != want {
|
|
t.Errorf("filter.LabelPattern = %q, want %q", got, want)
|
|
}
|
|
if got, want := filter.LabelRegex, "^tech-(debt|legacy)$"; got != want {
|
|
t.Errorf("filter.LabelRegex = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
// TestBuildReadyFilterNormalizes covers the normalization a frontend gets for
|
|
// free. The CLI reaches most of it pre-split by pflag, so these are the cases
|
|
// only a non-CLI caller hits.
|
|
func TestBuildReadyFilterNormalizes(t *testing.T) {
|
|
filter, err := BuildReadyFilter(issueops.ReadyRequest{
|
|
IssueType: "mr",
|
|
Labels: []string{" alpha ", "alpha", " ", "beta"},
|
|
LabelsAny: []string{"gamma", "gamma"},
|
|
ExcludeLabels: []string{" delta "},
|
|
ExcludeTypes: []string{"epic, mol", "", " "},
|
|
Sort: "priority",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("BuildReadyFilter() error = %v", err)
|
|
}
|
|
if got, want := filter.Type, "merge-request"; got != want {
|
|
t.Errorf("filter.Type = %q, want %q (alias expansion)", got, want)
|
|
}
|
|
if got, want := filter.Labels, []string{"alpha", "beta"}; !reflect.DeepEqual(got, want) {
|
|
t.Errorf("filter.Labels = %q, want %q", got, want)
|
|
}
|
|
if got, want := filter.LabelsAny, []string{"gamma"}; !reflect.DeepEqual(got, want) {
|
|
t.Errorf("filter.LabelsAny = %q, want %q", got, want)
|
|
}
|
|
if got, want := filter.ExcludeLabels, []string{"delta"}; !reflect.DeepEqual(got, want) {
|
|
t.Errorf("filter.ExcludeLabels = %q, want %q", got, want)
|
|
}
|
|
want := []types.IssueType{types.IssueType("epic"), types.IssueType("molecule")}
|
|
if !reflect.DeepEqual(filter.ExcludeTypes, want) {
|
|
t.Errorf("filter.ExcludeTypes = %v, want %v", filter.ExcludeTypes, want)
|
|
}
|
|
}
|
|
|
|
// TestBuildReadyFilterRejectsSortPolicy pins the message cmd/bd used to print
|
|
// itself: `bd ready --sort bogus` renders this error verbatim behind "Error: ".
|
|
func TestBuildReadyFilterRejectsSortPolicy(t *testing.T) {
|
|
_, err := BuildReadyFilter(issueops.ReadyRequest{Sort: "bogus"})
|
|
if err == nil {
|
|
t.Fatal("BuildReadyFilter unexpectedly accepted an invalid sort policy")
|
|
}
|
|
if got, want := err.Error(), "invalid sort policy 'bogus'. Valid values: hybrid, priority, oldest"; got != want {
|
|
t.Errorf("error = %q, want %q", got, want)
|
|
}
|
|
// An unset policy is the library default, not a usage error: storage
|
|
// resolves it the same way it resolves "priority".
|
|
if _, err := BuildReadyFilter(issueops.ReadyRequest{}); err != nil {
|
|
t.Errorf("BuildReadyFilter with no sort policy: %v", err)
|
|
}
|
|
}
|