Skip to content
1 change: 1 addition & 0 deletions changelog.d/fixed-16348.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- fix(prstatus): only treat status comments by this hive's own App login as editable or deletable (#16348)
1 change: 1 addition & 0 deletions src/pkg/github/attention_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
31 changes: 31 additions & 0 deletions src/pkg/github/automerge/automerge_quiet_notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.writeStatusSectionWith(context.Background(), "acme", "widget", 7, prstatus.KeyStageStalled, "new", prstatus.Write)
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)
}
})
}
}
4 changes: 3 additions & 1 deletion src/pkg/github/automerge/automerge_stage_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -1528,12 +1528,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
Expand Down
4 changes: 4 additions & 0 deletions src/pkg/github/issue_status_card_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/github/notification_fold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion src/pkg/github/pr_status_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package github
import (
"context"
"fmt"
"strings"

gh "github.com/google/go-github/v72/github"
"github.com/hivecommons/hive/pkg/prstatus"
Expand All @@ -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.
Expand All @@ -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
}
Expand Down
28 changes: 28 additions & 0 deletions src/pkg/github/pr_status_comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,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")
Expand Down Expand Up @@ -140,6 +141,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)
Expand All @@ -164,12 +166,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 {
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/github/review_evidence_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
Loading