diff --git a/changelog.d/fixed-18866-sha-hold-visibility.md b/changelog.d/fixed-18866-sha-hold-visibility.md new file mode 100644 index 0000000000..94bd87e3d8 --- /dev/null +++ b/changelog.d/fixed-18866-sha-hold-visibility.md @@ -0,0 +1 @@ +- Exempt trusted and code-specific bug reports from SHA holds, show work-blocking labels on dashboard issue rows, and let authorized maintainers persistently override a SHA hold. diff --git a/src/docs/dashboard-copy-inventory.md b/src/docs/dashboard-copy-inventory.md index b9441cd69e..8fe3bb7c9e 100644 --- a/src/docs/dashboard-copy-inventory.md +++ b/src/docs/dashboard-copy-inventory.md @@ -64,6 +64,7 @@ The new hover, verbatim (title line omitted): | Confirm: Merge now as maintainer | dialog | 76 | 53 | same | | ⋯ menu hints (`stageTrackerLeadActions` → `ham-menu-hint`) | ⋯ menu | server consequences (11–31 each) | server consequences (≤ 12 each) | Go budget test | | `stageTrackerOpenTriageNeeded` → `stageTrackerSegments` / `stageTrackerHeadline` Open word (`tracker-row.js`, `tracker-words.js`) | Open chevron, chevron hover first word, row tooltip headline | *New · since 28m* on a reporter-trust hold; the ask lived only in the caption ([#15437](https://github.com/hivecommons/hive/issues/15437)) | *Triage needed · since 28m* (same word as the `needs-triage` chip / 015) | `TestStageTrackerNewRowRendering`, `TestStageTracker_ReporterTrustHoldReadsTriageNeeded` | +| `stageTrackerControlLabels` (`tracker-row-strip.js`) | issue control-label pills and Open chevron hover | A SHA-gated issue could look merely open | The label names the gate; hover explains the reason and how to lift it. For SHA holds, add the affected commit SHA to the issue or a comment for the sweep to remove the label, or use **Override SHA hold** with hold-release permission. The override does not release other holds. | `stage_tracker_control_labels.test.js`, `TestStageTrackerSHAControlLabel` | | `stageTrackerTriageNeededCaption` (`stageTrackerCaption` 015, `stageTrackerNewState` hold text) | row caption, feed | 110 ("Actionable, but no maintainer has looked at it yet; waiting for triage — triage needed: carries needs triage": *triage* ×3 after the chevron word) / 84 ("New · waiting for a maintainer's triage (add `triage/accepted`); the hive's next pass in 7m") | 31 ("Triage needed — accept or close"; the next-mover and next-pass narration stay on the chevron hover) | `TestStageTracker_TriageNeededStage`, `TestStageTracker_ReporterTrustHoldReadsTriageNeeded`, `TestStageTrackerNewState` | | `stageTrackerLeadActionHtml` (`tracker-actions.js`) | the row header's inline lead button (chip slot) | — (the lead sat in the ⋯ menu only) | the menu entry's label (1–4), its hint as the hover | `TestStageTrackerLeadActionInline`, `TestStageTrackerMaintainerRowsHaveLeadAction` | | Toasts (`STAGE_TRACKER_ACTING_CAPTIONS`, acted labels) | toast | 2–4 each | unchanged | — | diff --git a/src/docs/labels-and-control-signals/glossary-and-operations.md b/src/docs/labels-and-control-signals/glossary-and-operations.md index 7a0ff58037..05c4698b18 100644 --- a/src/docs/labels-and-control-signals/glossary-and-operations.md +++ b/src/docs/labels-and-control-signals/glossary-and-operations.md @@ -135,7 +135,7 @@ Some sweeps list items themselves. They still use the same hold predicate (`Clie - Auto-merge sweeps use `Transport.IsHeldLabels`. The queued (`lgtm`) sweep skips a held PR before fetching it; the self-authored sweep skips held PRs and `needs-human` before merge (`src/pkg/github/automerge/automerge_sweep.go:23-38`, `src/pkg/github/automerge/automerge_sweep.go:954-959`, `src/pkg/github/automerge/automerge_sweep_loop.go:13-48`, `src/pkg/github/automerge/automerge_sweep_loop.go:73-92`). - The task-list sweep skips held issues before its exempt / issue `needs-human` gate. It does not comment on, relabel or close them (`src/pkg/github/task_list_sweep.go:848-854`). -- The SHA-hold sweep lists primary-repo `kind/bug` issues itself. Without a SHA it adds `issues.sha_hold_trusted_label` (default `needs-sha`) and a marker notice for every reporter; it never applies `hold`, and `needs-sha` keeps agents off the issue until it is removed (#18468; before that, untrusted reporters got literal `hold`, #12002). It removes only its own current hold: the newest label event must be a `labeled` by the App bot with an App-authored SHA-hold notice at or after it (`EnforceSHAHold` / `shaHoldIsOwn` in `src/pkg/github/client.go`). +- The SHA-hold sweep lists primary-repo `kind/bug` issues itself. Without a SHA it adds `issues.sha_hold_trusted_label` (default `needs-sha`) and a marker notice, except for owner/maintainer or Hive authors, bodies citing concrete paths, and issues with the persistent `hive/sha-override` label. It never applies `hold`; `needs-sha` keeps agents off the issue until removed. On exemption it removes a SHA label only when its newest label event was by the App, and removes a legacy hard hold only when also paired with the App-authored SHA notice (`EnforceSHAHold` / `shaHoldIsOwn` in `src/pkg/github/client.go`). - PR-request watching applies server-side holds after creation; the wrapper discards an agent's `--label hold` (`src/pkg/github/pr_request_watcher.go:452-524`, `bin/hive-open-pr.sh:142-150`). Policy templates also say to respect `hold`, `on-hold`, `hold/review`, `hive-pause/`, any label containing `hold`, and exempt `do-not-merge`. That instruction is a prompt-level backstop; enumeration and sweep checks are the hard enforcement. diff --git a/src/docs/labels-and-control-signals/reference.md b/src/docs/labels-and-control-signals/reference.md index c4b71de76f..795e34f92b 100644 --- a/src/docs/labels-and-control-signals/reference.md +++ b/src/docs/labels-and-control-signals/reference.md @@ -191,7 +191,7 @@ Commit committer dates and SHA-keyed `check_suite` / `status` times are never us **Applies to:** Issues. **Kind:** Hard issue hold. -Since [#18468](https://github.com/hivecommons/hive/issues/18468) the sweep gives every reporter the `needs-sha` label below and never applies `hold`; `needs-sha` itself keeps the issue out of agent work with reporter trust on or off. Before that, human-filed primary-repo `kind/bug` without a 7-40 hex SHA got `hold` and a notice carrying ``; once a SHA appears in body/comments, Hive removes `hold` only if the current hold is its own (newest `hold` event labeled by the App bot, paired with an App-authored notice at or after it). A human's hold, a re-hold, or another subsystem's hold stays. Reporters whose author association is trusted (`issue_filter.reporter_trust.trusted_associations`, default OWNER/MEMBER/COLLABORATOR) get the soft `needs-sha` row below instead, and a SHA-hold `hold` already on such an issue is swapped for it (#12002). +Since [#18468](https://github.com/hivecommons/hive/issues/18468) the sweep never applies `hold`. Before that, human-filed primary-repo `kind/bug` without a 7-40 hex SHA got `hold` and a notice carrying ``. Hive removes a legacy SHA hold when a SHA appears or the issue is exempt, only if the newest `hold` event was labeled by the App bot and paired with an App-authored notice at or after it. A human's hold, a re-hold, or another subsystem's hold stays. The hard-suppress reconcile also lifts this `hold` once a PR referencing the issue merges after it was applied. @@ -207,13 +207,13 @@ The hard-suppress reconcile also lifts this `hold` once a PR referencing the iss **Applies to:** Issues. **Kind:** Hard (issue gate; not a PR merge gate). -A `kind/bug` without a SHA gets this label plus the `` notice. While it is on the issue no agent implements, decomposes or claims it, whatever the reporter-trust setting; the issue shows as filtered in the work list. The sweep removes it once a SHA appears, which releases the issue. Description: "Waiting on the reporter for the commit SHA; hive won't work this until it's added." +An external primary-repo `kind/bug` without a SHA in its body or comments gets this label plus the `` notice. Issues authored by an OWNER, MEMBER, COLLABORATOR or Hive's own accounts, and issues whose body cites a concrete file or code path, are exempt. While the label is present no agent implements, decomposes or claims the issue, whatever the reporter-trust setting. The sweep removes its own existing label when an exemption applies; it leaves a human-applied label alone. The dashboard shows blocking control labels and explains how to lift them. **Who applies it:** Hive. **Checked by:** SHA-hold sweep. **When:** Eval tick SHA sweep. -**Release or override.** Add SHA evidence, or remove the label +**Release or override.** Post a commit SHA, or use the authorized dashboard override. The override records `hive/sha-override` on the issue so subsequent sweeps do not re-add the SHA hold. Other hold labels still apply. **Configuration and implementation.** `issues.sha_hold_trusted_label` (default `needs-sha`; `hold` is treated as unset, since the sweep never applies `hold`) diff --git a/src/docs/operator-reference/README.md b/src/docs/operator-reference/README.md index 1ea3922f00..1a57076aec 100644 --- a/src/docs/operator-reference/README.md +++ b/src/docs/operator-reference/README.md @@ -207,7 +207,7 @@ Top-level YAML keys accepted by `config.Config`: | `dedupe.advisory_autoclose` | `true`. | The close-on-merge backfill works the dedupe agent's advisory checklists itself ([#15754](https://github.com/hivecommons/hive/issues/15754)): for every open hive-authored issue whose body opens with `` it ticks each `- [ ] #N …` task line whose #N is closed or merged (one body edit per sweep, idempotent) and, once every line is ticked, comments `All N items resolved (#a closed, #b merged …) — closing this advisory.` and closes the issue as `completed`. A checklist with open items expires after seven days. The Activity Monitor never parks an advisory at 045 regardless. `false` leaves checklists untouched (they still expire). Env/dashboard: yaml-only. | | `issues.close_on_merge_recheck` | `24h`. | How long a merged-PR claim keeps its settled close-on-merge verdict before the ledger sweep re-verifies it against the API. Once a sweep reaches a final verdict for a claim — issue closed, already closed, Hive marker present, awaiting confirmation, untrusted author, reopened by a person, or PR not merged — it stamps `close_on_merge_settled_at` on the claim and later sweeps skip the claim with no API call until this window elapses. Transient failures (issue, timeline or comment reads/writes that errored) never settle and retry on the next sweep as before. The marker follows the claim while the same PR claims the issue and resets when a different PR takes it over. Env override: `HIVE_CLOSE_ON_MERGE_RECHECK` (Go duration). | | `issues.reporter_confirmation` | `false`. | Legacy opt-in switch for hives that want every human-filed bug-family issue to wait for reporter verification before close. Leave false for the default close-on-merge policy; add `hive: needs-confirmation` to an individual issue when only that issue needs the gate. `hive: reporter-confirmed` and `hive: close-on-merge` remain accepted legacy bypasses. | -| `issues.sha_hold_trusted_label` | `needs-sha`. | Soft label the SHA-hold sweep applies to a `kind/bug` without a commit SHA when the reporter's author association is in `project.issue_filter.reporter_trust.trusted_associations` (default OWNER/MEMBER/COLLABORATOR), instead of the hard `hold` (#12002). The label keeps the issue out of agent work until it is removed. A SHA-hold `hold` already on such an issue is swapped for this label. Set to `hold` to restore the hard hold for every reporter. | +| `issues.sha_hold_trusted_label` | `needs-sha`. | Label applied to primary-repo `kind/bug` issues without a SHA, except those from OWNER/MEMBER/COLLABORATOR or Hive authors, and those naming concrete files or code paths. The label blocks agent work until a SHA is supplied or an authorized dashboard user overrides it; the persistent `hive/sha-override` label prevents reapplication. Exempt issues have sweep-owned labels removed; human holds remain. Setting this to `hold` uses the default `needs-sha` instead. | | `issues.lift_hive_hard_suppress` | `true`. | Runs the hard-suppress reconcile (#12002): a `hold` or `blocked` label on an open issue is lifted when Hive provably applied it (newest label event is a `labeled` by the App bot; for `hold`, paired with the `` notice) and a PR cross-referencing the issue merged after it. Hive posts one note carrying ``. Human-applied labels are never lifted. Skipped with the other unstick steps when the API budget is critical. | | `issues.hard_suppress_reconcile_interval` | `30m`. | Minimum time between hard-suppress reconcile passes. | | `issues.rfc_existing_check.enabled` | `false`. | Triage existing-coverage check (#13575): new open issues labelled `rfc`, `enhancement` or `kind/feature` get one comment that lists the existing settings that may already cover the request. Each setting links to Settings with the search set to its key. The comment carries `` and is never posted twice. The check never labels or closes issues. Tuning keys are `post_when_nothing_found`, `labels`, `max_matches` and `max_age`; see [Triage: does this RFC already exist?](../settings.md#triage-does-this-rfc-already-exist). | diff --git a/src/docs/scale-envelope.md b/src/docs/scale-envelope.md index 0753118509..276a192836 100644 --- a/src/docs/scale-envelope.md +++ b/src/docs/scale-envelope.md @@ -34,7 +34,7 @@ ones to: 2. **Truncation must preserve the prioritization signal, not cut an arbitrary slice.** This holds today and is easy to assume backwards: - Issues are sorted by actionable rank tier, then **oldest first** within each tier before any cap is applied - (`RankActionableIssues`, `src/pkg/github/client.go:5369-5379`, descending `AgeMinutes` within each tier). + (`RankActionableIssues`, `src/pkg/github/client.go:5417-5427`, descending `AgeMinutes` within each tier). - PRs are sorted by **review class then oldest-first within class** (`SortPullRequestsForReview`, `src/pkg/github/review_priority.go:334`; fixes → refactors/docs → tests). diff --git a/src/pkg/dashboard/api_repo_hold.go b/src/pkg/dashboard/api_repo_hold.go index ddf59711a2..d51f015a87 100644 --- a/src/pkg/dashboard/api_repo_hold.go +++ b/src/pkg/dashboard/api_repo_hold.go @@ -16,8 +16,9 @@ import ( const repoHoldPermissionCacheTTL = 2 * time.Minute type repoHoldRequest struct { - Held bool `json:"held"` - Type string `json:"type"` + Held bool `json:"held"` + Type string `json:"type"` + OverrideSHA bool `json:"override_sha"` } type repoHoldResponse struct { @@ -672,6 +673,14 @@ func (s *Server) handleRepoItemHold(w http.ResponseWriter, r *http.Request) { if s.deps.Ctx != nil { ctx = s.deps.Ctx } + if body.OverrideSHA { + if body.Held || !strings.EqualFold(body.Type, "issue") { + jsonError(w, "SHA override requires an issue release", http.StatusBadRequest) + return + } + s.overrideRepoSHAHold(w, r, ctx, owner, repoName, number) + return + } canonical := s.canonicalHoldLabel() repoFull := owner + "/" + repoName var removed []string @@ -724,3 +733,47 @@ func (s *Server) handleRepoItemHold(w http.ResponseWriter, r *http.Request) { Result: result, }) } + +// overrideRepoSHAHold records the operator's decision before removing the +// SHA label, so subsequent sweeps can honor the override. +func (s *Server) overrideRepoSHAHold(w http.ResponseWriter, r *http.Request, ctx context.Context, owner, repo string, number int) { + repoFull := owner + "/" + repo + labels, err := s.currentItemLabels(ctx, owner, repo, number) + if err != nil { + s.repoHoldGitHubError(w, "read labels", repoFull, number, "", err) + return + } + shaLabel := "needs-sha" + if s.deps.Config != nil { + if configured := s.deps.Config.Issues.EffectiveSHAHoldTrustedLabel(); configured != "" && !strings.EqualFold(configured, "hold") { + shaLabel = configured + } + } + var removed []string + for _, label := range labels { + if strings.EqualFold(label, shaLabel) || strings.EqualFold(label, "needs-sha") { + removed = append(removed, label) + } + } + if len(removed) > 0 { + if err := s.deps.GHClient.EnsureIssueLabel(ctx, repoFull, github.SHAHoldOverrideLabel, "0e8a16", "A maintainer waived the SHA requirement for this issue."); err != nil { + s.repoHoldGitHubError(w, "ensure SHA override label", repoFull, number, github.SHAHoldOverrideLabel, err) + return + } + if err := s.deps.GHClient.AddLabels(ctx, repoFull, number, []string{github.SHAHoldOverrideLabel}); err != nil { + s.repoHoldGitHubError(w, "add SHA override label", repoFull, number, github.SHAHoldOverrideLabel, err) + return + } + for _, label := range removed { + if err := s.deps.GHClient.RemoveLabel(ctx, repoFull, number, label); err != nil { + s.repoHoldGitHubError(w, "remove SHA hold label", repoFull, number, label, err) + return + } + } + s.auditFromRequest(r, "repo_item_sha_override", auditDetail("repo", repoFull, "number", strconv.Itoa(number), "labels", strings.Join(removed, ",")), "") + } + jsonResponse(w, repoHoldResponse{ + OK: true, Repo: repoFull, Number: number, Removed: removed, + Result: repoHoldResult(repoFull, number, rowActionTargetIssue, false, shaLabel, removed), + }) +} diff --git a/src/pkg/dashboard/api_repo_hold_test.go b/src/pkg/dashboard/api_repo_hold_test.go index 550a45a5bd..8707a474ae 100644 --- a/src/pkg/dashboard/api_repo_hold_test.go +++ b/src/pkg/dashboard/api_repo_hold_test.go @@ -152,6 +152,30 @@ func TestRepoItemHoldToggleAuthorizationAndLabels(t *testing.T) { } } +func TestRepoItemSHAOverrideRequiresWriteAndPreservesOtherHolds(t *testing.T) { + mock := &repoHoldMock{permission: map[string]string{"writer": "maintain"}, issueLabels: []string{"needs-sha", "hold"}} + srv := newRepoHoldServer(t, mock) + post := func(user string) *httptest.ResponseRecorder { + req := httptest.NewRequest(http.MethodPost, "/api/repos/testorg/testrepo/items/7/hold", strings.NewReader(`{"held":false,"type":"issue","override_sha":true}`)) + req.Header.Set("X-Hive-User", user) + w := httptest.NewRecorder() + srv.mux.ServeHTTP(w, req) + return w + } + if w := post("reader"); w.Code != http.StatusForbidden { + t.Fatalf("reader: %d %s", w.Code, w.Body.String()) + } + if len(mock.added) != 0 || len(mock.removed) != 0 { + t.Fatal("reader changed labels") + } + if w := post("writer"); w.Code != http.StatusOK { + t.Fatalf("writer: %d %s", w.Code, w.Body.String()) + } + if strings.Join(mock.added, ",") != github.SHAHoldOverrideLabel || strings.Join(mock.removed, ",") != "needs-sha" { + t.Fatalf("added %v, removed %v; want override and needs-sha only", mock.added, mock.removed) + } +} + // TestRepoItemHoldGitHubFailureIsNotAGatewayStatus: a hold on an issue whose // GitHub label write fails answers 424 with GitHub's reason — never 502/503, // which the hosted Ingress replaces with its generic "hive unavailable" page diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 3b97811d1e..4efc7489cd 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -366,9 +366,11 @@ type StageTrackerItem struct { OpenChildren int `json:"open_children,omitempty"` // Labels are the item's GitHub labels as the snapshot saw them, so the // dashboard can offer a label filter without a second endpoint. - Labels []string `json:"labels,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` + Labels []string `json:"labels,omitempty"` + // SHA hold label actually present on this issue, including configured names. + SHAHoldLabel string `json:"sha_hold_label,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty"` + UpdatedAt *time.Time `json:"updated_at,omitempty"` // Bucket is the enumeration bucket of an item outside the actionable // set (claimed, in_progress, claimed_by_pr, filtered, hive_advisory, // reporter_triage, draft, …) and BucketReason the enumeration's note; diff --git a/src/pkg/dashboard/stage_tracker_build.go b/src/pkg/dashboard/stage_tracker_build.go index b7f626f710..c43b333686 100644 --- a/src/pkg/dashboard/stage_tracker_build.go +++ b/src/pkg/dashboard/stage_tracker_build.go @@ -298,6 +298,19 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto Labels: append([]string(nil), issue.Labels...), CreatedAt: timePtr(issue.CreatedAt), UpdatedAt: timePtr(issue.UpdatedAt), Bucket: bucket, BucketReason: bucketReason, URL: overviewItemURL(issue.URL, issue.Repo, issue.Number, "issue", status.GitHubBaseURL)} + shaLabel := config.DefaultSHAHoldTrustedLabel + if cfg != nil { + shaLabel = cfg.Issues.EffectiveSHAHoldTrustedLabel() + } + if strings.EqualFold(strings.TrimSpace(shaLabel), "hold") { + shaLabel = config.DefaultSHAHoldTrustedLabel + } + for _, label := range issue.Labels { + if strings.EqualFold(strings.TrimSpace(label), config.DefaultSHAHoldTrustedLabel) || strings.EqualFold(strings.TrimSpace(label), shaLabel) { + it.SHAHoldLabel = label + break + } + } it.Children = issue.Children if it.Children == nil { it.Children = progress diff --git a/src/pkg/dashboard/stage_tracker_control_labels.test.js b/src/pkg/dashboard/stage_tracker_control_labels.test.js new file mode 100644 index 0000000000..d199a84702 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_control_labels.test.js @@ -0,0 +1,35 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const strip = fs.readFileSync(path.join(__dirname, 'static-src/js/tracker-row-strip.js'), 'utf8'); +const actions = fs.readFileSync(path.join(__dirname, 'static-src/js/tracker-actions.js'), 'utf8'); +const pick = (source, re) => { const m = source.match(re); assert.ok(m); return m[0]; }; +const helpers = new Function('esc', 'stageTrackerActionCtx', 'stageTrackerActionAllowed', + pick(strip, /function stageTrackerControlLabels\(item\) \{[\s\S]*?\n \}/) + '\n' + + pick(strip, /function stageTrackerControlLabelsHtml\(item\) \{[\s\S]*?\n \}/) + + '\nreturn { labels: stageTrackerControlLabels, html: stageTrackerControlLabelsHtml };'); +const escape = s => String(s).replace(/&/g, '&').replace(/ { + const h = helpers(escape, () => ({}), () => ({ enabled: true })); + const labels = h.labels(issue); + assert.equal(labels.length, 2); + assert.match(labels[0].tip, /SHA.*comment.*sweep/); + assert.match(labels[1].tip, /acceptance criteria.*remove/); + assert.equal(h.labels({ kind: 'pr', labels: ['needs-sha'], sha_hold_label: 'needs-sha' }).length, 0); + assert.equal(h.labels({ kind: 'issue', labels: ['bug'] }).length, 0); + assert.equal(h.labels({ kind: 'issue', labels: ['WAIT-SHA'], sha_hold_label: 'wait-sha' })[0].sha, true); + assert.match(strip, /sg\.number === 0[\s\S]*?stageTrackerControlLabels\(item\)/); +}); + +test('SHA override follows hold permission and does not release other holds', () => { + const allowed = helpers(escape, () => ({}), () => ({ enabled: true })).html(issue); + assert.match(allowed, /data-ham-act="override-sha"/); + assert.doesNotMatch(allowed, /aria-disabled/); + const denied = helpers(escape, () => ({}), () => ({ enabled: false, why: 'write access required' })).html(issue); + assert.match(denied, /aria-disabled="true"/); + assert.match(denied, /write access required/); + assert.match(actions, /case 'override-sha':.*held: false, type, override_sha: true/); +}); diff --git a/src/pkg/dashboard/stage_tracker_sha_control_test.go b/src/pkg/dashboard/stage_tracker_sha_control_test.go new file mode 100644 index 0000000000..2151a408d4 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_sha_control_test.go @@ -0,0 +1,27 @@ +package dashboard + +import ( + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/github" +) + +func TestStageTrackerSHAControlLabel(t *testing.T) { + label := "wait-for-sha" + s := newTestServer() + s.deps = &Dependencies{Config: &config.Config{Issues: config.IssuesConfig{SHAHoldTrustedLabel: &label}}} + status := minimalPayload() + status.Repos = []FrontendRepo{{Name: "r", Full: "o/r", ActionableIssues: []any{ + github.Issue{Number: 1, Labels: []string{"WAIT-FOR-SHA"}}, + github.Issue{Number: 2, Labels: []string{"needs-sha"}}, + github.Issue{Number: 3, Labels: []string{"bug"}}, + }}} + resp := s.buildStageTracker(status, nil, time.Now()) + for number, want := range map[int]string{1: "WAIT-FOR-SHA", 2: "needs-sha", 3: ""} { + if got := trackerItem(t, resp, "issue", number).SHAHoldLabel; got != want { + t.Errorf("issue %d SHA hold label = %q, want %q", number, got, want) + } + } +} diff --git a/src/pkg/dashboard/static-src/js/tracker-actions.js b/src/pkg/dashboard/static-src/js/tracker-actions.js index 686651a28f..851af2d349 100644 --- a/src/pkg/dashboard/static-src/js/tracker-actions.js +++ b/src/pkg/dashboard/static-src/js/tracker-actions.js @@ -1349,6 +1349,7 @@ switch (id) { case 'hold': return { url: '/api/repos/' + seg + '/items/' + n + '/hold', body: { held: true, type } }; case 'release': return { url: '/api/repos/' + seg + '/items/' + n + '/hold', body: { held: false, type } }; + case 'override-sha': return type === 'issue' ? { url: '/api/repos/' + seg + '/items/' + n + '/hold', body: { held: false, type, override_sha: true } } : null; case 'retry': return { url: '/api/repos/rescan', body: {}, once: true }; case 'wf-dispatch': return { url: '/api/workflows/dispatch', body: { repo: item.repo, number: n } }; case 'needs-human': return { url: '/api/review/pipeline/' + seg + '/' + n + '/send-to-human', body: { reason: payload.comment || ('flagged from the activity monitor for ' + stageTrackerRefOf(item)) } }; diff --git a/src/pkg/dashboard/static-src/js/tracker-row-strip.js b/src/pkg/dashboard/static-src/js/tracker-row-strip.js index 823e437852..563b20b8d9 100644 --- a/src/pkg/dashboard/static-src/js/tracker-row-strip.js +++ b/src/pkg/dashboard/static-src/js/tracker-row-strip.js @@ -560,6 +560,10 @@ if (sg.draft) tip += ' — ' + STAGE_TRACKER_DRAFT_TIP; if (sg.isNew && typeof stageTrackerNewLines === 'function') tip = (typeof stageTrackerOpenTriageNeeded === 'function' && stageTrackerOpenTriageNeeded(item) ? 'Triage needed — ' : 'New — ') + stageTrackerNewLines(item, nowMs).join(' — '); if (sg.advisory) tip = (item.advisory && item.advisory.caption) || 'Advisory for maintainers · read, then close'; + if (sg.number === 0 && typeof stageTrackerControlLabels === 'function') { + const controls = stageTrackerControlLabels(item); + if (controls.length) tip += ' — ' + controls.map(c => c.label + ': ' + c.tip).join(' — '); + } if (sg.openSince) tip += ' — open since ' + new Date(sg.openSince.ms).toISOString() + (sg.openSince.fromCreated ? ' (opened)' : ''); // The shared Merge gate word hides 080 vs 095 vs 100; the chevron tooltip carries it. // With merge_gate in the payload the sentence is the gate's own @@ -968,7 +972,43 @@ const parked = Number(lp.stage) === STAGE_TRACKER_NEEDS_DECISION || (Array.isArray(lp.modifiers) && lp.modifiers.indexOf('needs-decision') >= 0) || !!(lp.decision_needed && lp.decision_needed.question); return parked ? lp : null; } + // Label gates are independent of the stage: a stale stage does not make + // an issue eligible while the scanner still sees one of these labels. + function stageTrackerControlLabels(item) { + if (!item || item.kind !== 'issue') return []; + const labels = Array.isArray(item.labels) ? item.labels : []; + const reasons = { + 'hold': 'Hive is paused on this issue. A maintainer can remove the hold to resume work.', + 'blocked': 'Hive is waiting for the blocker to clear. Resolve the blocker and remove the label.', + 'needs-human': 'Hive is waiting for a person. Address the request and remove the label.', + 'stage/045-needs-decision': 'Hive is waiting for a decision. Record the decision to lift the gate.', + 'stage/085-needs-decision': 'Hive is waiting for a decision. Record the decision to lift the gate.', + 'stage/017-possible-existing': 'Hive found possible prior art. Reply to the prior-art question to lift the gate.', + 'needs-spec': 'Hive needs a specification or acceptance criteria. Add them and remove the label.', + 'needs-direction': 'Hive needs direction. Give direction and remove the label.', + 'needs-decision': 'Hive needs a decision. Record the decision and remove the label.', + 'needs-reporter-confirmation': 'Hive is waiting for the reporter or a maintainer to confirm the fix. Confirm it to lift the gate.' + }; + return labels.map(label => { + const key = String(label).trim().toLowerCase(); + if (item.sha_hold_label && key === String(item.sha_hold_label).trim().toLowerCase()) { + return { label, sha: true, tip: 'Hive cannot work this bug without the affected commit SHA. Add the SHA to the issue or a comment; the SHA sweep removes the label. A maintainer may override this requirement.' }; + } + return reasons[key] ? { label, tip: reasons[key] } : null; + }).filter(Boolean); + } + function stageTrackerControlLabelsHtml(item) { + return stageTrackerControlLabels(item).map(c => { + const badge = `${esc(c.label)}`; + if (!c.sha) return badge; + const ctx = typeof stageTrackerActionCtx === 'function' ? stageTrackerActionCtx(item.repo) : {}; + const state = typeof stageTrackerActionAllowed === 'function' ? stageTrackerActionAllowed('release', ctx) : { enabled: false, why: 'Sign in to override' }; + const tip = state.enabled ? 'Override the SHA requirement for this issue; other holds remain in place.' : state.why; + return badge + ``; + }).join(''); + } function stageTrackerChipsHtml(item, opts) { + const controls = typeof stageTrackerControlLabelsHtml === 'function' ? stageTrackerControlLabelsHtml(item) : ''; // opts.gate: the row renders the one human-gate pill, which carries the // sentinel / hold / needs-human reasons itself — those chips step aside. const gated = !!(opts && opts.gate); @@ -987,7 +1027,7 @@ mods.push('needs-decision'); mods.sort((x, y) => STAGE_TRACKER_MOD_PRIORITY.indexOf(x) - STAGE_TRACKER_MOD_PRIORITY.indexOf(y)); } - if (!mods.length) return sentinel; + if (!mods.length) return controls + sentinel; // A regression the hive is working through yields the lead pill to any // other modifier and, alone, draws muted as "stage reset" rather than red. const handled = stageTrackerRegressionHandled(item); @@ -1033,7 +1073,7 @@ const cls = 'ham-mod-' + mods[0] + (handled && mods[0] === 'regressed' ? ' ham-mod-handled' : ''); const inner = `${esc(text)}${mods.length > 1 ? ' +' + (mods.length - 1) : ''}`; // The lead pill of a row blocked on a PR is the link to that PR. - if (blockedPR && blockedPR.url) return sentinel + `${inner}`; + if (blockedPR && blockedPR.url) return controls + sentinel + `${inner}`; // A lead needs-human / needs human decision pill opens the decision // popover (what to decide, who asked, the applicable actions) instead // of a native tooltip. @@ -1043,12 +1083,12 @@ // words fold into the icon so a nested PR's title keeps its line and // the popover / hover still carry the question (hivecommons/hive#17453). const askIco = askable && typeof stageTrackerIcon === 'function' ? stageTrackerIcon('human', 'ham-ico ham-mod-ico') : ''; - if (decision) return sentinel + stageTrackerDecisionTriggerHtml(decision, askIco ? askIco + `${inner}` : inner, tip, 'ham-badge ham-badge-mod ' + cls + (askIco ? ' ham-mod-ask' : '')); + if (decision) return controls + sentinel + stageTrackerDecisionTriggerHtml(decision, askIco ? askIco + `${inner}` : inner, tip, 'ham-badge ham-badge-mod ' + cls + (askIco ? ' ham-mod-ask' : '')); // No popover to open (the ask is the issue's own while a covering // PR drives the strip): the pill is a button that reveals the row's // "Needs human: …" note line and carries the full reason as its hover. - if (ask && typeof stageTrackerItemKey === 'function') return sentinel + ``; - return sentinel + `${inner}`; + if (ask && typeof stageTrackerItemKey === 'function') return controls + sentinel + ``; + return controls + sentinel + `${inner}`; } /* ---- "Did I act on this?" badge ------------------------------------ diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 32ff65a3f9..677a46571c 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -20220,6 +20220,10 @@

Where to get help

if (sg.draft) tip += ' — ' + STAGE_TRACKER_DRAFT_TIP; if (sg.isNew && typeof stageTrackerNewLines === 'function') tip = (typeof stageTrackerOpenTriageNeeded === 'function' && stageTrackerOpenTriageNeeded(item) ? 'Triage needed — ' : 'New — ') + stageTrackerNewLines(item, nowMs).join(' — '); if (sg.advisory) tip = (item.advisory && item.advisory.caption) || 'Advisory for maintainers · read, then close'; + if (sg.number === 0 && typeof stageTrackerControlLabels === 'function') { + const controls = stageTrackerControlLabels(item); + if (controls.length) tip += ' — ' + controls.map(c => c.label + ': ' + c.tip).join(' — '); + } if (sg.openSince) tip += ' — open since ' + new Date(sg.openSince.ms).toISOString() + (sg.openSince.fromCreated ? ' (opened)' : ''); // The shared Merge gate word hides 080 vs 095 vs 100; the chevron tooltip carries it. // With merge_gate in the payload the sentence is the gate's own @@ -20628,7 +20632,43 @@

Where to get help

const parked = Number(lp.stage) === STAGE_TRACKER_NEEDS_DECISION || (Array.isArray(lp.modifiers) && lp.modifiers.indexOf('needs-decision') >= 0) || !!(lp.decision_needed && lp.decision_needed.question); return parked ? lp : null; } + // Label gates are independent of the stage: a stale stage does not make + // an issue eligible while the scanner still sees one of these labels. + function stageTrackerControlLabels(item) { + if (!item || item.kind !== 'issue') return []; + const labels = Array.isArray(item.labels) ? item.labels : []; + const reasons = { + 'hold': 'Hive is paused on this issue. A maintainer can remove the hold to resume work.', + 'blocked': 'Hive is waiting for the blocker to clear. Resolve the blocker and remove the label.', + 'needs-human': 'Hive is waiting for a person. Address the request and remove the label.', + 'stage/045-needs-decision': 'Hive is waiting for a decision. Record the decision to lift the gate.', + 'stage/085-needs-decision': 'Hive is waiting for a decision. Record the decision to lift the gate.', + 'stage/017-possible-existing': 'Hive found possible prior art. Reply to the prior-art question to lift the gate.', + 'needs-spec': 'Hive needs a specification or acceptance criteria. Add them and remove the label.', + 'needs-direction': 'Hive needs direction. Give direction and remove the label.', + 'needs-decision': 'Hive needs a decision. Record the decision and remove the label.', + 'needs-reporter-confirmation': 'Hive is waiting for the reporter or a maintainer to confirm the fix. Confirm it to lift the gate.' + }; + return labels.map(label => { + const key = String(label).trim().toLowerCase(); + if (item.sha_hold_label && key === String(item.sha_hold_label).trim().toLowerCase()) { + return { label, sha: true, tip: 'Hive cannot work this bug without the affected commit SHA. Add the SHA to the issue or a comment; the SHA sweep removes the label. A maintainer may override this requirement.' }; + } + return reasons[key] ? { label, tip: reasons[key] } : null; + }).filter(Boolean); + } + function stageTrackerControlLabelsHtml(item) { + return stageTrackerControlLabels(item).map(c => { + const badge = `${esc(c.label)}`; + if (!c.sha) return badge; + const ctx = typeof stageTrackerActionCtx === 'function' ? stageTrackerActionCtx(item.repo) : {}; + const state = typeof stageTrackerActionAllowed === 'function' ? stageTrackerActionAllowed('release', ctx) : { enabled: false, why: 'Sign in to override' }; + const tip = state.enabled ? 'Override the SHA requirement for this issue; other holds remain in place.' : state.why; + return badge + ``; + }).join(''); + } function stageTrackerChipsHtml(item, opts) { + const controls = typeof stageTrackerControlLabelsHtml === 'function' ? stageTrackerControlLabelsHtml(item) : ''; // opts.gate: the row renders the one human-gate pill, which carries the // sentinel / hold / needs-human reasons itself — those chips step aside. const gated = !!(opts && opts.gate); @@ -20647,7 +20687,7 @@

Where to get help

mods.push('needs-decision'); mods.sort((x, y) => STAGE_TRACKER_MOD_PRIORITY.indexOf(x) - STAGE_TRACKER_MOD_PRIORITY.indexOf(y)); } - if (!mods.length) return sentinel; + if (!mods.length) return controls + sentinel; // A regression the hive is working through yields the lead pill to any // other modifier and, alone, draws muted as "stage reset" rather than red. const handled = stageTrackerRegressionHandled(item); @@ -20693,7 +20733,7 @@

Where to get help

const cls = 'ham-mod-' + mods[0] + (handled && mods[0] === 'regressed' ? ' ham-mod-handled' : ''); const inner = `${esc(text)}${mods.length > 1 ? ' +' + (mods.length - 1) : ''}`; // The lead pill of a row blocked on a PR is the link to that PR. - if (blockedPR && blockedPR.url) return sentinel + `${inner}`; + if (blockedPR && blockedPR.url) return controls + sentinel + `${inner}`; // A lead needs-human / needs human decision pill opens the decision // popover (what to decide, who asked, the applicable actions) instead // of a native tooltip. @@ -20703,12 +20743,12 @@

Where to get help

// words fold into the icon so a nested PR's title keeps its line and // the popover / hover still carry the question (hivecommons/hive#17453). const askIco = askable && typeof stageTrackerIcon === 'function' ? stageTrackerIcon('human', 'ham-ico ham-mod-ico') : ''; - if (decision) return sentinel + stageTrackerDecisionTriggerHtml(decision, askIco ? askIco + `${inner}` : inner, tip, 'ham-badge ham-badge-mod ' + cls + (askIco ? ' ham-mod-ask' : '')); + if (decision) return controls + sentinel + stageTrackerDecisionTriggerHtml(decision, askIco ? askIco + `${inner}` : inner, tip, 'ham-badge ham-badge-mod ' + cls + (askIco ? ' ham-mod-ask' : '')); // No popover to open (the ask is the issue's own while a covering // PR drives the strip): the pill is a button that reveals the row's // "Needs human: …" note line and carries the full reason as its hover. - if (ask && typeof stageTrackerItemKey === 'function') return sentinel + ``; - return sentinel + `${inner}`; + if (ask && typeof stageTrackerItemKey === 'function') return controls + sentinel + ``; + return controls + sentinel + `${inner}`; } /* ---- "Did I act on this?" badge ------------------------------------ @@ -26394,6 +26434,7 @@

All labels

switch (id) { case 'hold': return { url: '/api/repos/' + seg + '/items/' + n + '/hold', body: { held: true, type } }; case 'release': return { url: '/api/repos/' + seg + '/items/' + n + '/hold', body: { held: false, type } }; + case 'override-sha': return type === 'issue' ? { url: '/api/repos/' + seg + '/items/' + n + '/hold', body: { held: false, type, override_sha: true } } : null; case 'retry': return { url: '/api/repos/rescan', body: {}, once: true }; case 'wf-dispatch': return { url: '/api/workflows/dispatch', body: { repo: item.repo, number: n } }; case 'needs-human': return { url: '/api/review/pipeline/' + seg + '/' + n + '/send-to-human', body: { reason: payload.comment || ('flagged from the activity monitor for ' + stageTrackerRefOf(item)) } }; diff --git a/src/pkg/github/client.go b/src/pkg/github/client.go index 8da6cf9972..8ccc01eb33 100644 --- a/src/pkg/github/client.go +++ b/src/pkg/github/client.go @@ -4711,10 +4711,8 @@ type SHAHoldConfig struct { PrimaryRepo string AIAuthor string InternalAuthors []string - // TrustedAssociations are the GitHub author associations (OWNER, MEMBER, - // COLLABORATOR, ...) that got TrustedLabel instead of the hard `hold` - // (hivecommons/hive#12002). Since #18468 every reporter gets TrustedLabel - // and the sweep no longer consults this; it is kept for callers. + // TrustedAssociations is retained for compatibility; OWNER, MEMBER and + // COLLABORATOR are always exempt from the SHA gate. TrustedAssociations []string // TrustedLabel is the label the sweep applies while a SHA is missing. // Empty (or "hold") uses defaultSHAHoldLabel: the sweep never applies @@ -4735,6 +4733,9 @@ type SHAHoldResult struct { // configured (config.DefaultSHAHoldTrustedLabel). const defaultSHAHoldLabel = "needs-sha" +// SHAHoldOverrideLabel records an authorized operator's durable exemption. +const SHAHoldOverrideLabel = "hive/sha-override" + // NeedsSHALabelDescription is the repo label description for the SHA-hold label. const NeedsSHALabelDescription = "Waiting on the reporter for the commit SHA; hive won't work this until it's added." @@ -4775,11 +4776,8 @@ func (c *Client) ensureNeedsSHALabel(ctx context.Context, owner, repo, name stri // shaHoldLabel returns the label the sweep applies to an issue missing a SHA. // It is never `hold`: a `hold` means a person said hands-off, and the hive // no longer applies one itself (hivecommons/hive#18468). Before #18468 an -// untrusted reporter's issue got the hard `hold`; the sweep now gives every -// reporter this label and swaps any `hold` it applied itself for it. An -// untrusted reporter's issue still stays out of automatic work through the -// reporter-trust gate (issue_filter.reporter_trust) until a maintainer -// admits it. +// untrusted reporter's issue got the hard `hold`; the sweep now uses this +// label for non-exempt reporters. func (cfg SHAHoldConfig) shaHoldLabel() string { label := strings.TrimSpace(cfg.TrustedLabel) if label == "" || strings.EqualFold(label, LegacyHiveHoldLabel) { @@ -4813,12 +4811,15 @@ func (c *Client) EnforceSHAHold(ctx context.Context, cfg SHAHoldConfig) (*SHAHol } author := safeGetLogin(issue.GetUser()) - if author == cfg.AIAuthor || isInternalAuthor(author, cfg.InternalAuthors) { - result.Skipped++ + labels := extractLabels(issue.Labels) + association := strings.ToUpper(strings.TrimSpace(issue.GetAuthorAssociation())) + if (author != "" && strings.EqualFold(author, cfg.AIAuthor)) || isInternalAuthor(author, cfg.InternalAuthors) || + association == "OWNER" || association == "MEMBER" || association == "COLLABORATOR" || + labelPresent(labels, SHAHoldOverrideLabel) || shaHoldBodyHasPath(issue.GetBody()) { + c.releaseExemptSHAHold(ctx, owner, repo, issue.GetNumber(), cfg.shaHoldLabel(), labels, result) continue } - labels := extractLabels(issue.Labels) held := c.isHeld(labels) hasSHA := shaPattern.MatchString(issue.GetBody()) @@ -4832,6 +4833,53 @@ func (c *Client) EnforceSHAHold(ctx context.Context, cfg SHAHoldConfig) (*SHAHol return result, nil } +// shaHoldBodyHasPath accepts concrete repository paths in prose or backticks. +// Reuse the issue path recognizer, excluding URLs and arbitrary prose. +func shaHoldBodyHasPath(body string) bool { + for _, token := range strings.Fields(body) { + token = strings.Trim(token, "`\"'()[]<>,;.") + if _, ok := normalizeCitedPath(token); ok { + return true + } + } + return false +} + +// releaseExemptSHAHold removes only labels demonstrably owned by the sweep. +// A human or another subsystem's hold must remain in place. +func (c *Client) releaseExemptSHAHold(ctx context.Context, owner, repo string, number int, soft string, labels []string, result *SHAHoldResult) { + removed := false + if labelPresent(labels, soft) { + own, _, err := c.latestLabelEventByApp(ctx, owner, repo, number, soft) + if err != nil { + c.logger.Warn("SHA exemption: could not verify label provenance", "repo", repo, "issue", number, "label", soft, "error", err) + } else if own { + if _, err := c.client.Issues.RemoveLabelForIssue(ctx, owner, repo, number, soft); err != nil { + c.logger.Warn("SHA exemption: failed to remove label", "repo", repo, "issue", number, "label", soft, "error", err) + } else { + removed = true + } + } + } + if labelPresent(labels, "hold") { + own, err := c.shaHoldIsOwn(ctx, owner, repo, number) + if err != nil { + c.logger.Warn("SHA exemption: could not verify hold provenance", "repo", repo, "issue", number, "error", err) + } else if own { + if _, err := c.client.Issues.RemoveLabelForIssue(ctx, owner, repo, number, "hold"); err != nil { + c.logger.Warn("SHA exemption: failed to remove hold", "repo", repo, "issue", number, "error", err) + } else { + removed = true + } + } + } + if removed { + result.Unheld++ + } else { + result.Skipped++ + } +} + // enforceSoftSHAHold is EnforceSHAHold's one branch (trusted reporters since // hivecommons/hive#12002, every reporter since #18468). It never applies the // hard `hold`: a missing SHA diff --git a/src/pkg/github/sha_hold_soft_test.go b/src/pkg/github/sha_hold_soft_test.go index bd9b2ce47b..70829d74cc 100644 --- a/src/pkg/github/sha_hold_soft_test.go +++ b/src/pkg/github/sha_hold_soft_test.go @@ -72,6 +72,7 @@ func TestEnforceSHAHold_TrustedReporterGetsSoftLabel(t *testing.T) { cases := []struct { name string association string + body string labels []wireLabel comments []wireComment events []map[string]any @@ -81,12 +82,10 @@ func TestEnforceSHAHold_TrustedReporterGetsSoftLabel(t *testing.T) { want SHAHoldResult }{ { - name: "member without SHA gets needs-sha, not hold", - association: "MEMBER", - labels: []wireLabel{{Name: "kind/bug"}}, - wantAdded: []string{"needs-sha"}, - wantComments: 1, - want: SHAHoldResult{Held: 1}, + name: "member without SHA is exempt", + association: "MEMBER", + labels: []wireLabel{{Name: "kind/bug"}}, + want: SHAHoldResult{Skipped: 1}, }, { // hivecommons/hive#18468: the hive never applies `hold` @@ -99,15 +98,15 @@ func TestEnforceSHAHold_TrustedReporterGetsSoftLabel(t *testing.T) { wantComments: 1, }, { - name: "member supplies SHA and the soft label lifts", - association: "MEMBER", + name: "external reporter supplies SHA and the soft label lifts", + association: "NONE", labels: []wireLabel{{Name: "kind/bug"}, {Name: "needs-sha"}}, comments: []wireComment{{User: wireUser{"maintainer"}, Body: "running abc1234def"}}, wantRemoved: []string{"needs-sha"}, want: SHAHoldResult{Unheld: 1}, }, { - name: "sweep's legacy hard hold on a member issue is softened", + name: "sweep's legacy hard hold on an owner issue is released", association: "OWNER", labels: []wireLabel{{Name: "kind/bug"}, {Name: "hold"}}, comments: []wireComment{{User: wireUser{testHiveAppBotLogin}, Body: shaHoldComment, CreatedAt: "2026-09-15T12:00:01Z"}}, @@ -115,9 +114,8 @@ func TestEnforceSHAHold_TrustedReporterGetsSoftLabel(t *testing.T) { "event": "labeled", "created_at": "2026-09-15T12:00:00Z", "actor": map[string]string{"login": testHiveAppBotLogin}, "label": map[string]string{"name": "hold"}, }}, - wantAdded: []string{"needs-sha"}, wantRemoved: []string{"hold"}, - want: SHAHoldResult{Softened: 1}, + want: SHAHoldResult{Unheld: 1}, }, { name: "human hold on a member issue is left alone", @@ -129,11 +127,47 @@ func TestEnforceSHAHold_TrustedReporterGetsSoftLabel(t *testing.T) { }}, want: SHAHoldResult{Skipped: 1}, }, + { + name: "owner exemption removes sweep label", + association: "OWNER", + labels: []wireLabel{{Name: "kind/bug"}, {Name: "needs-sha"}}, + events: []map[string]any{{"event": "labeled", "created_at": "2026-09-15T12:00:00Z", "actor": map[string]string{"login": testHiveAppBotLogin}, "label": map[string]string{"name": "needs-sha"}}}, + wantRemoved: []string{"needs-sha"}, + want: SHAHoldResult{Unheld: 1}, + }, + { + name: "human reapplied label remains", + association: "OWNER", + labels: []wireLabel{{Name: "kind/bug"}, {Name: "needs-sha"}}, + events: []map[string]any{{"event": "labeled", "created_at": "2026-09-15T12:00:00Z", "actor": map[string]string{"login": "alice"}, "label": map[string]string{"name": "needs-sha"}}}, + want: SHAHoldResult{Skipped: 1}, + }, + { + name: "external report with path is exempt", + association: "NONE", + body: "Failure in src/pkg/github/client.go:123", + labels: []wireLabel{{Name: "kind/bug"}}, + want: SHAHoldResult{Skipped: 1}, + }, + { + name: "override persists without SHA", + association: "NONE", + labels: []wireLabel{{Name: "kind/bug"}, {Name: SHAHoldOverrideLabel}}, + want: SHAHoldResult{Skipped: 1}, + }, + { + name: "override removes sweep label", + association: "NONE", + labels: []wireLabel{{Name: "kind/bug"}, {Name: SHAHoldOverrideLabel}, {Name: "needs-sha"}}, + events: []map[string]any{{"event": "labeled", "created_at": "2026-09-15T12:00:00Z", "actor": map[string]string{"login": testHiveAppBotLogin}, "label": map[string]string{"name": "needs-sha"}}}, + wantRemoved: []string{"needs-sha"}, + want: SHAHoldResult{Unheld: 1}, + }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { rec := &shaSoftRecorder{} - issue := wireIssue{Number: 11732, Title: "bug", User: wireUser{"maintainer"}, Labels: tc.labels, CreatedAt: hoursAgo(1), AuthorAssociation: tc.association} + issue := wireIssue{Number: 11732, Title: "bug", Body: tc.body, User: wireUser{"maintainer"}, Labels: tc.labels, CreatedAt: hoursAgo(1), AuthorAssociation: tc.association} server := httptest.NewServer(buildSHASoftMux(t, org, repo, issue, tc.comments, tc.events, rec)) defer server.Close() c := newTestClient(t, server, org, []string{repo}) @@ -163,6 +197,31 @@ func TestEnforceSHAHold_TrustedReporterGetsSoftLabel(t *testing.T) { } } +func TestSHAHoldBodyHasPath(t *testing.T) { + for _, tc := range []struct { + body string + want bool + }{ + {"Fix `src/pkg/github/client.go:123`", true}, + {"Look at src/pkg/github/client.go", true}, + {"See `Makefile`", true}, + {"Inspect `src/pkg/`", true}, + {"The console crashes on startup", false}, + {"See https://example.com/path/file.go", false}, + {"Version 1.2.3 is broken", false}, + } { + if got := shaHoldBodyHasPath(tc.body); got != tc.want { + t.Errorf("shaHoldBodyHasPath(%q) = %v, want %v", tc.body, got, tc.want) + } + } +} + +func TestSHAHoldOverrideIsNotAHold(t *testing.T) { + if HasHoldLabel([]string{SHAHoldOverrideLabel}) { + t.Fatal("the durable SHA override must not itself block work") + } +} + func TestSHAHoldConfig_LabelIsNeverHold(t *testing.T) { for _, label := range []string{"", "hold", " HOLD "} { cfg := SHAHoldConfig{TrustedAssociations: []string{"MEMBER"}, TrustedLabel: label}