From a194936a49e6f89dcb66006132dcb2cbd6bbfd1f Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Tue, 17 Nov 2026 22:32:09 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Never=20auto-close=20epics=20or?= =?UTF-8?q?=20parents=20a=20person=20reopened=20(#18869)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andrew Anderson --- .../fixed-18869-parent-autoclose-reopen.md | 1 + src/cmd/hive/main_sweeps.go | 2 +- .../stage-labels.md | 33 ++++- src/docs/operator-reference/README.md | 1 + src/pkg/config/repo_settings.go | 30 ++++ src/pkg/config/repo_settings_test.go | 16 ++ .../dashboard/settings_parity_allowlist.txt | 1 + src/pkg/github/decomposed_parents.go | 109 ++++++++++++++ src/pkg/github/decomposed_parents_test.go | 137 ++++++++++++++++++ src/pkg/github/issue_stage_labels.go | 4 + src/pkg/github/issue_stage_labels_test.go | 13 ++ src/pkg/github/issue_timeline.go | 4 +- 12 files changed, 345 insertions(+), 6 deletions(-) create mode 100644 changelog.d/fixed-18869-parent-autoclose-reopen.md diff --git a/changelog.d/fixed-18869-parent-autoclose-reopen.md b/changelog.d/fixed-18869-parent-autoclose-reopen.md new file mode 100644 index 0000000000..4c97cae251 --- /dev/null +++ b/changelog.d/fixed-18869-parent-autoclose-reopen.md @@ -0,0 +1 @@ +- Never auto-close a decomposed parent that a person reopened after a hive auto-close or that is labelled epic/hold, and add the per-repo `repos..parent_autoclose` (`true`/`epics_too`/`false`) switch (#18869). diff --git a/src/cmd/hive/main_sweeps.go b/src/cmd/hive/main_sweeps.go index eebae1bf67..c49fc48dda 100644 --- a/src/cmd/hive/main_sweeps.go +++ b/src/cmd/hive/main_sweeps.go @@ -2055,7 +2055,7 @@ func installReviewRelaySettings(client *github.Client, cfg *config.Config, logge for name := range cfg.Agents { agents = append(agents, name) } - return github.IssueStagePolicy{Enabled: p.Enabled, Dwell: p.Dwell, AgentNames: agents} + return github.IssueStagePolicy{Enabled: p.Enabled, Dwell: p.Dwell, AgentNames: agents, ParentAutoClose: func(repo string) string { return cfg.ParentAutoCloseFor(repo) }} }) client.SetReviewCadenceLimits( func() bool { return cfg.Review.CombinedPerspectives }, diff --git a/src/docs/labels-and-control-signals/stage-labels.md b/src/docs/labels-and-control-signals/stage-labels.md index 2cfbfc4d61..5033591d7c 100644 --- a/src/docs/labels-and-control-signals/stage-labels.md +++ b/src/docs/labels-and-control-signals/stage-labels.md @@ -277,7 +277,7 @@ final, and maps each row ([#12436](https://github.com/hivecommons/hive/issues/12 | covered by an open PR the sweep has staged (≥ 050) | still `040-covered-by-pr`; the reason reads `open PR #N covers it (PR at )`. `050`+ are PR-only stages and never land on an issue ([#12451](https://github.com/hivecommons/hive/issues/12451)) | | reporter triage (human-filed, held by the #9665 gate until the triage label lands) | `015-triage-needed` — the gate still withholds it from agents | | exempt / filtered / advisory / dependency dashboard | no stage | -| **decomposed parent** — an issue with tracked child issues (GitHub sub-issues the relay linked with `parent: N`; see below) | keeps the stage the rows above give it while any child is open, **never `stage/stalled`**; once every child is closed the parent is **closed as completed** by the sweep ([#12857](https://github.com/hivecommons/hive/issues/12857)) | +| **decomposed parent** — an issue with tracked child issues (GitHub sub-issues the relay linked with `parent: N`; see below) | keeps the stage the rows above give it while any child is open, **never `stage/stalled`**; once every child is closed the parent is **closed as completed** by the sweep unless it is an epic/hold, was reopened by a person, or the repo disables it ([#12857](https://github.com/hivecommons/hive/issues/12857)) | Labels come from the issue list payload the cycle already fetched — no per-issue GETs — and are written only when the planned set differs from the @@ -694,9 +694,34 @@ the open-issue snapshot instead — and then: "delivered" comment is posted until the close succeeds. - **No children** → nothing changes. -Reopen the parent if something it asked for is still missing; the sweep does -not close it again until a child is reopened and closed once more (the -sub-issue summary is read fresh each cycle). +Reopen the parent if something it asked for is still missing. A parent a +person reopens after a hive auto-close is **never auto-closed again** +([#18869](https://github.com/hivecommons/hive/issues/18869)): once every +child is confirmed closed the sweep reads the parent's timeline (one read, +only at that point, cached per parent) and keeps it open when a non-bot +`reopened` event follows the `` comment (or a +bot's close). The timeline is the record, so the rule survives restarts; +an unreadable timeline means no close that cycle. This holds under every +config value below. + +**Epics and holds are never auto-closed.** An issue labelled `epic` (any +case) or `hold` stays open for a person to close, with all children closed. +Per repo, `repos..parent_autoclose` chooses the policy: + +| value | behaviour | +|---|---| +| `true` (default) | close a decomposed parent when all children are closed, except `epic`/`hold`-labelled issues | +| `epics_too` | also close `epic`/`hold`-labelled parents | +| `false` | never auto-close a parent in this repo | + +```yaml +repos: + torch-spyre/spyre-inference: + parent_autoclose: false +``` + +The dashboard does not yet show a "kept open: reopened by " pill; the +kept-open decision is logged (`decomposed parent kept open`). ### `stage/stalled` — "nobody is working this" diff --git a/src/docs/operator-reference/README.md b/src/docs/operator-reference/README.md index 1ea3922f00..b56b139b55 100644 --- a/src/docs/operator-reference/README.md +++ b/src/docs/operator-reference/README.md @@ -298,6 +298,7 @@ Go callers keep reading `cfg.Agents`, `cfg.Governor.Gateways` and so on through | `governor.trajectory.enabled` | Defaults to enabled. | The lane no-ops until a reviewer endpoint and model resolve from `governor.trajectory` or `governor.litellm`. | | `governor.kick_limits.max_issues` / `max_prs` | `100` / `50` | Caps on every issue list and every PR list (actionable, stale drafts, merge-eligible, CI-failing) rendered into a kick prompt; a cut list ends with an explicit "… and N more" line. An absent key or a negative value means the default; an explicit `0` opts out of the cap entirely (`KickListUnlimited` — every item is listed), and anything above `500` is pinned to `500`. Editable without touching this file under **Settings → Repos → Kick prompt list caps**. Truncation drops the *newest, lowest-priority* items: issues are listed oldest first, and PRs in review-priority order (fixes, then refactors/docs, then tests, oldest first within each class), so lowering a cap never hides the most urgent work. Raise `max_prs` only if your agents actually work more than 50 PRs per turn; the tail of a long list costs tokens and delivery time on every kick without changing behaviour (#7368). | | `project.agents_md_max_bytes` | `32768` (or env `HIVE_AGENTS_MD_MAX_BYTES`); clamped to `2048`..`262144`. `repos..agents_md_max_bytes` overrides it per repo. | Caps the repo `AGENTS.md` block prepended to a kick. Whole sections (split at `#`/`##` headings; each resolved skill is its own unit) are kept or dropped, never clipped mid-rule; when any are dropped the kick carries a one-line `⚠️ AGENTS.md exceeded N bytes; … — read AGENTS.md …` warning naming them and the scheduler logs it. See [agents-md.md](../agents-md.md#size-cap-whole-sections-visible-warning). | +| `repos..parent_autoclose` | `true` (default), `epics_too` or `false` | Decomposed-parent auto-close policy for the repo: `true` closes a parent when every child is closed except `epic`/`hold`-labelled issues; `epics_too` also closes those; `false` never closes a parent. A parent a person reopened after a hive auto-close is never re-closed under any value. See [stage-labels.md](../labels-and-control-signals/stage-labels.md#decomposed-parents--closed-by-their-children-never-stalled). | | `project.style` | unset (built-in text applies) | Hive-wide **house style**: a short how-to-change rule list prepended to every kick on every backend, directly under the header. A managed repo's root `HIVE_STYLE.md` (read from `project.checkouts_dir`) overrides it; precedence repo > hive > built-in. Inline text wins over `project.style_file`. See [house-style.md](../house-style.md). | | `project.style_file` | unset | Path on the hive host holding the hive-wide house style; used when `project.style` is empty. | | `project.style_max_bytes` | `4096`; values under `512` are raised to `512`. | Caps each house-style candidate. An oversize candidate is skipped whole (not clipped) and the next source applies; the skip is audited as `house_style_skip`. The repo file is also run through ioscan at the issue-body policy and refused whole on a block. | diff --git a/src/pkg/config/repo_settings.go b/src/pkg/config/repo_settings.go index fa2a5f9dc7..6dd5b08303 100644 --- a/src/pkg/config/repo_settings.go +++ b/src/pkg/config/repo_settings.go @@ -11,6 +11,36 @@ type RepoSettings struct { // project.agents_md_max_bytes. Zero inherits it. The agentsmd floor and // hard ceiling still apply (agentsmd.EffectiveMaxBytes). AgentsMdMaxBytes int `yaml:"agents_md_max_bytes,omitempty" json:"agents_md_max_bytes,omitempty"` + // ParentAutoClose is the decomposed-parent auto-close policy for this + // repo (hivecommons/hive#18869): "true" (the default when empty) closes a + // decomposed parent once every child is closed, except an issue labelled + // epic or hold; "false" never auto-closes a parent; "epics_too" also + // closes epic/hold-labelled parents. A parent a person reopened after a + // hive auto-close is never re-closed under any value. YAML booleans + // true/false are accepted and read as the strings. + ParentAutoClose string `yaml:"parent_autoclose,omitempty" json:"parent_autoclose,omitempty"` +} + +// Parent auto-close policy values for RepoSettings.ParentAutoClose. +const ( + ParentAutoCloseOn = "true" + ParentAutoCloseOff = "false" + ParentAutoCloseEpicsToo = "epics_too" +) + +// ParentAutoCloseFor is the normalised parent auto-close policy for repo: +// one of ParentAutoCloseOn (default), ParentAutoCloseOff or +// ParentAutoCloseEpicsToo. An unrecognised value falls back to the default. +func (c *Config) ParentAutoCloseFor(repo string) string { + rs, ok := c.RepoSettingsFor(repo) + if !ok { + return ParentAutoCloseOn + } + switch v := strings.ToLower(strings.TrimSpace(rs.ParentAutoClose)); v { + case ParentAutoCloseOff, ParentAutoCloseEpicsToo: + return v + } + return ParentAutoCloseOn } // RepoSettingsFor returns repo's entry from the `repos:` map, and whether one diff --git a/src/pkg/config/repo_settings_test.go b/src/pkg/config/repo_settings_test.go index 245f098881..4efa7e3384 100644 --- a/src/pkg/config/repo_settings_test.go +++ b/src/pkg/config/repo_settings_test.go @@ -50,3 +50,19 @@ func TestReposAgentsMdMaxBytesYAML(t *testing.T) { t.Errorf("yaml per-repo cap = %d, want 49152", got) } } + +func TestParentAutoCloseFor(t *testing.T) { + var cfg Config + if err := yaml.Unmarshal([]byte("project: {org: acme}\nrepos:\n off: {parent_autoclose: false}\n epics: {parent_autoclose: epics_too}\n on: {parent_autoclose: true}\n junk: {parent_autoclose: maybe}\n other: {}\n"), &cfg); err != nil { + t.Fatal(err) + } + cases := map[string]string{ + "off": ParentAutoCloseOff, "acme/epics": ParentAutoCloseEpicsToo, "on": ParentAutoCloseOn, + "junk": ParentAutoCloseOn, "other": ParentAutoCloseOn, "unlisted": ParentAutoCloseOn, + } + for repo, want := range cases { + if got := cfg.ParentAutoCloseFor(repo); got != want { + t.Errorf("%s = %q, want %q", repo, got, want) + } + } +} diff --git a/src/pkg/dashboard/settings_parity_allowlist.txt b/src/pkg/dashboard/settings_parity_allowlist.txt index b0b909b1a2..acf9474de7 100644 --- a/src/pkg/dashboard/settings_parity_allowlist.txt +++ b/src/pkg/dashboard/settings_parity_allowlist.txt @@ -547,6 +547,7 @@ project.repos[] # TODO #11854 providers.status.enabled # TODO #11854 removed_agents[] # TODO #11854 repos..agents_md_max_bytes # TODO #18495 (per-repo AGENTS.md cap; Settings control pending) +repos..parent_autoclose # TODO #18869 (per-repo decomposed-parent auto-close policy; Settings control pending) review.backlog.labels[] # TODO #11854 review.bot_author_full_review_paths[] # TODO #14625 review.bot_author_model # TODO #14625 diff --git a/src/pkg/github/decomposed_parents.go b/src/pkg/github/decomposed_parents.go index 0a3bba42b1..5a63abb560 100644 --- a/src/pkg/github/decomposed_parents.go +++ b/src/pkg/github/decomposed_parents.go @@ -8,8 +8,11 @@ import ( "regexp" "strconv" "strings" + "sync" + "time" gh "github.com/google/go-github/v72/github" + "github.com/hivecommons/hive/pkg/config" "github.com/hivecommons/hive/pkg/prstatus" "github.com/hivecommons/hive/pkg/stagelabels" ) @@ -351,6 +354,13 @@ func decomposedParentCloseComment(children []ChildRef, closers map[ChildRef]int) // gate refuses does not leave a "delivered" note every cycle. func (c *Client) closeDecomposedParent(ctx context.Context, in IssueStageInput, store *stagelabels.Store, key string, logger *slog.Logger) bool { owner, name := c.splitRepo(in.Repo) + // Label/config exemptions cost no API call, so they run first. + if reason := parentAutoCloseExempt(c.parentAutoClosePolicy(in.Repo), in.Labels); reason != "" { + if logger != nil { + logger.Debug("issue stage labels: decomposed parent not auto-closed", "repo", in.Repo, "issue", in.Number, "reason", reason) + } + return false + } children, open, ok, err := c.decomposedChildren(ctx, owner, name, in.Number) if err != nil { if logger != nil { @@ -361,6 +371,14 @@ func (c *Client) closeDecomposedParent(ctx context.Context, in IssueStageInput, if !ok || open > 0 { return false } + // Only now, with every child confirmed closed, spend a timeline read: + // a parent a person reopened after a hive auto-close stays open. + if by, kept := c.parentKeptOpenBy(ctx, owner, name, in.Number, logger); kept || by != "" { + if logger != nil { + logger.Info("issue stage labels: decomposed parent kept open, reopened by a person after a hive auto-close", "repo", in.Repo, "issue", in.Number, "reopened_by", by) + } + return false + } closers := map[ChildRef]int{} for _, ref := range children { childOwner, childName := owner, name @@ -394,3 +412,94 @@ func (c *Client) closeDecomposedParent(ctx context.Context, in IssueStageInput, } return true } + +// parentAutoClosePolicy is the repo's configured parent auto-close policy. +func (c *Client) parentAutoClosePolicy(repo string) string { + if p := c.issueStagePolicy(); p.ParentAutoClose != nil { + return p.ParentAutoClose(repo) + } + return config.ParentAutoCloseOn +} + +// parentAutoCloseExempt returns why a parent must not be auto-closed from +// its policy and labels alone, or "" when it may be (hivecommons/hive#18869). +// "false" exempts every parent; unless the policy is "epics_too", an issue +// labelled epic (any case) or hold is left for a person to close. +func parentAutoCloseExempt(policy string, labels []string) string { + if policy == config.ParentAutoCloseOff { + return "repo parent_autoclose is false" + } + if policy == config.ParentAutoCloseEpicsToo { + return "" + } + for _, l := range labels { + if strings.EqualFold(strings.TrimSpace(l), "epic") { + return "labelled epic" + } + } + if HasHoldLabel(labels) { + return "labelled hold" + } + return "" +} + +// Reopen-verdict cache (hivecommons/hive#18869). A reopen by a person never +// un-happens, so a "kept open" verdict is cached for the process lifetime +// (a restart re-derives it from the timeline, which is the durable record); +// a "no reopen" verdict is cached briefly so a parent whose close is refused +// each cycle does not cost a timeline read per sweep. +const parentReopenNegativeTTL = 30 * time.Minute + +type parentReopenVerdict struct { + by string + checked time.Time +} + +var ( + parentReopenMu sync.Mutex + parentReopenCache = map[string]parentReopenVerdict{} +) + +// parentKeptOpenBy reports the login of a person who reopened the parent +// after a hive auto-close. A timeline that cannot be read fails closed: the +// returned login is "(unknown)" so the parent is not closed this cycle. +func (c *Client) parentKeptOpenBy(ctx context.Context, owner, name string, number int, logger *slog.Logger) (string, bool) { + key := strings.ToLower(owner+"/"+name) + "#" + strconv.Itoa(number) + parentReopenMu.Lock() + v, ok := parentReopenCache[key] + parentReopenMu.Unlock() + if ok && (v.by != "" || time.Since(v.checked) < parentReopenNegativeTTL) { + return v.by, v.by != "" + } + events, err := c.IssueTimelineSince(ctx, owner+"/"+name, number, time.Time{}) + if err != nil { + if logger != nil { + logger.Warn("issue stage labels: parent timeline unreadable, not closing", "repo", owner+"/"+name, "issue", number, "error", err) + } + return "(unknown)", true + } + by := reopenedByPersonAfterAutoClose(events) + parentReopenMu.Lock() + parentReopenCache[key] = parentReopenVerdict{by: by, checked: time.Now()} + parentReopenMu.Unlock() + return by, by != "" +} + +// reopenedByPersonAfterAutoClose scans a timeline (oldest first) for a +// `reopened` event by a non-bot actor that follows a hive auto-close: the +// close comment carrying parentAutoCloseMarker, or a `closed` event by a +// bot (the comment is best-effort and can be missing). Returns the reopener. +func reopenedByPersonAfterAutoClose(events []IssueEvent) string { + autoClosed := false + for _, ev := range events { + switch { + case ev.Event == "commented" && ev.Body != "" && strings.Contains(ev.Body, parentAutoCloseMarker): + autoClosed = true + case ev.Event == "closed" && ev.ActorIsBot: + autoClosed = true + case ev.Event == "reopened" && autoClosed && !ev.ActorIsBot && ev.Actor != "": + return ev.Actor + } + } + return "" +} diff --git a/src/pkg/github/decomposed_parents_test.go b/src/pkg/github/decomposed_parents_test.go index f1e02a8842..af6e0c810b 100644 --- a/src/pkg/github/decomposed_parents_test.go +++ b/src/pkg/github/decomposed_parents_test.go @@ -281,3 +281,140 @@ func TestEnumerateActionable_SubIssueSummaryBecomesChildren(t *testing.T) { t.Errorf("leaves must carry no children: %+v / %+v", byNumber[42].Children, byNumber[43].Children) } } + +func resetParentReopenCacheForTest(t *testing.T) { + t.Helper() + parentReopenMu.Lock() + parentReopenCache = map[string]parentReopenVerdict{} + parentReopenMu.Unlock() +} + +func timelineEvent(event, actor, actorType, body, at string) map[string]any { + return map[string]any{"event": event, "created_at": at, "body": body, "actor": map[string]any{"login": actor, "type": actorType}} +} + +// runParentSweep sweeps one all-children-closed parent #7 and reports +// whether it was closed and how many timeline reads it cost. +func runParentSweep(t *testing.T, policy func(string) string, timeline []map[string]any, labels ...string) (closed bool, res IssueStageResult, timelineGets int) { + t.Helper() + resetParentReopenCacheForTest(t) + fake := newIssueStageServer(t) + c := NewClientForTest(fake.srv.URL, "acme", []string{"widgets"}, testLogger()) + c.SetIssueStageLabels(func() IssueStagePolicy { return IssueStagePolicy{Enabled: true, ParentAutoClose: policy} }) + store := stagelabels.NewStore("", stageNow) + store.Observe(stagelabels.Key("acme/widgets", 7), stagelabels.Actionable, "actionable") + fake.mu.Lock() + fake.subIssues[7] = []subIssueRef{{Number: 3, State: "closed"}, {Number: 4, State: "closed"}} + fake.timelines = map[int][]map[string]any{7: timeline} + fake.mu.Unlock() + result := &ActionableResult{} + result.Issues = IssueResultFromItems([]Issue{parentInput(&IssueChildren{Total: 2, Completed: 2}, append([]string{stagelabels.Actionable.Label()}, labels...)...)}) + res = syncSeeded(t, fake, c, result, store, stageNow()) + fake.mu.Lock() + defer fake.mu.Unlock() + _, closed = fake.closed[7] + return closed, res, fake.timelineGets +} + +func TestParentAutoClose_HiveCreatedParentStillCloses(t *testing.T) { + closed, res, _ := runParentSweep(t, nil, nil) + if !closed || res.ParentsClosed != 1 { + t.Fatalf("default policy must still close a plain decomposed parent: closed=%v res=%+v", closed, res) + } +} + +func TestParentAutoClose_EpicLabelledParentStaysOpen(t *testing.T) { + for _, label := range []string{"EPIC", "epic"} { + closed, res, gets := runParentSweep(t, nil, nil, label) + if closed || res.ParentsClosed != 0 { + t.Fatalf("%s-labelled parent with all children closed must stay open: closed=%v res=%+v", label, closed, res) + } + if gets != 0 { + t.Fatalf("label exemption must not cost a timeline read, got %d", gets) + } + } +} + +func TestParentAutoClose_EpicsTooOptInCloses(t *testing.T) { + closed, _, _ := runParentSweep(t, func(string) string { return "epics_too" }, nil, "EPIC") + if !closed { + t.Fatal("epics_too must let an epic-labelled parent close") + } +} + +func TestParentAutoClose_ConfigOffNeverCloses(t *testing.T) { + closed, _, gets := runParentSweep(t, func(string) string { return "false" }, nil) + if closed || gets != 0 { + t.Fatalf("parent_autoclose=false must not close (closed=%v gets=%d)", closed, gets) + } +} + +func TestParentAutoClose_HumanReopenedParentNeverReclosed(t *testing.T) { + timeline := []map[string]any{ + timelineEvent("closed", "hive[bot]", "Bot", "", "2026-10-19T10:00:00Z"), + timelineEvent("commented", "hive[bot]", "Bot", parentAutoCloseMarker+"\nAll children delivered", "2026-10-19T10:00:01Z"), + timelineEvent("reopened", "maintainer", "User", "", "2026-10-19T11:00:00Z"), + } + // Even with epics_too: a reopen outranks every config value. + for _, policy := range []func(string) string{nil, func(string) string { return "epics_too" }} { + closed, res, _ := runParentSweep(t, policy, timeline) + if closed || res.ParentsClosed != 0 { + t.Fatalf("a parent a person reopened after a hive auto-close must stay open: closed=%v res=%+v", closed, res) + } + } +} + +func TestParentAutoClose_ReopenWithoutCommentStillRespected(t *testing.T) { + timeline := []map[string]any{ + timelineEvent("closed", "hive[bot]", "Bot", "", "2026-10-19T10:00:00Z"), + timelineEvent("reopened", "maintainer", "User", "", "2026-10-19T11:00:00Z"), + } + if closed, _, _ := runParentSweep(t, nil, timeline); closed { + t.Fatal("reopen after a bot close must be respected even when the close comment is missing") + } +} + +func TestParentAutoClose_ReopenBeforeAnyAutoCloseDoesNotBlock(t *testing.T) { + timeline := []map[string]any{ + timelineEvent("closed", "maintainer", "User", "", "2026-10-01T10:00:00Z"), + timelineEvent("reopened", "maintainer", "User", "", "2026-10-02T10:00:00Z"), + } + if closed, _, _ := runParentSweep(t, nil, timeline); !closed { + t.Fatal("a reopen that precedes any hive auto-close is not a veto") + } +} + +func TestParentAutoClose_NegativeVerdictCachedPerParent(t *testing.T) { + resetParentReopenCacheForTest(t) + fake := newIssueStageServer(t) + c := NewClientForTest(fake.srv.URL, "acme", []string{"widgets"}, testLogger()) + for i := 0; i < 3; i++ { + if by, kept := c.parentKeptOpenBy(context.Background(), "acme", "widgets", 7, nil); kept || by != "" { + t.Fatalf("no reopen expected, got %q", by) + } + } + fake.mu.Lock() + defer fake.mu.Unlock() + if fake.timelineGets != 1 { + t.Fatalf("timeline reads = %d, want 1 (cached)", fake.timelineGets) + } +} + +func TestParentAutoCloseExempt(t *testing.T) { + cases := []struct { + policy string + labels []string + exempt bool + }{ + {"true", nil, false}, + {"true", []string{"Epic"}, true}, + {"true", []string{"hold"}, true}, + {"epics_too", []string{"epic", "hold"}, false}, + {"false", nil, true}, + } + for _, tc := range cases { + if got := parentAutoCloseExempt(tc.policy, tc.labels) != ""; got != tc.exempt { + t.Errorf("policy=%s labels=%v exempt=%v want %v", tc.policy, tc.labels, got, tc.exempt) + } + } +} diff --git a/src/pkg/github/issue_stage_labels.go b/src/pkg/github/issue_stage_labels.go index 1e8902a54d..a9c1178190 100644 --- a/src/pkg/github/issue_stage_labels.go +++ b/src/pkg/github/issue_stage_labels.go @@ -87,6 +87,10 @@ type IssueStagePolicy struct { // the generic human one, a retired per-login one, another hive's // agent — is never touched by that sweep. AgentNames []string + // ParentAutoClose returns the decomposed-parent auto-close policy for a + // repo (config.ParentAutoCloseOn / Off / EpicsToo, repos.. + // parent_autoclose, hivecommons/hive#18869). Nil means the default. + ParentAutoClose func(repo string) string } // SetIssueStageLabels installs the live policy resolver. Nil disables. diff --git a/src/pkg/github/issue_stage_labels_test.go b/src/pkg/github/issue_stage_labels_test.go index 2e069389c4..475373148e 100644 --- a/src/pkg/github/issue_stage_labels_test.go +++ b/src/pkg/github/issue_stage_labels_test.go @@ -64,6 +64,10 @@ type issueStageServer struct { // counts them in prLookups (guarded by mu). prRateLimited bool prLookups int + // timelines is what GET /issues/N/timeline reports per issue (empty by + // default); timelineGets counts the reads. + timelines map[int][]map[string]any + timelineGets int } func newIssueStageServer(t *testing.T) *issueStageServer { @@ -181,6 +185,15 @@ func newIssueStageServer(t *testing.T) *issueStageServer { state = "closed" } _ = json.NewEncoder(w).Encode(map[string]any{"number": n, "labels": labels, "state": state, "body": s.bodies[n], "user": map[string]any{"login": "hive[bot]", "type": "Bot"}}) + case r.Method == http.MethodGet && strings.HasSuffix(rest, "/timeline"): + var n int + _, _ = sscanIssue(rest, &n) + s.timelineGets++ + out := s.timelines[n] + if out == nil { + out = []map[string]any{} + } + _ = json.NewEncoder(w).Encode(out) case r.Method == http.MethodGet && strings.HasSuffix(rest, "/comments"): var n int _, _ = sscanIssue(rest, &n) diff --git a/src/pkg/github/issue_timeline.go b/src/pkg/github/issue_timeline.go index 5f3b1815d9..320b446cb9 100644 --- a/src/pkg/github/issue_timeline.go +++ b/src/pkg/github/issue_timeline.go @@ -31,6 +31,8 @@ type IssueEvent struct { // verify-once gate (#10527) can tell the hive's own comments from a // reporter or maintainer acting. ActorIsBot bool + // Body is the comment text on a "commented" event. + Body string } // IssueTimelineSince returns the issue's timeline events that happened after @@ -64,7 +66,7 @@ func issueEventFrom(t *gh.Timeline, since time.Time) (IssueEvent, bool) { if t == nil || t.CreatedAt == nil || !t.CreatedAt.After(since) { return IssueEvent{}, false } - ev := IssueEvent{Event: t.GetEvent(), At: t.CreatedAt.Time, CommitID: t.GetCommitID()} + ev := IssueEvent{Event: t.GetEvent(), At: t.CreatedAt.Time, CommitID: t.GetCommitID(), Body: t.GetBody()} if t.Label != nil { ev.Label = t.Label.GetName() }