beads/internal/workapi/stats_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

126 lines
4.9 KiB
Go

package workapi
import (
"errors"
"testing"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/issueops"
)
// TestValidateStatsAssignee pins the one refusal on the summary role, and pins
// it here because it needs no database: an assignee-scoped summary of nobody is
// ErrValidation, and an accepted assignee comes back BYTE-IDENTICAL. The second
// half is the load-bearing one: trimming would answer for a different actor
// than the caller named.
func TestValidateStatsAssignee(t *testing.T) {
for _, blank := range []string{"", " ", "\t\n"} {
got, err := ValidateStatsAssignee(blank)
if !errors.Is(err, issueops.ErrValidation) {
t.Errorf("ValidateStatsAssignee(%q) error = %v, want ErrValidation", blank, err)
}
if got != "" {
t.Errorf("ValidateStatsAssignee(%q) = %q alongside a refusal, want the empty string", blank, got)
}
}
for _, assignee := range []string{"alice", " alice ", "Alice", "agent:worker-3"} {
got, err := ValidateStatsAssignee(assignee)
if err != nil {
t.Errorf("ValidateStatsAssignee(%q): %v", assignee, err)
}
if got != assignee {
t.Errorf("ValidateStatsAssignee(%q) = %q, want it unchanged", assignee, got)
}
}
}
// TestBuildStatsAssigneeFiltersCarryOnlyTheAssignee pins what the two
// assignee-scoped predicates deliberately leave out. A status restriction, a
// limit or a wisp suppression appearing in either of them would change what
// `bd status --assigned` counts without changing a line of either front door.
func TestBuildStatsAssigneeFiltersCarryOnlyTheAssignee(t *testing.T) {
issueFilter := BuildStatsAssigneeIssueFilter("alice")
if issueFilter.Assignee == nil || *issueFilter.Assignee != "alice" {
t.Fatalf("issue filter assignee = %v, want alice", issueFilter.Assignee)
}
if issueFilter.Limit != 0 {
t.Errorf("issue filter limit = %d, want 0 — a capped scan under-reports a busy actor's total", issueFilter.Limit)
}
if issueFilter.Status != nil || len(issueFilter.Statuses) != 0 {
t.Errorf("issue filter restricts status (%v/%v); the fold tallies every status including closed", issueFilter.Status, issueFilter.Statuses)
}
if issueFilter.SkipWisps {
t.Error("issue filter skips wisps; AssigneeStats documents the merged tier")
}
workFilter := BuildStatsAssigneeWorkFilter("alice")
if workFilter.Assignee == nil || *workFilter.Assignee != "alice" {
t.Fatalf("work filter assignee = %v, want alice", workFilter.Assignee)
}
}
// TestFoldStatsAssigneeSummary is the definition of what `bd status --assigned`
// means, checked without a database. Both routes read it from this one function,
// so a change to any number below is a change to both surfaces at once.
func TestFoldStatsAssigneeSummary(t *testing.T) {
tests := []struct {
name string
issues []*types.Issue
ready int
total int
open int
inProgress int
blocked int
deferred int
closed int
}{
{
name: "counts every status and ready work",
issues: []*types.Issue{
{Status: types.StatusOpen},
{Status: types.StatusInProgress},
{Status: types.StatusBlocked},
{Status: types.StatusDeferred},
{Status: types.StatusClosed},
},
ready: 2, total: 5, open: 1, inProgress: 1, blocked: 1, deferred: 1, closed: 1,
},
{
name: "empty input retains explicit zero counts",
ready: 0,
},
{
// A status outside the five the fold knows lands in the total and
// in no bucket, exactly as the workspace-wide answer's tallies do.
name: "an unknown status is counted once and bucketed nowhere",
issues: []*types.Issue{{Status: types.Status("triage")}, {Status: types.StatusOpen}},
ready: 1, total: 2, open: 1,
},
{
name: "a nil row is counted nowhere at all",
issues: []*types.Issue{nil, {Status: types.StatusOpen}},
ready: 0, total: 1, open: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := FoldStatsAssigneeSummary(tt.issues, tt.ready)
if got.TotalIssues != tt.total || got.OpenIssues != tt.open || got.InProgressIssues != tt.inProgress || got.DeferredIssues != tt.deferred || got.ClosedIssues != tt.closed {
t.Errorf("FoldStatsAssigneeSummary() = %+v, want total=%d open=%d in_progress=%d deferred=%d closed=%d", got, tt.total, tt.open, tt.inProgress, tt.deferred, tt.closed)
}
if got.BlockedIssues == nil || *got.BlockedIssues != tt.blocked {
t.Errorf("blocked issues = %v, want %d", got.BlockedIssues, tt.blocked)
}
if got.ReadyIssues == nil || *got.ReadyIssues != tt.ready {
t.Errorf("ready issues = %v, want %d", got.ReadyIssues, tt.ready)
}
// The three fields AssigneeStats says are always zero here. They
// are not "not yet implemented" on this path: the fold has no
// input that could produce them.
if got.PinnedIssues != 0 || got.EpicsEligibleForClosure != 0 || got.AverageLeadTime != 0 {
t.Errorf("extended fields = %d/%d/%v, want zeros", got.PinnedIssues, got.EpicsEligibleForClosure, got.AverageLeadTime)
}
})
}
}