beads/internal/httpclient/errors.go
Julian Knutsen e6a891b900
feat(list): bd list --no-assignee, --title and --id over http behind per-parameter tokens (S15b) (#7550)
* 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>
2026-10-14 00:18:00 +00:00

109 lines
4.6 KiB
Go

// Contributed by gascity from bd-enterprise (internal/enterprise/httpstore/errors.go@49d1df2f6)
// to OSS beads under the MIT license.
package httpclient
import (
"fmt"
"sort"
"github.com/steveyegge/beads/internal/storage"
)
// ErrHTTPUnsupported is returned by every refused method of the http store. It
// unwraps to *storage.ErrUnsupported{Op: <method>, Backend: "http"} so that
// errors.Is/errors.As classification and backend/conformance's
// RunUnsupportedContract hold unchanged, and it carries what the refusal
// taxonomy needs to say about the server that refused.
//
// The taxonomy (design D7) renders these fields at the standard error path
// rather than letting a Go method name escape to a user; the shape here is the
// one D8 ("The sentinel") specifies.
type ErrHTTPUnsupported struct {
// Unsup is the portable sentinel: Op is the method name, Backend is "http".
Unsup *storage.ErrUnsupported
// ServerURL is the target this store speaks to. Empty for a backstop
// refusal raised before a target was resolved (see errUnsupported).
ServerURL string
// BdVersion is the serving binary's release, from the cached
// ContextResponse; empty before the handshake has run (D6).
BdVersion string
// Capabilities are the tokens the server advertises, sorted. Nil before the
// handshake.
Capabilities []string
}
func (e *ErrHTTPUnsupported) Error() string {
// D8 pins this shape for a refusal that knows its server. A backstop
// refusal has no URL to name, so it falls back to the portable sentinel's
// own rendering rather than printing "bd serve at " with nothing after it.
if e.ServerURL == "" {
return e.Unsup.Error()
}
// A capability refusal names its token, as the portable sentinel does:
// "Reader.List" alone cannot tell a caller which of a listing's tokened
// filters the server lacks.
if e.Unsup.Capability != "" {
return fmt.Sprintf("operation %q not supported by the http backend (capability %q not advertised by bd serve at %s)",
e.Unsup.Op, e.Unsup.Capability, e.ServerURL)
}
return fmt.Sprintf("operation %q not supported by the http backend (bd serve at %s)",
e.Unsup.Op, e.ServerURL)
}
func (e *ErrHTTPUnsupported) Unwrap() error { return e.Unsup }
// errUnsupported is the constructor every generated stub in unsupported_gen.go
// calls. Those stubs hang off the generated empty value receiver and therefore
// cannot reach a store, so they are the backstop arm: Op and Backend only.
//
// Every HAND-WRITTEN refusal in this package goes through (*Store).unsupported
// instead, which fills in the server context D7 renders. That split is the
// reason the taxonomy's user-facing texts always have a URL: whole-command and
// flag-mode refusals are raised before RunE from the store, never from a
// promoted shell stub.
func errUnsupported(op string) error {
return &ErrHTTPUnsupported{Unsup: &storage.ErrUnsupported{Op: op, Backend: Backend}}
}
// unsupported is the store-bound refusal: the same typed sentinel, enriched
// with the target and the handshake snapshot so the D7 taxonomy can name the
// server, its version and what it does advertise.
func (s *Store) unsupported(op string) error {
e := &ErrHTTPUnsupported{Unsup: &storage.ErrUnsupported{Op: op, Backend: Backend}}
if s == nil {
return e
}
e.ServerURL = s.target.String()
if snap := s.cachedSnapshot(); snap != nil {
e.BdVersion = snap.BdVersion
e.Capabilities = append([]string(nil), snap.Capabilities...)
sort.Strings(e.Capabilities)
}
return e
}
// unsupportedCapability is unsupported's sibling for a BEHAVIOR-token refusal
// rather than a whole-operation one: the operation itself is fine (countIssues
// exists on every server this client speaks to), but one caller-supplied field
// requires a behavior the handshake snapshot does not advertise.
//
// It fills in Unsup.Capability, which (*Store).unsupported never sets — that
// one is for a method this build cannot express on this backend at all, and
// has no single token to name. errors.As(err, &unsupported) reaching
// unsupported.Capability == capability is what counter.go's pre-dial scope
// refusal promises the caller (S8's CLIENT-SKEW NOTE in
// internal/httpapi/routes.go, beside CapIssuesCountScope): refuse before
// dialing, never drop the fields and answer a wider count than asked for.
func (s *Store) unsupportedCapability(op, capability string) error {
e := &ErrHTTPUnsupported{Unsup: &storage.ErrUnsupported{Op: op, Backend: Backend, Capability: capability}}
if s == nil {
return e
}
e.ServerURL = s.target.String()
if snap := s.cachedSnapshot(); snap != nil {
e.BdVersion = snap.BdVersion
e.Capabilities = append([]string(nil), snap.Capabilities...)
sort.Strings(e.Capabilities)
}
return e
}