fix(defer): undefer clears a stray defer_until when status isn't deferred (ga-bq3w5) (#6390)
* fix(defer): undefer clears a stray defer_until when status isn't deferred (ga-bq3w5) `bd undefer` gated entirely on issue.Status == StatusDeferred. But the ready-work query hides any issue whose defer_until is in the future regardless of status, so `bd update <id> --status open --defer <date>` (an explicit --status wins over --defer's own status=deferred default) leaves status=open with a live defer_until: permanently invisible to `bd ready`, with no command able to clear it. `bd undefer` refused with a technically-true, practically-misleading "is not deferred (status: open)" and never touched the timestamp actually doing the hiding. Gate on defer_until instead of status alone: only flip status to open when the issue really was deferred (mirrors the guard GH#3233 already gave `bd update --defer=""`), but always clear a stray defer_until so the issue can return to `bd ready`. Adds a regression test reproducing the exact shape (status=open + future defer_until via a single `bd update --status open --defer ...` call). Confirmed it fails against the pre-fix code and passes with the fix. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * fix(defer): mirror the undefer defer_until fix to the proxied-server route (ga-bq3w5) PR review (bee-ghosttrack, round 1): the previous fix only patched the embedded backend (undefer.go). runUndeferProxiedServer, used by proxied-server/beads-team-server installs, still gated solely on status == deferred and still overwrote status unconditionally — the exact bug survives on that route, and CI treats it as first-class (15 green Proxied Dolt Cmd shards). Mirror the same gate/write shape into defer_proxied_server.go: only refuse when status isn't deferred AND there's no defer_until to clear; only flip status to open when the issue really was deferred. Also closes the reviewer's MINOR finding: the existing "open" fixture can't distinguish the conditional status write from an unconditional one (writing status=open to an already-open issue is a no-op). Adds an in_progress case to both the embedded and the new proxied test — confirmed by mutation that it fails against the unconditional-write code and passes with the fix. Shortens the undefer.go rationale comment and documents the clear-without-clobbering behavior in the command's Long description, per the reviewer's non-blocking nits. Verified: go build/vet clean; gofmt clean; golangci-lint (native) 0 issues; BEADS_TEST_EMBEDDED_DOLT=1 go test -run TestEmbeddedUndefer all 5 subtests PASS. The new proxied-server subtest could not be executed in this sandbox (no Docker available for the shared Dolt container), but go vet confirms it compiles and type-checks, and it mirrors the embedded test byte-for-byte in structure. The windows cross-lint step in `make ci-pr-lint` fails in this sandbox on files untouched by this diff (confirmed byte-identical to origin/main) — a pre-existing local environment gap, not a regression. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
147047e153
commit
fc2351a51c
4 changed files with 146 additions and 7 deletions
|
|
@ -92,6 +92,37 @@ func TestProxiedServerDeferUndefer(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("undefer_clears_stray_defer_until_when_status_not_deferred", func(t *testing.T) {
|
||||
// Mirrors TestEmbeddedUndefer's ga-bq3w5 coverage on the proxied-server
|
||||
// route (runUndeferProxiedServer): a status that is neither "open" nor
|
||||
// "deferred" makes the conditional status write observable — writing
|
||||
// status=open here would be a real change, not a no-op.
|
||||
j := bdProxiedCreate(t, bd, p.dir, "Stray future defer on in_progress issue", "--type", "task")
|
||||
if out, err := bdProxiedRun(t, bd, p.dir, "update", j.ID, "--status", "in_progress", "--defer", "2099-01-01"); err != nil {
|
||||
t.Fatalf("update --status in_progress --defer: %v\n%s", err, out)
|
||||
}
|
||||
status, deferUntil := showStatus(t, j.ID)
|
||||
if status != string(types.StatusInProgress) || deferUntil == nil {
|
||||
t.Fatalf("precondition: expected status=in_progress with defer_until set, got status=%q defer_until=%v", status, deferUntil)
|
||||
}
|
||||
|
||||
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, "undefer", j.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("undefer: %v\nstdout=%s\nstderr=%s", err, stdout, stderr)
|
||||
}
|
||||
if strings.Contains(stdout+stderr, "is not deferred") {
|
||||
t.Errorf("undefer refused instead of clearing the stray defer_until: stdout=%s stderr=%s", stdout, stderr)
|
||||
}
|
||||
|
||||
status, deferUntil = showStatus(t, j.ID)
|
||||
if status != string(types.StatusInProgress) {
|
||||
t.Errorf("expected status to stay in_progress (not clobbered to open), got %q", status)
|
||||
}
|
||||
if deferUntil != nil {
|
||||
t.Errorf("expected defer_until cleared after undefer, got %v", deferUntil)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("defer_is_idempotent", func(t *testing.T) {
|
||||
d := bdProxiedCreate(t, bd, p.dir, "Idempotent defer", "--type", "task")
|
||||
if out, err := bdProxiedRun(t, bd, p.dir, "defer", d.ID); err != nil {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,12 @@ import (
|
|||
type deferProxiedResult struct {
|
||||
issues []*types.Issue
|
||||
errs []string
|
||||
|
||||
// wasDeferred tracks, in lockstep with issues, whether each undeferred
|
||||
// issue was actually status=deferred (status flips to open) versus just
|
||||
// carrying a stray defer_until on some other status (status untouched,
|
||||
// only the timestamp cleared — ga-bq3w5). Unused by runDeferProxiedServer.
|
||||
wasDeferred []bool
|
||||
}
|
||||
|
||||
func proxiedUpdateByID(ctx context.Context, uw uow.UnitOfWork, id string, isWisp bool, updates map[string]any) error {
|
||||
|
|
@ -125,21 +131,29 @@ func runUndeferProxiedServer(ctx context.Context, args []string) error {
|
|||
continue
|
||||
}
|
||||
fullID := issue.ID
|
||||
if issue.Status != types.StatusDeferred {
|
||||
|
||||
// Gate on defer_until, not status alone (ga-bq3w5) — mirrors the
|
||||
// embedded-backend fix in undefer.go. See that file's comment for
|
||||
// the full rationale.
|
||||
wasDeferred := issue.Status == types.StatusDeferred
|
||||
if !wasDeferred && issue.DeferUntil == nil {
|
||||
r.errs = append(r.errs, fmt.Sprintf("%s is not deferred (status: %s)", fullID, string(issue.Status)))
|
||||
continue
|
||||
}
|
||||
|
||||
updates := map[string]interface{}{
|
||||
"status": string(types.StatusOpen),
|
||||
"defer_until": nil,
|
||||
}
|
||||
if wasDeferred {
|
||||
updates["status"] = string(types.StatusOpen)
|
||||
}
|
||||
if uerr := proxiedUpdateByID(ctx, uw, fullID, isWisp, updates); uerr != nil {
|
||||
r.errs = append(r.errs, fmt.Sprintf("Error undeferring %s: %v", fullID, uerr))
|
||||
continue
|
||||
}
|
||||
if updated := proxiedGetByID(ctx, uw, fullID, isWisp); updated != nil {
|
||||
r.issues = append(r.issues, updated)
|
||||
r.wasDeferred = append(r.wasDeferred, wasDeferred)
|
||||
}
|
||||
}
|
||||
if len(r.issues) == 0 {
|
||||
|
|
@ -162,8 +176,12 @@ func runUndeferProxiedServer(ctx context.Context, args []string) error {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
for _, iss := range res.issues {
|
||||
fmt.Printf("%s Undeferred %s (now open)\n", ui.RenderPass("*"), iss.ID)
|
||||
for i, iss := range res.issues {
|
||||
if i < len(res.wasDeferred) && res.wasDeferred[i] {
|
||||
fmt.Printf("%s Undeferred %s (now open)\n", ui.RenderPass("*"), iss.ID)
|
||||
} else {
|
||||
fmt.Printf("%s Cleared stale defer_until on %s (status unchanged: %s)\n", ui.RenderPass("*"), iss.ID, string(iss.Status))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ var undeferCmd = &cobra.Command{
|
|||
This brings issues back from the icebox so they can be worked on again.
|
||||
Issues will appear in 'bd ready' if they have no blockers.
|
||||
|
||||
If an issue carries a defer_until timestamp but its status isn't
|
||||
"deferred" (e.g. after an explicit --status change), undefer clears
|
||||
the stray timestamp without touching status.
|
||||
|
||||
Examples:
|
||||
bd undefer bd-abc # Undefer a single issue
|
||||
bd undefer bd-abc bd-def # Undefer multiple issues`,
|
||||
|
|
@ -64,15 +68,26 @@ Examples:
|
|||
fmt.Fprintf(os.Stderr, "Error getting %s: %v\n", fullID, err)
|
||||
continue
|
||||
}
|
||||
if issue.Status != types.StatusDeferred {
|
||||
|
||||
// Gate on defer_until, not status alone (ga-bq3w5): bd ready hides
|
||||
// any issue with a future defer_until regardless of status, so
|
||||
// `bd update <id> --status open --defer <date>` leaves a status=open
|
||||
// issue permanently invisible with no status-based signal anywhere.
|
||||
// Mirrors GH#3233's `bd update --defer=""` gate (update.go): only
|
||||
// flip status to open when it was actually "deferred" — other
|
||||
// statuses shouldn't be clobbered just to clear a stray timestamp.
|
||||
wasDeferred := issue.Status == types.StatusDeferred
|
||||
if !wasDeferred && issue.DeferUntil == nil {
|
||||
fmt.Fprintf(os.Stderr, "%s is not deferred (status: %s)\n", fullID, string(issue.Status))
|
||||
continue
|
||||
}
|
||||
|
||||
updates := map[string]interface{}{
|
||||
"status": string(types.StatusOpen),
|
||||
"defer_until": nil,
|
||||
}
|
||||
if wasDeferred {
|
||||
updates["status"] = string(types.StatusOpen)
|
||||
}
|
||||
|
||||
if err := store.UpdateIssue(ctx, fullID, updates, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error undeferring %s: %v\n", fullID, err)
|
||||
|
|
@ -84,8 +99,10 @@ Examples:
|
|||
if issue != nil {
|
||||
undeferredIssues = append(undeferredIssues, issue)
|
||||
}
|
||||
} else {
|
||||
} else if wasDeferred {
|
||||
fmt.Printf("%s Undeferred %s (now open)\n", ui.RenderPass("*"), fullID)
|
||||
} else {
|
||||
fmt.Printf("%s Cleared stale defer_until on %s (status unchanged: %s)\n", ui.RenderPass("*"), fullID, string(issue.Status))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,79 @@ func TestEmbeddedUndefer(t *testing.T) {
|
|||
t.Errorf("expected 'not deferred' message: %s", out)
|
||||
}
|
||||
})
|
||||
|
||||
// ===== Stray defer_until on a non-deferred status (ga-bq3w5) =====
|
||||
|
||||
t.Run("undefer_clears_stray_defer_until_when_status_not_deferred", func(t *testing.T) {
|
||||
issue := bdCreate(t, bd, dir, "Stray future defer on open issue", "--type", "task")
|
||||
// Reproduces ga-bq3w5: an explicit --status wins over --defer's own
|
||||
// status=deferred default (update.go), so this single command leaves
|
||||
// status=open with a live future defer_until — exactly the shape that
|
||||
// silently starves an issue out of `bd ready` with no status-based
|
||||
// signal anywhere.
|
||||
cmd := exec.Command(bd, "update", issue.ID, "--status", "open", "--defer", "2099-01-01")
|
||||
cmd.Dir = dir
|
||||
cmd.Env = bdEnv(dir)
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("bd update --status open --defer failed: %v\n%s", err, out)
|
||||
}
|
||||
status, deferUntil := showDeferState(t, bd, dir, issue.ID)
|
||||
if status != "open" || deferUntil == nil {
|
||||
t.Fatalf("precondition: expected status=open with defer_until set, got status=%q defer_until=%v", status, deferUntil)
|
||||
}
|
||||
if ids := wakeReadyIDs(t, bd, dir); ids[issue.ID] {
|
||||
t.Fatalf("precondition: issue should be hidden from bd ready by its future defer_until")
|
||||
}
|
||||
|
||||
out := bdUndefer(t, bd, dir, issue.ID)
|
||||
if strings.Contains(out, "is not deferred") {
|
||||
t.Errorf("undefer refused instead of clearing the stray defer_until: %s", out)
|
||||
}
|
||||
|
||||
status, deferUntil = showDeferState(t, bd, dir, issue.ID)
|
||||
if status != "open" {
|
||||
t.Errorf("expected status to stay open, got %q", status)
|
||||
}
|
||||
if deferUntil != nil {
|
||||
t.Errorf("expected defer_until cleared after undefer, got %v", deferUntil)
|
||||
}
|
||||
if ids := wakeReadyIDs(t, bd, dir); !ids[issue.ID] {
|
||||
t.Errorf("expected issue back in bd ready after undefer cleared its defer_until")
|
||||
}
|
||||
})
|
||||
|
||||
// ===== Stray defer_until on a non-open status must not be clobbered =====
|
||||
|
||||
t.Run("undefer_clears_stray_defer_until_without_clobbering_in_progress", func(t *testing.T) {
|
||||
// The "open" case above can't distinguish the conditional status
|
||||
// write (only flip to open when wasDeferred) from an unconditional
|
||||
// one: writing status=open to an already-open issue is a no-op.
|
||||
// in_progress makes the distinction observable.
|
||||
issue := bdCreate(t, bd, dir, "Stray future defer on in_progress issue", "--type", "task")
|
||||
cmd := exec.Command(bd, "update", issue.ID, "--status", "in_progress", "--defer", "2099-01-01")
|
||||
cmd.Dir = dir
|
||||
cmd.Env = bdEnv(dir)
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("bd update --status in_progress --defer failed: %v\n%s", err, out)
|
||||
}
|
||||
status, deferUntil := showDeferState(t, bd, dir, issue.ID)
|
||||
if status != "in_progress" || deferUntil == nil {
|
||||
t.Fatalf("precondition: expected status=in_progress with defer_until set, got status=%q defer_until=%v", status, deferUntil)
|
||||
}
|
||||
|
||||
out := bdUndefer(t, bd, dir, issue.ID)
|
||||
if strings.Contains(out, "is not deferred") {
|
||||
t.Errorf("undefer refused instead of clearing the stray defer_until: %s", out)
|
||||
}
|
||||
|
||||
status, deferUntil = showDeferState(t, bd, dir, issue.ID)
|
||||
if status != "in_progress" {
|
||||
t.Errorf("expected status to stay in_progress (not clobbered to open), got %q", status)
|
||||
}
|
||||
if deferUntil != nil {
|
||||
t.Errorf("expected defer_until cleared after undefer, got %v", deferUntil)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestEmbeddedUndeferConcurrent exercises undefer operations concurrently.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue