fix: close issue when build passes with 0 changes (no-op detection)

This commit is contained in:
sam committed 2026-07-23 17:25:03 +10:00
1 parent 0d6b26244e
commit 212b48a0a0
4 files changed
+93 -2

No files matched your search

+3
View File
@@ -148,6 +148,9 @@ func Implement() Workflow {
},
OnResult: func(tc *TaskContext, res agentexec.Result) error {
tc.BuildSummary = res.Summary
if res.Status == agentexec.StatusPassed && len(res.Changes) == 0 {
tc.BuildNoChanges = true
}
return nil
},
}.Stage(),
+75
View File
@@ -0,0 +1,75 @@
package workflow
import (
"context"
"strings"
"testing"
"github.com/samcharles93/archie-core/internal/forge"
"github.com/samcharles93/archie-core/internal/store"
)
// fakeForge implements forge.Forge for TestStageCommitPushCloses.
type fakeForge struct {
closed int
commented []string
}
func (f *fakeForge) CloseIssue(ctx context.Context, owner, repo string, number int, comment string) error { f.closed++; return nil }
func (f *fakeForge) Comment(ctx context.Context, owner, repo string, number int, body string) (int64, error) {
f.commented = append(f.commented, body)
return 0, nil
}
// Remaining forge.Forge stubs — only CloseIssue and Comment are used by StageCommitPush.
func (f *fakeForge) Name() string { return "fake" }
func (f *fakeForge) AcceptInvitations(ctx context.Context) error { return nil }
func (f *fakeForge) AssignedIssues(ctx context.Context, owner, repo, user string) ([]forge.Issue, error) { return nil, nil }
func (f *fakeForge) IssuesWithLabel(ctx context.Context, owner, repo, label string) ([]forge.Issue, error) { return nil, nil }
func (f *fakeForge) CreatePR(ctx context.Context, owner, repo, title, head, base, body string) (int, error) { return 0, nil }
func (f *fakeForge) PRState(ctx context.Context, owner, repo string, number int) (string, error) { return "", nil }
func (f *fakeForge) React(ctx context.Context, owner, repo string, number int, reaction string) error { return nil }
func (f *fakeForge) RepliesAfter(ctx context.Context, owner, repo string, number int, afterID int64, exclude string) ([]forge.Reply, error) { return nil, nil }
func (f *fakeForge) SetStateLabel(ctx context.Context, owner, repo string, number int, label string, known []string) {}
func (f *fakeForge) VerifyPush(ctx context.Context, owner, repo string) error { return nil }
// TestStageCommitPushClosesIssueWhenBuildNoChanges verifies that
// StageCommitPush closes the issue with a comment when BuildNoChanges
// is true, instead of trying to commit and failing.
func TestStageCommitPushClosesIssueWhenBuildNoChanges(t *testing.T) {
f := &fakeForge{}
stage := StageCommitPush(func(tc *TaskContext) string {
return "commit msg"
})
tc := &TaskContext{
Forge: f,
BuildSummary: "already fixed",
BuildNoChanges: true,
Dir: "/tmp/test",
Branch: "archie/issue-1",
Task: &store.Task{ID: 1, Owner: "o", Repo: "r", IssueNumber: 1},
}
err := stage.Run(context.Background(), tc)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if f.closed != 1 {
t.Errorf("expected CloseIssue to be called once, got %d", f.closed)
} else {
t.Log("CloseIssue called (no changes needed)")
}
found := false
for _, c := range f.commented {
if strings.Contains(c, "no changes required") {
found = true
break
}
}
if !found {
t.Error("expected a comment about no changes required")
}
}
+11 -2
View File
@@ -48,10 +48,19 @@ func StageCommit(name string, message func(*TaskContext) string) Stage {
}
// StageCommitPush commits everything in the worktree and pushes the
// branch; an empty tree parks (the workflow produced nothing).
// branch. When the builder completed with no changes (BuildNoChanges is
// set), the issue is already resolved — close it with a comment instead
// of erroring on an empty tree.
func StageCommitPush(message func(*TaskContext) string) Stage {
commit := StageCommit("commit-push", message)
return Stage{Name: "commit-push", Run: func(ctx context.Context, tc *TaskContext) error {
if tc.BuildNoChanges {
body := fmt.Sprintf("**archie closed this issue — no changes required.**\n\n%s", tc.BuildSummary)
if _, err := tc.Forge.Comment(ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.IssueNumber, body); err != nil {
tc.Log.Warn("no-op close comment failed", "err", err)
}
return tc.Forge.CloseIssue(ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.IssueNumber, "")
}
commit := StageCommit("commit-push", message)
if err := commit.Run(ctx, tc); err != nil {
return err
}
+4
View File
@@ -56,6 +56,10 @@ type TaskContext struct {
Branch string
// BuildSummary is the builder agent's finish summary — the PR body.
BuildSummary string
// BuildNoChanges is set when the builder returned StatusPassed but
// made no file changes — the fix already exists or the issue is a
// no-op. StageCommitPush closes the issue instead of erroring.
BuildNoChanges bool
// ReproProof is the captured failing-test output from a TDD repro
// stage, posted on the PR as evidence the bug was reproduced.
ReproProof string