beads/cmd/bd/simple_helpers_test.go
Steve Yegge 672d942083
fix(label): support comma-separated multi-label add/remove; fail hard on bad issue IDs (#4713)
* fix(label): support comma-separated multi-label add/remove; fail hard on bad issue IDs (bd-vu5kv)

'bd label add <id> a b c' silently applied only 'c': the grammar treats
the last arg as THE label and everything before it as issue IDs, and
unresolvable IDs were skipped with a stderr warning while the command
exited 0. An agent hit this in the wild and only noticed because
'bd ready --label ...' came back empty.

Two changes:

- The final positional arg now splits on commas, so
  'bd label add bd-123 a,b,c' adds all three labels in one transaction
  (same convention as 'bd create --labels a,b,c'). Same for remove.
- Issue-ID args that fail to resolve are now a hard error before any
  mutation, instead of warn-and-continue. When several ID-position args
  fail, the error hints at the comma-separated form, which is exactly
  the space-separated-labels mistake.

The reserved 'provides:' check now runs against every label in the
list. Regenerated CLI reference docs (freshness probe) and updated
docs/LABELS.md.

Closes bd-vu5kv

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012VBUR4qkHbssPomBDuJgkQ

* docs: sync website label mirrors

Agent-Signature: codex-gpt-5.6-terra-high on behalf of matt wilkie

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-12 08:23:52 -07:00

122 lines
2.8 KiB
Go

package main
import (
"strings"
"testing"
)
func TestParseLabelArgs(t *testing.T) {
tests := []struct {
name string
args []string
expectIDs int
expectLabels []string
}{
{
name: "single ID single label",
args: []string{"bd-1", "bug"},
expectIDs: 1,
expectLabels: []string{"bug"},
},
{
name: "multiple IDs single label",
args: []string{"bd-1", "bd-2", "critical"},
expectIDs: 2,
expectLabels: []string{"critical"},
},
{
name: "three IDs one label",
args: []string{"bd-1", "bd-2", "bd-3", "bug"},
expectIDs: 3,
expectLabels: []string{"bug"},
},
{
name: "comma-separated labels",
args: []string{"bd-1", "bug,critical,needs-review"},
expectIDs: 1,
expectLabels: []string{"bug", "critical", "needs-review"},
},
{
name: "comma-separated labels with whitespace and empties",
args: []string{"bd-1", " bug , ,critical,"},
expectIDs: 1,
expectLabels: []string{"bug", "critical"},
},
{
name: "whitespace-only label yields no labels",
args: []string{"bd-1", " "},
expectIDs: 1,
expectLabels: []string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ids, labels := parseLabelArgs(tt.args)
if len(ids) != tt.expectIDs {
t.Errorf("Expected %d IDs, got %d", tt.expectIDs, len(ids))
}
if len(labels) != len(tt.expectLabels) {
t.Fatalf("Expected labels %v, got %v", tt.expectLabels, labels)
}
for i, want := range tt.expectLabels {
if labels[i] != want {
t.Errorf("Expected label %d to be %q, got %q", i, want, labels[i])
}
}
})
}
}
func TestListRejectsPositionalArgs(t *testing.T) {
tests := []struct {
name string
args []string
wantErr bool
errSubstr string
}{
{
name: "no args is fine",
args: []string{},
wantErr: false,
},
{
name: "ready is rejected with hint",
args: []string{"ready"},
wantErr: true,
errSubstr: `did you mean "--ready"`,
},
{
name: "tree is rejected with hint",
args: []string{"tree"},
wantErr: true,
errSubstr: `did you mean "--tree"`,
},
{
name: "unknown arg is rejected generically",
args: []string{"foobar"},
wantErr: true,
errSubstr: "does not accept positional arguments",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := listCmd.Args(listCmd, tt.args)
if tt.wantErr {
if err == nil {
t.Fatalf("Expected error for args %v, got nil", tt.args)
}
if !strings.Contains(err.Error(), tt.errSubstr) {
t.Errorf("Error %q should contain %q", err.Error(), tt.errSubstr)
}
} else {
if err != nil {
t.Errorf("Unexpected error for args %v: %v", tt.args, err)
}
}
})
}
}