* fix(show): --current through issueops.FindCurrentIssue over the Querier role; no swallowed refusal (S6e)
Over http `bd show --current` printed the WRONG issue, exit 0.
resolveCurrentIssueID asked the raw SearchIssues method for the actor's
in_progress and then hooked work; the http backend refuses that method, the
refusal was taken for "nothing found", and the command fell back to the
last-touched issue. The proxied route had its own copy of the lookup, read
inside its unit of work, with the same swallow.
One library entry now: issueops.FindCurrentIssue(ctx, Querier, actor). It
asks the Querier role (queryIssues over http, which every deployed server
publishes) for `status=<s> AND assignee="<actor>"`, limit 1 — exactly the
raw filter, answered in the store's default order, so the same row comes
first on every backend — in_progress, then hooked. A failed read is an
error; "" (two reads that answered and found nothing) is the only miss. The
actor is a quoted, escaped query value; the query language reads
`assignee=none`/`null` as "unassigned", so such an actor (or an empty one)
is not asked about.
Both CLI routes call it with their route's Querier (store.Querier() or the
proxied provider's) through one cmd/bd helper; what stays in the CLI is the
actor and the last-touched fallback (a workspace file). The proxied route
resolves --current before it opens its unit of work, and its duplicate
in-transaction lookup is deleted.
Tests: issueops unit tests (order, failure is an error on either read,
quoting, unaskable actors, each expression evaluates to exactly the raw
filter); cmd/bd fallback tests; served e2e TestE2E_ShowCurrentOverHTTP
(in-progress beats a later-touched issue, hooked when nothing is in
progress, last-touched only when neither). Against the old code the e2e
fails with exactly the reported bug.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(recompute-blocked): one library entry, storage.RecomputeBlocked; a no-op on a remote backend (S25)
`bd recompute-blocked` refused over http ("storage backend does not support
is_blocked recompute"), and gc's BdStore.RecomputeBlocked issues it.
is_blocked is server-derived. Every write a remote client makes is committed
by the server's own store, which keeps the flag under
issueops.BlockedStateInvariant's local-write clause (targeted, inside the
write's transaction; a Postgres-family server has no full recompute at all
and runs a no-op readiness strategy for the same reason). A client cannot
leave the flag stale and holds no copy of it. The invariant's merge clause
(a recompute skipped after a pull, bd-6dnrw.37; a migration that over-set
it, beads#7037) happens to the SERVER's database, and its repair is this
command in the server's workspace.
So the decision is in the library, not the CLI: storage.RecomputeBlocked
(internal/storage/blocked_recomputer.go) is the one entry every backend goes
through. A local store (storage.BlockedRecomputer) recomputes its column; a
store implementing storage.ServerMaintainedBlockedState — the http client,
whose BlockedStateMaintainedByServer answers true — recomputes nothing and
reports MaintainedBy "server". No wire operation: a whole-column rewrite any
bearer of a workspace credential could trigger, for state no client can have
caused, is not one to publish. The proxied route keeps its pinned-connection
plumbing around the same versioncontrolops body the stores run.
--json keeps rows_corrected (gc requires the member; wh-bridge-sync reads the
exit code) as 0 and adds maintained_by: "server"; the text says where the
repair runs.
Tests: storage unit tests (local repair runs, server-maintained wins even
over a local repair and runs none, neither refuses); served e2e
TestE2E_RecomputeBlockedOverHTTP (exit 0, JSON shape, text, ready set
unchanged). With the server-maintained branch disabled the e2e fails with
the old refusal.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(search): every bd search route through Reader.List with issueops.SearchListRequest; listIssues `q` behind issues.list.search (S26)
`bd search` called the raw SearchIssues method with its text, which the http
backend refuses ("partial-id search is not available over HTTP"), and its
direct and proxied routes each mapped the flags onto a storage filter by
hand. No served operation could carry search's meaning (title OR id contains
the text, case-insensitively; an id-shaped text also matches exact id, id
prefix and external ref): TitleSearch is title-only and the query language
has no title-or-id predicate.
The library entry is issueops.Reader.List:
- issueops.ListRequest gains Query, SearchIssues' free-text argument as a
member. Both Reader bodies (workapi/storereader and the uow reader) pass it
to SearchIssuesWithCounts where they passed "". It narrows and lifts no
default exclusion; the ready arm refuses it (readyScopeFields).
- issueops.SearchListRequest(query) is search's scope as a request: Query,
every status (AllFlag), every kind of row (the four Include*), and the
store's default order (SortBy priority), so --limit keeps the rows a raw
read kept.
- CLI: ONE runSearch for the direct, proxied and remote routes. One builder
(searchListRequest) maps the flags onto SearchListRequest; the route only
picks the reader (store.IssueReader() or the proxied provider's).
--sort/--reverse reorder the page as before. search_proxied_server.go and
its hand-built filter are deleted, and search leaves the forbidigo
filter-writing exemption.
- Server: GET /v0/beads/issues decodes `q` into ListRequest.Query and calls
the same Reader role, behind the new issues.list.search behavior token
(spec parameter cites it; additive, no wire_revision bump; apigen and the
wire-shape digest regenerated).
- Client: the encoder maps Query to `q`; httpReader.List refuses a request
carrying Query BEFORE dialing, with ErrUnsupported{Capability:
issues.list.search}, unless the handshake advertises it — never a round
trip an old server would 400, never the unsearched listing passed off as
the search. CapListSearch mirrors the server token. Flags listIssues
publishes nothing for are put on the request so the encoder refuses them
rather than widening the search.
Tests: Reader contract case RunReaderListQueryMatchesTheTitleOrTheID (also
pins SearchListRequest's scope) on all four legs — dolt, embedded dolt, uow,
served http (label-scoped, so the served leg runs it as written); handler
test that `q` reaches the seam as the search text, not TitleSearch; client
tests for `q` and the pre-dial refusal (zero dials); round-trip and
vocabulary gates; TestSearchRoutesAgree runs the same twelve flag sets on
the direct, proxied and remote routes and requires identical answers
(remote is bd serve over the proxied database, so ids and order too); served
e2e TestE2E_SearchOverHTTP. The remote legs skip with the
SearchIssuesWithCounts refusal until S6c's externaldeps reader passthrough is
underneath (loud refusal, never an empty or wrong answer); with S6c
cherry-picked all three routes agree.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* build: resync BUILD srcs and the embedded storage shard manifest for S6e/S25/S26
gazelle picks up cmd/bd/show_current.go, cmd/bd/search_remote.go, the three
backend/http e2e files and internal/httpclient/list_search_test.go; the
embedded storage shard manifest gains
TestEmbeddedReaderListQueryMatchesTheTitleOrTheID
(scripts/ci/gen_embedded_storage_shard_manifest.py 15 --weights=duration
--write).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* style: gofmt list_show_filter_modes.go (trailing blank line)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(backend/http/corpus): drop the show --current and recompute-blocked marks S6e and S25 retire
With S26 folded in, `bd show --current` resolves through
issueops.FindCurrentIssue over the Querier role and `bd recompute-blocked`
goes through storage.RecomputeBlocked (a no-op on a remote backend), so
gc-show-current and gc-recompute-blocked lose their pending marks.
mc-search stays pending, relabelled S6c+SRV-1: bd search now asks listIssues
with q behind issues.list.search, which the reference server profile does
not advertise, so the client refuses before dialing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(cmd/bd): split the bd search route agreement into the embedded and proxied lanes
TestSearchRoutesAgree skipped unless BEADS_TEST_EMBEDDED_DOLT=1, then ran
its proxied and remote legs only under BEADS_TEST_PROXIED_SERVER=1, and
its name matched neither lane's discovery (TestEmbedded* in
*_embedded_test.go, TestProxiedServer*/TestServerMode*). No CI lane ran
it, which main's #7468 guard (TestProxiedGatedTestsRunInTheProxiedLane)
now fails on.
Split it:
- TestEmbeddedSearchRoutesAgree (search_routes_embedded_test.go): the
direct route, embedded lane.
- TestProxiedServerSearchRoutesAgree (search_routes_proxied_test.go): the
proxied route and the remote route (bd serve over the proxied
workspace), gated only on BEADS_TEST_PROXIED_SERVER. The remote route
must still answer the proxied one row for row, ids and order included,
and refuse the flag listIssues cannot carry.
Neither lane can run the other's workspace, so the shared helper
(search_routes_parity_test.go: the seed, the twelve flag sets, and
checkSearchRoute) holds every route to one expected answer per flag set;
agreeing with it is agreeing with each other. The remote leg's "needs
S6c" skip is gone: S6c is on main, so a refusal now fails.
Both manifests regenerated incrementally (embedded 100-shard block, shard
71; proxied 34-shard block, shard 23). Bazel: bd_embedded_part2_test
(--config=embedded) and bd_proxied_test (--config=doltserver-proxied)
pass and run the new tests; //scripts:go_test_sources_test passes.
Swapping the title-sort expectation fails both routes of the proxied
test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(search): keep an infra type's durable rows, expand --type aliases, fail the S26 e2e on refusal (bd-1ejjv6)
Review fixes for #7528, attempt 1: the three majors and three minors of
the synthesis.
`bd search --type <infra type>` dropped the type's durable rows (a
promoted wisp, an issue retyped after it was created), exit 0. The shared
listing (workapi.BuildListFilter) narrowed an infra --type to its
ephemeral rows unconditionally, so SearchListRequest's IncludeEphemeral
did not bring back what raw SearchIssues used to return. The narrowing
now applies only without IncludeEphemeral, in BuildListFilter and in the
count lockstep (applyCountIncludeInfra), and the http parent-walk
recognizer reads an infra type's Ephemeral back as the include_ephemeral
intent. This also fixes `bd list --type <infra type> --include-ephemeral`
and GET /v0/beads/issues, which shipped the narrowing in v1.3.1. Pinned by
workapi tests and by template, gate, wisp and promoted-message rows in the
Reader conformance Query case (new ReaderFixture.PromoteWisp) on the
dolt, embedded, uow and served backends; the issueops Reader/Counter docs
and the openapi descriptions say the same.
`bd search --type` handed the raw string to the Reader: an alias (feat,
mol, mr, ...) answered nothing and an unknown type an empty result. It is
now expanded with utils.NormalizeIssueType as `bd list` does, and an
unknown type exits 1. The help text and the CHANGELOG say so, and the
CHANGELOG also records the additive comments_omitted field in
`bd search --json` rows.
TestE2E_SearchOverHTTP skipped on the very SearchIssuesWithCounts refusal
it exists to catch; it now fails. The route agreement seeds "kinded"
template, gate, wisp and promoted-message rows and pins the alias, the
unknown-type refusal and the infra rows on the direct, proxied and remote
routes.
Minors: the CHANGELOG states the proxied `bd show --current` miss
fallback; the CommentsOmitted contract names `bd search --json`; the
storage.RecomputeBlocked and `bd recompute-blocked` comments name the
deliberate --proxied-server bypass.
Validation: go vet and gofmt on every changed package; make api-check;
workapi, issueops, httpclient/encode, types and storage unit tests; the
Reader conformance on dolt, embedded, uow and served; the embedded and
proxied route agreements (remote included), the embedded search tests,
TestProxiedServerSearch, TestProxiedServerRecomputeBlocked, the http e2e
search/show/recompute tests; docs flag, freshness and docsync checks; and
a hand-run bd search/list/count against a scratch workspace.
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
469 lines
20 KiB
Go
469 lines
20 KiB
Go
package workapi
|
|
|
|
import (
|
|
"errors"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// TestBuildCountFilterIncludeInfraMirrorsListFilter pins `bd count
|
|
// --include-infra` to the exact cardinality semantics of `bd list
|
|
// --include-infra --all` (GH#4387): for any filter set, the count must equal
|
|
// the number of rows the equivalent list invocation returns. The trap
|
|
// dimensions are the wisps merge (SkipWisps), template exclusion (IsTemplate),
|
|
// the default gate exclusion (ExcludeTypes), and infra-type routing to the
|
|
// ephemeral tier (Ephemeral).
|
|
//
|
|
// Each type runs twice, the second time with --include-ephemeral on both
|
|
// sides. That flag lifts the infra-type routing on the list side (an
|
|
// infra-typed row can live in the durable table too, and the flag promises
|
|
// the durable answer plus the plane), so a count that kept routing would read
|
|
// only the wisp tier while the listing it mirrors reads both: the `message`
|
|
// arm is the one that fails if the two builders stop moving in lockstep.
|
|
func TestBuildCountFilterIncludeInfraMirrorsListFilter(t *testing.T) {
|
|
cfg := ListConfig{}
|
|
for _, includeEphemeral := range []bool{false, true} {
|
|
for _, issueType := range []string{"", "task", "gate", "message"} {
|
|
name := issueType
|
|
if name == "" {
|
|
name = "none"
|
|
}
|
|
if includeEphemeral {
|
|
name += "_include_ephemeral"
|
|
}
|
|
t.Run("type_"+name, func(t *testing.T) {
|
|
assertCountMirrorsListIncludeInfra(t, cfg, issueType, includeEphemeral)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
// assertCountMirrorsListIncludeInfra compares one `bd count --include-infra`
|
|
// filter against the `bd list --include-infra --all` filter it mirrors.
|
|
func assertCountMirrorsListIncludeInfra(t *testing.T, cfg ListConfig, issueType string, includeEphemeral bool) {
|
|
t.Helper()
|
|
want, err := BuildListFilter(issueops.ListRequest{
|
|
AllFlag: true, IncludeInfra: true, IssueType: issueType, IncludeEphemeral: includeEphemeral,
|
|
}, cfg)
|
|
if err != nil {
|
|
t.Fatalf("BuildListFilter(%q): %v", issueType, err)
|
|
}
|
|
got, err := BuildCountFilter(issueops.CountRequest{
|
|
IncludeInfra: true, IssueType: issueType, IncludeEphemeral: includeEphemeral,
|
|
}, cfg)
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter(%q): %v", issueType, err)
|
|
}
|
|
|
|
if got.SkipWisps != want.SkipWisps {
|
|
t.Errorf("SkipWisps = %v, list --include-infra --all uses %v", got.SkipWisps, want.SkipWisps)
|
|
}
|
|
if !reflect.DeepEqual(got.IsTemplate, want.IsTemplate) {
|
|
t.Errorf("IsTemplate = %v, list --include-infra --all uses %v", countPtrStr(got.IsTemplate), countPtrStr(want.IsTemplate))
|
|
}
|
|
if !reflect.DeepEqual(got.ExcludeTypes, want.ExcludeTypes) {
|
|
t.Errorf("ExcludeTypes = %v, list --include-infra --all uses %v", got.ExcludeTypes, want.ExcludeTypes)
|
|
}
|
|
if !reflect.DeepEqual(got.Ephemeral, want.Ephemeral) {
|
|
t.Errorf("Ephemeral = %v, list --include-infra --all uses %v", countPtrStr(got.Ephemeral), countPtrStr(want.Ephemeral))
|
|
}
|
|
if !reflect.DeepEqual(got.IssueType, want.IssueType) {
|
|
t.Errorf("IssueType = %v, list --include-infra --all uses %v", got.IssueType, want.IssueType)
|
|
}
|
|
// A count defaults to all statuses and all pinned states, which is
|
|
// exactly what list's --all flag selects.
|
|
if !reflect.DeepEqual(got.Status, want.Status) {
|
|
t.Errorf("Status = %v, list --include-infra --all uses %v", got.Status, want.Status)
|
|
}
|
|
if !reflect.DeepEqual(got.Statuses, want.Statuses) {
|
|
t.Errorf("Statuses = %v, list --include-infra --all uses %v", got.Statuses, want.Statuses)
|
|
}
|
|
if !reflect.DeepEqual(got.ExcludeStatus, want.ExcludeStatus) {
|
|
t.Errorf("ExcludeStatus = %v, list --include-infra --all uses %v", got.ExcludeStatus, want.ExcludeStatus)
|
|
}
|
|
if !reflect.DeepEqual(got.Pinned, want.Pinned) {
|
|
t.Errorf("Pinned = %v, list --include-infra --all uses %v", countPtrStr(got.Pinned), countPtrStr(want.Pinned))
|
|
}
|
|
}
|
|
|
|
// TestBuildCountFilterHonorsTheWorkspaceInfraSet verifies that the infra-type
|
|
// routing honors a store-configured infra set, exactly like bd list does.
|
|
func TestBuildCountFilterHonorsTheWorkspaceInfraSet(t *testing.T) {
|
|
cfg := ListConfig{InfraSet: map[string]bool{"robot": true}}
|
|
|
|
robot, err := BuildCountFilter(issueops.CountRequest{IncludeInfra: true, IssueType: "robot"}, cfg)
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter(robot): %v", err)
|
|
}
|
|
if robot.Ephemeral == nil || !*robot.Ephemeral {
|
|
t.Errorf("custom infra type %q must route to the ephemeral tier (Ephemeral=true), got %v", "robot", countPtrStr(robot.Ephemeral))
|
|
}
|
|
|
|
// "message" is a default infra type but NOT part of the custom set, so it
|
|
// must not route to the ephemeral tier (mirrors ListConfig.IsInfra).
|
|
msg, err := BuildCountFilter(issueops.CountRequest{IncludeInfra: true, IssueType: "message"}, cfg)
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter(message): %v", err)
|
|
}
|
|
if msg.Ephemeral != nil {
|
|
t.Errorf("non-infra type under custom set must keep Ephemeral=nil, got %v", countPtrStr(msg.Ephemeral))
|
|
}
|
|
}
|
|
|
|
// TestBuildCountFilterDefaultsToTheDurablePlane pins the no-flag path, which
|
|
// is the answer every scripted `bd count` has always read: durable rows only
|
|
// (SkipWisps), and none of the listing's template, gate, status or pinned
|
|
// exclusions.
|
|
func TestBuildCountFilterDefaultsToTheDurablePlane(t *testing.T) {
|
|
got, err := BuildCountFilter(issueops.CountRequest{}, ListConfig{})
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter: %v", err)
|
|
}
|
|
if !got.SkipWisps {
|
|
t.Error("SkipWisps = false without IncludeInfra, want the durable plane only")
|
|
}
|
|
if got.IsTemplate != nil {
|
|
t.Errorf("IsTemplate = %v without IncludeInfra, want no template predicate: a count includes templates", countPtrStr(got.IsTemplate))
|
|
}
|
|
if len(got.ExcludeTypes) != 0 {
|
|
t.Errorf("ExcludeTypes = %v without IncludeInfra, want none: a count excludes no type by default", got.ExcludeTypes)
|
|
}
|
|
if got.Ephemeral != nil {
|
|
t.Errorf("Ephemeral = %v without IncludeInfra, want nil", countPtrStr(got.Ephemeral))
|
|
}
|
|
if got.Status != nil || len(got.ExcludeStatus) != 0 || got.Pinned != nil {
|
|
t.Errorf("a bare count filter carries status/pinned predicates (Status=%v ExcludeStatus=%v Pinned=%v): a count answers for closed and pinned rows too",
|
|
countPtrStr(got.Status), got.ExcludeStatus, countPtrStr(got.Pinned))
|
|
}
|
|
// Limit and Offset are the two fields the count seam ignores, and
|
|
// issueops.CountRequest has no knob for either: pinning them at zero says
|
|
// the builder does not invent one.
|
|
if got.Limit != 0 || got.Offset != 0 {
|
|
t.Errorf("Limit=%d Offset=%d, want a count filter to bound nothing", got.Limit, got.Offset)
|
|
}
|
|
}
|
|
|
|
// TestBuildCountFilterNormalizesLabelsAndIDs pins the normalization
|
|
// issueops.CountRequest promises happens INSIDE: entries are trimmed and
|
|
// de-duplicated, an all-blank slice is the same as an unset one, and the
|
|
// caller's own slices come back untouched.
|
|
func TestBuildCountFilterNormalizesLabelsAndIDs(t *testing.T) {
|
|
labels := []string{" alpha ", "alpha", "", "beta"}
|
|
labelsAny := []string{" ", ""}
|
|
snapshot := append([]string(nil), labels...)
|
|
|
|
got, err := BuildCountFilter(issueops.CountRequest{
|
|
Labels: labels,
|
|
LabelsAny: labelsAny,
|
|
IDFilter: " bd-1 , bd-2 ,, bd-1 ",
|
|
}, ListConfig{})
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter: %v", err)
|
|
}
|
|
if want := []string{"alpha", "beta"}; !reflect.DeepEqual(got.Labels, want) {
|
|
t.Errorf("Labels = %v, want %v", got.Labels, want)
|
|
}
|
|
if got.LabelsAny != nil {
|
|
t.Errorf("LabelsAny = %v, want nil: a slice of blanks is the same as an unset one", got.LabelsAny)
|
|
}
|
|
if want := []string{"bd-1", "bd-2"}; !reflect.DeepEqual(got.IDs, want) {
|
|
t.Errorf("IDs = %v, want %v", got.IDs, want)
|
|
}
|
|
if !reflect.DeepEqual(labels, snapshot) {
|
|
t.Errorf("the caller's Labels became %v, want them left as %v", labels, snapshot)
|
|
}
|
|
}
|
|
|
|
// TestBuildCountFilterMapsParentAndNoParent pins ParentID/NoParent's mapping
|
|
// into types.IssueFilter, mirroring BuildListFilter's ParentID/NoParent
|
|
// mapping (internal/workapi/list.go) field for field.
|
|
func TestBuildCountFilterMapsParentAndNoParent(t *testing.T) {
|
|
got, err := BuildCountFilter(issueops.CountRequest{ParentID: "bd-1"}, ListConfig{})
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter: %v", err)
|
|
}
|
|
if got.ParentID == nil || *got.ParentID != "bd-1" {
|
|
t.Errorf("ParentID = %v, want \"bd-1\"", countPtrStr(got.ParentID))
|
|
}
|
|
if got.NoParent {
|
|
t.Errorf("NoParent = true, want false: request did not set it")
|
|
}
|
|
|
|
got, err = BuildCountFilter(issueops.CountRequest{NoParent: true}, ListConfig{})
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter: %v", err)
|
|
}
|
|
if got.ParentID != nil {
|
|
t.Errorf("ParentID = %v, want nil: request did not set it", countPtrStr(got.ParentID))
|
|
}
|
|
if !got.NoParent {
|
|
t.Error("NoParent = false, want true")
|
|
}
|
|
}
|
|
|
|
// TestBuildCountFilterExcludeTypesSplitsAndNormalizes pins ExcludeTypes'
|
|
// mapping: comma-separated entries split, trim and normalize exactly as
|
|
// BuildListFilter's ExcludeTypes does, and the result APPENDS to (rather than
|
|
// replaces) whatever applyCountIncludeInfra later contributes.
|
|
func TestBuildCountFilterExcludeTypesSplitsAndNormalizes(t *testing.T) {
|
|
got, err := BuildCountFilter(issueops.CountRequest{
|
|
// "feat" is an alias (-> "feature", internal/utils/strings.go);
|
|
// "bug" is not, so it passes through unchanged.
|
|
ExcludeTypes: []string{" bug , feat", "", "chore"},
|
|
}, ListConfig{})
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter: %v", err)
|
|
}
|
|
want := []types.IssueType{"bug", "feature", "chore"}
|
|
if !reflect.DeepEqual(got.ExcludeTypes, want) {
|
|
t.Errorf("ExcludeTypes = %v, want %v", got.ExcludeTypes, want)
|
|
}
|
|
|
|
// Composes with IncludeInfra's own "gate" exclusion rather than
|
|
// discarding it.
|
|
got, err = BuildCountFilter(issueops.CountRequest{
|
|
ExcludeTypes: []string{"chore"},
|
|
IncludeInfra: true,
|
|
}, ListConfig{})
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter: %v", err)
|
|
}
|
|
want = []types.IssueType{"chore", "gate"}
|
|
if !reflect.DeepEqual(got.ExcludeTypes, want) {
|
|
t.Errorf("ExcludeTypes = %v, want %v (explicit exclusions composed with IncludeInfra's)", got.ExcludeTypes, want)
|
|
}
|
|
}
|
|
|
|
// TestBuildCountFilterParentFieldsMatchListFilter extends the GH#4387
|
|
// count/list cardinality-parity pin to the three new Count fields that DO
|
|
// have a List counterpart: ParentID, NoParent and ExcludeTypes must produce
|
|
// the identical types.IssueFilter contribution BuildListFilter does for the
|
|
// same request, since a filter contract test (backend/conformance) can only
|
|
// show the two AGREE on one backend's rows — this shows WHY, at the one place
|
|
// both builders share.
|
|
func TestBuildCountFilterParentFieldsMatchListFilter(t *testing.T) {
|
|
cfg := ListConfig{}
|
|
|
|
countGot, err := BuildCountFilter(issueops.CountRequest{ParentID: "bd-1"}, cfg)
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter: %v", err)
|
|
}
|
|
listGot, err := BuildListFilter(issueops.ListRequest{ParentID: "bd-1", AllFlag: true}, cfg)
|
|
if err != nil {
|
|
t.Fatalf("BuildListFilter: %v", err)
|
|
}
|
|
if !reflect.DeepEqual(countGot.ParentID, listGot.ParentID) {
|
|
t.Errorf("Count ParentID = %v, List ParentID = %v, want equal", countPtrStr(countGot.ParentID), countPtrStr(listGot.ParentID))
|
|
}
|
|
|
|
countGot, err = BuildCountFilter(issueops.CountRequest{NoParent: true}, cfg)
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter: %v", err)
|
|
}
|
|
listGot, err = BuildListFilter(issueops.ListRequest{NoParent: true, AllFlag: true}, cfg)
|
|
if err != nil {
|
|
t.Fatalf("BuildListFilter: %v", err)
|
|
}
|
|
if countGot.NoParent != listGot.NoParent {
|
|
t.Errorf("Count NoParent = %v, List NoParent = %v, want equal", countGot.NoParent, listGot.NoParent)
|
|
}
|
|
|
|
countGot, err = BuildCountFilter(issueops.CountRequest{ExcludeTypes: []string{"wisp,feat"}}, cfg)
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter: %v", err)
|
|
}
|
|
// IncludeAllTypes on the list side skips applyTypeSuppressions' OWN
|
|
// exclusions (template/gate/infra defaults), isolating the one thing this
|
|
// case compares: the explicit --exclude-type mapping.
|
|
listGot, err = BuildListFilter(issueops.ListRequest{ExcludeTypes: []string{"wisp,feat"}, AllFlag: true, IncludeAllTypes: true}, cfg)
|
|
if err != nil {
|
|
t.Fatalf("BuildListFilter: %v", err)
|
|
}
|
|
if !reflect.DeepEqual(countGot.ExcludeTypes, listGot.ExcludeTypes) {
|
|
t.Errorf("Count ExcludeTypes = %v, List ExcludeTypes = %v, want equal", countGot.ExcludeTypes, listGot.ExcludeTypes)
|
|
}
|
|
}
|
|
|
|
// TestBuildCountFilterExcludeStatusTakesNamesAsWritten pins ExcludeStatus: a
|
|
// Count-only field with no List counterpart (ListRequest computes its default
|
|
// exclusions internally and exposes no caller-facing knob for them). Entries
|
|
// split and trim like ExcludeTypes. UNLIKE Status and ExcludeTypes, each name
|
|
// IS validated against the workspace vocabulary (review S8 follow-up #3): a
|
|
// built-in name passes as written, and an unrecognized one is ErrValidation
|
|
// rather than silently excluding nothing.
|
|
func TestBuildCountFilterExcludeStatusTakesNamesAsWritten(t *testing.T) {
|
|
got, err := BuildCountFilter(issueops.CountRequest{
|
|
ExcludeStatus: []string{" closed , pinned", ""},
|
|
}, ListConfig{})
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter: %v", err)
|
|
}
|
|
want := []types.Status{"closed", "pinned"}
|
|
if !reflect.DeepEqual(got.ExcludeStatus, want) {
|
|
t.Errorf("ExcludeStatus = %v, want %v", got.ExcludeStatus, want)
|
|
}
|
|
}
|
|
|
|
// TestBuildCountFilterExcludeStatusRejectsAnUnknownName pins the ErrValidation
|
|
// refusal (review S8 follow-up #3): a typo'd status name in --exclude-status
|
|
// must fail loudly rather than silently excluding nothing and overcounting.
|
|
func TestBuildCountFilterExcludeStatusRejectsAnUnknownName(t *testing.T) {
|
|
_, err := BuildCountFilter(issueops.CountRequest{
|
|
ExcludeStatus: []string{"no-such-status"},
|
|
}, ListConfig{})
|
|
if err == nil {
|
|
t.Fatal("BuildCountFilter accepted an unknown exclude-status name, want ErrValidation")
|
|
}
|
|
if !errors.Is(err, issueops.ErrValidation) {
|
|
t.Errorf("err = %v, want errors.Is(err, issueops.ErrValidation)", err)
|
|
}
|
|
}
|
|
|
|
// TestBuildCountFilterExcludeStatusAllowsAWorkspaceCustomStatus pins the other
|
|
// half of #3: a workspace-defined custom status is NOT a typo and must be
|
|
// accepted, following ApplyStatusFilter's own IsValidWithCustom precedent in
|
|
// list.go.
|
|
func TestBuildCountFilterExcludeStatusAllowsAWorkspaceCustomStatus(t *testing.T) {
|
|
cfg := ListConfig{CustomStatuses: []types.CustomStatus{{Name: "triaged"}}}
|
|
got, err := BuildCountFilter(issueops.CountRequest{
|
|
ExcludeStatus: []string{"triaged"},
|
|
}, cfg)
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter rejected the workspace's own custom status: %v", err)
|
|
}
|
|
want := []types.Status{"triaged"}
|
|
if !reflect.DeepEqual(got.ExcludeStatus, want) {
|
|
t.Errorf("ExcludeStatus = %v, want %v", got.ExcludeStatus, want)
|
|
}
|
|
}
|
|
|
|
// TestBuildCountFilterRefusesParentAndNoParentTogether pins review S8
|
|
// follow-up #1: the role refuses the combination as ErrValidation, with the
|
|
// same wording `bd list`'s CLI already uses for the same combination
|
|
// (cmd/bd/list_input.go), so a caller reaching this role from any front door
|
|
// gets the identical refusal.
|
|
func TestBuildCountFilterRefusesParentAndNoParentTogether(t *testing.T) {
|
|
_, err := BuildCountFilter(issueops.CountRequest{ParentID: "bd-1", NoParent: true}, ListConfig{})
|
|
if err == nil {
|
|
t.Fatal("BuildCountFilter accepted --parent with --no-parent, want ErrValidation")
|
|
}
|
|
if !errors.Is(err, issueops.ErrValidation) {
|
|
t.Errorf("err = %v, want errors.Is(err, issueops.ErrValidation)", err)
|
|
}
|
|
const want = "--parent and --no-parent are mutually exclusive"
|
|
if err.Error() != want {
|
|
t.Errorf("err = %q, want %q", err.Error(), want)
|
|
}
|
|
}
|
|
|
|
// TestBuildCountFilterStatusAllIsNotValidation pins DESIGN's requirement that
|
|
// Status "all" have well-defined semantics: it is the no-filter spelling
|
|
// (same as empty), NOT ErrValidation, because BuildListFilter's own "all"
|
|
// selector means the same thing and a count must stay able to answer the
|
|
// cardinality of `bd list --status all --all` for the shared predicate
|
|
// (GH#4387 count/list parity).
|
|
func TestBuildCountFilterStatusAllIsNotValidation(t *testing.T) {
|
|
got, err := BuildCountFilter(issueops.CountRequest{Status: "all"}, ListConfig{})
|
|
if err != nil {
|
|
t.Fatalf(`BuildCountFilter(status="all") returned an error, want nil: %v`, err)
|
|
}
|
|
if got.Status != nil {
|
|
t.Errorf(`status "all" produced Status = %v, want no status predicate`, countPtrStr(got.Status))
|
|
}
|
|
}
|
|
|
|
func TestBuildCountFilterCarriesMetadataFields(t *testing.T) {
|
|
fields := map[string]string{"team": "platform", "env": "prod"}
|
|
got, err := BuildCountFilter(issueops.CountRequest{MetadataFields: fields}, ListConfig{})
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter: %v", err)
|
|
}
|
|
if !reflect.DeepEqual(got.MetadataFields, fields) {
|
|
t.Errorf("MetadataFields = %#v, want %#v", got.MetadataFields, fields)
|
|
}
|
|
|
|
if _, err := BuildCountFilter(issueops.CountRequest{MetadataFields: map[string]string{"bad$key": "value"}}, ListConfig{}); err == nil {
|
|
t.Fatal("BuildCountFilter accepted an invalid metadata key")
|
|
}
|
|
}
|
|
|
|
func TestBuildCountFilterCarriesHasMetadataKey(t *testing.T) {
|
|
got, err := BuildCountFilter(issueops.CountRequest{HasMetadataKey: "audit_ref"}, ListConfig{})
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter: %v", err)
|
|
}
|
|
if got.HasMetadataKey != "audit_ref" {
|
|
t.Errorf("HasMetadataKey = %q, want %q", got.HasMetadataKey, "audit_ref")
|
|
}
|
|
|
|
if _, err := BuildCountFilter(issueops.CountRequest{HasMetadataKey: "1bad"}, ListConfig{}); err == nil {
|
|
t.Fatal("BuildCountFilter accepted an invalid has-metadata key")
|
|
}
|
|
}
|
|
|
|
// TestBuildCountFilterTakesStatusAndTypeAsWritten pins the deliberate absence
|
|
// of validation: an unrecognized status or type reaches the filter as written
|
|
// and matches nothing, rather than failing. A scripted caller counting a
|
|
// retired status reads 0.
|
|
func TestBuildCountFilterTakesStatusAndTypeAsWritten(t *testing.T) {
|
|
got, err := BuildCountFilter(issueops.CountRequest{Status: "no-such-status", IssueType: "no-such-type"}, ListConfig{})
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter with unknown vocabulary: %v, want the filter as written", err)
|
|
}
|
|
if got.Status == nil || *got.Status != types.Status("no-such-status") {
|
|
t.Errorf("Status = %v, want the literal the caller wrote", countPtrStr(got.Status))
|
|
}
|
|
if got.IssueType == nil || *got.IssueType != types.IssueType("no-such-type") {
|
|
t.Errorf("IssueType = %v, want the literal the caller wrote", countPtrStr(got.IssueType))
|
|
}
|
|
|
|
// "all" and the empty string are the two spellings of "every status".
|
|
for _, status := range []string{"", "all"} {
|
|
filter, err := BuildCountFilter(issueops.CountRequest{Status: status}, ListConfig{})
|
|
if err != nil {
|
|
t.Fatalf("BuildCountFilter(status=%q): %v", status, err)
|
|
}
|
|
if filter.Status != nil {
|
|
t.Errorf("status %q produced Status = %v, want no status predicate", status, countPtrStr(filter.Status))
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestValidateCountGroupClosesTheDimensionSet pins the five published
|
|
// dimensions and the typed refusal for everything else. The refusal has to be
|
|
// ErrValidation rather than a bare string because both front doors classify it,
|
|
// and because an empty GroupBy reaching storage comes back as an "unsupported
|
|
// groupBy" that no caller can match on.
|
|
func TestValidateCountGroupClosesTheDimensionSet(t *testing.T) {
|
|
for group, want := range map[issueops.CountGroup]string{
|
|
issueops.CountGroupStatus: "status",
|
|
issueops.CountGroupPriority: "priority",
|
|
issueops.CountGroupType: "type",
|
|
issueops.CountGroupAssignee: "assignee",
|
|
issueops.CountGroupLabel: "label",
|
|
} {
|
|
got, err := ValidateCountGroup(group)
|
|
if err != nil {
|
|
t.Errorf("ValidateCountGroup(%q): %v", group, err)
|
|
continue
|
|
}
|
|
if got != want {
|
|
t.Errorf("ValidateCountGroup(%q) = %q, want %q", group, got, want)
|
|
}
|
|
}
|
|
for _, group := range []issueops.CountGroup{"", "Status", "owner", "label "} {
|
|
if _, err := ValidateCountGroup(group); !errors.Is(err, issueops.ErrValidation) {
|
|
t.Errorf("ValidateCountGroup(%q) error = %v, want ErrValidation", group, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func countPtrStr[T any](p *T) string {
|
|
if p == nil {
|
|
return "<nil>"
|
|
}
|
|
return "&" + reflect.ValueOf(*p).String()
|
|
}
|