beads/cmd/bd/ready_role_request_test.go
CI Bot 67d38d2620 Trim this series' comments toward the repo's own density
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.
2026-08-06 08:06:59 +00:00

91 lines
3.5 KiB
Go

package main
import (
"reflect"
"slices"
"testing"
"github.com/steveyegge/beads/internal/workapi"
)
// TestReadyRoleRequestDropsThePage pins what both role-taking questions of
// `bd ready` share: the claim and the count are asked over the LISTING's
// request with the page removed.
//
// Both roles refuse a Limit and an Offset (ErrValidation). For the count,
// published as "showing 2 of N", a limit that survived would make N the size of
// the page instead of the size of the set.
func TestReadyRoleRequestDropsThePage(t *testing.T) {
got := runGatherReadyInput(t, newReadyFlagsCommand(t, "--limit", "5", "--label", "api"), nil)
if got.err != nil {
t.Fatalf("gatherReadyInput: %v", got.err)
}
// The listing itself is bounded, which is what makes the drop observable.
if got.in.Limit == nil || *got.in.Limit != 5 {
t.Fatalf("the listing request carries limit %v, want 5: the drop below would prove nothing", got.in.Limit)
}
req := readyRoleRequest(got.in)
if req.Limit != nil {
t.Errorf("role request carries limit %d; both roles refuse one", *req.Limit)
}
if req.Offset != 0 {
t.Errorf("role request carries offset %d; both roles refuse one", req.Offset)
}
if !slices.Equal(req.Labels, []string{"api"}) {
t.Errorf("role request Labels = %q, want the listing's own %q", req.Labels, []string{"api"})
}
// The claim asks the same question, plus the claimant: one builder, so the
// count and the claim cannot drift apart from each other either.
claim := claimNextRequest(got.in)
if !reflect.DeepEqual(claim.Filter, req) {
t.Errorf("the claim's filter and the shared role request differ:\nclaim: %+v\nrole: %+v", claim.Filter, req)
}
// And the predicate the count actually runs is the listing's, unbounded —
// the identity issueops.ReadyCounter promises, checked at the front door
// rather than only at the three backends.
counted, err := workapi.BuildReadyCountFilter(req)
if err != nil {
t.Fatalf("BuildReadyCountFilter: %v", err)
}
unlimited := 0
listing := got.in.ReadyRequest
listing.Limit = &unlimited
want, err := workapi.BuildReadyFilter(listing)
if err != nil {
t.Fatalf("BuildReadyFilter: %v", err)
}
if !reflect.DeepEqual(counted, want) {
t.Errorf("the count's filter and the unbounded listing filter differ:\ncount: %+v\nlisting: %+v", counted, want)
}
}
// TestReadyRoleRequestCarriesTheDirectoryLabelDefault pins the one thing the
// role request adds that the raw flags do not: GH#541's configured label,
// applied under the same gate the listing applies it under. A count or a claim
// that missed the default would answer for a wider set than the listing beside
// it shows.
func TestReadyRoleRequestCarriesTheDirectoryLabelDefault(t *testing.T) {
const configured = "scope:web"
configureDirectoryLabel(t, configured)
got := runGatherReadyInput(t, newReadyFlagsCommand(t), nil)
if got.err != nil {
t.Fatalf("gatherReadyInput: %v", got.err)
}
if req := readyRoleRequest(got.in); !slices.Equal(req.LabelsAny, []string{configured}) {
t.Errorf("role request LabelsAny = %q, want the configured %q", req.LabelsAny, []string{configured})
}
// An explicit label suppresses it, the same way it suppresses the
// listing's.
explicit := runGatherReadyInput(t, newReadyFlagsCommand(t, "--label", "chosen"), nil)
if explicit.err != nil {
t.Fatalf("gatherReadyInput: %v", explicit.err)
}
if req := readyRoleRequest(explicit.in); len(req.LabelsAny) != 0 {
t.Errorf("role request LabelsAny = %q with an explicit --label, want none", req.LabelsAny)
}
}