* storage: add RenameLabel primitive with merge semantics
Add a storage primitive that renames a label across every issue and
wisp that carries it, in one transaction per store. An issue that
already carries the new label is a merge - the stale old-label row is
dropped rather than raising a duplicate-key error - and the call
reports renamed/merged counts plus every touched id.
- internal/storage/issueops/labels.go: RenameLabelInTx sweeps the
labels and wisp_labels tables (INSERT IGNORE then DELETE, so the
merge never errors), emitting one EventLabelRenamed plus the usual
full-snapshot journal row per touched issue/wisp, matching
AddLabelInTx/RemoveLabelInTx's journal shape. A single batch event
was considered and rejected: the journal-completeness guard requires
every touched row to carry its own journal entry.
- internal/storage/storage.go: RenameLabel added to the Storage
interface, next to AddLabel/RemoveLabel/GetIssuesByLabel.
- internal/storage/dolt, internal/storage/embeddeddolt: direct
implementations. The dolt commit targets the fixed events/labels
table pair; doltAddAndCommit's own HasStagedChanges guard skips it
when the rename touched wisps only (wisp tables are dolt-ignored,
same as AddLabel/RemoveLabel).
- internal/storage/hook_decorator.go: HookFiringStore.RenameLabel
fires on_update per touched issue, matching AddLabel/RemoveLabel.
- internal/types/types.go: new EventLabelRenamed event type. Unlike
EventLabelAdded/EventLabelRemoved, one rename produces exactly one
of these per touched row, never a paired add+remove.
- internal/jira/tracker_test.go: mock stub for the new interface
method.
Tests: internal/storage/dolt/label_rename_test.go, against a real
dolt-sql-server container - basic rename, merge, wisp sweep,
zero-carrier no-op, over-length refusal, event assertion. All green.
Also verified TestEveryBeadMutatorJournalsOrIsExempt still passes.
Gates: gofmt clean, go vet ./... clean, CGO_ENABLED=0 go test -tags
gms_pure_go -c -o /dev/null ./cmd/bd clean, go build ./... clean.
* storage: refuse RenameLabel(x, x) instead of wiping the label
RenameLabelInTx's merge branch treats every carrier of oldLabel as
already carrying newLabel when the two names collide (they are the
same string): the batched INSERT IGNORE no-ops on every row, and the
unconditional DELETE FROM <table> WHERE label = ? that follows then
removes every row for that label plane. A self-rename silently wiped
the label instead of leaving it untouched.
Reject oldLabel == newLabel (compared after trimming, case-sensitive)
before any write, returning the new ErrRenameLabelSameName. Verified
red->green: TestRenameLabel_SameNameRefused and
TestRenameLabel_SameNameAfterTrimRefused both fail (GetLabels returns
[] on both the labels and wisp_labels planes) against the pre-fix
code, and pass against the fix. Full TestRenameLabel* suite in
internal/storage/dolt still green.
* telemetry: instrument InstrumentedStorage.RenameLabel
AddLabel and RemoveLabel already get OTel spans/metrics through
InstrumentedStorage; RenameLabel had no override and so fell through
to the embedded storage.DoltStorage passthrough, invisible to
storage.* tracing. Add the override, mirroring the AddLabel/RemoveLabel
shape: span attributes for the old/new label pair (bd.label.old,
bd.label.new, matching the existing bd.dep.from/bd.dep.to pairing
convention), and on success a bd.result.count / bd.merged.count pair
following the SearchIssues-style "set result attributes after a
successful call" pattern already used elsewhere in this file.
* storage: document the O(N) round-trip cost of RenameLabelInTx's event loop
renameLabelInPlane's per-issue loop (InsertDerivedEvent + RecordEventInTx)
is O(len(oldIDs)) SQL round trips inside one transaction, up to four per
touched issue. On a huge label population that lengthens the transaction
and raises the odds an optimistic-concurrency retry has to redo the whole
rename from scratch.
No batching added: InsertDerivedEvent's dedup SELECT is a real
cross-replica convergence check (Protocol v0.1 C2.3), not a redundant one
this transaction could skip, and no batch primitive for this shape exists
anywhere in this package - building one here would be new shared
infrastructure grown for a single caller. AddLabelInTx/RemoveLabelInTx
already pay the identical per-call cost for their one issue; this loop is
that cost repeated once per touched issue. Documented inline as a
disclosed limitation rather than silently left unremarked.
* bda-lbjv: derive rename merge count from rows-affected, not a prior read
renameLabelInPlane computed merged from a snapshot SELECT of newLabel's
carriers taken before the INSERT IGNORE - a check-then-insert whose
result is used. A concurrent AddLabel(issue, newLabel) committing between
snapshot and insert made the reported count schedule-dependent while the
stored data stayed correct (cross-model finding: the Opus panel cleared
A1, codex flipped it to NOT-SAFE on exactly this line).
Now the count is a measurement: INSERT IGNORE reports one affected row
per id actually inserted, so merged = len(oldIDs) - inserted, and the
newLabel pre-read is gone entirely.
Tests: sqlmock scripts the racing schedule (insert sees a row the
snapshot read could not); mutation control confirms the old
implementation fails the new test. Full issueops package + live-store
TestRenameLabel_* green.
* bda-c77s: first-party coverage for EmbeddedDoltStore.RenameLabel
The embedded impl had zero tests while DoltStore.RenameLabel carries a
dedicated suite; AddLabel/RemoveLabel both have parallel embedded
coverage by convention. Four wiring cases (basic, merge, zero-carrier
no-op, same-name refusal) - the deep semantics stay pinned by the shared
issueops suite and the dolt-side tests against the same implementation.
BEADS_TEST_EMBEDDED_DOLT=1: 5 RUN, all green, 2.8s.
* storage: scope the rename delete to the ids the sweep captured
An unrestricted DELETE ... WHERE label = ? makes the sweep's blast radius
engine-dependent: under current-read DELETE semantics a row a concurrent
AddLabel(oldLabel) committed after this transaction's snapshot would be
removed without ever being renamed, counted or journaled. Restricting the
delete to the captured ids touches exactly the rows the INSERT IGNORE above
accounted for on every engine; a concurrent add outside the snapshot now
deterministically SURVIVES the rename - the same observable state as that
add landing after the rename committed, which is the only order-independent
reading of the race.
sqlmock WithArgs pins the id-scoped statement shape; the embedded-Dolt
lifecycle set stays green (5/5).
* cmd/bd: add `bd label rename <old> <new>` with dry-run preview
Wire the storage.RenameLabel primitive (previous commit) into a CLI
command that renames a label everywhere it appears in one call instead
of a per-issue add-then-remove loop.
- cmd/bd/label.go: `bd label rename <old> <new> [--dry-run]`.
validateLabelRename refuses empty/identical labels and the
'provides:' reserved prefix before any store call - it is a pure
function so those rules are testable without a store. --dry-run
previews the blast radius (count plus the first issues) read-only,
via a path kept separate from the write path so it can never reach a
transaction.
- cmd/bd/label_proxied_server.go: the proxied-server route composes
the existing per-issue LabelUseCase.AddLabel/RemoveLabel (and wisp
twins) in one uow.RunTx, the same fan-out shape label propagate
already uses on this route. It journals as an add/remove pair per
issue rather than the direct route's single EventLabelRenamed,
because LabelUseCase has no rename-shaped event; the rename
semantics (merge-on-collision, honest zero-carrier no-op, dry-run
preview) are identical on both routes.
- docs/core-concepts/labels.md: documents rename, dry-run, and merge
semantics under Label Management.
Tests: cmd/bd/label_rename_test.go (pure argument-validation table
test, no store needed) plus new subtests in
cmd/bd/label_embedded_test.go covering the full CLI path - basic
rename, merge, dry-run writes nothing, zero-carrier no-op,
identical/empty/reserved-prefix refusals. All green.
Gates: gofmt clean, go vet ./... clean, CGO_ENABLED=0 go test -tags
gms_pure_go -c -o /dev/null ./cmd/bd clean, go build ./... clean.
* cmd/bd,domain: emit label_renamed on the proxied route, not add+remove
runLabelRenameProxiedServer used to fan a rename out into a per-issue
AddLabel-then-RemoveLabel pair, journaling label_added/label_removed
instead of one EventLabelRenamed - a divergence from the direct
DoltStore/EmbeddedDoltStore route the upstream reviewer has already
rejected for another PR touching the same class of proxied/direct
split.
Add domain.LabelUseCase.RenameLabel and domain.LabelSQLRepository.
RenameLabel. The repository method delegates straight to
issueops.RenameLabelInTx (r.runner satisfies issueops.DBTX
structurally), so the proxied route is not merely the same SQL SHAPE
as the direct one, it is the same function: identical merge semantics,
the same ErrRenameLabelSameName refusal, and one EventLabelRenamed per
touched issue. runLabelRenameProxiedServer now just calls
uw.LabelUseCase().RenameLabel(...) inside its existing uow.RunTx.
Declare recordingLabelUC.RenameLabel so the notifying unit of work
records one update per touched issue/wisp (mirroring
HookFiringStore.RenameLabel on the direct route) instead of silently
recording nothing through the embedded interface - caught by the
existing structural parity guard, TestRecordingLabelUseCaseCoversItsSurface,
which fails on any domain.LabelUseCase method neither declared on
recordingLabelUC nor exempted with a reason.
Tests, verified red->green:
- internal/storage/domain/db: TestLabelUseCase/RenameLabel adds 5
subtests. EmitsOneRenamedEventPerIssue is the direct regression
test - reverting RenameLabel to a simulated add-then-remove
fan-out reproduces exactly the pre-fix event counts (renamed=0,
added=2, removed=1) it now asserts against (renamed=1, added=1,
removed=0).
- cmd/bd/label_proxied_integration_test.go: new "rename" subtest
exercises `bd label rename` end to end through the real proxied
server and asserts the same label_renamed/added/removed counts
directly against the events table.
- internal/storage/uow: TestRecordingLabelUseCaseCoversItsSurface
goes red (RenameLabel inherited, records nothing) without the
recordingLabelUC override and green with it.
Full internal/storage/uow suite (287s) and the new domain/db and
cmd/bd tests all pass.
* cmd/bd: record commandDidWrite before the rename error return
runLabelRename read renamed>0 into commandDidWrite only after the
`if err != nil` early return, so a rename whose SQL side committed but
whose store call also returned an error - the Dolt publication step
failing after the working-set write landed - never marked the command
as having written. The caller's deferred auto-commit would then skip
creating a Dolt commit for a write that, on disk, actually happened.
Move the commandDidWrite.Store(true) check ahead of the error check,
matching applyLabelEdit's existing per-issue marking a few lines above
in the same file.
New test: TestRunLabelRename_CommandDidWriteSetBeforeErrorReturn wraps
a real *dolt.DoltStore in a spy whose RenameLabel reports a publish
failure (renamed>0, err!=nil) after delegating to the real rename, and
asserts commandDidWrite is set despite the returned error. Verified
red->green: reverting the ordering reproduces the exact failure this
guards against.
* bda-bnid: nolint:forbidigo on proxied bulk rename call
The route delegates to domain.LabelUseCase.RenameLabel deliberately: one
EventLabelRenamed per issue with identical merge semantics to the direct
route. Patch.Labels (the lint's suggested remedy) would reintroduce the
per-issue add/remove event divergence this delegation replaced. Matches
the file's own convention (4 sibling nolints, same shape).
Negative control: without the nolint golangci-lint forbidigo reports
exactly this line; with it, 0 issues.
* cmd/bd: address review on label rename (CHANGELOG entry, dry-run caveat, partial-failure count)
Two blocking items from review (bee-ghosttrack, PR #6009):
- Add the CHANGELOG entry for `bd label rename`, in the house voice used
by the neighboring bd-label entries (bold lead sentence, PR link, dense
explanatory prose on the merge/dry-run/partial-failure contract).
- The `--dry-run` merged count is a plain snapshot intersection of two
independent reads - exactly the check-then-count shape
renameLabelInPlane's own comment documents rejecting for the write
path, because it is schedule-dependent under a concurrent
AddLabel/RemoveLabel. That is an acceptable estimate for a preview, but
nothing said so: the command's Long text, the --dry-run flag help, and
an inline comment at the computation site now all say the number is
not authoritative.
One non-blocking nit fixed (the other - hydrating full issue rows in the
direct dry-run just to print 10 titles - is left alone; see below):
- On a partial rename failure (renamed>0, err!=nil - e.g. a Dolt
publication failure after the SQL side already committed) the command
now reports how many issues were renamed and merged before the
failure, instead of only the error. Mirrors the existing shape in
conflicts.go's ResolveConflictRows handling ("resolved %d of %d
conflict(s) before failing").
Left alone, and why: the GetIssuesByIDs-hydration nit. GetIssuesByLabel
hydrates every matching issue via GetIssuesByIDs on both the old-label
and new-label reads, which is wasteful on a label carrying 10k issues
when the text-mode preview only prints 10. But the JSON-mode contract
already returns every matching issue's id+title (not capped at the
preview limit), so avoiding hydration only helps the text-mode path and
would branch the two output modes apart for a marginal win on an
uncommon case (a rename dry-run over a 10k-issue label). Not clean
enough to do inline without its own test coverage and a decision about
whether the JSON contract should change too - flagged in the review as
skippable, so skipping it here.
Verification:
- go build ./... - clean
- go vet ./cmd/bd/... - clean
- gofmt -l cmd/bd/label.go - clean
- go test ./cmd/bd/... -run 'Label|LabelRename' - all pass
- BEADS_TEST_EMBEDDED_DOLT=1 go test ./cmd/bd/... -run 'TestEmbeddedLabel$' -v
- all pass, including label_rename_basic/merge/dry_run_writes_nothing
- BEADS_TEST_PROXIED_SERVER=1 BEADS_TEST_EMBEDDED_DOLT=1 go test ./cmd/bd/...
-run TestProxiedServerLabel -v - all pass, including the "rename" subtest
- BEADS_TEST_EMBEDDED_DOLT=1 go test ./internal/storage/issueops/... -run Rename -v
- BEADS_TEST_EMBEDDED_DOLT=1 go test ./internal/storage/dolt/... -run Rename -v (live dolt-sql-server)
- BEADS_TEST_EMBEDDED_DOLT=1 go test ./internal/storage/embeddeddolt/... -run Rename -v
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* cmd/bd: report an upper bound on a failed rename, not a landed count
The partial-failure message asserted that renamed>0 means the SQL side committed. On both routes the counts are assigned inside the transaction closure (label_proxied_server.go RunTx, dolt/labels.go withRetryTx), so a Commit failure or retry exhaustion returns them holding the rolled-back attempt numbers - nothing landed, and the user read 'renamed 6 issue(s) before failing'. Retry exhaustion under a busy server is the likely failure for a bulk rename, so it misreported exactly when it fired. Now reports an upper bound. commandDidWrite keeps the same premise deliberately: it is fail-safe in the other direction.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* cmd/bd: pin the partial-failure wording, and hedge the merged count too
Round-3 review: the r2 correction rode unpinned. Nothing in the suite drives
a failing rename with renamed > 0, so the whole TestEmbeddedLabel suite passed
with the hunk reverted - the fix was unfalsifiable, which is the same defect
class the correction itself was about.
Extracts the sentence into labelRenamePartialFailureMessage, a pure function a
test can assert on without inducing a mid-transaction failure, and pins it:
the hedged phrasings must be present AND the two pre-correction phrasings must
be absent. Mutation-checked - restoring the old wording turns it red on three
assertions.
Also the round-3 nit: (%d merged) was the one unhedged clause in a hedged
sentence. It now reads (of which up to %d merged), so no number in the message
asserts a write that may never have landed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* docs: retire the landed-count premise from the CHANGELOG too
Round-4 review, MAJOR: the code retracted a premise and the CHANGELOG kept
publishing it. The entry still said a partway failure 'reports how many issues
were renamed and merged before the failure' - a landed count - while
labelRenamePartialFailureMessage had already become an upper bound.
The sentence carried the premise TWICE and the review named one: besides the
count, its parenthetical offered 'a Dolt publication failure after the SQL side
already committed' as the case, when the whole point of the correction is that
renamed > 0 cannot distinguish that from a rollback. Rewrote both halves: the
bound is explicit, and the two failure shapes are named as indistinguishable
from the count alone.
Also round-4 MINOR: the helper had been inserted between reportLabelRename's
doc comment and its func, so the comment headed the wrong function and
reportLabelRename was left undocumented. Moved back down.
Not done, deliberately: the round-4 NIT that the pin covers the helper and not
the call site. It is marked 'noting, not asking', and an unrequested fix is the
one that ships a defect - this PR already demonstrated that.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* CHANGELOG: move this PR's entry under [Unreleased]
The 1.3.0 cut renamed the old [Unreleased] block, so these lines
merged cleanly into a released section (gastownhall/beads#6643).
Moved 31 line(s); the code is unchanged.
* cmd/bd: register label rename in the proxied capability registry
TestProxyCapabilityRegistryCoversCommandTree requires every command path to
carry a proxied-server row. label rename has a proxied route (RunE hands the
rename to runLabelRenameProxiedServer and the --dry-run preview to a proxied
read UOW), so it joins its label siblings in proxyPermittedPaths.
* storage: mint a version for every bead a label rename touches
TestEveryBeadMutatorMintsOrIsExempt (added with #6650) fails on this PR:
RenameLabelInTx writes the labels table but never reached
RecordVersionInTx. A rename changes the label set - part of the durable
snapshot - of every issue that carried oldLabel, whether it gained
newLabel or already had it (merge), so each touched issue now mints one
version row, the same gate AddLabelInTx/RemoveLabelInTx draw on a row
that landed. RecordVersionInTx is already a no-op for wisps and when
versioned history is disabled, and a rename nobody carries touches no
id, so the no-op shape mints nothing.
TestRenameLabelMintsOneVersionPerTouchedBead is the runtime twin of the
static guard: plain rename +1, merge +1, untouched bead +0, a second
rename with no carriers +0, current_revision equal to the row count.
* build(bazel): list this PR's six new test files in their go_test srcs
Generated-artifact drift repair, produced by the repository's own command
(`make bazel-sync`) and inspected before committing, not hand-written.
The PR adds six `_test.go` files and none were listed in their package's
`go_test` srcs, so Bazel compiled each of those packages' test targets without
them - green by omission. That was invisible on the pre-merge head because its
CI predates the Bazel lanes entirely (zero `Bazel /` rows). This merge brings in
e1b2e79484 (#6941), which makes those lanes feed the required gate, so the
omission would now surface as a real red.
Purely additive: 6 insertions, 0 deletions, `go_test` srcs only. No `go_library`
srcs change is needed because every added file is a test, which is also why this
cannot break the build the way a missing production source would.
Verified: `make bazel-sync` is now a no-op against this tree (empty porcelain),
and `bazel build //cmd/bd/... //internal/storage/... //internal/types/...
//internal/telemetry/...` completes successfully - 3429 actions, 0 errors.
---------
Co-authored-by: Marco Del Pin <marco@omniaevo.it>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
650 lines
22 KiB
Go
650 lines
22 KiB
Go
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
// bdLabel runs "bd label" with the given args and returns stdout.
|
|
func bdLabel(t *testing.T, bd, dir string, args ...string) string {
|
|
t.Helper()
|
|
fullArgs := append([]string{"label"}, args...)
|
|
cmd := exec.Command(bd, fullArgs...)
|
|
cmd.Dir = dir
|
|
cmd.Env = bdEnv(dir)
|
|
stdout, stderr, err := runCommandBuffers(t, cmd)
|
|
if err != nil {
|
|
t.Fatalf("bd label %s failed: %v\nstdout:\n%s\nstderr:\n%s", strings.Join(args, " "), err, stdout.String(), stderr.String())
|
|
}
|
|
return stdout.String()
|
|
}
|
|
|
|
func bdLabelJSONOutput(t *testing.T, bd, dir string, args ...string) string {
|
|
t.Helper()
|
|
fullArgs := append([]string{"label"}, args...)
|
|
cmd := exec.Command(bd, fullArgs...)
|
|
cmd.Dir = dir
|
|
cmd.Env = bdEnv(dir)
|
|
stdout, stderr, err := runCommandBuffers(t, cmd)
|
|
if err != nil {
|
|
t.Fatalf("bd label %s failed: %v\nstdout:\n%s\nstderr:\n%s",
|
|
strings.Join(args, " "), err, stdout.String(), stderr.String())
|
|
}
|
|
return stdout.String()
|
|
}
|
|
|
|
// bdLabelEditJSON runs "bd label <op> ... --json" and returns its result rows.
|
|
func bdLabelEditJSON(t *testing.T, bd, dir, op string, args ...string) []map[string]interface{} {
|
|
t.Helper()
|
|
s := strings.TrimSpace(bdLabelJSONOutput(t, bd, dir, append(append([]string{op}, args...), "--json")...))
|
|
start := strings.Index(s, "[")
|
|
if start < 0 {
|
|
t.Fatalf("no JSON array in label %s output: %s", op, s)
|
|
}
|
|
var rows []map[string]interface{}
|
|
if err := json.Unmarshal([]byte(s[start:]), &rows); err != nil {
|
|
t.Fatalf("parse label %s JSON: %v\nstdout: %s", op, err, s)
|
|
}
|
|
return rows
|
|
}
|
|
|
|
// bdLabelFail runs "bd label" expecting failure.
|
|
func bdLabelFail(t *testing.T, bd, dir string, args ...string) string {
|
|
t.Helper()
|
|
fullArgs := append([]string{"label"}, args...)
|
|
cmd := exec.Command(bd, fullArgs...)
|
|
cmd.Dir = dir
|
|
cmd.Env = bdEnv(dir)
|
|
out, err := cmd.CombinedOutput()
|
|
if err == nil {
|
|
t.Fatalf("expected bd label %s to fail, but succeeded:\n%s", strings.Join(args, " "), out)
|
|
}
|
|
return string(out)
|
|
}
|
|
|
|
// bdLabelListJSON runs "bd label list --json" and returns parsed labels.
|
|
func bdLabelListJSON(t *testing.T, bd, dir, issueID string) []string {
|
|
t.Helper()
|
|
s := strings.TrimSpace(bdLabelJSONOutput(t, bd, dir, "list", issueID, "--json"))
|
|
start := strings.Index(s, "[")
|
|
if start < 0 {
|
|
return nil
|
|
}
|
|
var labels []string
|
|
if err := json.Unmarshal([]byte(s[start:]), &labels); err != nil {
|
|
t.Fatalf("parse label list JSON: %v\nstdout: %s", err, s)
|
|
}
|
|
return labels
|
|
}
|
|
|
|
// bdLabelListAllJSON runs "bd label list-all --json" and returns parsed results.
|
|
func bdLabelListAllJSON(t *testing.T, bd, dir string) []map[string]interface{} {
|
|
t.Helper()
|
|
s := strings.TrimSpace(bdLabelJSONOutput(t, bd, dir, "list-all", "--json"))
|
|
start := strings.Index(s, "[")
|
|
if start < 0 {
|
|
return nil
|
|
}
|
|
var results []map[string]interface{}
|
|
if err := json.Unmarshal([]byte(s[start:]), &results); err != nil {
|
|
t.Fatalf("parse label list-all JSON: %v\nstdout: %s", err, s)
|
|
}
|
|
return results
|
|
}
|
|
|
|
func TestEmbeddedLabel(t *testing.T) {
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
|
|
}
|
|
t.Parallel()
|
|
|
|
bd := buildEmbeddedBD(t)
|
|
dir, _, _ := bdInit(t, bd, "--prefix", "tl")
|
|
|
|
// ===== Label Add =====
|
|
|
|
t.Run("label_add_single", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Label add test", "--type", "task")
|
|
out := bdLabel(t, bd, dir, "add", issue.ID, "urgent")
|
|
if !strings.Contains(out, "Added") {
|
|
t.Errorf("expected 'Added' in output: %s", out)
|
|
}
|
|
labels := bdLabelListJSON(t, bd, dir, issue.ID)
|
|
found := false
|
|
for _, l := range labels {
|
|
if l == "urgent" {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Errorf("expected 'urgent' in labels: %v", labels)
|
|
}
|
|
})
|
|
|
|
t.Run("label_add_batch", func(t *testing.T) {
|
|
issue1 := bdCreate(t, bd, dir, "Batch label 1", "--type", "task")
|
|
issue2 := bdCreate(t, bd, dir, "Batch label 2", "--type", "task")
|
|
bdLabel(t, bd, dir, "add", issue1.ID, issue2.ID, "batch-label")
|
|
|
|
for _, id := range []string{issue1.ID, issue2.ID} {
|
|
labels := bdLabelListJSON(t, bd, dir, id)
|
|
found := false
|
|
for _, l := range labels {
|
|
if l == "batch-label" {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Errorf("expected 'batch-label' on %s: %v", id, labels)
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("label_add_json", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Label JSON add", "--type", "task")
|
|
s := strings.TrimSpace(bdLabelJSONOutput(t, bd, dir, "add", issue.ID, "json-label", "--json"))
|
|
start := strings.Index(s, "[")
|
|
if start < 0 {
|
|
t.Fatalf("no JSON array in output: %s", s)
|
|
}
|
|
if !json.Valid([]byte(s[start:])) {
|
|
t.Errorf("expected valid JSON: %s", s)
|
|
}
|
|
})
|
|
|
|
t.Run("label_add_comma_separated_multi", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Multi label add", "--type", "task")
|
|
out := bdLabel(t, bd, dir, "add", issue.ID, "multi-a,multi-b,multi-c")
|
|
if !strings.Contains(out, "Added") {
|
|
t.Errorf("expected 'Added' in output: %s", out)
|
|
}
|
|
labels := bdLabelListJSON(t, bd, dir, issue.ID)
|
|
labelSet := map[string]bool{}
|
|
for _, l := range labels {
|
|
labelSet[l] = true
|
|
}
|
|
for _, want := range []string{"multi-a", "multi-b", "multi-c"} {
|
|
if !labelSet[want] {
|
|
t.Errorf("expected %q in labels: %v", want, labels)
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("label_remove_comma_separated_multi", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Multi label remove", "--type", "task",
|
|
"--label", "rm-a", "--label", "rm-b", "--label", "rm-keep")
|
|
bdLabel(t, bd, dir, "remove", issue.ID, "rm-a,rm-b")
|
|
labels := bdLabelListJSON(t, bd, dir, issue.ID)
|
|
for _, l := range labels {
|
|
if l == "rm-a" || l == "rm-b" {
|
|
t.Errorf("label %q should have been removed: %v", l, labels)
|
|
}
|
|
}
|
|
found := false
|
|
for _, l := range labels {
|
|
if l == "rm-keep" {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Errorf("expected 'rm-keep' to survive: %v", labels)
|
|
}
|
|
})
|
|
|
|
t.Run("label_add_duplicate_idempotent", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Dup label", "--type", "task")
|
|
bdLabel(t, bd, dir, "add", issue.ID, "dup")
|
|
bdLabel(t, bd, dir, "add", issue.ID, "dup")
|
|
labels := bdLabelListJSON(t, bd, dir, issue.ID)
|
|
count := 0
|
|
for _, l := range labels {
|
|
if l == "dup" {
|
|
count++
|
|
}
|
|
}
|
|
if count != 1 {
|
|
t.Errorf("expected exactly 1 'dup' label, got %d in %v", count, labels)
|
|
}
|
|
})
|
|
|
|
// ===== Label Remove =====
|
|
|
|
t.Run("label_remove", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Remove label", "--type", "task", "--label", "removeme")
|
|
bdLabel(t, bd, dir, "remove", issue.ID, "removeme")
|
|
labels := bdLabelListJSON(t, bd, dir, issue.ID)
|
|
for _, l := range labels {
|
|
if l == "removeme" {
|
|
t.Error("label should have been removed")
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("label_remove_batch", func(t *testing.T) {
|
|
issue1 := bdCreate(t, bd, dir, "Batch rm 1", "--type", "task", "--label", "batch-rm")
|
|
issue2 := bdCreate(t, bd, dir, "Batch rm 2", "--type", "task", "--label", "batch-rm")
|
|
bdLabel(t, bd, dir, "remove", issue1.ID, issue2.ID, "batch-rm")
|
|
for _, id := range []string{issue1.ID, issue2.ID} {
|
|
labels := bdLabelListJSON(t, bd, dir, id)
|
|
for _, l := range labels {
|
|
if l == "batch-rm" {
|
|
t.Errorf("label should have been removed from %s", id)
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("label_remove_json", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "JSON rm label", "--type", "task", "--label", "jsonrm")
|
|
cmd := exec.Command(bd, "label", "remove", issue.ID, "jsonrm", "--json")
|
|
cmd.Dir = dir
|
|
cmd.Env = bdEnv(dir)
|
|
stdout, stderr, err := runCommandBuffers(t, cmd)
|
|
if err != nil {
|
|
t.Fatalf("bd label remove --json failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout.String(), stderr.String())
|
|
}
|
|
s := strings.TrimSpace(stdout.String())
|
|
start := strings.Index(s, "[")
|
|
if start < 0 {
|
|
t.Fatalf("no JSON array in output:\nstdout: %s\nstderr: %s", s, stderr.String())
|
|
}
|
|
if !json.Valid([]byte(s[start:])) {
|
|
t.Errorf("expected valid JSON: %s", s)
|
|
}
|
|
})
|
|
|
|
// ===== No-op edits (GH#5988) =====
|
|
//
|
|
// A label edit that leaves the set as it was used to print the same
|
|
// "✓ Removed"/"✓ Added" line and JSON status as a real one. It still exits
|
|
// 0 (bdLabel fails the test otherwise), but it now says so.
|
|
|
|
t.Run("label_remove_absent_reports_noop", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Remove absent", "--type", "task", "--label", "present")
|
|
out := bdLabel(t, bd, dir, "remove", issue.ID, "never-applied")
|
|
if strings.Contains(out, "Removed") {
|
|
t.Errorf("remove of an absent label claimed a removal: %s", out)
|
|
}
|
|
if want := "Label 'never-applied' was not on " + issue.ID; !strings.Contains(out, want) {
|
|
t.Errorf("expected %q in output: %s", want, out)
|
|
}
|
|
rows := bdLabelEditJSON(t, bd, dir, "remove", issue.ID, "never-applied")
|
|
if len(rows) != 1 || rows[0]["status"] != "unchanged" || rows[0]["label"] != "never-applied" || rows[0]["issue_id"] != issue.ID {
|
|
t.Errorf("remove of an absent label JSON = %v, want one unchanged row", rows)
|
|
}
|
|
})
|
|
|
|
t.Run("label_add_present_reports_noop", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Add present", "--type", "task", "--label", "present")
|
|
out := bdLabel(t, bd, dir, "add", issue.ID, "present")
|
|
if strings.Contains(out, "Added") {
|
|
t.Errorf("add of a present label claimed an addition: %s", out)
|
|
}
|
|
if want := issue.ID + " already has label 'present'"; !strings.Contains(out, want) {
|
|
t.Errorf("expected %q in output: %s", want, out)
|
|
}
|
|
rows := bdLabelEditJSON(t, bd, dir, "add", issue.ID, "present")
|
|
if len(rows) != 1 || rows[0]["status"] != "unchanged" || rows[0]["label"] != "present" || rows[0]["issue_id"] != issue.ID {
|
|
t.Errorf("add of a present label JSON = %v, want one unchanged row", rows)
|
|
}
|
|
})
|
|
|
|
t.Run("label_edit_real_change_still_reported", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Real edit", "--type", "task")
|
|
if rows := bdLabelEditJSON(t, bd, dir, "add", issue.ID, "real"); len(rows) != 1 || rows[0]["status"] != "added" {
|
|
t.Errorf("real add JSON = %v, want one added row", rows)
|
|
}
|
|
if rows := bdLabelEditJSON(t, bd, dir, "remove", issue.ID, "real"); len(rows) != 1 || rows[0]["status"] != "removed" {
|
|
t.Errorf("real remove JSON = %v, want one removed row", rows)
|
|
}
|
|
if out := bdLabel(t, bd, dir, "add", issue.ID, "real"); !strings.Contains(out, "Added label 'real' to "+issue.ID) {
|
|
t.Errorf("real add text = %s", out)
|
|
}
|
|
if out := bdLabel(t, bd, dir, "remove", issue.ID, "real"); !strings.Contains(out, "Removed label 'real' from "+issue.ID) {
|
|
t.Errorf("real remove text = %s", out)
|
|
}
|
|
})
|
|
|
|
t.Run("label_edit_mixed_reports_each_label", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Mixed edit", "--type", "task", "--label", "have")
|
|
out := bdLabel(t, bd, dir, "add", issue.ID, "have,fresh")
|
|
if !strings.Contains(out, "Added label 'fresh' to "+issue.ID) || !strings.Contains(out, issue.ID+" already has label 'have'") {
|
|
t.Errorf("mixed add text = %s", out)
|
|
}
|
|
rows := bdLabelEditJSON(t, bd, dir, "remove", issue.ID, "have,ghost")
|
|
got := map[interface{}]interface{}{}
|
|
for _, r := range rows {
|
|
got[r["label"]] = r["status"]
|
|
}
|
|
if len(rows) != 2 || got["have"] != "removed" || got["ghost"] != "unchanged" {
|
|
t.Errorf("mixed remove JSON = %v, want have=removed ghost=unchanged", rows)
|
|
}
|
|
})
|
|
|
|
// One label, two issues, only one of which has it: the divergence is
|
|
// BETWEEN the issues, so this pins the per-issue derivation the way
|
|
// label_edit_mixed_reports_each_label pins the per-label one. The outcome
|
|
// is built inside the id loop from that id's own UpdateResult, and a
|
|
// refactor that hoisted it out — or reused the last result for every id —
|
|
// would print one identical line per issue again, which is what the
|
|
// pre-GH#5988 code did. Every other subtest here edits a single issue and
|
|
// so would pass such a refactor.
|
|
t.Run("label_edit_divergent_multi_issue", func(t *testing.T) {
|
|
fresh := bdCreate(t, bd, dir, "Divergent JSON fresh", "--type", "task")
|
|
holder := bdCreate(t, bd, dir, "Divergent JSON holder", "--type", "task", "--label", "shared")
|
|
rows := bdLabelEditJSON(t, bd, dir, "add", fresh.ID, holder.ID, "shared")
|
|
got := map[interface{}]interface{}{}
|
|
for _, r := range rows {
|
|
if r["label"] != "shared" {
|
|
t.Errorf("unexpected label in row %v", r)
|
|
}
|
|
got[r["issue_id"]] = r["status"]
|
|
}
|
|
if len(rows) != 2 || got[fresh.ID] != "added" || got[holder.ID] != "unchanged" {
|
|
t.Errorf("divergent multi-issue add JSON = %v, want %s=added %s=unchanged",
|
|
rows, fresh.ID, holder.ID)
|
|
}
|
|
|
|
// Same shape in the text report: one line per issue, each naming its
|
|
// own id, and the no-op issue must not be claimed as an edit.
|
|
freshText := bdCreate(t, bd, dir, "Divergent text fresh", "--type", "task")
|
|
holderText := bdCreate(t, bd, dir, "Divergent text holder", "--type", "task", "--label", "shared")
|
|
out := bdLabel(t, bd, dir, "add", freshText.ID, holderText.ID, "shared")
|
|
if want := "Added label 'shared' to " + freshText.ID; !strings.Contains(out, want) {
|
|
t.Errorf("expected %q in output: %s", want, out)
|
|
}
|
|
if want := holderText.ID + " already has label 'shared'"; !strings.Contains(out, want) {
|
|
t.Errorf("expected %q in output: %s", want, out)
|
|
}
|
|
if claim := "Added label 'shared' to " + holderText.ID; strings.Contains(out, claim) {
|
|
t.Errorf("add claimed an edit on the issue that already had the label: %s", out)
|
|
}
|
|
})
|
|
|
|
// ===== Label List =====
|
|
|
|
t.Run("label_list", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "List labels", "--type", "task", "--label", "alpha", "--label", "beta")
|
|
out := bdLabel(t, bd, dir, "list", issue.ID)
|
|
if !strings.Contains(out, "alpha") || !strings.Contains(out, "beta") {
|
|
t.Errorf("expected both labels in list output: %s", out)
|
|
}
|
|
})
|
|
|
|
t.Run("label_list_empty", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "No labels", "--type", "task")
|
|
labels := bdLabelListJSON(t, bd, dir, issue.ID)
|
|
if len(labels) != 0 {
|
|
t.Errorf("expected empty labels, got %v", labels)
|
|
}
|
|
})
|
|
|
|
t.Run("label_list_json", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "JSON list", "--type", "task", "--label", "x", "--label", "y")
|
|
labels := bdLabelListJSON(t, bd, dir, issue.ID)
|
|
labelSet := map[string]bool{}
|
|
for _, l := range labels {
|
|
labelSet[l] = true
|
|
}
|
|
if !labelSet["x"] || !labelSet["y"] {
|
|
t.Errorf("expected labels x and y, got %v", labels)
|
|
}
|
|
})
|
|
|
|
// ===== Label List-All =====
|
|
|
|
t.Run("label_list_all", func(t *testing.T) {
|
|
out := bdLabel(t, bd, dir, "list-all")
|
|
// Should show some labels from earlier tests
|
|
if !strings.Contains(out, "urgent") {
|
|
t.Logf("list-all output may not contain 'urgent': %s", out)
|
|
}
|
|
})
|
|
|
|
t.Run("label_list_all_json", func(t *testing.T) {
|
|
results := bdLabelListAllJSON(t, bd, dir)
|
|
if len(results) == 0 {
|
|
t.Error("expected labels in list-all")
|
|
}
|
|
// Each result should have label and count
|
|
for _, r := range results {
|
|
if _, ok := r["label"]; !ok {
|
|
t.Error("expected 'label' key in list-all result")
|
|
}
|
|
if _, ok := r["count"]; !ok {
|
|
t.Error("expected 'count' key in list-all result")
|
|
}
|
|
}
|
|
})
|
|
|
|
// ===== Label Propagate =====
|
|
|
|
t.Run("label_propagate", func(t *testing.T) {
|
|
parent := bdCreate(t, bd, dir, "Propagate parent", "--type", "epic")
|
|
child1 := bdCreate(t, bd, dir, "Propagate child 1", "--type", "task")
|
|
child2 := bdCreate(t, bd, dir, "Propagate child 2", "--type", "task")
|
|
bdDepAdd(t, bd, dir, child1.ID, parent.ID, "--type", "parent-child")
|
|
bdDepAdd(t, bd, dir, child2.ID, parent.ID, "--type", "parent-child")
|
|
|
|
out := bdLabel(t, bd, dir, "propagate", parent.ID, "team:platform")
|
|
if !strings.Contains(out, "Propagated") {
|
|
t.Errorf("expected 'Propagated' in output: %s", out)
|
|
}
|
|
|
|
// Verify children got the label
|
|
for _, id := range []string{child1.ID, child2.ID} {
|
|
labels := bdLabelListJSON(t, bd, dir, id)
|
|
found := false
|
|
for _, l := range labels {
|
|
if l == "team:platform" {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Errorf("expected 'team:platform' on child %s: %v", id, labels)
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("label_propagate_json", func(t *testing.T) {
|
|
parent := bdCreate(t, bd, dir, "JSON propagate", "--type", "epic")
|
|
child := bdCreate(t, bd, dir, "JSON prop child", "--type", "task")
|
|
bdDepAdd(t, bd, dir, child.ID, parent.ID, "--type", "parent-child")
|
|
|
|
s := strings.TrimSpace(bdLabelJSONOutput(t, bd, dir, "propagate", parent.ID, "prop-json", "--json"))
|
|
start := strings.Index(s, "[")
|
|
if start >= 0 && !json.Valid([]byte(s[start:])) {
|
|
t.Errorf("expected valid JSON: %s", s)
|
|
}
|
|
})
|
|
|
|
t.Run("label_propagate_no_children", func(t *testing.T) {
|
|
parent := bdCreate(t, bd, dir, "No children parent", "--type", "task")
|
|
out := bdLabel(t, bd, dir, "propagate", parent.ID, "orphan-label")
|
|
if !strings.Contains(out, "No children") {
|
|
t.Logf("propagate with no children: %s", out)
|
|
}
|
|
})
|
|
|
|
// ===== Label Rename =====
|
|
|
|
t.Run("label_rename_basic", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Rename basic", "--type", "task", "--label", "backend")
|
|
out := bdLabel(t, bd, dir, "rename", "backend", "server")
|
|
if !strings.Contains(out, "Renamed") {
|
|
t.Errorf("expected 'Renamed' in output: %s", out)
|
|
}
|
|
labels := bdLabelListJSON(t, bd, dir, issue.ID)
|
|
if len(labels) != 1 || labels[0] != "server" {
|
|
t.Errorf("expected labels [server], got %v", labels)
|
|
}
|
|
})
|
|
|
|
t.Run("label_rename_merge", func(t *testing.T) {
|
|
onlyOld := bdCreate(t, bd, dir, "Rename merge only-old", "--type", "task", "--label", "wip-r")
|
|
both := bdCreate(t, bd, dir, "Rename merge both", "--type", "task",
|
|
"--label", "wip-r", "--label", "in-progress-r")
|
|
|
|
out := bdLabel(t, bd, dir, "rename", "wip-r", "in-progress-r")
|
|
if !strings.Contains(out, "Renamed") {
|
|
t.Errorf("expected 'Renamed' in output: %s", out)
|
|
}
|
|
|
|
labels := bdLabelListJSON(t, bd, dir, onlyOld.ID)
|
|
if len(labels) != 1 || labels[0] != "in-progress-r" {
|
|
t.Errorf("only-old: expected [in-progress-r], got %v", labels)
|
|
}
|
|
labels = bdLabelListJSON(t, bd, dir, both.ID)
|
|
if len(labels) != 1 || labels[0] != "in-progress-r" {
|
|
t.Errorf("both: expected exactly [in-progress-r] (no duplicate), got %v", labels)
|
|
}
|
|
})
|
|
|
|
t.Run("label_rename_dry_run_writes_nothing", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Rename dry run", "--type", "task", "--label", "dry-old")
|
|
out := bdLabel(t, bd, dir, "rename", "dry-old", "dry-new", "--dry-run")
|
|
if !strings.Contains(out, "Would rename") {
|
|
t.Errorf("expected 'Would rename' in dry-run output: %s", out)
|
|
}
|
|
labels := bdLabelListJSON(t, bd, dir, issue.ID)
|
|
if len(labels) != 1 || labels[0] != "dry-old" {
|
|
t.Errorf("dry-run must not write: expected [dry-old] unchanged, got %v", labels)
|
|
}
|
|
})
|
|
|
|
t.Run("label_rename_zero_carrier_is_honest_noop", func(t *testing.T) {
|
|
out := bdLabel(t, bd, dir, "rename", "no-such-label-anywhere", "irrelevant")
|
|
if !strings.Contains(out, "No issues found") {
|
|
t.Errorf("expected 'No issues found' for a zero-carrier rename: %s", out)
|
|
}
|
|
})
|
|
|
|
t.Run("label_rename_identical_fails", func(t *testing.T) {
|
|
bdLabelFail(t, bd, dir, "rename", "same-label", "same-label")
|
|
})
|
|
|
|
t.Run("label_rename_empty_fails", func(t *testing.T) {
|
|
bdLabelFail(t, bd, dir, "rename", "", "new-name")
|
|
})
|
|
|
|
t.Run("label_rename_reserved_provides_fails", func(t *testing.T) {
|
|
bdLabelFail(t, bd, dir, "rename", "plain-label", "provides:auth")
|
|
})
|
|
|
|
// ===== Error Cases =====
|
|
|
|
t.Run("label_add_empty_label", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Empty label", "--type", "task")
|
|
bdLabelFail(t, bd, dir, "add", issue.ID, "")
|
|
})
|
|
|
|
t.Run("label_add_reserved_provides", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Reserved label", "--type", "task")
|
|
bdLabelFail(t, bd, dir, "add", issue.ID, "provides:auth")
|
|
})
|
|
|
|
t.Run("label_add_reserved_provides_in_comma_list", func(t *testing.T) {
|
|
issue := bdCreate(t, bd, dir, "Reserved label in list", "--type", "task")
|
|
bdLabelFail(t, bd, dir, "add", issue.ID, "ok-label,provides:auth")
|
|
})
|
|
|
|
t.Run("label_add_unresolvable_id_fails", func(t *testing.T) {
|
|
bdLabelFail(t, bd, dir, "add", "tl-doesnotexist", "some-label")
|
|
})
|
|
|
|
t.Run("label_add_space_separated_labels_fails_loudly", func(t *testing.T) {
|
|
// Regression test for bd-vu5kv: "bd label add <id> a b c" used to
|
|
// treat a/b as unresolvable issue IDs, skip them with a stderr
|
|
// warning, and exit 0 having applied only "c". It must now fail
|
|
// hard, apply nothing, and hint at the comma-separated form.
|
|
issue := bdCreate(t, bd, dir, "Space separated labels", "--type", "task")
|
|
out := bdLabelFail(t, bd, dir, "add", issue.ID, "space-a", "space-b", "space-c")
|
|
if !strings.Contains(out, "comma-separated") {
|
|
t.Errorf("expected comma-separated hint in error output: %s", out)
|
|
}
|
|
labels := bdLabelListJSON(t, bd, dir, issue.ID)
|
|
for _, l := range labels {
|
|
if strings.HasPrefix(l, "space-") {
|
|
t.Errorf("no label should have been applied, found %q: %v", l, labels)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
// TestEmbeddedLabelConcurrent exercises label operations concurrently.
|
|
func TestEmbeddedLabelConcurrent(t *testing.T) {
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
|
|
}
|
|
t.Parallel()
|
|
|
|
bd := buildEmbeddedBD(t)
|
|
dir, _, _ := bdInit(t, bd, "--prefix", "lx")
|
|
|
|
const numWorkers = 8
|
|
|
|
// Pre-create issues
|
|
var issueIDs []string
|
|
for i := 0; i < numWorkers; i++ {
|
|
issue := bdCreate(t, bd, dir, fmt.Sprintf("label-concurrent-%d", i), "--type", "task")
|
|
issueIDs = append(issueIDs, issue.ID)
|
|
}
|
|
|
|
type workerResult struct {
|
|
worker int
|
|
err error
|
|
}
|
|
|
|
results := make([]workerResult, numWorkers)
|
|
var wg sync.WaitGroup
|
|
wg.Add(numWorkers)
|
|
|
|
for w := 0; w < numWorkers; w++ {
|
|
go func(worker int) {
|
|
defer wg.Done()
|
|
r := workerResult{worker: worker}
|
|
id := issueIDs[worker]
|
|
|
|
// Add labels
|
|
for i := 0; i < 3; i++ {
|
|
label := fmt.Sprintf("w%d-label-%d", worker, i)
|
|
cmd := exec.Command(bd, "label", "add", id, label)
|
|
cmd.Dir = dir
|
|
cmd.Env = bdEnv(dir)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
r.err = fmt.Errorf("add label %s to %s: %v\n%s", label, id, err, out)
|
|
results[worker] = r
|
|
return
|
|
}
|
|
}
|
|
|
|
// List labels
|
|
cmd := exec.Command(bd, "label", "list", id, "--json")
|
|
cmd.Dir = dir
|
|
cmd.Env = bdEnv(dir)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
r.err = fmt.Errorf("list labels for %s: %v\n%s", id, err, out)
|
|
results[worker] = r
|
|
return
|
|
}
|
|
|
|
results[worker] = r
|
|
}(w)
|
|
}
|
|
wg.Wait()
|
|
|
|
for _, r := range results {
|
|
if r.err != nil && !strings.Contains(r.err.Error(), "one writer at a time") {
|
|
t.Errorf("worker %d failed: %v", r.worker, r.err)
|
|
}
|
|
}
|
|
}
|