From cf802565063fdaaf1a567c9fd5184ba271a5abfb Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 21:15:11 -0500 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20fix(prstatus):=20only=20trea?= =?UTF-8?q?t=20this=20hive's=20own=20App=20login=20as=20the=20status-comme?= =?UTF-8?q?nt=20owner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-16348.md | 1 + .../automerge_quiet_notifications_test.go | 31 +++++++++++++++++++ .../automerge/automerge_stage_labels.go | 4 ++- src/pkg/github/pr_status_comment.go | 12 ++++++- src/pkg/github/pr_status_comment_test.go | 28 +++++++++++++++++ 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 changelog.d/fixed-16348.md diff --git a/changelog.d/fixed-16348.md b/changelog.d/fixed-16348.md new file mode 100644 index 0000000000..41cbe40e36 --- /dev/null +++ b/changelog.d/fixed-16348.md @@ -0,0 +1 @@ +- fix(prstatus): only treat status comments by this hive's own App login as editable or deletable (#16348) diff --git a/src/pkg/github/automerge/automerge_quiet_notifications_test.go b/src/pkg/github/automerge/automerge_quiet_notifications_test.go index c28c45c0c1..9c718fd565 100644 --- a/src/pkg/github/automerge/automerge_quiet_notifications_test.go +++ b/src/pkg/github/automerge/automerge_quiet_notifications_test.go @@ -180,3 +180,34 @@ func TestQuietNotificationsHuman071MentionOncePerCause(t *testing.T) { t.Fatalf("still one comment expected, got %q", api.comments) } } + +// Own is this hive's App login, not "any bot": a status comment another App +// posted is neither edited nor deleted (a fresh one is created), while one by +// this hive's login is edited in place. +func TestWriteStatusSectionOwnsOnlyThisAppLogin(t *testing.T) { + statusBody := prstatus.Upsert("", prstatus.KeyStageStalled, "old") + for _, tc := range []struct { + name string + login string + wantCreated int + wantEdits int + }{ + {"other bot", "other-app[bot]", 1, 0}, + {"this hive", testHiveAppBotLogin, 0, 1}, + } { + t.Run(tc.name, func(t *testing.T) { + api := &stageAPI{issueComments: map[int][]map[string]any{ + 7: {{"id": 55, "body": statusBody, "user": map[string]any{"login": tc.login, "type": "Bot"}}}, + }} + clock := &contributorLaneClock{at: time.Date(2026, 10, 30, 12, 0, 0, 0, time.UTC)} + e, _ := quietStageEngine(t, api, clock) + created, err := e.writeStatusSection(context.Background(), "acme", "widget", 7, prstatus.KeyStageStalled, "new") + if err != nil { + t.Fatal(err) + } + if created != tc.wantCreated || len(api.commentEdits) != tc.wantEdits { + t.Fatalf("created=%d edits=%d, want created=%d edits=%d", created, len(api.commentEdits), tc.wantCreated, tc.wantEdits) + } + }) + } +} diff --git a/src/pkg/github/automerge/automerge_stage_labels.go b/src/pkg/github/automerge/automerge_stage_labels.go index a4b5f3be5f..c6aa0a49af 100644 --- a/src/pkg/github/automerge/automerge_stage_labels.go +++ b/src/pkg/github/automerge/automerge_stage_labels.go @@ -1512,12 +1512,14 @@ func (f *engineStatusForge) ListComments(ctx context.Context) ([]prstatus.Commen if err != nil { return nil, err } + // Own is an exact match on this hive's App login; unknown fails closed. + appLogin := strings.TrimSpace(f.e.transport.AppBotLogin()) out := make([]prstatus.Comment, 0, len(comments)) for _, cm := range comments { if cm == nil { continue } - own := strings.TrimSpace(cm.GetUser().GetLogin()) != "" && !f.e.isPersonLogin(cm.GetUser()) + own := appLogin != "" && strings.EqualFold(strings.TrimSpace(cm.GetUser().GetLogin()), appLogin) out = append(out, prstatus.Comment{ID: cm.GetID(), Body: cm.GetBody(), Own: own}) } return out, nil diff --git a/src/pkg/github/pr_status_comment.go b/src/pkg/github/pr_status_comment.go index e5e3e8f188..d8cc3ec806 100644 --- a/src/pkg/github/pr_status_comment.go +++ b/src/pkg/github/pr_status_comment.go @@ -3,6 +3,7 @@ package github import ( "context" "fmt" + "strings" gh "github.com/google/go-github/v72/github" "github.com/hivecommons/hive/pkg/prstatus" @@ -29,6 +30,15 @@ func (c *Client) UpsertPRStatusSection(ctx context.Context, repo string, number return res.Created, err } +// ownStatusCommentLogin reports whether login is exactly this hive's App bot +// login. Any other account, including another bot, is not the owner, and an +// unknown App login fails closed so nothing is ever edited or deleted. +func (c *Client) ownStatusCommentLogin(login string) bool { + login = strings.TrimSpace(login) + app := strings.TrimSpace(c.appBotLogin) + return login != "" && app != "" && strings.EqualFold(login, app) +} + // clientStatusForge adapts the client's comment calls on one item to // prstatus.Forge. Creates go through CreateIssueComment (canary gate, // effects journal, created tally); edits are tallied as edited. @@ -49,7 +59,7 @@ func (f *clientStatusForge) ListComments(ctx context.Context) ([]prstatus.Commen if cm == nil { continue } - out = append(out, prstatus.Comment{ID: cm.GetID(), Body: cm.GetBody(), Own: f.c.hiveAuthoredLogin(cm.GetUser().GetLogin())}) + out = append(out, prstatus.Comment{ID: cm.GetID(), Body: cm.GetBody(), Own: f.c.ownStatusCommentLogin(cm.GetUser().GetLogin())}) } return out, nil } diff --git a/src/pkg/github/pr_status_comment_test.go b/src/pkg/github/pr_status_comment_test.go index 3bccbbd9ef..3844eb8bdb 100644 --- a/src/pkg/github/pr_status_comment_test.go +++ b/src/pkg/github/pr_status_comment_test.go @@ -85,6 +85,7 @@ func TestUpsertPRStatusSectionCreatesOnceThenEdits(t *testing.T) { s := &statusCommentServer{} srv := s.start(t) c := testClient(t, srv.URL) + c.SetAppBotLogin("hive-app[bot]") ctx := context.Background() created, err := c.UpsertPRStatusSection(ctx, "o/r", 5, prstatus.KeyStageStalled, "stalled at 080") @@ -131,6 +132,7 @@ func TestUpsertPRStatusSectionMergesDuplicateStatusComments(t *testing.T) { {"id": 12, "body": prstatus.Upsert("", prstatus.KeyStageRegressed, "regressed"), "user": bot}, }} c := testClient(t, s.start(t).URL) + c.SetAppBotLogin("hive-app[bot]") created, err := c.UpsertPRStatusSection(context.Background(), "o/r", 5, prstatus.KeyEvidence, "evidence") if err != nil || created { t.Fatalf("created=%v err=%v", created, err) @@ -155,12 +157,38 @@ func TestUpsertPRStatusSectionMergesDuplicateStatusComments(t *testing.T) { } } +// Own is this hive's App login, not "any bot": another App's status comment +// is never edited or deleted, and an unknown App login fails closed. +func TestUpsertPRStatusSectionIgnoresOtherBotsComments(t *testing.T) { + for _, tc := range []struct{ name, appLogin string }{ + {"other bot", "hive-app[bot]"}, + {"unknown own login", ""}, + } { + t.Run(tc.name, func(t *testing.T) { + other := map[string]any{"login": "other-app[bot]", "type": "Bot"} + s := &statusCommentServer{comments: []map[string]any{ + {"id": 11, "body": prstatus.Upsert("", prstatus.KeyStageStalled, "stalled"), "user": other}, + }} + c := testClient(t, s.start(t).URL) + c.SetAppBotLogin(tc.appLogin) + created, err := c.UpsertPRStatusSection(context.Background(), "o/r", 5, prstatus.KeyEvidence, "evidence") + if err != nil || !created { + t.Fatalf("created=%v err=%v, want a fresh comment", created, err) + } + if s.edits != 0 || len(s.deletes) != 0 { + t.Fatalf("edits=%d deletes=%v, want the other bot's comment untouched", s.edits, s.deletes) + } + }) + } +} + // Quiet mode: the duplicate-guard redirect lands in the status comment of // the PR it points at and a retry edits it rather than stacking comments. func TestCreatePR_DuplicateGuardQuietModeUsesStatusComment(t *testing.T) { g := &guardServer{open: []guardPR{{Number: 7, Ref: "a", Body: "Fixes #42", User: "human"}}} srv := g.start(t) c := NewClientForTest(srv.URL, "o", nil, prTestLogger()) + c.SetAppBotLogin("hive-app[bot]") c.SetNotificationsQuiet(func() bool { return true }) res, err := c.CreatePR(context.Background(), "o/r", "new-branch", "main", "title", "Closes #42") if err != nil || res.Number != 7 || res.DuplicateReason != DuplicateReasonClosesIssue { From b1101b217c51f36c244b8ea8150fb81ad03af425 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 21:22:35 -0500 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=A7=AA=20test(github):=20set=20the=20?= =?UTF-8?q?App=20login=20in=20status-comment=20fixtures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The status-comment fixtures stamp hive-app[bot] as the comment author, and ownership is now an exact match on this hive's App login, so the clients in these tests must carry that login to own their own comments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/pkg/github/attention_test.go | 1 + src/pkg/github/notification_fold_test.go | 2 ++ src/pkg/github/review_evidence_read_test.go | 2 ++ 3 files changed, 5 insertions(+) diff --git a/src/pkg/github/attention_test.go b/src/pkg/github/attention_test.go index ba1658dca8..93ad09d9e0 100644 --- a/src/pkg/github/attention_test.go +++ b/src/pkg/github/attention_test.go @@ -42,6 +42,7 @@ func TestAttentionNonAdmitterOnlyFoldsStatus(t *testing.T) { server := &statusCommentServer{} srv := server.start(t) c := testClient(t, srv.URL) + c.SetAppBotLogin("hive-app[bot]") c.SetWritebackGate(writeback.New(writeback.Config{}, writeback.Deps{}, "")) c.SetAttention("other-hive", func() attention.Config { return attention.Config{Admitter: map[string]string{"o/r": "owner-hive"}} }) item := writeback.Item{Number: 5, HiveAuthored: true} diff --git a/src/pkg/github/notification_fold_test.go b/src/pkg/github/notification_fold_test.go index fc33b4c200..6203f61dbd 100644 --- a/src/pkg/github/notification_fold_test.go +++ b/src/pkg/github/notification_fold_test.go @@ -94,6 +94,7 @@ func TestPostUnblockedNoteIdempotentPerCause(t *testing.T) { t.Run("quiet", func(t *testing.T) { s := &statusCommentServer{} c := testClient(t, s.start(t).URL) + c.SetAppBotLogin("hive-app[bot]") c.SetNotificationsQuiet(func() bool { return true }) c.postUnblockedNote(ctx, "o/r", 5, note, logger) c.postUnblockedNote(ctx, "o/r", 5, note, logger) @@ -141,6 +142,7 @@ func TestPostNoteOrFoldQuietEditsNormalCreates(t *testing.T) { ctx := context.Background() s := &statusCommentServer{} c := testClient(t, s.start(t).URL) + c.SetAppBotLogin("hive-app[bot]") c.SetNotificationsQuiet(func() bool { return true }) key := prstatus.KeyAgentNotePrefix + agentNoteAwaitingCI if created, err := c.PostNoteOrFold(ctx, "o/r", 3, key, "hive/awaiting-ci: CI pending — sweep will merge when green."); err != nil || !created { diff --git a/src/pkg/github/review_evidence_read_test.go b/src/pkg/github/review_evidence_read_test.go index 4bd06cb43b..0492420bd6 100644 --- a/src/pkg/github/review_evidence_read_test.go +++ b/src/pkg/github/review_evidence_read_test.go @@ -294,6 +294,8 @@ func newEvidenceMergeServer(t *testing.T, f *evidenceMergeFixture) *httptest.Ser func evidenceMergeClient(t *testing.T, f *evidenceMergeFixture, settings *ReviewEvidenceSettings) *Client { t.Helper() c := newTestClient(t, newEvidenceMergeServer(t, f), "o", []string{"o/r"}) + // The fixture stamps comments as hive-app[bot]; make the client own them. + c.SetAppBotLogin("hive-app[bot]") if settings != nil { s := *settings c.SetReviewEvidence(func(string) ReviewEvidenceSettings { return s }) From 72b92e8a223568d738972af82b9b1cea835c1e6c Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 00:06:18 -0500 Subject: [PATCH 3/4] test(automerge): follow writeStatusSectionWith rename after v5 merge Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/pkg/github/automerge/automerge_quiet_notifications_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg/github/automerge/automerge_quiet_notifications_test.go b/src/pkg/github/automerge/automerge_quiet_notifications_test.go index 9c718fd565..5e40513f4a 100644 --- a/src/pkg/github/automerge/automerge_quiet_notifications_test.go +++ b/src/pkg/github/automerge/automerge_quiet_notifications_test.go @@ -201,7 +201,7 @@ func TestWriteStatusSectionOwnsOnlyThisAppLogin(t *testing.T) { }} clock := &contributorLaneClock{at: time.Date(2026, 10, 30, 12, 0, 0, 0, time.UTC)} e, _ := quietStageEngine(t, api, clock) - created, err := e.writeStatusSection(context.Background(), "acme", "widget", 7, prstatus.KeyStageStalled, "new") + created, err := e.writeStatusSectionWith(context.Background(), "acme", "widget", 7, prstatus.KeyStageStalled, "new", prstatus.Write) if err != nil { t.Fatal(err) } From 9ba2d8915552c17a617efc9aba3cf9cd7f2d7ac4 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 00:33:22 -0500 Subject: [PATCH 4/4] fix(prstatus): recognise this hive's own status card in issue status-card tests Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/pkg/github/issue_status_card_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pkg/github/issue_status_card_test.go b/src/pkg/github/issue_status_card_test.go index 53b3a0473e..abac0d075e 100644 --- a/src/pkg/github/issue_status_card_test.go +++ b/src/pkg/github/issue_status_card_test.go @@ -60,6 +60,7 @@ func TestIssueStatusCardPilotFoldsRoutineNotes(t *testing.T) { ctx := context.Background() s := &statusCommentServer{} c := testClient(t, s.start(t).URL) + c.SetAppBotLogin("hive-app[bot]") c.SetAttentionPilot(func() bool { return true }) logger := slog.New(slog.NewTextHandler(&bytes.Buffer{}, nil)) noLegacy := func(context.Context) error { @@ -126,6 +127,7 @@ func TestIssueStatusCardAttentionAfterCardExists(t *testing.T) { ctx := context.Background() s := &statusCommentServer{} c := testClient(t, s.start(t).URL) + c.SetAppBotLogin("hive-app[bot]") c.SetAttentionPilot(func() bool { return true }) noLegacy := func(context.Context) error { t.Error("legacy write ran with the attention pilot on") @@ -174,6 +176,7 @@ func TestIssueStatusCardAttentionCreatesCardOnce(t *testing.T) { ctx := context.Background() s := &statusCommentServer{} c := testClient(t, s.start(t).URL) + c.SetAppBotLogin("hive-app[bot]") c.SetAttentionPilot(func() bool { return true }) noLegacy := func(context.Context) error { t.Error("legacy write ran with the attention pilot on") @@ -202,6 +205,7 @@ func TestIssueStatusCardAttentionGateRefusalRetries(t *testing.T) { ctx := context.Background() s := &statusCommentServer{} c := testClient(t, s.start(t).URL) + c.SetAppBotLogin("hive-app[bot]") c.SetAttentionPilot(func() bool { return true }) noLegacy := func(context.Context) error { t.Error("legacy write ran with the attention pilot on")