Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Eddie the Engineer
0520516fb0 fix(defer): resolve bd defer/undefer IDs once (mc-qec7j)
On the non-proxied path, bd defer and bd undefer resolved every argument
twice: an all-arguments utils.ResolvePartialIDs pre-pass whose result has
been discarded since the daemon removal (6a51223b6f), then a per-argument
utils.ResolvePartialID inside the write loop. Since #6302 the resolver
prints a stderr notice whenever it expands an abbreviation, so
`bd defer <abbrev>` and `bd undefer <abbrev>` printed that notice twice.

Keep the pre-pass and loop over its result. The pre-pass is what makes
one unresolvable argument abort the command with exit 1 before any
write; deleting it instead would turn `bd defer <ok> <missing>` into a
partial write that exits 0. The loop's "Error resolving" branch goes
with the second resolution: after a successful pre-pass it could fire
only if the workspace changed between the two calls.

Tests: a partial-ID subtest in TestEmbeddedDefer and TestEmbeddedUndefer
counts the notice (twice before the fix, once after) and pins the abort:
an unresolvable second argument fails the command and leaves the first
issue unchanged. Both subtests also fail against the delete-the-pre-pass
alternative.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 17:39:06 +00:00
4 changed files with 77 additions and 16 deletions

View file

@ -82,7 +82,10 @@ Examples:
ctx := rootCtx
_, err := utils.ResolvePartialIDs(ctx, store, args)
// Resolve every argument before any write so one bad ID aborts the
// command. The loop reuses these IDs: resolving again would repeat
// the partial-ID notice (mc-qec7j).
resolvedIDs, err := utils.ResolvePartialIDs(ctx, store, args)
if err != nil {
return HandleError("%v", err)
}
@ -93,13 +96,7 @@ Examples:
return HandleErrorWithHint("database not initialized", diagHint())
}
for _, id := range args {
fullID, err := utils.ResolvePartialID(ctx, store, id)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
continue
}
for _, fullID := range resolvedIDs {
updates := map[string]interface{}{
"status": string(types.StatusDeferred),
}

View file

@ -40,6 +40,18 @@ func bdUndefer(t *testing.T, bd, dir string, args ...string) string {
return stdout.String()
}
// bdStderrAllowError runs bd with the given args and returns stderr and the
// exit error without failing the test. BD_NO_PARTIAL_ID_NOTICE is dropped so
// an inherited opt-out cannot hide the partial-ID notice a caller counts.
func bdStderrAllowError(t *testing.T, bd, dir string, args ...string) (string, error) {
t.Helper()
cmd := exec.Command(bd, args...)
cmd.Dir = dir
cmd.Env = envWithout(bdEnv(dir), "BD_NO_PARTIAL_ID_NOTICE")
_, stderr, err := runCommandBuffers(t, cmd)
return stderr.String(), err
}
// getIssueStatus returns the status of an issue via bd show --json.
func getIssueStatus(t *testing.T, bd, dir, id string) string {
t.Helper()
@ -140,6 +152,33 @@ func TestEmbeddedDefer(t *testing.T) {
t.Errorf("expected 'Deferred' on second defer: %s", out)
}
})
// ===== Partial ID (mc-qec7j) =====
t.Run("defer_partial_id_notice_once", func(t *testing.T) {
// An explicit ID keeps the abbreviation unambiguous in this workspace.
issue := bdCreate(t, bd, dir, "Defer partial ID", "--type", "task", "--id", "df-qec7jnotice")
// Every argument is resolved before any write, so one unresolvable
// argument still aborts the whole command.
if stderr, err := bdStderrAllowError(t, bd, dir, "defer", "qec7jnot", "df-qec7jmissing"); err == nil {
t.Errorf("bd defer with an unresolvable ID succeeded; want a non-zero exit\nstderr:\n%s", stderr)
}
if status := getIssueStatus(t, bd, dir, issue.ID); status != "open" {
t.Errorf("aborted bd defer changed %s to %q; want it left open", issue.ID, status)
}
stderr, err := bdStderrAllowError(t, bd, dir, "defer", "qec7jnot")
if err != nil {
t.Fatalf("bd defer qec7jnot failed: %v\nstderr:\n%s", err, stderr)
}
if n := strings.Count(stderr, `"qec7jnot" is not an exact issue ID`); n != 1 {
t.Errorf("partial-ID notice printed %d times; want exactly once\nstderr:\n%s", n, stderr)
}
if status := getIssueStatus(t, bd, dir, issue.ID); status != "deferred" {
t.Errorf("expected status=deferred, got %q", status)
}
})
}
// TestEmbeddedDeferConcurrent exercises defer operations concurrently.

View file

@ -45,7 +45,10 @@ Examples:
ctx := rootCtx
_, err := utils.ResolvePartialIDs(ctx, store, args)
// Resolve every argument before any write so one bad ID aborts the
// command. The loop reuses these IDs: resolving again would repeat
// the partial-ID notice (mc-qec7j).
resolvedIDs, err := utils.ResolvePartialIDs(ctx, store, args)
if err != nil {
return HandleError("%v", err)
}
@ -56,13 +59,7 @@ Examples:
return HandleErrorWithHint("database not initialized", diagHint())
}
for _, id := range args {
fullID, err := utils.ResolvePartialID(ctx, store, id)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
continue
}
for _, fullID := range resolvedIDs {
issue, err := store.GetIssue(ctx, fullID)
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting %s: %v\n", fullID, err)

View file

@ -142,6 +142,34 @@ func TestEmbeddedUndefer(t *testing.T) {
t.Errorf("expected defer_until cleared after undefer, got %v", deferUntil)
}
})
// ===== Partial ID (mc-qec7j) =====
t.Run("undefer_partial_id_notice_once", func(t *testing.T) {
// An explicit ID keeps the abbreviation unambiguous in this workspace.
issue := bdCreate(t, bd, dir, "Undefer partial ID", "--type", "task", "--id", "ud-qec7jnotice")
bdDefer(t, bd, dir, issue.ID)
// Every argument is resolved before any write, so one unresolvable
// argument still aborts the whole command.
if stderr, err := bdStderrAllowError(t, bd, dir, "undefer", "qec7jnot", "ud-qec7jmissing"); err == nil {
t.Errorf("bd undefer with an unresolvable ID succeeded; want a non-zero exit\nstderr:\n%s", stderr)
}
if s := getIssueStatus(t, bd, dir, issue.ID); s != "deferred" {
t.Errorf("aborted bd undefer changed %s to %q; want it left deferred", issue.ID, s)
}
stderr, err := bdStderrAllowError(t, bd, dir, "undefer", "qec7jnot")
if err != nil {
t.Fatalf("bd undefer qec7jnot failed: %v\nstderr:\n%s", err, stderr)
}
if n := strings.Count(stderr, `"qec7jnot" is not an exact issue ID`); n != 1 {
t.Errorf("partial-ID notice printed %d times; want exactly once\nstderr:\n%s", n, stderr)
}
if s := getIssueStatus(t, bd, dir, issue.ID); s != "open" {
t.Errorf("expected status=open after undefer, got %q", s)
}
})
}
// TestEmbeddedUndeferConcurrent exercises undefer operations concurrently.