* feat(httpapi): serve `bd list`'s order with `sort` on listIssues
The issue listing served one order, `(created_at DESC, id ASC)`, because the
cursor is a keyset position in it. The spec stated the constraint in its own
words: "the sort order is welded to the cursor contract, and a new order needs
new surface." That welding put the cost on every client wanting `bd list`'s
ordering — the only way to get it was to page the whole result set and sort
locally, which is the one cost on this surface that grows with the project.
Measured against a real `bd serve` over 1400 rows at the 200-row page an HTTP
client actually uses: walk-and-sort is 7 requests plus a client-side
comparator, `?sort=priority` is 1. Both are checked against `bd list --json`
row for row, because the claim that matters is not "fewer requests" but "the
same order".
`sort` takes `created` and `priority` and nothing else. Each value is a keyset
contract — a position shape, a strictly-after predicate, an index — not a
display preference, and both keys are provably total (priority and created_at
are non-null, id is unique) so a page boundary inside a run of equal keys
resolves on id. The seven other orders `bd list --sort` takes have no such key:
`id` is natural-numeric and no database expresses it, `updated` moves on every
write, `closed` is nullable, and status/title/type/assignee are mutable and
unindexed. `priority` here is (priority ASC, created_at DESC, id ASC), which is
both `bd list`'s flagless order and what `--sort priority` produces — a stable
priority sort over the created order is the same sequence — so one served order
retires the walk for both.
Absent `sort` still means `created`, permanently: it is the compatibility
contract for every client written before the parameter existed.
THE CURSOR NOW CARRIES ITS ORDER. This is the half that makes the parameter
safe rather than merely useful, and the obvious implementation gets it wrong.
The token was base64 of `{t,i}` with no binding, so a created-order cursor
replayed under `sort=priority` decoded perfectly and was read as a position in
a different total order — a page that skips and duplicates rows, served with a
200, undetectable by the client. Tokens are now `v2` with an explicit order
member, and decode takes the wanted order as a parameter so a mismatch is
unrepresentable at the seam rather than merely detectable past it. Outstanding
`v1` tokens stay readable as the created-order positions they are, so no
traversal in flight has to restart. This does not contradict "the token carries
no filters": filters select the set, the order decides what the position means.
Storage grows one field. IssueFilter.AfterPriority extends the existing
position; the predicate nests the created one rather than restating it, because
the created/id comparison is only reachable at the cursor's own priority.
Flattening it the way the created predicate's leading-bound trick invites looks
equivalent and is not — it re-delivers rows at the cursor's priority created
after it, which the new conformance walk catches against real Dolt.
NO INDEX MIGRATION, by measurement rather than by omission. A composite
(priority, created_at, id) index was tried on Dolt 2.2.0 against the production
predicate, in both the plain ascending and the mixed-direction spelling Dolt's
DDL accepts: the plan is byte-identical in all three cases, keeping the
single-column priority seek and the TopN. It would have bought write
amplification on every insert and every priority update for no measured change.
The sargability guard pins what is achieved — an IndexedTableAccess range on
idx_issues_priority — and records the measurement to redo if Dolt learns to
stream the composite.
Agent-Signature: claude-opus-5
Co-authored-by: CI Bot <ci@beads.test>
* fix(changelog): drop leftover diff3 conflict marker in sort entry
The rebased adopt-PR head left a stray '|||||||' merge-base marker on the first line of the new `sort` CHANGELOG entry (CHANGELOG.md:381), which `git diff --check` flagged as a leftover conflict marker. Remove only the marker line; the resolved entry content is unchanged. Maintainer fixup for PR #5666 adoption review.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: CI Bot <ci@beads.test>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
450 lines
18 KiB
Go
450 lines
18 KiB
Go
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"reflect"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// The CLI/HTTP parity oracle for the three read operations, against real Dolt
|
|
// through a real `bd serve` subprocess.
|
|
//
|
|
// IT COMPARES FULL ITEM JSON, not id sets, and that is the whole point. An
|
|
// id-set oracle passes while `ready` ships a bare Issue against the CLI's
|
|
// IssueWithCounts — the item sets agree perfectly and every field the caller
|
|
// actually reads is missing. Field-level drift is the failure mode this epic
|
|
// exists to prevent, so it is the thing the oracle has to be able to see.
|
|
//
|
|
// The comparison is on DECODED JSON, so key order and whitespace do not enter
|
|
// into it; what is compared is every key and every value of every item.
|
|
|
|
// readsParityAllowlist is the complete set of documented per-field differences
|
|
// between the two surfaces' bodies. An entry here is a permanent, reviewed
|
|
// divergence — not a place to record a surprise. Both surfaces marshal the same
|
|
// canonical Go structs (the wire schemas are x-go-type-pinned to them), so the
|
|
// field-level answer is identical and the map is EMPTY.
|
|
//
|
|
// It was not always. `revision` — the guarded-write optimistic-concurrency
|
|
// token — used to live here, because `bd show --json` projected it through a
|
|
// CLI-only wrapper while GET /v0/beads/issues/{id} serialized a raw
|
|
// IssueDetails whose RowVersion is json:"-". That entry ended with "if the
|
|
// token is ever needed over HTTP, extend that surface and delete this entry",
|
|
// and the read-token slice did exactly that: the projection moved onto
|
|
// types.IssueDetails behind types.NewIssueDetails, both front doors read it
|
|
// from the one detail seam, and the divergence stopped existing rather than
|
|
// being waived. The map stays declared, and empty, because an empty allowlist
|
|
// is a stronger statement than no allowlist: the next divergence has to be
|
|
// written down here to pass.
|
|
//
|
|
// Three further differences exist but are structural rather than per-field, so
|
|
// every comparison below states its terms explicitly instead of waving them
|
|
// through here:
|
|
//
|
|
// - `bd show --json` emits an array of one; GET /v0/beads/issues/{id} emits
|
|
// the object. The CLI envelope is byte-pinned by the protocol corpus.
|
|
// - `bd list`'s default order is priority-first; the list endpoint's DEFAULT
|
|
// is (created_at DESC, id ASC), because that is what the operation served
|
|
// before it had a `sort` parameter and the default is its compatibility
|
|
// contract. It is no longer a divergence a client has to live with:
|
|
// `sort=priority` serves `bd list`'s own order, row for row, and
|
|
// TestProxiedServerListSortRetiresTheWalk measures that against this same
|
|
// CLI over 1400 rows. The ITEM SET and every item's JSON match under
|
|
// either order.
|
|
// - THE DEFAULT LIMIT. The endpoint always defaults to
|
|
// workapi.DefaultListLimit; `bd list` resolves a five-way CLI policy
|
|
// first (an explicit --limit, --all, a configured list.limit, piped
|
|
// stdout -> unlimited per GH#4094, agent mode -> 20), so the shared
|
|
// request-level default is unreachable from the CLI. A client swapping
|
|
// `bd list --json | ...` for the HTTP call therefore loses rows past 50.
|
|
// TestListLimitPolicyIsResolvedBeforeTheRequest pins that policy branch by
|
|
// branch; every comparison here passes an EXPLICIT limit on both sides so
|
|
// it is comparing the operation and not that policy.
|
|
var readsParityAllowlist = map[string]string{}
|
|
|
|
// getJSONArray fetches a page endpoint and returns its decoded items.
|
|
func (sp *serveProcess) items(t *testing.T, path string) []map[string]any {
|
|
t.Helper()
|
|
resp, err := sp.client.Get(sp.url(path))
|
|
if err != nil {
|
|
t.Fatalf("GET %s: %v\nstderr:\n%s", path, err, sp.stderr.String())
|
|
}
|
|
defer func() { _ = resp.Body.Close() }()
|
|
raw, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
t.Fatalf("read %s: %v", path, err)
|
|
}
|
|
if resp.StatusCode != http.StatusOK {
|
|
t.Fatalf("GET %s: status = %d, body = %s\nstderr:\n%s", path, resp.StatusCode, raw, sp.stderr.String())
|
|
}
|
|
var page struct {
|
|
Items []map[string]any `json:"items"`
|
|
HasMore bool `json:"has_more"`
|
|
NextCursor *string `json:"next_cursor"`
|
|
}
|
|
if err := json.Unmarshal(raw, &page); err != nil {
|
|
t.Fatalf("decode %s: %v\nraw: %s", path, err, raw)
|
|
}
|
|
if page.Items == nil {
|
|
t.Errorf("GET %s returned a null `items`; the document promises an empty array", path)
|
|
}
|
|
return page.Items
|
|
}
|
|
|
|
// object fetches a single-object endpoint.
|
|
func (sp *serveProcess) object(t *testing.T, path string) (int, map[string]any) {
|
|
t.Helper()
|
|
resp, err := sp.client.Get(sp.url(path))
|
|
if err != nil {
|
|
t.Fatalf("GET %s: %v\nstderr:\n%s", path, err, sp.stderr.String())
|
|
}
|
|
defer func() { _ = resp.Body.Close() }()
|
|
raw, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
t.Fatalf("read %s: %v", path, err)
|
|
}
|
|
var body map[string]any
|
|
if len(raw) > 0 {
|
|
if err := json.Unmarshal(raw, &body); err != nil {
|
|
t.Fatalf("decode %s: %v\nraw: %s", path, err, raw)
|
|
}
|
|
}
|
|
return resp.StatusCode, body
|
|
}
|
|
|
|
// cliItems runs a `bd ... --json` array-emitting command and decodes it.
|
|
func cliItems(t *testing.T, bd, dir string, args ...string) []map[string]any {
|
|
t.Helper()
|
|
stdout, stderr, err := bdProxiedRunBuffers(t, bd, dir, args...)
|
|
if err != nil {
|
|
t.Fatalf("bd %s: %v\nstdout:\n%s\nstderr:\n%s", strings.Join(args, " "), err, stdout, stderr)
|
|
}
|
|
start := strings.Index(stdout, "[")
|
|
if start < 0 {
|
|
t.Fatalf("no JSON array in `bd %s` output:\n%s", strings.Join(args, " "), stdout)
|
|
}
|
|
var items []map[string]any
|
|
if err := json.Unmarshal([]byte(stdout[start:]), &items); err != nil {
|
|
t.Fatalf("decode `bd %s` output: %v\nraw: %s", strings.Join(args, " "), err, stdout[start:])
|
|
}
|
|
return items
|
|
}
|
|
|
|
func itemIDs(items []map[string]any) []string {
|
|
out := make([]string, 0, len(items))
|
|
for _, item := range items {
|
|
id, _ := item["id"].(string)
|
|
out = append(out, id)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func byID(t *testing.T, label string, items []map[string]any) map[string]map[string]any {
|
|
t.Helper()
|
|
out := make(map[string]map[string]any, len(items))
|
|
for _, item := range items {
|
|
id, _ := item["id"].(string)
|
|
if id == "" {
|
|
t.Fatalf("%s: item with no id: %v", label, item)
|
|
}
|
|
out[id] = item
|
|
}
|
|
return out
|
|
}
|
|
|
|
// assertItemsMatch is the oracle proper: same ids, and for each id, the same
|
|
// JSON object field by field.
|
|
func assertItemsMatch(t *testing.T, what string, cli, http []map[string]any) {
|
|
t.Helper()
|
|
|
|
cliByID := byID(t, "cli", cli)
|
|
httpByID := byID(t, "http", http)
|
|
|
|
cliIDs := sortedIDs(cliByID)
|
|
httpIDs := sortedIDs(httpByID)
|
|
if !reflect.DeepEqual(cliIDs, httpIDs) {
|
|
t.Fatalf("%s: item sets differ\n cli: %v\nhttp: %v", what, cliIDs, httpIDs)
|
|
}
|
|
if len(cliIDs) == 0 {
|
|
t.Fatalf("%s: both surfaces returned nothing, so this oracle proved nothing", what)
|
|
}
|
|
|
|
for _, id := range cliIDs {
|
|
a, b := cliByID[id], httpByID[id]
|
|
for _, key := range unionKeys(a, b) {
|
|
if why, allowed := readsParityAllowlist[key]; allowed {
|
|
t.Logf("%s: %s: field %q excused: %s", what, id, key, why)
|
|
continue
|
|
}
|
|
av, ok := a[key]
|
|
if !ok {
|
|
t.Errorf("%s: %s: field %q present over HTTP (%v) and absent from `bd --json`", what, id, key, b[key])
|
|
continue
|
|
}
|
|
bv, ok := b[key]
|
|
if !ok {
|
|
t.Errorf("%s: %s: field %q present in `bd --json` (%v) and absent over HTTP", what, id, key, av)
|
|
continue
|
|
}
|
|
if !reflect.DeepEqual(av, bv) {
|
|
t.Errorf("%s: %s: field %q differs\n cli: %#v\nhttp: %#v", what, id, key, av, bv)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func sortedIDs(m map[string]map[string]any) []string {
|
|
out := make([]string, 0, len(m))
|
|
for id := range m {
|
|
out = append(out, id)
|
|
}
|
|
sort.Strings(out)
|
|
return out
|
|
}
|
|
|
|
func unionKeys(a, b map[string]any) []string {
|
|
seen := map[string]bool{}
|
|
for k := range a {
|
|
seen[k] = true
|
|
}
|
|
for k := range b {
|
|
seen[k] = true
|
|
}
|
|
out := make([]string, 0, len(seen))
|
|
for k := range seen {
|
|
out = append(out, k)
|
|
}
|
|
sort.Strings(out)
|
|
return out
|
|
}
|
|
|
|
// TestProxiedServerServeReadParity is the property this epic claims, made
|
|
// checkable: over the same fixture data, `bd ready --json`, `bd list --json`
|
|
// and `bd show --json` and their three endpoints answer with the same items and
|
|
// the same JSON for each item — because both front doors go through
|
|
// issueops.Reader and neither builds a filter of its own.
|
|
func TestProxiedServerServeReadParity(t *testing.T) {
|
|
requireSharedProxiedServer(t)
|
|
t.Parallel()
|
|
bd := buildEmbeddedBD(t)
|
|
p := newSharedProxiedProject(t, bd, "srvrp")
|
|
sp := startServe(t, bd, p.dir, bdProxiedEnv(p.dir))
|
|
|
|
// A fixture with enough shape that a filter mistake shows: several
|
|
// priorities, two types, labels, an assignee, and a real blocker so the
|
|
// ready set is a strict subset of the list set.
|
|
top := bdProxiedCreate(t, bd, p.dir, "parity top", "-p", "0", "-t", "bug", "-l", "alpha")
|
|
mid := bdProxiedCreate(t, bd, p.dir, "parity mid", "-p", "2", "-t", "task", "-l", "alpha,beta")
|
|
low := bdProxiedCreate(t, bd, p.dir, "parity low", "-p", "3", "-t", "task")
|
|
blocked := bdProxiedCreate(t, bd, p.dir, "parity blocked", "-p", "1", "-t", "task")
|
|
if out, err := bdProxiedRun(t, bd, p.dir, "dep", "add", blocked.ID, top.ID); err != nil {
|
|
t.Fatalf("bd dep add: %v\n%s", err, out)
|
|
}
|
|
|
|
t.Run("ready", func(t *testing.T) {
|
|
// --limit 0 on both surfaces: unlimited means the same thing on each,
|
|
// and an unbounded read is the one that cannot hide a row behind a
|
|
// default that differs.
|
|
cli := cliItems(t, bd, p.dir, "ready", "--json", "--limit", "0")
|
|
got := sp.items(t, "/v0/beads/ready?limit=0")
|
|
assertItemsMatch(t, "ready", cli, got)
|
|
|
|
// ORDER, not just membership. bd ready's default sort is priority and
|
|
// the endpoint's documented default is the same, so the sequences must
|
|
// agree — this is the assertion that catches a handler forwarding an
|
|
// absent `sort` as "", which the storage layer reads as hybrid and
|
|
// which reorders (and, once a limit truncates, re-SELECTS) the page.
|
|
if cliIDs, gotIDs := itemIDs(cli), itemIDs(got); !reflect.DeepEqual(cliIDs, gotIDs) {
|
|
t.Errorf("ready order differs; the endpoint's default sort is not `bd ready`'s\n cli: %v\nhttp: %v", cliIDs, gotIDs)
|
|
}
|
|
// And the same again with the policy stated explicitly on both sides:
|
|
// if these two HTTP answers ever differ, the default is not priority
|
|
// whatever the document says.
|
|
explicit := sp.items(t, "/v0/beads/ready?limit=0&sort=priority")
|
|
if !reflect.DeepEqual(itemIDs(got), itemIDs(explicit)) {
|
|
t.Errorf("ready with no `sort` differs from `sort=priority`\n default: %v\npriority: %v",
|
|
itemIDs(got), itemIDs(explicit))
|
|
}
|
|
if ids := itemIDs(got); contains(strings.Join(ids, ","), blocked.ID) {
|
|
t.Errorf("ready returned the blocked issue %s: %v", blocked.ID, ids)
|
|
}
|
|
})
|
|
|
|
t.Run("list", func(t *testing.T) {
|
|
cli := cliItems(t, bd, p.dir, "list", "--json", "--limit", "0")
|
|
got := sp.items(t, "/v0/beads/issues?limit=0")
|
|
assertItemsMatch(t, "list", cli, got)
|
|
|
|
for _, want := range []string{top.ID, mid.ID, low.ID, blocked.ID} {
|
|
if !contains(strings.Join(itemIDs(got), ","), want) {
|
|
t.Errorf("list is missing %s: %v", want, itemIDs(got))
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("list with a filter both surfaces have to build the same way", func(t *testing.T) {
|
|
cli := cliItems(t, bd, p.dir, "list", "--json", "--limit", "0", "--label", "alpha")
|
|
got := sp.items(t, "/v0/beads/issues?limit=0&label=alpha")
|
|
assertItemsMatch(t, "list --label alpha", cli, got)
|
|
})
|
|
|
|
t.Run("a limit truncates on both surfaces, and to the same rows", func(t *testing.T) {
|
|
// The whole oracle above runs at limit 0, so until this subtest no
|
|
// comparison exercised truncation at all — and truncation is where the
|
|
// read epilogue (fetch, sort, trim, has_more) can differ without
|
|
// changing the unlimited answer.
|
|
//
|
|
// Naming the order on BOTH sides is what makes a truncated page
|
|
// comparable row for row rather than by count: the two surfaces have
|
|
// different defaults (the endpoint keeps `created` for compatibility,
|
|
// the CLI is priority-first), so a truncation comparison that named
|
|
// neither would be comparing two different top-2s.
|
|
cli := cliItems(t, bd, p.dir, "list", "--json", "--limit", "2", "--sort", "created")
|
|
got := sp.items(t, "/v0/beads/issues?limit=2&sort=created")
|
|
if len(cli) != 2 {
|
|
t.Fatalf("`bd list --limit 2` returned %d items, want 2", len(cli))
|
|
}
|
|
if len(got) != 2 {
|
|
t.Fatalf("GET issues?limit=2 returned %d items, want 2", len(got))
|
|
}
|
|
assertItemsMatch(t, "list --limit 2", cli, got)
|
|
|
|
// The other order, under the same truncation. This is where the two
|
|
// defaults used to force a client to choose between the CLI's ordering
|
|
// and a bounded page; now the same two rows come back on both sides.
|
|
cliByPriority := cliItems(t, bd, p.dir, "list", "--json", "--limit", "2", "--sort", "priority")
|
|
gotByPriority := sp.items(t, "/v0/beads/issues?limit=2&sort=priority")
|
|
assertItemsMatch(t, "list --sort priority --limit 2", cliByPriority, gotByPriority)
|
|
if a, b := itemIDs(cliByPriority), itemIDs(gotByPriority); !reflect.DeepEqual(a, b) {
|
|
t.Errorf("a truncated priority page differs between the surfaces\n cli: %v\nhttp: %v", a, b)
|
|
}
|
|
})
|
|
|
|
t.Run("a limit the database cannot push down still truncates", func(t *testing.T) {
|
|
// `--sort id` needs natural-numeric comparison (bd-9 < bd-10) that SQL
|
|
// cannot express, so workapi.SQLLimit zeroes the query's row limit and
|
|
// the whole result set comes back. The client-side trim is then the
|
|
// ONLY thing bounding the page — and the proxied route had no trim, so
|
|
// this command answered with every row while the direct route answered
|
|
// with two.
|
|
//
|
|
// There is no HTTP half to compare against, and that is deliberate
|
|
// rather than an oversight: `id` is precisely the order the list
|
|
// endpoint's `sort` refuses, because a sort SQL cannot express has no
|
|
// keyset predicate and so cannot be paged with a cursor. What is being
|
|
// pinned is that the CLI's two routes agree, which is the same property
|
|
// by a different pair.
|
|
cli := cliItems(t, bd, p.dir, "list", "--json", "--limit", "2", "--sort", "id")
|
|
if len(cli) != 2 {
|
|
t.Errorf("`bd list --sort id --limit 2` returned %d items (%v), want 2 — a sort SQL cannot express still has to respect the limit",
|
|
len(cli), itemIDs(cli))
|
|
}
|
|
// The endpoint turns it down by name, so a client that tried to move
|
|
// this command onto HTTP learns why rather than receiving a page in an
|
|
// order it did not ask for.
|
|
status, body := sp.object(t, "/v0/beads/issues?limit=2&sort=id")
|
|
if status != http.StatusBadRequest {
|
|
t.Errorf("GET issues?sort=id: status = %d, want 400: %v", status, body)
|
|
} else if body["param"] != "sort" || body["reason"] != "invalid_value" {
|
|
t.Errorf("GET issues?sort=id: body = %v, want param=sort reason=invalid_value", body)
|
|
}
|
|
})
|
|
|
|
t.Run("show", func(t *testing.T) {
|
|
for _, id := range []string{top.ID, mid.ID, blocked.ID} {
|
|
// `bd show --json` emits an array of one; the endpoint emits the
|
|
// object. That envelope difference is the CLI's, byte-pinned by the
|
|
// protocol corpus, and is the only structural divergence here.
|
|
cli := cliItems(t, bd, p.dir, "show", id, "--json")
|
|
if len(cli) != 1 {
|
|
t.Fatalf("bd show %s --json returned %d items, want the array of one", id, len(cli))
|
|
}
|
|
status, got := sp.object(t, "/v0/beads/issues/"+id)
|
|
if status != http.StatusOK {
|
|
t.Fatalf("GET issue %s: status = %d, body = %v", id, status, got)
|
|
}
|
|
assertItemsMatch(t, "show "+id, cli, []map[string]any{got})
|
|
}
|
|
})
|
|
|
|
t.Run("a page limit truncates identically and pages back to the same set", func(t *testing.T) {
|
|
all := sp.items(t, "/v0/beads/issues?limit=0")
|
|
if len(all) < 3 {
|
|
t.Skipf("fixture too small to page: %d rows", len(all))
|
|
}
|
|
|
|
var walked []map[string]any
|
|
path := "/v0/beads/issues?limit=2"
|
|
for range 10 {
|
|
resp, err := sp.client.Get(sp.url(path))
|
|
if err != nil {
|
|
t.Fatalf("GET %s: %v", path, err)
|
|
}
|
|
raw, _ := io.ReadAll(resp.Body)
|
|
_ = resp.Body.Close()
|
|
var page struct {
|
|
Items []map[string]any `json:"items"`
|
|
HasMore bool `json:"has_more"`
|
|
NextCursor *string `json:"next_cursor"`
|
|
}
|
|
if err := json.Unmarshal(raw, &page); err != nil {
|
|
t.Fatalf("decode page: %v\nraw: %s", err, raw)
|
|
}
|
|
walked = append(walked, page.Items...)
|
|
if !page.HasMore {
|
|
if page.NextCursor != nil {
|
|
t.Error("has_more is false but next_cursor is present; the document makes those a biconditional")
|
|
}
|
|
break
|
|
}
|
|
if page.NextCursor == nil {
|
|
t.Fatal("has_more is true but next_cursor is absent; paging cannot continue")
|
|
}
|
|
path = fmt.Sprintf("/v0/beads/issues?limit=2&cursor=%s", *page.NextCursor)
|
|
}
|
|
|
|
if got, want := itemIDs(walked), itemIDs(all); !reflect.DeepEqual(got, want) {
|
|
t.Errorf("a cursored walk did not reproduce the unlimited page\nwalked: %v\n all: %v", got, want)
|
|
}
|
|
})
|
|
|
|
t.Run("a foreign cursor is refused, not silently ignored", func(t *testing.T) {
|
|
status, body := sp.object(t, "/v0/beads/issues?cursor=not-a-cursor")
|
|
if status != http.StatusBadRequest {
|
|
t.Fatalf("status = %d, want 400: %v", status, body)
|
|
}
|
|
if body["code"] != "invalid_cursor" {
|
|
t.Errorf("code = %v, want invalid_cursor", body["code"])
|
|
}
|
|
})
|
|
|
|
t.Run("an unknown filter parameter is refused by name", func(t *testing.T) {
|
|
// Silently ignoring it would WIDEN the result set, which is the one
|
|
// failure a client cannot detect.
|
|
status, body := sp.object(t, "/v0/beads/ready?nosuchparam=1")
|
|
if status != http.StatusBadRequest {
|
|
t.Fatalf("status = %d, want 400: %v", status, body)
|
|
}
|
|
if body["reason"] != "unknown_parameter" || body["param"] != "nosuchparam" {
|
|
t.Errorf("body = %v, want reason=unknown_parameter param=nosuchparam", body)
|
|
}
|
|
})
|
|
|
|
t.Run("an unknown id is 404, on the same shape as every other failure", func(t *testing.T) {
|
|
status, body := sp.object(t, "/v0/beads/issues/bd-no-such-issue")
|
|
if status != http.StatusNotFound {
|
|
t.Fatalf("status = %d, want 404: %v", status, body)
|
|
}
|
|
if body["code"] != "not_found" {
|
|
t.Errorf("code = %v, want not_found", body["code"])
|
|
}
|
|
})
|
|
|
|
sp.shutdown(t)
|
|
}
|