Ten agents over 216 files, one directory-balanced group each, working to a rubric that named what to cut (duplication narration, restatement of the next line, the governing rule echoed in every command file, throat-clearing) and what to keep (traps, invariants, security, tracker ids, behaviour changes, and the "why a naive simplification destroys this assertion" rationale). Net 1,523 lines. Density against this repo's own per-directory norm on main: cmd/bd 33.6% -> 27.3% (main 10.7%) internal/storage 26.1% -> 23.1% (main 14.1%) backend/conformance 34.0% -> 29.6% (main 22.8%) internal/httpapi 30.9% -> 27.8% (main 30.6%, now below) overall 34.7% -> 31.6% Every agent landed at 18-25% rather than the 30% asked for, and every one gave the same reason independently: what remained was on the keep list. Ten separate judgements agreeing is the most useful result here — the prose is dense, but it is mostly load-bearing, and the shortfall is the honest answer rather than a failure to try. TWO REVERTS, both to protect something worth more than the lines. issueops/ is back to its pre-trim state, giving up 610 lines. The conformance contracts cite the leaf docs BY LINE — "pins treewalker.go:52-66" — 155 times. Trimming the cited files silently repointed those at whatever text moved into those numbers, across agent boundaries so no agent could see it. A semantic remapper recovered 141 of them, but 23 needed judgement and several landed on struct fields. The leaf docs are the spec the contracts are written against; they are the one place in this change where dense prose IS the deliverable, and keeping them stable is worth more than the 610 lines. tree_walker_contract.go and version_reconciler_contract.go went back for the same reason: an agent had deleted a paragraph containing a citation, so positional restoration could not align them. After the reverts, exactly 5 citations point into a still-trimmed file and 2 of those are weak — both in cmd/bd/config_guard_test.go, which this series never touched and whose citations were already wrong on main (init.go:361 pointed at a closing brace; the guard it names is at init.go:1499). VERIFICATION. A guard strips every comment and all whitespace from each of the 193 modified files at HEAD and in the worktree and requires the two to be byte-identical, so a code change cannot hide in a comment diff. It handles `//` inside string and raw-string literals, and was tested against a deliberate code change before being trusted. gofmt clean, go build, go vet, golangci-lint 0 issues, and the two AST-based tests that PARSE trimmed files — the timed provider binding pin over claim.go and the serve database-source gate over serve.go — both pass. One real defect found while trimming: checkDatabaseSource's doc block ran into `// sourceRoles is ...` with no blank line, so godoc attached thirty-one lines of the wrong prose to func sourceRoles and left checkDatabaseSource undocumented. Fixed by separating them.
109 lines
4.8 KiB
Go
109 lines
4.8 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"net/http"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// The provider-path pins for GET /v0/beads/ready:count. The roles-path twin
|
|
// lives in roles_test.go, beside the other store-shaped-source cases.
|
|
|
|
// TestCountReadyRunsTheListingsQueryUnbounded asserts the property the
|
|
// operation exists to deliver: the count runs the SAME ready query the listing
|
|
// runs, with the page taken off.
|
|
//
|
|
// A body carrying the right total says nothing about which set was counted —
|
|
// every wrong predicate also produces a number — so the assertions are on the
|
|
// filter: the label the wire named, the listing's own sort policy, and Limit 0.
|
|
// Limit is the one that would silently break the operation's promise, because
|
|
// the shared builder defaults an UNSET limit to workapi.DefaultReadyLimit: a
|
|
// count assembled without the role would answer "how many of the first 100" and
|
|
// be published as a total.
|
|
func TestCountReadyRunsTheListingsQueryUnbounded(t *testing.T) {
|
|
rec := &recordingIssues{items: countedPage()}
|
|
ts := newTestServer(t, Config{Provider: &fakeProvider{
|
|
issues: &fakeIssues{},
|
|
readIssues: rec,
|
|
readConfig: emptyConfig{},
|
|
}})
|
|
|
|
resp := ts.get(t, "/v0/beads/ready:count?label=api")
|
|
if resp.StatusCode != http.StatusOK {
|
|
t.Fatalf("status = %d, want 200: %s", resp.StatusCode, readAll(t, resp))
|
|
}
|
|
if body := decodeBody(t, resp); body["total"] != float64(len(countedPage())) {
|
|
t.Errorf("total = %v, want %d — the size of the set the reader answered with", body["total"], len(countedPage()))
|
|
}
|
|
|
|
filters := rec.readyFilters()
|
|
if len(filters) != 1 {
|
|
t.Fatalf("%d ready queries, want 1", len(filters))
|
|
}
|
|
if got := filters[0].Limit; got != 0 {
|
|
t.Errorf("Limit = %d, want 0: a bounded count answers \"how many of the first N\" and would be read as a total", got)
|
|
}
|
|
if got := filters[0].Offset; got != 0 {
|
|
t.Errorf("Offset = %d, want 0", got)
|
|
}
|
|
if got := filters[0].SortPolicy; got != types.SortPolicy("priority") {
|
|
t.Errorf("SortPolicy = %q, want the listing's own default: an empty policy is the storage layer's hybrid fallback", got)
|
|
}
|
|
if got := filters[0].Labels; len(got) != 1 || got[0] != "api" {
|
|
t.Errorf("Labels = %v, want the label the wire named", got)
|
|
}
|
|
}
|
|
|
|
// TestCountReadyPublishesNoPageParameters: `limit`, `offset` and `sort` are the
|
|
// listing's parameters and are absent from this operation's table, so sending
|
|
// one is version skew rather than a bad value and `unknown_parameter` is the
|
|
// answer. Silently accepting `limit` would be the failure the role itself
|
|
// refuses; silently accepting `sort` would advertise a knob that changes nothing
|
|
// about a set with no order.
|
|
func TestCountReadyPublishesNoPageParameters(t *testing.T) {
|
|
for _, param := range []string{"limit=5", "limit=0", "offset=1", "sort=oldest"} {
|
|
ts, _ := newReadServer(t, Config{})
|
|
resp := ts.get(t, "/v0/beads/ready:count?"+param)
|
|
if resp.StatusCode != http.StatusBadRequest {
|
|
t.Errorf("GET ready:count?%s: status = %d, want 400", param, resp.StatusCode)
|
|
continue
|
|
}
|
|
body := decodeBody(t, resp)
|
|
if body["reason"] != string(ReasonUnknownParameter) {
|
|
t.Errorf("GET ready:count?%s: body = %v, want reason=unknown_parameter", param, body)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestCountReadyAndListReadyAdmitTheSameFilters is the parity the identity
|
|
// rests on: every filter the listing accepts, the count accepts too, and both
|
|
// build the same predicate from it. A parameter one of them knew and the other
|
|
// did not would make "the size of the page you would get" false for exactly the
|
|
// clients that sent it, and would fail as a 400 on one path only.
|
|
func TestCountReadyAndListReadyAdmitTheSameFilters(t *testing.T) {
|
|
shared := "assignee=alice&unassigned=false&type=bug&exclude_type=epic&label=api&label_any=x" +
|
|
"&exclude_label=wip&label_pattern=tech-*&label_regex=^tech-&priority=1&parent=bd-1" +
|
|
"&metadata_field=team%3Dcore&has_metadata_key=team&include_ephemeral=true&include_deferred=true"
|
|
|
|
listing, listRec := newReadServer(t, Config{})
|
|
if resp := listing.get(t, "/v0/beads/ready?"+shared); resp.StatusCode != http.StatusOK {
|
|
t.Fatalf("GET ready: status = %d, want 200: %s", resp.StatusCode, readAll(t, resp))
|
|
}
|
|
counting, countRec := newReadServer(t, Config{})
|
|
if resp := counting.get(t, "/v0/beads/ready:count?"+shared); resp.StatusCode != http.StatusOK {
|
|
t.Fatalf("GET ready:count: status = %d, want 200: %s", resp.StatusCode, readAll(t, resp))
|
|
}
|
|
|
|
listed, counted := listRec.readyFilters(), countRec.readyFilters()
|
|
if len(listed) != 1 || len(counted) != 1 {
|
|
t.Fatalf("%d listing queries and %d counting queries, want 1 each", len(listed), len(counted))
|
|
}
|
|
// The page is the only thing that may differ.
|
|
want := listed[0]
|
|
want.Limit = 0
|
|
if !reflect.DeepEqual(counted[0], want) {
|
|
t.Errorf("the count and the listing built different predicates from one query string:\ncount: %+v\nlisting: %+v", counted[0], want)
|
|
}
|
|
}
|