Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/guides/user/issues-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@ HTML comment in the body. For Jira, the marker is stored as a comment
entity property (Jira has no HTML comments, so a body-embedded marker
would be visible to users).

On GitHub, when you post with one of these agent result markers, your
identity's earlier comments with the same marker are minimized as
outdated. They collapse, and a reader can still expand them.

- `<!-- fullsend:review-agent -->`
- `<!-- fullsend:review-skip -->`
- `<!-- fullsend:triage-agent -->`
- `<!-- fullsend:prioritize-agent -->`
- `<!-- fullsend:risk-assessment -->`

Minimizing is best effort: if it fails, the earlier comments stay
expanded. GitLab and Jira cannot minimize comments, and other markers
never minimize anything.

```bash
echo "Triage complete. See PR #99." | fullsend issues post-comment \
--fullsend-dir .fullsend \
Expand Down
23 changes: 21 additions & 2 deletions internal/cli/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,16 @@ For --tracker jira, the marker is stored as an invisible comment
entity property rather than embedded in the visible comment body,
so marker character restrictions do not apply.

On GitHub, once the new comment is posted, this identity's earlier
comments with the same marker are minimized as outdated (collapsed,
still expandable) for these agent result markers:
"<!-- fullsend:review-agent -->"
"<!-- fullsend:review-skip -->"
"<!-- fullsend:triage-agent -->"
"<!-- fullsend:prioritize-agent -->"
"<!-- fullsend:risk-assessment -->"
GitLab and Jira cannot minimize comments; other markers never do.

With --only-if-exists, the comment is posted only when an earlier
comment with this marker exists (written by the identity this
command posts as — the login on GitHub and GitLab, the account ID on
Expand Down Expand Up @@ -502,8 +512,9 @@ func runIssuesPostComment(ctx context.Context, cfg *issuesPostCommentConfig) err
printer.Header("Post Comment")

stickyCfg := sticky.Config{
Marker: cfg.marker,
DryRun: cfg.dryRun,
Marker: cfg.marker,
DryRun: cfg.dryRun,
MinimizeSuperseded: supersedingResultMarkers[cfg.marker],
}

// Jira stores markers as comment entity properties instead
Expand Down Expand Up @@ -603,6 +614,10 @@ func postJiraStickyComment(ctx context.Context, jc *tracker.JiraClient, project
// anyone could plant with the same marker is ignored). When that login
// cannot be resolved (after a short retry) it returns an error and posts
// nothing.
//
// With cfg.MinimizeSuperseded, a tracker implementing
// tracker.SupersededMinimizer folds the poster's earlier comments with
// this marker once the new one is created. Nothing posted, nothing folded.
func postTrackerStickyComment(ctx context.Context, tc tracker.Client, project string, number int, body string, cfg sticky.Config, onlyIfExists bool, printer *ui.Printer) (string, error) {
if strings.TrimSpace(body) == "" {
return "", fmt.Errorf("comment body is empty")
Expand Down Expand Up @@ -647,6 +662,10 @@ func postTrackerStickyComment(ctx context.Context, tc tracker.Client, project st
return "", fmt.Errorf("creating comment: %w", err)
}
printer.StepDone("Comment created")
// Only trackers that can fold comments do; the rest leave them visible.
if m, ok := tc.(tracker.SupersededMinimizer); ok && cfg.MinimizeSuperseded {
m.MinimizeSuperseded(ctx, project, number, cfg.Marker, created, printer)
}
return created.HTMLURL, nil
}

Expand Down
176 changes: 176 additions & 0 deletions internal/cli/issues_minimize_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package cli

import (
"bytes"
"context"
"io"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/fullsend-ai/fullsend/internal/forge"
"github.com/fullsend-ai/fullsend/internal/tracker"
"github.com/fullsend-ai/fullsend/internal/ui"
)

// Issue #10092: issues post-comment --tracker github folds the poster's
// earlier results for superseding markers, as post-comment does (#9957).

func minimizedCommentIDs(fc *forge.FakeClient) []string {
var ids []string
for _, m := range fc.MinimizedComments {
ids = append(ids, m.NodeID)
}
return ids
}

// postTwiceOnGitHub runs issues post-comment twice with marker through a
// fake GitHub tracker and returns the fake and the thread afterwards.
func postTwiceOnGitHub(t *testing.T, fc *forge.FakeClient, marker string) []forge.IssueComment {
t.Helper()
ctx := context.Background()
if fc.AuthenticatedUser == "" {
fc.AuthenticatedUser = "bot"
}
cfg := &issuesPostCommentConfig{
trackerName: trackerGitHub,
project: "acme/widgets",
number: 42,
marker: marker,
testClient: tracker.NewForgeClient(fc),
testPrinter: ui.New(io.Discard),
testBody: "first run",
}
require.NoError(t, runIssuesPostComment(ctx, cfg))
cfg.testBody = "second run"
require.NoError(t, runIssuesPostComment(ctx, cfg))
return fc.IssueComments["acme/widgets/42"]
}

func TestRunIssuesPostComment_GitHubMinimizesSupersededResult(t *testing.T) {
for marker := range supersedingResultMarkers {
t.Run(marker, func(t *testing.T) {
fc := forge.NewFakeClient()
comments := postTwiceOnGitHub(t, fc, marker)

require.Len(t, comments, 2)
assert.Equal(t, []string{comments[0].NodeID}, minimizedCommentIDs(fc),
"the first result is folded, the newest stays expanded")
assert.Equal(t, "OUTDATED", fc.MinimizedComments[0].Reason)
})
}
}

func TestRunIssuesPostComment_OtherMarkerMinimizesNothing(t *testing.T) {
fc := forge.NewFakeClient()
comments := postTwiceOnGitHub(t, fc, "<!-- fullsend:custom-agent -->")

require.Len(t, comments, 2)
assert.Empty(t, fc.MinimizedComments, "only superseding result markers fold earlier comments")
}

func TestRunIssuesPostComment_NeverMinimizesAnotherAuthorsComment(t *testing.T) {
const marker = "<!-- fullsend:triage-agent -->"
fc := forge.NewFakeClient()
fc.IssueComments = map[string][]forge.IssueComment{
"acme/widgets/42": {{ID: 1, NodeID: "IC_planted", Body: marker + "\nplanted", Author: "mallory"}},
}
comments := postTwiceOnGitHub(t, fc, marker)

require.Len(t, comments, 3)
assert.Equal(t, []string{comments[1].NodeID}, minimizedCommentIDs(fc),
"only the poster's own earlier result is folded")
}

func TestRunIssuesPostComment_MinimizeNotSupportedStillPosts(t *testing.T) {
// GitLab's forge client reports minimize as not supported.
fc := forge.NewFakeClient()
fc.Errors = map[string]error{"MinimizeComment": forge.ErrNotSupported}
comments := postTwiceOnGitHub(t, fc, "<!-- fullsend:triage-agent -->")

require.Len(t, comments, 2)
assert.Empty(t, fc.MinimizedComments)
}

func TestRunIssuesPostComment_DryRunMinimizesNothing(t *testing.T) {
const marker = "<!-- fullsend:triage-agent -->"
fc := forge.NewFakeClient()
fc.AuthenticatedUser = "bot"
fc.IssueComments = map[string][]forge.IssueComment{
"acme/widgets/42": {{ID: 1, NodeID: "IC_1", Body: marker + "\nfirst", Author: "bot"}},
}
cfg := &issuesPostCommentConfig{
trackerName: trackerGitHub,
project: "acme/widgets",
number: 42,
marker: marker,
dryRun: true,
testClient: tracker.NewForgeClient(fc),
testPrinter: ui.New(io.Discard),
testBody: "second",
}
require.NoError(t, runIssuesPostComment(context.Background(), cfg))
assert.Empty(t, fc.MinimizedComments)
}

func TestRunIssuesPostComment_OnlyIfExistsNothingPostedMinimizesNothing(t *testing.T) {
const marker = "<!-- fullsend:triage-agent -->"
fastSelfLookup(t)
fc := forge.NewFakeClient()
fc.AuthenticatedUser = "bot"
// Another author's result does not open the gate, so nothing is posted.
fc.IssueComments = map[string][]forge.IssueComment{
"acme/widgets/42": {{ID: 1, NodeID: "IC_1", Body: marker + "\nplanted", Author: "mallory"}},
}
var out bytes.Buffer
cfg := &issuesPostCommentConfig{
trackerName: trackerGitHub,
project: "acme/widgets",
number: 42,
marker: marker,
onlyIfExists: true,
testClient: tracker.NewForgeClient(fc),
testPrinter: ui.New(&out),
testBody: "all clear",
}
require.NoError(t, runIssuesPostComment(context.Background(), cfg))
assert.Contains(t, out.String(), "nothing to post")
assert.Len(t, fc.IssueComments["acme/widgets/42"], 1)
assert.Empty(t, fc.MinimizedComments)
}

func TestRunIssuesPostComment_JiraSupersedingMarkerUnchanged(t *testing.T) {
// Jira does not implement tracker.SupersededMinimizer: both results stay.
tc, _, err := tracker.NewFakeJiraClientWithFake("https://acme.atlassian.net")
require.NoError(t, err)
_, ok := any(tc).(tracker.SupersededMinimizer)
require.False(t, ok, "Jira cannot fold comments")

ctx := context.Background()
cfg := &issuesPostCommentConfig{
trackerName: trackerJira,
project: "PROJ",
number: 42,
marker: "<!-- fullsend:triage-agent -->",
testClient: tc,
testPrinter: ui.New(io.Discard),
testBody: "first run",
}
require.NoError(t, runIssuesPostComment(ctx, cfg))
cfg.testBody = "second run"
require.NoError(t, runIssuesPostComment(ctx, cfg))

comments, err := tc.ListComments(ctx, "PROJ", 42)
require.NoError(t, err)
require.Len(t, comments, 2)
assert.Contains(t, string(comments[0].Body), "first run")
assert.Contains(t, string(comments[1].Body), "second run")
}

func TestNewIssuesPostCommentCmd_HelpNamesSupersedingMarkers(t *testing.T) {
long := newIssuesPostCommentCmd().Long
for marker := range supersedingResultMarkers {
assert.Contains(t, long, marker, "the help text names every marker that folds earlier results")
}
}
28 changes: 9 additions & 19 deletions internal/cli/postcomment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,6 @@ import (
"github.com/fullsend-ai/fullsend/internal/ui"
)

// supersedingResultMarkers are the agent result markers whose newest
// comment replaces the earlier ones on the thread. When a comment with one
// of them is posted, the poster's earlier comments with the same marker are
// minimized as outdated (#9957). The review result and review-skip note
// are posted by post-review and review-dedup; triage, prioritize and the
// risk assessment are posted through post-comment by the agents' post
// scripts. Other markers (notices, custom agents) are left visible.
var supersedingResultMarkers = map[string]bool{
reviewMarker: true,
reviewSkipMarker: true,
"<!-- fullsend:risk-assessment -->": true,
"<!-- fullsend:triage-agent -->": true,
"<!-- fullsend:prioritize-agent -->": true,
}

func newPostCommentCmd() *cobra.Command {
var (
repo string
Expand Down Expand Up @@ -54,10 +39,15 @@ the thread itself is the history.
The --marker flag identifies this agent's comments. Each agent should
use a unique marker (e.g. "<!-- fullsend:triage-agent -->").

For the triage, prioritize and risk-assessment result markers, the
poster's earlier comments with the same marker are minimized as
outdated once the new comment is posted, so only the newest result
stays expanded.
On GitHub, once the new comment is posted, this identity's earlier
comments with the same marker are minimized as outdated (collapsed,
still expandable) for these agent result markers:
"<!-- fullsend:review-agent -->"
"<!-- fullsend:review-skip -->"
"<!-- fullsend:triage-agent -->"
"<!-- fullsend:prioritize-agent -->"
"<!-- fullsend:risk-assessment -->"
Other markers never minimize anything.

The --result flag accepts a file path or "-" for stdin.`,
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
17 changes: 17 additions & 0 deletions internal/cli/superseding_markers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cli

// supersedingResultMarkers are the agent result markers whose newest
// comment replaces the earlier ones on the thread. When a comment with one
// of them is posted, the poster's earlier comments with the same marker are
// minimized as outdated (#9957). The review result and review-skip note
// are posted by post-review and review-dedup; triage, prioritize and the
// risk assessment are posted by the agents' post scripts through
// post-comment or issues post-comment. Other markers (notices, custom
// agents) are left visible.
var supersedingResultMarkers = map[string]bool{
reviewMarker: true,
reviewSkipMarker: true,
"<!-- fullsend:risk-assessment -->": true,
"<!-- fullsend:triage-agent -->": true,
"<!-- fullsend:prioritize-agent -->": true,
}
Loading
Loading