* feat(list): bd list --no-assignee, --title and --id over http behind per-parameter tokens (S15b) Over http `bd list --no-assignee`, `--title` and `--id` refused: the list encoder had no listIssues parameter for ListRequest.NoAssignee, TitleSearch or IDFilter (B3 #11). All three are maintainer-city cutover blockers: gc's default on_boot hook runs `bd list --no-assignee --status=in_progress ...` on every agent boot, the PR-intake formula lists by `--title "$SUBJECT"`, and the pr-review skill by `--id <ids>`. The library entry is unchanged: issueops.Reader.List, whose bodies already apply all three through workapi.BuildListFilter, the same entry the local route reads through. - Server: GET /v0/beads/issues decodes `no_assignee`, `title` and `id` into those ListRequest members (`id` handed over as written; the role splits, trims and de-duplicates, as countIssues already does). Each is behind its own new behavior token, issues.list.noAssignee, issues.list.title and issues.list.id (additive, wire_revision stays 2): each is a separate caller's dependency, and a refusal names exactly the one it needed. The spec parameters cite their tokens; apigen and the wire-shape golden are regenerated. - Client: the encoder maps the three members to their parameters, and httpReader.List refuses a request carrying one BEFORE dialing, with ErrUnsupported{Capability: <token>}, unless the handshake advertises that token (refuseUnservedSearch generalised to one table, tokenedListFilters, with bd search's `q`). Never a round trip an older server answers unknown_parameter, never a wider listing. - ErrHTTPUnsupported's text names the capability when it has one, as the portable sentinel does, so `bd list` says which token the server lacks. - The three E-ListRequest ledger rows retire; the ledger is re-rendered. The id scope unparks the served Reader contract: the sixteen cases parked on E-ListRequest.IDFilter now run against the in-process server. Twelve pass as written; four still park, each now on the member it actually needs (Offset twice, PinnedFlag, ExcludeTypes). The served refusal sweep asserts SpecPrefix where it asserted IDFilter. Tests (failing first): handler test that each parameter reaches the storage filter; client tests that each member rides its parameter behind its token and refuses pre-dial, zero dials, naming its token, against a server lacking it; round-trip and vocabulary gates; capability lists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(backend/http): the four maintainer-city list shapes end to end; corpus marks relabelled SRV-1 (S15b) TestE2E_ListScopeFiltersOverHTTP runs the corpus shapes gc-list-on-boot, gc-list-on-boot-workflow, mc-list-title and mc-list-id through the real bd against the in-process server (which advertises the three new tokens) and requires each to answer an embedded workspace's rows and exactly the rows it names: --no-assignee leaves out an assigned in-progress row on the same lane, --title is case-insensitive, --id lists a closed id under --all. Against the MC production server's handshake shape each shape exits non-zero naming its token and never dials listIssues. The corpus suite masks the served side to reference_server.json, the deployed bd 1.3.0 surface, which advertises none of the tokens, so the four shapes now get the named pre-dial refusal there. Their marks move from S6c+S15b to SRV-1 with that reason, like mc-search. With a scratch profile that adds the three tokens and parameters (not committed) exactly these four shapes report "now passes; remove the pending mark" and nothing else changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(list): adopt bd-enterprise's listIssues `id` contract: repeatable, issues.list.ids (S15b) bd-enterprise already publishes listIssues `id` (E9-S2): a REPEATABLE parameter, one id per value, behind `issues.list.ids`, with its client sending IDFilter split into one value per member. The first cut of S15b took ONE comma-separated `id` behind `issues.list.id`, so the same parameter name had two incompatible meanings: an OSS client's "a,b" is a 400 on an enterprise server, and the enterprise rebase onto main would collide. OSS now publishes enterprise's contract unchanged: - Server: listIDFilter (ported verbatim) decodes the repeated `id` into ListRequest.IDFilter's comma set; more than 200 values, an empty value, a comma, leading or trailing whitespace, a control character or an over-long id is a 400 `invalid_argument` on `id`. The spec parameter is enterprise's (array, maxItems 200); apigen and the wireshape golden are regenerated. - Token: CapListIDs = "issues.list.ids", the enterprise spelling and name on both sides. - Client: the encoder splits the set the way the role does (splitIDSet) and sends one `id` per member; the pre-dial gate fires only when the set names an id. - Tests: list_ids_test.go is enterprise's id cases (the exact set reaches storage, the 200 bound is served, every refusal beside its control, the spec bound matches the constant); the handler, client, round-trip and e2e cases move to the repeated shape and the new token. `no_assignee` and `title` are unchanged. Served tier, http e2e (including TestE2E_ListScopeFiltersOverHTTP) and corpus_served_test pass; with a scratch reference profile advertising the three tokens exactly the four S15b shapes report "now passes". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
196 lines
8.2 KiB
Go
196 lines
8.2 KiB
Go
// Contributed by gascity from bd-enterprise (internal/enterprise/httpstore/role_reader.go@49d1df2f6)
|
|
// to OSS beads under the MIT license.
|
|
package httpclient
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/steveyegge/beads/internal/httpapi/apigen"
|
|
"github.com/steveyegge/beads/internal/httpclient/encode"
|
|
"github.com/steveyegge/beads/internal/httpclient/wire"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// httpReader is issueops.Reader over the v0 wire (design D8 row 1): Ready is
|
|
// listReadyWork, List is listIssues, Get is getIssue.
|
|
//
|
|
// It builds no filter and applies no default. Both request types are handed to
|
|
// the encoder whole, and the SERVER runs the same two workapi builders a local
|
|
// command would — against its own authoritative vocabulary, which is what heals
|
|
// L7's degraded client-side status/type set for every query that goes through
|
|
// here. What stays on this side is the part the wire genuinely cannot carry:
|
|
// the display order, the caller-supplied keyset position and the MaxRows cap,
|
|
// all three of them ledgered client-side in the encoder table and all three
|
|
// implemented in list_walk.go.
|
|
type httpReader struct{ store *Store }
|
|
|
|
// Ready serves listReadyWork.
|
|
//
|
|
// One request, no paging: the operation publishes no cursor, so `limit` and the
|
|
// server's own has_more ARE the page contract. An Offset is refused by the
|
|
// encoder rather than dropped — ready work carries no keyset position, so there
|
|
// is no honest way to page it (E-ReadyRequest.Offset).
|
|
//
|
|
// An explicit Limit of 0 (unlimited) is NOT sent as `limit=0`: it becomes one
|
|
// request bounded at the client cap plus one, refused past the cap rather than
|
|
// truncated (unlimited_read.go).
|
|
func (r httpReader) Ready(ctx context.Context, req issueops.ReadyRequest) (issueops.IssuePage, error) {
|
|
params, err := encode.ReadyParams(req)
|
|
if err != nil {
|
|
return issueops.IssuePage{}, r.store.inexpressible("Reader.Ready", err)
|
|
}
|
|
readCap, err := boundUnlimitedPage(params, req.Limit != nil && *req.Limit == 0)
|
|
if err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
var body apigen.ReadyPage
|
|
if err := r.store.dispatch(ctx, wire.Request{
|
|
Op: wire.OpListReadyWork,
|
|
Method: http.MethodGet,
|
|
Path: wire.PathReady,
|
|
Query: params,
|
|
}, &body); err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
if err := checkUnlimitedPage(wire.OpListReadyWork, readCap, len(body.Items), body.HasMore); err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
return issueops.IssuePage{Items: wireRows(body.Items, req.Brief), HasMore: body.HasMore}, nil
|
|
}
|
|
|
|
// List serves listIssues, through the pager in list_walk.go.
|
|
func (r httpReader) List(ctx context.Context, req issueops.ListRequest) (issueops.IssuePage, error) {
|
|
if err := r.refuseUnservedListFilters(ctx, req); err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
params, err := encode.ListParams(req)
|
|
if err != nil {
|
|
return issueops.IssuePage{}, r.store.inexpressible("Reader.List", err)
|
|
}
|
|
return r.store.walkIssues(ctx, params, req)
|
|
}
|
|
|
|
// tokenedListFilters are the ListRequest members listIssues carries only on a
|
|
// server advertising a behavior token of their own, each with that token:
|
|
// `bd search`'s text (S26) and `bd list --title`, `--id` and `--no-assignee`
|
|
// (S15b). Order decides which token a request carrying several names; each
|
|
// refusal is complete on its own, so any order is honest.
|
|
var tokenedListFilters = []struct {
|
|
token string
|
|
set func(issueops.ListRequest) bool
|
|
}{
|
|
{wire.CapListSearch, func(r issueops.ListRequest) bool { return r.Query != "" }},
|
|
{wire.CapListNoAssignee, func(r issueops.ListRequest) bool { return r.NoAssignee }},
|
|
{wire.CapListTitle, func(r issueops.ListRequest) bool { return r.TitleSearch != "" }},
|
|
// An id set naming no id (only commas and blanks) sends no `id`, so it
|
|
// needs no token.
|
|
{wire.CapListIDs, func(r issueops.ListRequest) bool {
|
|
return strings.TrimSpace(strings.ReplaceAll(r.IDFilter, ",", "")) != ""
|
|
}},
|
|
}
|
|
|
|
// refuseUnservedListFilters is the pre-dial gate for the tokened members. An
|
|
// older server answers each one's parameter with 400 unknown_parameter, so a
|
|
// request carrying one against a server that does not advertise its token is
|
|
// refused HERE, with the typed capability error naming that token: never a
|
|
// round trip that is refused anyway, and never a wider listing (the
|
|
// unsearched one, every in-progress bead instead of the unassigned ones, the
|
|
// whole workspace instead of an id set) passed off as the answer.
|
|
//
|
|
// listIssues is a baseline operation, so dispatch preflights nothing for it;
|
|
// this is the one handshake a tokened request costs, and a request without
|
|
// any of these members never asks for it.
|
|
func (r httpReader) refuseUnservedListFilters(ctx context.Context, req issueops.ListRequest) error {
|
|
var snap *apigen.ContextResponse
|
|
for _, f := range tokenedListFilters {
|
|
if !f.set(req) {
|
|
continue
|
|
}
|
|
if snap == nil {
|
|
var err error
|
|
if snap, err = r.store.snapshot(ctx); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if snap == nil || !slices.Contains(snap.Capabilities, f.token) {
|
|
return r.store.unsupportedCapability("Reader.List", f.token)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Get serves getIssue, including the two landed include parameters that retired
|
|
// ledger row L4.
|
|
//
|
|
// A 404 arrives as the `not_found` problem code, which the wire's problem
|
|
// mapper has already turned into issueops.ErrNotFound — the same sentinel a
|
|
// local miss answers with — so the role's "a miss is ErrNotFound, a backend
|
|
// failure passes through unchanged" promise holds without a single decision
|
|
// here. The nil detail view on any error is the other half of it.
|
|
func (r httpReader) Get(ctx context.Context, req issueops.GetRequest) (*issueops.IssueDetails, error) {
|
|
id, params := encode.GetTarget(req)
|
|
path, err := wire.IssuePath(id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var details types.IssueDetails
|
|
if err := r.store.dispatch(ctx, wire.Request{
|
|
Op: wire.OpGetIssue,
|
|
Method: http.MethodGet,
|
|
Path: path,
|
|
Query: params,
|
|
IssueID: id,
|
|
}, &details); err != nil {
|
|
return nil, err
|
|
}
|
|
// Issue.RowVersion is json:"-"; the wire's only spelling of the token is
|
|
// Revision (the decimal string getIssue publishes), so a bare decode
|
|
// leaves RowVersion at its zero value on every read — a guarded write
|
|
// built off this result would carry a token the row never held, same as
|
|
// bd-enterprise's (*Store).GetIssue bridge below and the write
|
|
// responses parseRevision already stitches this way.
|
|
version, err := parseRevision("getIssue", details.Revision)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
details.Issue.RowVersion = version
|
|
return &details, nil
|
|
}
|
|
|
|
// wireRows lifts a wire page onto the pointer slice the role's page carries,
|
|
// and stamps the projection marker the wire cannot carry.
|
|
//
|
|
// The element type is an ALIAS of types.IssueWithCounts — the same struct the
|
|
// server projects onto and the same one `bd list --json` marshals — so this
|
|
// takes an address and copies nothing under the header. The result is never
|
|
// nil: an empty page is an empty slice on every surface, and a caller must not
|
|
// have to tell null from empty to learn that nothing matched.
|
|
//
|
|
// brief IS A PARAMETER RATHER THAN A FIELD ON ANYTHING, so every page decode on
|
|
// this client has to answer the question. types.Issue.IsLitePartial is
|
|
// `json:"-"` — it never crosses — and a `brief` page therefore arrives
|
|
// byte-identical to a page of genuinely textless rows. The only thing that can
|
|
// tell them apart is having ASKED, which is what issueops.ListRequest.Brief's
|
|
// own leaf says a wire consumer distinguishes them by, and this client is the
|
|
// consumer that asked. A call site that could forget it would be a page whose
|
|
// rows lie about being whole; making it an argument means the compiler asks.
|
|
//
|
|
// IT IS NEVER STAMPED ON A HYDRATED READ. The marker means "the heavy columns
|
|
// were not selected", so setting it on a full page would send a caller to
|
|
// refetch a body it already has — the same defect as the missing stamp, pointed
|
|
// the other way.
|
|
func wireRows(items []apigen.IssueWithCounts, brief bool) []*types.IssueWithCounts {
|
|
out := make([]*types.IssueWithCounts, 0, len(items))
|
|
for i := range items {
|
|
row := &items[i]
|
|
if brief && row.Issue != nil {
|
|
row.IsLitePartial = true
|
|
}
|
|
out = append(out, row)
|
|
}
|
|
return out
|
|
}
|