diff --git a/.github/scripts/proxied-cmd-test-shards.txt b/.github/scripts/proxied-cmd-test-shards.txt index 66175781b..b3dad0293 100644 --- a/.github/scripts/proxied-cmd-test-shards.txt +++ b/.github/scripts/proxied-cmd-test-shards.txt @@ -25,7 +25,6 @@ 8 3 TestProxiedServerGateList 8 3 TestProxiedServerPriority -8 4 TestProxiedServerReady 8 4 TestProxiedServerReopen 8 4 TestProxiedServerDeleteConcurrent 8 4 TestProxiedServerReadyWisp @@ -62,6 +61,7 @@ 8 8 TestProxiedServerReopenConcurrent 8 8 TestProxiedServerDoltRemoteRemove 8 8 TestProxiedServerChildren +8 8 TestProxiedServerReady # Parity-suite proxied tests (added with the cmd/bd embedded-parity port). # Balanced by subtest count; shard 1 stays TestProxiedServerUpdate-only. diff --git a/cmd/bd/defer_proxied_integration_test.go b/cmd/bd/defer_proxied_integration_test.go index 7c031fe74..44b5b1b79 100644 --- a/cmd/bd/defer_proxied_integration_test.go +++ b/cmd/bd/defer_proxied_integration_test.go @@ -14,10 +14,11 @@ func TestProxiedServerDeferUndefer(t *testing.T) { requireSharedProxiedServer(t) t.Parallel() bd := buildEmbeddedBD(t) + p := newSharedProxiedProject(t, bd, "dfr") - showStatus := func(t *testing.T, dir, id string) (string, interface{}) { + showStatus := func(t *testing.T, id string) (string, interface{}) { t.Helper() - out, err := bdProxiedRun(t, bd, dir, "show", id, "--json") + out, err := bdProxiedRun(t, bd, p.dir, "show", id, "--json") if err != nil { t.Fatalf("show %s: %v\n%s", id, err, out) } @@ -32,8 +33,6 @@ func TestProxiedServerDeferUndefer(t *testing.T) { } t.Run("defer_then_undefer", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "dfrt") a := bdProxiedCreate(t, bd, p.dir, "Defer target", "--type", "task") out, err := bdProxiedRun(t, bd, p.dir, "defer", a.ID, "--until", "tomorrow", "--reason", "waiting on X", "--json") @@ -51,7 +50,7 @@ func TestProxiedServerDeferUndefer(t *testing.T) { t.Errorf("expected defer_until to be set") } - status, deferUntil := showStatus(t, p.dir, a.ID) + status, deferUntil := showStatus(t, a.ID) if status != string(types.StatusDeferred) { t.Errorf("status = %s, want deferred", status) } @@ -59,10 +58,11 @@ func TestProxiedServerDeferUndefer(t *testing.T) { t.Errorf("defer_until should be set after defer") } + // Undefer restores to open and clears defer_until. if out, err := bdProxiedRun(t, bd, p.dir, "undefer", a.ID); err != nil { t.Fatalf("undefer: %v\n%s", err, out) } - status, deferUntil = showStatus(t, p.dir, a.ID) + status, deferUntil = showStatus(t, a.ID) if status != string(types.StatusOpen) { t.Errorf("status = %s, want open after undefer", status) } @@ -72,8 +72,6 @@ func TestProxiedServerDeferUndefer(t *testing.T) { }) t.Run("deferred_excluded_from_ready", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "dfrr") b := bdProxiedCreate(t, bd, p.dir, "Ready-then-deferred", "--type", "task", "--priority", "1") if out, err := bdProxiedRun(t, bd, p.dir, "defer", b.ID); err != nil { t.Fatalf("defer: %v\n%s", err, out) @@ -87,8 +85,6 @@ func TestProxiedServerDeferUndefer(t *testing.T) { }) t.Run("undefer_nondeferred_errors", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "dfrn") c := bdProxiedCreate(t, bd, p.dir, "Open issue", "--type", "task") stdout, stderr, _ := bdProxiedRunBuffers(t, bd, p.dir, "undefer", c.ID) if !strings.Contains(stdout+stderr, "is not deferred") { @@ -97,20 +93,17 @@ func TestProxiedServerDeferUndefer(t *testing.T) { }) t.Run("defer_is_idempotent", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "dfri") d := bdProxiedCreate(t, bd, p.dir, "Idempotent defer", "--type", "task") if out, err := bdProxiedRun(t, bd, p.dir, "defer", d.ID); err != nil { t.Fatalf("first defer: %v\n%s", err, out) } + // Second defer on an already-deferred issue must not error (ClientFoundRows fix). if out, err := bdProxiedRun(t, bd, p.dir, "defer", d.ID, "--json"); err != nil { t.Fatalf("second defer errored (no-op update regression): %v\n%s", err, out) } }) t.Run("defer_multiple", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "dfrm") e := bdProxiedCreate(t, bd, p.dir, "Defer multi 1", "--type", "task") f := bdProxiedCreate(t, bd, p.dir, "Defer multi 2", "--type", "task") @@ -122,15 +115,13 @@ func TestProxiedServerDeferUndefer(t *testing.T) { t.Errorf("expected both IDs in defer output, got:\n%s", out) } for _, id := range []string{e.ID, f.ID} { - if status, _ := showStatus(t, p.dir, id); status != string(types.StatusDeferred) { + if status, _ := showStatus(t, id); status != string(types.StatusDeferred) { t.Errorf("status of %s = %s, want deferred", id, status) } } }) t.Run("undefer_multiple", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "dfru") g := bdProxiedCreate(t, bd, p.dir, "Undefer multi 1", "--type", "task") h := bdProxiedCreate(t, bd, p.dir, "Undefer multi 2", "--type", "task") if out, err := bdProxiedRun(t, bd, p.dir, "defer", g.ID, h.ID); err != nil { @@ -145,15 +136,13 @@ func TestProxiedServerDeferUndefer(t *testing.T) { t.Errorf("expected both IDs in undefer output, got:\n%s", out) } for _, id := range []string{g.ID, h.ID} { - if status, _ := showStatus(t, p.dir, id); status != string(types.StatusOpen) { + if status, _ := showStatus(t, id); status != string(types.StatusOpen) { t.Errorf("status of %s = %s, want open after undefer", id, status) } } }) t.Run("defer_reason_appended_to_notes", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "dfrz") i := bdProxiedCreate(t, bd, p.dir, "Defer with reason", "--type", "task") if out, err := bdProxiedRun(t, bd, p.dir, "defer", i.ID, "--reason", "waiting on API access"); err != nil { t.Fatalf("defer --reason: %v\n%s", err, out) diff --git a/cmd/bd/epic_proxied_integration_test.go b/cmd/bd/epic_proxied_integration_test.go index b3ababa49..716d1f26a 100644 --- a/cmd/bd/epic_proxied_integration_test.go +++ b/cmd/bd/epic_proxied_integration_test.go @@ -14,10 +14,29 @@ func TestProxiedServerEpic(t *testing.T) { requireSharedProxiedServer(t) t.Parallel() bd := buildEmbeddedBD(t) + p := newSharedProxiedProject(t, bd, "epc") - epicStatus := func(t *testing.T, dir string, args ...string) []*types.EpicStatus { + // An epic with all children closed becomes eligible for closure. + epic := bdProxiedCreate(t, bd, p.dir, "Shipping epic", "--type", "epic") + c1 := bdProxiedCreate(t, bd, p.dir, "Child one", "--type", "task", "--parent", epic.ID) + c2 := bdProxiedCreate(t, bd, p.dir, "Child two", "--type", "task", "--parent", epic.ID) + + // A second epic that stays incomplete (one open child). + openEpic := bdProxiedCreate(t, bd, p.dir, "Incomplete epic", "--type", "epic") + bdProxiedCreate(t, bd, p.dir, "Open child", "--type", "task", "--parent", openEpic.ID) + + // A partially-done epic: two children, one closed. It shows progress but is + // never eligible for closure (one child stays open the whole test). + partialEpic := bdProxiedCreate(t, bd, p.dir, "Partial epic", "--type", "epic") + pc1 := bdProxiedCreate(t, bd, p.dir, "Partial child one", "--type", "task", "--parent", partialEpic.ID) + bdProxiedCreate(t, bd, p.dir, "Partial child two", "--type", "task", "--parent", partialEpic.ID) + if out, err := bdProxiedRun(t, bd, p.dir, "close", pc1.ID); err != nil { + t.Fatalf("close partial child: %v\n%s", err, out) + } + + epicStatus := func(t *testing.T, args ...string) []*types.EpicStatus { t.Helper() - out, err := bdProxiedRun(t, bd, dir, append([]string{"epic", "status", "--json"}, args...)...) + out, err := bdProxiedRun(t, bd, p.dir, append([]string{"epic", "status", "--json"}, args...)...) if err != nil { t.Fatalf("epic status %v: %v\n%s", args, err, out) } @@ -29,15 +48,6 @@ func TestProxiedServerEpic(t *testing.T) { } t.Run("status_shows_progress", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "epcp") - partialEpic := bdProxiedCreate(t, bd, p.dir, "Partial epic", "--type", "epic") - pc1 := bdProxiedCreate(t, bd, p.dir, "Partial child one", "--type", "task", "--parent", partialEpic.ID) - bdProxiedCreate(t, bd, p.dir, "Partial child two", "--type", "task", "--parent", partialEpic.ID) - if out, err := bdProxiedRun(t, bd, p.dir, "close", pc1.ID); err != nil { - t.Fatalf("close partial child: %v\n%s", err, out) - } - out, err := bdProxiedRun(t, bd, p.dir, "epic", "status") if err != nil { t.Fatalf("epic status: %v\n%s", err, out) @@ -52,28 +62,14 @@ func TestProxiedServerEpic(t *testing.T) { }) t.Run("status_json_is_array", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "epcj") - epic := bdProxiedCreate(t, bd, p.dir, "Some epic", "--type", "epic") - bdProxiedCreate(t, bd, p.dir, "A child", "--type", "task", "--parent", epic.ID) - got := epicStatus(t, p.dir) + got := epicStatus(t) if len(got) < 1 { t.Errorf("expected at least 1 epic in status, got %d", len(got)) } }) t.Run("status_eligible_only_excludes_incomplete", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "epce") - openEpic := bdProxiedCreate(t, bd, p.dir, "Incomplete epic", "--type", "epic") - bdProxiedCreate(t, bd, p.dir, "Open child", "--type", "task", "--parent", openEpic.ID) - partialEpic := bdProxiedCreate(t, bd, p.dir, "Partial epic", "--type", "epic") - pc1 := bdProxiedCreate(t, bd, p.dir, "Partial child one", "--type", "task", "--parent", partialEpic.ID) - bdProxiedCreate(t, bd, p.dir, "Partial child two", "--type", "task", "--parent", partialEpic.ID) - if out, err := bdProxiedRun(t, bd, p.dir, "close", pc1.ID); err != nil { - t.Fatalf("close partial child: %v\n%s", err, out) - } - + // Neither the partially-done epic nor the fully-open epic is eligible. out, err := bdProxiedRun(t, bd, p.dir, "epic", "status", "--eligible-only") if err != nil { t.Fatalf("epic status --eligible-only: %v\n%s", err, out) @@ -88,9 +84,8 @@ func TestProxiedServerEpic(t *testing.T) { }) t.Run("status_no_open_epics", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "epcn") - out, err := bdProxiedRun(t, bd, p.dir, "epic", "status") + p2 := newSharedProxiedProject(t, bd, "epq") + out, err := bdProxiedRun(t, bd, p2.dir, "epic", "status") if err != nil { t.Fatalf("epic status: %v\n%s", err, out) } @@ -100,29 +95,20 @@ func TestProxiedServerEpic(t *testing.T) { }) t.Run("status_not_eligible_while_open", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "epco") - epic := bdProxiedCreate(t, bd, p.dir, "Shipping epic", "--type", "epic") - bdProxiedCreate(t, bd, p.dir, "Child one", "--type", "task", "--parent", epic.ID) - bdProxiedCreate(t, bd, p.dir, "Child two", "--type", "task", "--parent", epic.ID) - for _, es := range epicStatus(t, p.dir) { + for _, es := range epicStatus(t) { if es.Epic.ID == epic.ID && es.EligibleForClose { t.Errorf("epic should not be eligible before children closed") } } }) - t.Run("status_eligible_after_children_closed", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "epca") - epic := bdProxiedCreate(t, bd, p.dir, "Shipping epic", "--type", "epic") - c1 := bdProxiedCreate(t, bd, p.dir, "Child one", "--type", "task", "--parent", epic.ID) - c2 := bdProxiedCreate(t, bd, p.dir, "Child two", "--type", "task", "--parent", epic.ID) - bdProxiedRun(t, bd, p.dir, "close", c1.ID) - bdProxiedRun(t, bd, p.dir, "close", c2.ID) + // Close both children of the first epic. + bdProxiedRun(t, bd, p.dir, "close", c1.ID) + bdProxiedRun(t, bd, p.dir, "close", c2.ID) + t.Run("status_eligible_after_children_closed", func(t *testing.T) { var found bool - for _, es := range epicStatus(t, p.dir) { + for _, es := range epicStatus(t) { if es.Epic.ID == epic.ID { found = true if !es.EligibleForClose { @@ -139,16 +125,6 @@ func TestProxiedServerEpic(t *testing.T) { }) t.Run("dry_run_lists_without_closing", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "epcd") - epic := bdProxiedCreate(t, bd, p.dir, "Shipping epic", "--type", "epic") - c1 := bdProxiedCreate(t, bd, p.dir, "Child one", "--type", "task", "--parent", epic.ID) - c2 := bdProxiedCreate(t, bd, p.dir, "Child two", "--type", "task", "--parent", epic.ID) - bdProxiedRun(t, bd, p.dir, "close", c1.ID) - bdProxiedRun(t, bd, p.dir, "close", c2.ID) - openEpic := bdProxiedCreate(t, bd, p.dir, "Incomplete epic", "--type", "epic") - bdProxiedCreate(t, bd, p.dir, "Open child", "--type", "task", "--parent", openEpic.ID) - out, err := bdProxiedRun(t, bd, p.dir, "epic", "close-eligible", "--dry-run", "--json") if err != nil { t.Fatalf("dry-run: %v\n%s", err, out) @@ -162,13 +138,14 @@ func TestProxiedServerEpic(t *testing.T) { if es.Epic.ID == epic.ID { listed = true } - if es.Epic.ID == openEpic.ID { + if es.Epic.ID == openEpic.ID || es.Epic.ID == partialEpic.ID { t.Errorf("incomplete epic %s must not be listed as eligible", es.Epic.ID) } } if !listed { t.Errorf("dry-run should list eligible epic %s, got %+v", epic.ID, eligible) } + // Confirm it was NOT closed. show := bdProxiedShow(t, bd, p.dir, epic.ID) if show.Status == types.StatusClosed { t.Errorf("dry-run must not close the epic") @@ -176,14 +153,6 @@ func TestProxiedServerEpic(t *testing.T) { }) t.Run("write_closes_eligible", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "epcw") - epic := bdProxiedCreate(t, bd, p.dir, "Shipping epic", "--type", "epic") - c1 := bdProxiedCreate(t, bd, p.dir, "Child one", "--type", "task", "--parent", epic.ID) - c2 := bdProxiedCreate(t, bd, p.dir, "Child two", "--type", "task", "--parent", epic.ID) - bdProxiedRun(t, bd, p.dir, "close", c1.ID) - bdProxiedRun(t, bd, p.dir, "close", c2.ID) - out, err := bdProxiedRun(t, bd, p.dir, "epic", "close-eligible", "--json") if err != nil { t.Fatalf("close-eligible: %v\n%s", err, out) diff --git a/cmd/bd/set_state_proxied_integration_test.go b/cmd/bd/set_state_proxied_integration_test.go index 27434ecee..ec8695c41 100644 --- a/cmd/bd/set_state_proxied_integration_test.go +++ b/cmd/bd/set_state_proxied_integration_test.go @@ -12,11 +12,13 @@ func TestProxiedServerSetState(t *testing.T) { requireSharedProxiedServer(t) t.Parallel() bd := buildEmbeddedBD(t) + p := newSharedProxiedProject(t, bd, "sst") + issue := bdProxiedCreate(t, bd, p.dir, "Set-state target") - setStateJSON := func(t *testing.T, dir, id, spec string, extra ...string) map[string]interface{} { + setStateJSON := func(t *testing.T, spec string, extra ...string) map[string]interface{} { t.Helper() - args := append([]string{"set-state", id, spec, "--json"}, extra...) - out, err := bdProxiedRun(t, bd, dir, args...) + args := append([]string{"set-state", issue.ID, spec, "--json"}, extra...) + out, err := bdProxiedRun(t, bd, p.dir, args...) if err != nil { t.Fatalf("set-state %s: %v\n%s", spec, err, out) } @@ -27,33 +29,34 @@ func TestProxiedServerSetState(t *testing.T) { return got } - t.Run("set_change_noop_lifecycle", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "sstl") - issue := bdProxiedCreate(t, bd, p.dir, "Set-state target") + t.Run("set_new_dimension", func(t *testing.T) { + got := setStateJSON(t, "patrol=active", "--reason", "starting patrol") + if got["changed"] != true { + t.Errorf("expected changed=true, got %v", got["changed"]) + } + if got["old_value"] != nil { + t.Errorf("expected old_value nil for a new dimension, got %v", got["old_value"]) + } + if got["new_value"] != "active" { + t.Errorf("new_value = %v, want active", got["new_value"]) + } + if _, ok := got["event_id"].(string); !ok || got["event_id"] == "" { + t.Errorf("expected an event_id, got %v", got["event_id"]) + } + // Label cache must reflect the new state. db := openProxiedDB(t, p) - - set := setStateJSON(t, p.dir, issue.ID, "patrol=active", "--reason", "starting patrol") - if set["changed"] != true { - t.Errorf("expected changed=true, got %v", set["changed"]) - } - if set["old_value"] != nil { - t.Errorf("expected old_value nil for a new dimension, got %v", set["old_value"]) - } - if set["new_value"] != "active" { - t.Errorf("new_value = %v, want active", set["new_value"]) - } - if _, ok := set["event_id"].(string); !ok || set["event_id"] == "" { - t.Errorf("expected an event_id, got %v", set["event_id"]) - } - if labels := getProxiedLabels(t, db, issue.ID); !containsStr(labels, "patrol:active") { + labels := getProxiedLabels(t, db, issue.ID) + if !containsStr(labels, "patrol:active") { t.Errorf("expected label patrol:active, got %v", labels) } + }) - change := setStateJSON(t, p.dir, issue.ID, "patrol=muted") - if change["changed"] != true || change["old_value"] != "active" || change["new_value"] != "muted" { - t.Errorf("unexpected change result: %v", change) + t.Run("change_swaps_label", func(t *testing.T) { + got := setStateJSON(t, "patrol=muted") + if got["changed"] != true || got["old_value"] != "active" || got["new_value"] != "muted" { + t.Errorf("unexpected change result: %v", got) } + db := openProxiedDB(t, p) labels := getProxiedLabels(t, db, issue.ID) if containsStr(labels, "patrol:active") { t.Errorf("old label patrol:active should have been removed, got %v", labels) @@ -61,12 +64,16 @@ func TestProxiedServerSetState(t *testing.T) { if !containsStr(labels, "patrol:muted") { t.Errorf("expected label patrol:muted, got %v", labels) } + }) - noop := setStateJSON(t, p.dir, issue.ID, "patrol=muted") - if noop["changed"] != false { - t.Errorf("expected changed=false for identical value, got %v", noop) + t.Run("no_change_is_noop", func(t *testing.T) { + got := setStateJSON(t, "patrol=muted") + if got["changed"] != false { + t.Errorf("expected changed=false for identical value, got %v", got) } + }) + t.Run("event_bead_created_as_child", func(t *testing.T) { out, err := bdProxiedRun(t, bd, p.dir, "state", "list", issue.ID, "--json") if err != nil { t.Fatalf("state list: %v\n%s", err, out) @@ -80,6 +87,7 @@ func TestProxiedServerSetState(t *testing.T) { if res.States["patrol"] != "muted" { t.Errorf("state list shows patrol=%q, want muted", res.States["patrol"]) } + // The set-state calls created event children under the issue. children := bdProxiedListJSON(t, bd, p, "--parent", issue.ID, "--status", "all") var events int for _, c := range children { @@ -93,9 +101,6 @@ func TestProxiedServerSetState(t *testing.T) { }) t.Run("invalid_format", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "ssti") - issue := bdProxiedCreate(t, bd, p.dir, "Invalid format target") out, err := bdProxiedRun(t, bd, p.dir, "set-state", issue.ID, "patrolactive") if err == nil { t.Fatalf("expected error for missing '=', got success: %s", out) @@ -103,8 +108,6 @@ func TestProxiedServerSetState(t *testing.T) { }) t.Run("multiple_dimensions", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "sstm") m := bdProxiedCreate(t, bd, p.dir, "Multi-dimension state") for _, spec := range []string{"phase=planning", "env=staging"} { @@ -131,6 +134,7 @@ func TestProxiedServerSetState(t *testing.T) { t.Errorf("env = %q, want staging (states=%v)", res.States["env"], res.States) } + // Each distinct dimension is an independent label; both must be present. db := openProxiedDB(t, p) labels := getProxiedLabels(t, db, m.ID) if !containsStr(labels, "phase:planning") || !containsStr(labels, "env:staging") { @@ -139,8 +143,6 @@ func TestProxiedServerSetState(t *testing.T) { }) t.Run("set_state_on_wisp", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "sstw") wisp := bdProxiedCreate(t, bd, p.dir, "Wisp set-state", "--ephemeral") out, err := bdProxiedRun(t, bd, p.dir, "set-state", wisp.ID, "patrol=muted", "--json") @@ -155,6 +157,7 @@ func TestProxiedServerSetState(t *testing.T) { t.Errorf("unexpected wisp set-state result: %v", got) } + // Wisp state lives in wisp_labels; verify via the state reader. val, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, "state", wisp.ID, "patrol") if err != nil { t.Fatalf("state on wisp: %v\nstderr:\n%s", err, stderr) diff --git a/cmd/bd/unclaim_proxied_integration_test.go b/cmd/bd/unclaim_proxied_integration_test.go index 0b8b69fae..f7fcdfa06 100644 --- a/cmd/bd/unclaim_proxied_integration_test.go +++ b/cmd/bd/unclaim_proxied_integration_test.go @@ -16,26 +16,25 @@ func TestProxiedServerUnclaim(t *testing.T) { requireSharedProxiedServer(t) t.Parallel() bd := buildEmbeddedBD(t) + p := newSharedProxiedProject(t, bd, "unc") - statusAssignee := func(t *testing.T, dir, id string) (string, string) { + statusAssignee := func(t *testing.T, id string) (string, string) { t.Helper() - iss := bdProxiedShow(t, bd, dir, id) + iss := bdProxiedShow(t, bd, p.dir, id) return string(iss.Status), iss.Assignee } t.Run("unclaim_own_claim", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "unco") a := bdProxiedCreate(t, bd, p.dir, "Unclaim target", "--type", "task") bdProxiedUpdate(t, bd, p.dir, a.ID, "--claim") - if st, as := statusAssignee(t, p.dir, a.ID); st != string(types.StatusInProgress) || as == "" { + if st, as := statusAssignee(t, a.ID); st != string(types.StatusInProgress) || as == "" { t.Fatalf("expected in_progress+assignee after claim, got status=%s assignee=%q", st, as) } if out, err := bdProxiedRun(t, bd, p.dir, "unclaim", a.ID, "--reason", "abandoning"); err != nil { t.Fatalf("unclaim: %v\n%s", err, out) } - st, as := statusAssignee(t, p.dir, a.ID) + st, as := statusAssignee(t, a.ID) if st != string(types.StatusOpen) { t.Errorf("status = %s, want open after unclaim", st) } @@ -54,8 +53,6 @@ func TestProxiedServerUnclaim(t *testing.T) { }) t.Run("unclaim_unassigned_errors", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "uncu") b := bdProxiedCreate(t, bd, p.dir, "Never claimed", "--type", "task") stdout, stderr, _ := bdProxiedRunBuffers(t, bd, p.dir, "unclaim", b.ID) if !strings.Contains(stdout+stderr, "not assigned") { @@ -64,8 +61,6 @@ func TestProxiedServerUnclaim(t *testing.T) { }) t.Run("unclaim_reason_in_output", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "uncr") c := bdProxiedCreate(t, bd, p.dir, "Reason output", "--type", "task") bdProxiedUpdate(t, bd, p.dir, c.ID, "--claim") out, err := bdProxiedRun(t, bd, p.dir, "unclaim", c.ID, "--reason", "Agent crashed") @@ -75,14 +70,12 @@ func TestProxiedServerUnclaim(t *testing.T) { if !strings.Contains(string(out), "Agent crashed") { t.Errorf("expected reason in output, got: %s", out) } - if st, as := statusAssignee(t, p.dir, c.ID); st != string(types.StatusOpen) || as != "" { + if st, as := statusAssignee(t, c.ID); st != string(types.StatusOpen) || as != "" { t.Errorf("expected open+cleared after unclaim, got status=%s assignee=%q", st, as) } }) t.Run("unclaim_json_output", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "uncj") d := bdProxiedCreate(t, bd, p.dir, "JSON output", "--type", "task") bdProxiedUpdate(t, bd, p.dir, d.ID, "--claim") out, err := bdProxiedRun(t, bd, p.dir, "unclaim", d.ID, "--json") @@ -108,8 +101,6 @@ func TestProxiedServerUnclaim(t *testing.T) { }) t.Run("unclaim_multiple_ids", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "uncm") e := bdProxiedCreate(t, bd, p.dir, "Multi 1", "--type", "task") f := bdProxiedCreate(t, bd, p.dir, "Multi 2", "--type", "task") bdProxiedUpdate(t, bd, p.dir, e.ID, "--claim") @@ -118,15 +109,13 @@ func TestProxiedServerUnclaim(t *testing.T) { t.Fatalf("unclaim multiple: %v\n%s", err, out) } for _, id := range []string{e.ID, f.ID} { - if st, as := statusAssignee(t, p.dir, id); st != string(types.StatusOpen) || as != "" { + if st, as := statusAssignee(t, id); st != string(types.StatusOpen) || as != "" { t.Errorf("%s: expected open+cleared, got status=%s assignee=%q", id, st, as) } } }) t.Run("unclaim_nonexistent_errors", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "uncn") stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, "unclaim", "nonexistent") if err == nil { t.Fatalf("expected failure for nonexistent id, got success:\n%s", stdout) @@ -137,8 +126,6 @@ func TestProxiedServerUnclaim(t *testing.T) { }) t.Run("unclaim_closed_errors", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "uncc") g := bdProxiedCreate(t, bd, p.dir, "Closed target", "--type", "task") bdProxiedUpdate(t, bd, p.dir, g.ID, "--claim") if out, err := bdProxiedRun(t, bd, p.dir, "close", g.ID); err != nil { @@ -158,27 +145,26 @@ func TestProxiedServerReclaim(t *testing.T) { requireSharedProxiedServer(t) t.Parallel() bd := buildEmbeddedBD(t) + p := newSharedProxiedProject(t, bd, "rcl") + + issue := bdProxiedCreate(t, bd, p.dir, "Reclaim target", "--type", "task") + bdProxiedUpdate(t, bd, p.dir, issue.ID, "--claim") + + // Backdate the lease so it is expired well in the past. + db := openProxiedDB(t, p) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + res, err := db.ExecContext(ctx, + "UPDATE leases SET lease_expires_at = ? WHERE issue_id = ?", + time.Now().UTC().Add(-1*time.Hour), issue.ID) + if err != nil { + t.Fatalf("backdate lease: %v", err) + } + if n, _ := res.RowsAffected(); n == 0 { + t.Fatalf("claim did not create a lease row for %s; cannot test reclaim", issue.ID) + } t.Run("reclaims_stale_lease", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "rcls") - issue := bdProxiedCreate(t, bd, p.dir, "Reclaim target", "--type", "task") - bdProxiedUpdate(t, bd, p.dir, issue.ID, "--claim") - - // Backdate the lease so it is expired well in the past. - db := openProxiedDB(t, p) - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - res, err := db.ExecContext(ctx, - "UPDATE leases SET lease_expires_at = ? WHERE issue_id = ?", - time.Now().UTC().Add(-1*time.Hour), issue.ID) - if err != nil { - t.Fatalf("backdate lease: %v", err) - } - if n, _ := res.RowsAffected(); n == 0 { - t.Fatalf("claim did not create a lease row for %s; cannot test reclaim", issue.ID) - } - out, err := bdProxiedRun(t, bd, p.dir, "reclaim", "--older-than", "0s", "--json") if err != nil { t.Fatalf("reclaim: %v\n%s", err, out) @@ -206,6 +192,7 @@ func TestProxiedServerReclaim(t *testing.T) { t.Fatalf("expected %s in reclaimed set, got %+v", issue.ID, got.Reclaimed) } + // Issue must now be open with the assignee cleared. iss := bdProxiedShow(t, bd, p.dir, issue.ID) if iss.Status != types.StatusOpen { t.Errorf("status = %s, want open after reclaim", iss.Status) @@ -216,11 +203,6 @@ func TestProxiedServerReclaim(t *testing.T) { }) t.Run("nothing_to_reclaim", func(t *testing.T) { - t.Parallel() - p := newSharedProxiedProject(t, bd, "rcln") - issue := bdProxiedCreate(t, bd, p.dir, "Fresh claim", "--type", "task") - bdProxiedUpdate(t, bd, p.dir, issue.ID, "--claim") - out, err := bdProxiedRun(t, bd, p.dir, "reclaim", "--older-than", "0s", "--json") if err != nil { t.Fatalf("reclaim: %v\n%s", err, out) @@ -232,7 +214,7 @@ func TestProxiedServerReclaim(t *testing.T) { t.Fatalf("unmarshal: %v\n%s", err, out) } if got.Count != 0 { - t.Errorf("expected 0 reclaimed for a fresh lease, got %d", got.Count) + t.Errorf("expected 0 reclaimed on second run, got %d", got.Count) } }) }