* feat(label): add --prefix to bd label remove
bd list/bd ready already support --label-pattern/--label-regex for
finding issues by label shape. label remove had no equivalent for
stripping a whole label family in one call: callers had to fetch an
issue's labels themselves and issue one exact-match "bd label
remove" per matching label.
--prefix resolves the matching labels per issue (labelsWithPrefix, a
plain strings.HasPrefix filter over the labels already returned by
GetLabels) and removes them in a single transaction. Implemented for
both the embedded store path and the proxied-server (bd serve) path,
wisp-aware in the latter via workapi.GetIssueOrWisp — gc bd in Gas
Town runs proxied against a shared Dolt server, so an embedded-only
implementation would not have been usable there.
TDD: pure-function unit test (TestLabelsWithPrefix), plus embedded
and proxied CLI-level integration test cases mirroring the existing
label_remove_batch/add_list_remove conventions. Full existing
cmd/bd label suite re-run green (24/24 embedded subtests) for
regressions. The new proxied integration subtest could not be run
locally (this environment has no Docker, which the
testcontainers-go Dolt harness requires) but compiles clean under
go vet and golangci-lint and mirrors the existing, working
labelMutateProxied/runLabelListProxiedServer structure exactly.
Ref: ga-r8haw (gastownhall Gas Town city, Proposal 1).
* fix(label): address review feedback on --prefix (tense, arg validation, help text)
steveyegge's PR review (2026-08-08) asked for three small fixes before
merge, none of which the two subsequent rebases (2026-08-29, 2026-09-07)
touched:
1. Error-string tense: both label-remove failure paths (applyLabelEdit,
shared with label add; removeLabelsByPrefix) rendered "label
removed"/"added" on a FAILURE, claiming success on the very branch
that reports an error. Added labelOperationGerund() and used it on
both failure paths ("removing"/"adding"); the success-path constants
(labelOperationAdded/Removed, used by reportLabelEdit's JSON status
and human-readable verb) are untouched — they were already correct.
2. Reject --prefix combined with a label-shaped positional explicitly:
`bd label remove bd-1 stale-label --prefix x` used to hand ALL
positionals to resolveLabelIssueIDs, which (a) failed with a
confusing "could not resolve issue ID" error whose hint recommends
the exact comma-separated label syntax --prefix does not take, and
(b) left a live (if unlikely) risk that ResolvePartialID's fuzziness
could silently resolve a label-shaped string to an unrelated real
issue. Added resolveIssueIDsForPrefix, used only by the --prefix
branch of labelRemoveCmd's RunE, which fails with an explicit
"cannot combine --prefix with label arguments" instead.
3. Sharp-edge guard: per the reviewer's "at minimum" option, expanded
the --prefix flag help text to name the blast radius (a short
prefix can remove multiple unrelated label families in one
transaction) and point at `bd set-state` for state-dimension labels
(launch:, scalegate:), which --prefix bypasses without the
event-bead audit trail bd set-state provides.
TDD: new TestLabelOperationGerund (pure unit) and
label_remove_prefix_rejects_label_shaped_positional (embedded CLI
integration, mirrors the existing label_remove_prefix* subtests) —
both confirmed RED against the pre-fix code (temporarily reverted,
re-run, restored) before GREEN. Full cmd/bd label suite re-run green:
25/25 embedded subtests (24 pre-existing + 1 new), no regressions.
go vet + gofmt clean.
Ref: ga-r8haw (gastownhall Gas Town city, Proposal 1 — addresses the
2026-08-08 review verdict "MERGE AFTER FIXES (small ones)" on PR #5384).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* chore(bazel): add label_prefix_test.go to cmd/bd go_test srcs
cmd/bd/BUILD.bazel enumerates go_test srcs explicitly, so this PR's new
label_prefix_test.go was absent from the list. bazel.yml's "BUILD files in
sync" step runs `make bazel-sync` and exits 1 on any resulting drift
(.github/workflows/bazel.yml:382-406), and that job feeds pr.yml's
required CI_GATE_REQUIRED contexts (BAZEL, BAZEL_TEST, BAZEL_PURE, ...),
so the branch would red a required gate.
The bazel lane did not exist at the merge base the PR's green CI run was
built on, so no existing green covers it.
Generated with `make bazel-sync` (gazelle); re-running it is a no-op.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* fix(label): report --prefix removals from the write result, not the pre-read set
Review fixes for the adopted PR. The gating finding is the reporting
contract on the new --prefix path.
MAJOR - removeLabelsByPrefix discarded the UpdateResult (`if _, uerr :=
lifecycle.Update(...)`) and then printed one `status: "removed"` row and one
`✓ Removed` line per entry in the pre-read snapshot, so it asserted label
removals that had not happened. That is the GH#5988 false-confirmation
defect base commit 0b9e644ba9 removed from the sibling path three commits
earlier, reintroduced on a new surface that never called the handler which
fixes it.
The path now builds a labelEditOutcome per issue from the returned
UpdateResult and reports through reportLabelEdit, the same handler the plain
path uses, so an edit that wrote nothing reports "unchanged" and the human
"was not on" line instead of a removal. Per-label attribution stays
best-effort on the same terms applyLabelEdit documents (the Get is outside
the write transaction); what is no longer possible is claiming a removal for
an edit that wrote nothing at all.
labelEditOutcome carries its own label set, because --prefix resolves a
different set per issue while applyLabelEdit repeats one caller-supplied
set. reportLabelEdit therefore reads outcome.labels and its shared `labels`
parameter is gone; it had one caller before this change and has two now.
resolveIssueIDsForPrefix collapses duplicate ids. Naming one issue twice
used to yield two "removed" rows per label deterministically - the grouping
map recorded the repeat once, but the report loops iterated the ungrouped
pairs - which is the arm that needed no concurrency to reproduce.
Minors from the same review:
- cmd/bd/label.go:159 passed the past-tense `operation` constant into an
error string, the anti-pattern this PR's own labelOperationGerund exists
to remove; the site is byte-identical at base, so the PR did not introduce
it, it shipped the remedy and applied it 13 lines below only.
- resolveIssueIDsForPrefix prefixed EVERY resolution failure with "cannot
combine --prefix with label arguments", blaming a lone typo'd id on an
argument mistake the caller did not make. The hint is speculative, so it
is now gated on len(issueIDs) > 1, matching resolveLabelIssueIDs' twin.
- The --prefix help text claimed a short prefix "removes every match in one
transaction", but a multi-issue call is one Update per issue and can land
some and fail others - the partial application applyLabelEdit documents.
Reworded to per-issue semantics, keeping the breadth caution. The same
overclaim was in this PR's own CHANGELOG entry and is reworded there too.
Tests: six subtests on TestEmbeddedLabel covering the surfaces that had no
guard - the --json row shape, the no-match empty array, two issues with
different matching sets, the duplicate-id arm, an already-removed re-run,
and the lone-bad-id message. The duplicate-id case is the pin for the
major: run against the pre-fix label.go it gets 4 rows for 2 labels. The
re-run case is not a pin. A re-run matches nothing and takes the no-match
branch before any write, so it passes against the pre-fix code too; the
"unchanged" report it cannot reach is covered through the shared handler
by the plain path's GH#5988 subtests.
Verified at this head: cmd/bd TestEmbeddedLabel 36/36 subtests and
TestProxiedServerLabel 22/22 PASS (BEADS_TEST_EMBEDDED_DOLT=1 and
BEADS_TEST_PROXIED_SERVER=1, ambient BEADS_* scrubbed), TestLabelsWithPrefix
5/5, TestLabelOperationGerund 3/3, 0 FAIL and 0 SKIP; the GH#5988
discovery-suite regression checks for the plain path
(TestDiscovery_LabelRemoveNonexistentSilentSuccess,
TestDiscovery_LabelAddDuplicateReportsAdded) PASS; build, vet and gofmt
clean; `make bazel-sync` produces no drift (no files added); and
scripts/check-doc-flags.sh passes, including the CLI docs freshness gate.
Measured complexity moved down where it changed: removeLabelsByPrefix
cyclomatic 16 to 12 and cognitive 21 to 16; reportLabelEdit is unchanged at
12 and 25.
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
84 lines
2.3 KiB
Go
84 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestLabelsWithPrefix(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
labels []string
|
|
prefix string
|
|
want []string
|
|
}{
|
|
{
|
|
name: "matches multiple labels sharing a prefix",
|
|
labels: []string{"pool:refused:bd-cli-blast-radius-needs-human", "pool:refused:engine-rebuild-required", "needs-human"},
|
|
prefix: "pool:refused:",
|
|
want: []string{"pool:refused:bd-cli-blast-radius-needs-human", "pool:refused:engine-rebuild-required"},
|
|
},
|
|
{
|
|
name: "no match returns empty",
|
|
labels: []string{"needs-human", "story:blocked"},
|
|
prefix: "pool:refused:",
|
|
want: nil,
|
|
},
|
|
{
|
|
name: "empty prefix matches everything",
|
|
labels: []string{"a", "b"},
|
|
prefix: "",
|
|
want: []string{"a", "b"},
|
|
},
|
|
{
|
|
name: "does not match a substring that isn't a prefix",
|
|
labels: []string{"gate:passed", "needs-gate:review"},
|
|
prefix: "gate:",
|
|
want: []string{"gate:passed"},
|
|
},
|
|
{
|
|
name: "empty label set returns empty",
|
|
labels: nil,
|
|
prefix: "pool:refused:",
|
|
want: nil,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := labelsWithPrefix(tt.labels, tt.prefix)
|
|
if len(got) == 0 && len(tt.want) == 0 {
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("labelsWithPrefix(%v, %q) = %v, want %v", tt.labels, tt.prefix, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestLabelOperationGerund guards against the past-tense-on-failure bug a PR
|
|
// reviewer flagged on this exact code path: "label removed: ...: <err>" reads
|
|
// as a success report when it is actually the error message for a removal
|
|
// that failed. The failure-path callers must use the gerund form instead.
|
|
func TestLabelOperationGerund(t *testing.T) {
|
|
tests := []struct {
|
|
operation string
|
|
want string
|
|
}{
|
|
{labelOperationAdded, "adding"},
|
|
{labelOperationRemoved, "removing"},
|
|
{"custom", "custom"}, // unknown input passes through rather than panicking
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.operation, func(t *testing.T) {
|
|
if got := labelOperationGerund(tt.operation); got != tt.want {
|
|
t.Errorf("labelOperationGerund(%q) = %q, want %q", tt.operation, got, tt.want)
|
|
}
|
|
if got := labelOperationGerund(tt.operation); strings.HasSuffix(got, "ed") {
|
|
t.Errorf("labelOperationGerund(%q) = %q, still reads as past tense", tt.operation, got)
|
|
}
|
|
})
|
|
}
|
|
}
|