diff --git a/changelog.d/fixed-16841-tooling-release-hive-label-only.md b/changelog.d/fixed-16841-tooling-release-hive-label-only.md new file mode 100644 index 0000000000..ea7c393358 --- /dev/null +++ b/changelog.d/fixed-16841-tooling-release-hive-label-only.md @@ -0,0 +1 @@ +- A tooling-failure blocked verdict now releases the `blocked` label only when the hive applied it; a human-applied `blocked` label is left in place ([#16841](https://github.com/hivecommons/hive/issues/16841)). diff --git a/src/pkg/dashboard/contribute_blocked_tooling.go b/src/pkg/dashboard/contribute_blocked_tooling.go index 7eff98cae7..4652879912 100644 --- a/src/pkg/dashboard/contribute_blocked_tooling.go +++ b/src/pkg/dashboard/contribute_blocked_tooling.go @@ -121,6 +121,14 @@ func (h *ContributeWSHub) releaseToolingBlockedLabel(ctx context.Context, repo s return ghpkg.ErrNoGitHubClient } client := h.server.deps.GHClient + ours, err := client.BlockedLabelAppliedByHive(ctx, repo, number) + if err != nil { + return err + } + if !ours { + // A human-applied `blocked` is theirs to lift. + return nil + } if err := client.RemoveLabel(ctx, repo, number, blockedWorkflowLabel); err != nil { return err } diff --git a/src/pkg/dashboard/contribute_blocked_tooling_test.go b/src/pkg/dashboard/contribute_blocked_tooling_test.go index 23f4e725a3..be5c3f9e64 100644 --- a/src/pkg/dashboard/contribute_blocked_tooling_test.go +++ b/src/pkg/dashboard/contribute_blocked_tooling_test.go @@ -13,6 +13,8 @@ import ( "time" "github.com/gorilla/websocket" + + ghpkg "github.com/hivecommons/hive/pkg/github" ) // hivecommons/hive#11775 / #11776: a contributor's agent could not push to its @@ -248,3 +250,59 @@ func TestBlockedVerdictToolingFailure_GenuineBlockedUntouched(t *testing.T) { t.Fatalf("no release may happen for a genuine blocked verdict, got %v", fx.calls) } } + +// A human-applied `blocked` must survive a tooling-failure verdict; only the +// label the hive applied itself is released. +func TestReleaseToolingBlockedLabel_OnlyHiveAppliedLabel(t *testing.T) { + cases := []struct { + name string + timeline string + wantDelete bool + }{ + {"hive bot applied", `[{"event":"labeled","created_at":"2026-10-20T10:00:00Z","label":{"name":"blocked"},"actor":{"login":"hive-app[bot]","type":"Bot"}}]`, true}, + {"human applied", `[{"event":"labeled","created_at":"2026-10-20T10:00:00Z","label":{"name":"blocked"},"actor":{"login":"maintainer","type":"User"}}]`, false}, + {"human re-applied after bot", `[{"event":"labeled","created_at":"2026-10-20T10:00:00Z","label":{"name":"blocked"},"actor":{"login":"hive-app[bot]","type":"Bot"}},{"event":"labeled","created_at":"2026-10-20T11:00:00Z","label":{"name":"blocked"},"actor":{"login":"maintainer","type":"User"}}]`, false}, + {"no labeled event", `[]`, false}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + var mu sync.Mutex + var calls []string + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + mu.Lock() + calls = append(calls, r.Method+" "+r.URL.Path) + mu.Unlock() + switch { + case r.Method == "GET" && r.URL.Path == "/repos/o/r/issues/5/timeline": + _, _ = fmt.Fprint(w, tc.timeline) + case r.Method == "GET": + _, _ = fmt.Fprint(w, `[]`) + default: + _, _ = fmt.Fprint(w, `{}`) + } + })) + defer ts.Close() + + hub, s := covK2Hub(t) + client := ghpkg.NewClientForTest(ts.URL, "o", []string{"r"}, covBLogger()) + client.SetAppBotLogin("hive-app[bot]") + s.deps.GHClient = client + + if err := hub.releaseToolingBlockedLabel(context.Background(), "o/r", 5, "u", "r"); err != nil { + t.Fatalf("release: %v", err) + } + mu.Lock() + defer mu.Unlock() + deleted := false + for _, c := range calls { + if strings.HasPrefix(c, "DELETE ") || strings.HasPrefix(c, "POST ") { + deleted = true + } + } + if deleted != tc.wantDelete { + t.Fatalf("mutating calls = %v, want label removal %v", calls, tc.wantDelete) + } + }) + } +} diff --git a/src/pkg/github/issue_blocked.go b/src/pkg/github/issue_blocked.go index d286621e41..3c0970f9a3 100644 --- a/src/pkg/github/issue_blocked.go +++ b/src/pkg/github/issue_blocked.go @@ -593,6 +593,17 @@ func (c *Client) blockedLabelActor(ctx context.Context, repo string, number int) return "", false, nil } +// BlockedLabelAppliedByHive reports whether the most recent application of +// `blocked` to the issue was by this hive. A human-applied label, a missing +// labeled event, or a client with no hive identity reports false. +func (c *Client) BlockedLabelAppliedByHive(ctx context.Context, repo string, number int) (bool, error) { + actor, found, err := c.blockedLabelActor(ctx, repo, number) + if err != nil || !found { + return false, err + } + return c.isOwnBotLogin(actor) || c.IsHiveAuthorLogin(actor), nil +} + // parseBlockedOnReason reads "blocked on owner/repo#N" back into its parts. func parseBlockedOnReason(reason string) (repo string, pr int, ok bool) { rest, found := strings.CutPrefix(strings.TrimSpace(reason), blockedFilterReasonPrefix+" on ")