* fix(routing): warn when contributor auto-routing swaps list/ready results bd list and bd ready silently swap to the auto-routed contributor planning store (routing.mode=auto + routing.contributor, set up via `bd init --contributor`) whenever beads.role resolves to contributor. If that store is empty or just doesn't have the issue you expect, the commands report zero results with no indication that anything was routed at all — bd stats and bd show <id> don't go through this path, so they keep reporting the local project truth, making the split look like data loss instead of a routing decision. Print a stderr note (with the local issue count and the fix command) whenever openRoutedReadStore actually swaps the active store for these two commands. JSON output on stdout is unchanged; the note is stderr only and, like the existing ready --json truncation notice, is not gated on --quiet since it communicates a change of data source rather than decorative output. * fix(routing): attribute the routing-swap notice to the matched rule; honor --quiet Addresses the 2026-07-23 maphew/mybd review on gastownhall/beads#4866 (fix/contributor-role-visibility). printContributorRoutingNotice was hardcoded to blame beads.role=contributor and recommend `git config beads.role maintainer` for every routed read, even when the swap was actually caused by routing.maintainer or the unconditional routing.default fallback (internal/routing.DetermineTargetRepo) - misdiagnosing the cause in those cases. - internal/routing: DetermineTargetRepo now delegates to a new DetermineTargetRepoWithRule, which also reports which rule matched (RuleContributor/RuleMaintainer/RuleDefault/RuleExplicitOverride/RuleNone). - cmd/bd/routing_read.go: thread that rule out of determineAutoRoutedRepoPath and openRoutedReadStore, and branch printContributorRoutingNotice's text and remediation command on it via routingNoticeText, so a maintainer- or default-routed swap gets its own accurate wording instead of the contributor-role message. - Gate the notice on !quietFlag, matching quietFlag's documented contract ("Suppress non-essential output (errors only)") and the other non-error stderr notices in this package (tips.go, metrics.go). - Reword the parenthetical issue count to "this project has N total issue(s)" rather than claiming all N are "hidden as a result" of routing, since stats.TotalIssues is an unfiltered COUNT(*) that includes closed/deferred/blocked issues bd ready would never surface anyway; comment the GetStatistics-error fallback (count omitted) as an explicit decision. - Add routing_notice_test.go covering each rule variant's notice text and --quiet suppression; update the existing openRoutedReadStore/ determineAutoRoutedRepoPath tests for the new return signatures. The broader routing x {list,ready} x --quiet x JSON-stdout-isolation subprocess test matrix the review also asked for (non-blocking finding) is left for follow-up; it needs dolt-backed subprocess coverage beyond this fix's scope. Agent-Signature: claude-sonnet-5-medium on behalf of maphew --------- Co-authored-by: Ravi Tharuma <RaviTharuma@users.noreply.github.com> Co-authored-by: matt wilkie <maphew@gmail.com>
132 lines
4.4 KiB
Go
132 lines
4.4 KiB
Go
// routing_notice_test.go - Tests for the routing-swap stderr notice printed
|
|
// by list/ready when reads are auto-routed to a different store.
|
|
//
|
|
// Deliberately untagged (no `cgo` build tag): printContributorRoutingNotice
|
|
// and routingNoticeText don't need a real store or the embedded Dolt server,
|
|
// so these tests exercise them with a nil storage.DoltStorage and must stay
|
|
// compilable under CGO_ENABLED=0 with the gms_pure_go build tag alongside
|
|
// the rest of the pure-Go test suite.
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/routing"
|
|
)
|
|
|
|
// TestRoutingNoticeText_VariesByRule verifies the notice's reason and fix
|
|
// command are branched on the matched routing rule instead of always
|
|
// attributing the swap to beads.role=contributor (gastownhall/beads#4866
|
|
// review, 2026-07-23).
|
|
func TestRoutingNoticeText_VariesByRule(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
rule routing.RoutingRule
|
|
wantReason string
|
|
wantFix string
|
|
}{
|
|
{
|
|
name: "contributor rule",
|
|
rule: routing.RuleContributor,
|
|
wantReason: "beads.role=contributor",
|
|
wantFix: "git config beads.role maintainer",
|
|
},
|
|
{
|
|
name: "maintainer rule",
|
|
rule: routing.RuleMaintainer,
|
|
wantReason: "routing.maintainer",
|
|
wantFix: "bd config unset routing.maintainer",
|
|
},
|
|
{
|
|
name: "default rule",
|
|
rule: routing.RuleDefault,
|
|
wantReason: "routing.default",
|
|
wantFix: "bd config unset routing.default",
|
|
},
|
|
{
|
|
name: "no rule (fallback wording)",
|
|
rule: routing.RuleNone,
|
|
wantReason: "auto-routing rule",
|
|
wantFix: "bd config get",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
reason, fix := routingNoticeText(tt.rule)
|
|
if !strings.Contains(reason, tt.wantReason) {
|
|
t.Errorf("routingNoticeText(%v) reason = %q, want substring %q", tt.rule, reason, tt.wantReason)
|
|
}
|
|
if !strings.Contains(fix, tt.wantFix) {
|
|
t.Errorf("routingNoticeText(%v) fix = %q, want substring %q", tt.rule, fix, tt.wantFix)
|
|
}
|
|
})
|
|
}
|
|
|
|
// The contributor-rule wording must not leak into the other rules'
|
|
// notices: that mislabeling (fixed `git config beads.role maintainer`
|
|
// advice for a maintainer- or default-routed swap) was the review's
|
|
// blocking finding.
|
|
for _, rule := range []routing.RoutingRule{routing.RuleMaintainer, routing.RuleDefault, routing.RuleNone} {
|
|
reason, fix := routingNoticeText(rule)
|
|
if strings.Contains(reason, "beads.role") || strings.Contains(fix, "beads.role") {
|
|
t.Errorf("routingNoticeText(%v) incorrectly mentions beads.role: reason=%q fix=%q", rule, reason, fix)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestPrintContributorRoutingNotice_TextMatchesRule verifies the emitted
|
|
// stderr notice reflects the rule passed in, for each rule variant.
|
|
func TestPrintContributorRoutingNotice_TextMatchesRule(t *testing.T) {
|
|
origQuiet := quietFlag
|
|
quietFlag = false
|
|
t.Cleanup(func() { quietFlag = origQuiet })
|
|
|
|
tests := []struct {
|
|
name string
|
|
rule routing.RoutingRule
|
|
want string
|
|
}{
|
|
{"contributor", routing.RuleContributor, "beads.role=contributor"},
|
|
{"maintainer", routing.RuleMaintainer, "routing.maintainer"},
|
|
{"default", routing.RuleDefault, "routing.default"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
out := captureStderr(t, func() {
|
|
printContributorRoutingNotice(context.Background(), nil, tt.rule)
|
|
})
|
|
if !strings.Contains(out, tt.want) {
|
|
t.Errorf("printContributorRoutingNotice(rule=%v) stderr = %q, want substring %q", tt.rule, out, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestPrintContributorRoutingNotice_QuietSuppresses verifies --quiet
|
|
// suppresses the routing notice, matching the other non-error stderr
|
|
// notices in this package (tips.go, metrics.go) that respect quietFlag.
|
|
func TestPrintContributorRoutingNotice_QuietSuppresses(t *testing.T) {
|
|
origQuiet := quietFlag
|
|
t.Cleanup(func() { quietFlag = origQuiet })
|
|
|
|
quietFlag = true
|
|
out := captureStderr(t, func() {
|
|
printContributorRoutingNotice(context.Background(), nil, routing.RuleContributor)
|
|
})
|
|
if out != "" {
|
|
t.Errorf("printContributorRoutingNotice() with quietFlag=true wrote stderr = %q, want empty", out)
|
|
}
|
|
|
|
quietFlag = false
|
|
out = captureStderr(t, func() {
|
|
printContributorRoutingNotice(context.Background(), nil, routing.RuleContributor)
|
|
})
|
|
if out == "" {
|
|
t.Error("printContributorRoutingNotice() with quietFlag=false wrote no stderr, want non-empty")
|
|
}
|
|
}
|