fix(workflow): set BuildNoChanges from writable stages and clear it on commit
A writable agent stage that passes now marks BuildNoChanges; repo.commit clears it when the stage commits changes. The flag had no setter, so the signal was lost in the YAML migration. The outcome of an empty commit stays with if_empty: unset still fails, complete closes the issue, skip moves on.
This commit is contained in:
1 parent
062f5332a0
commit
c833b651a9
4 files changed
+96
-3
No files matched your search
@@ -220,6 +220,10 @@ func (a AgentStage) deliverResult(tc *TaskContext, res agentrun.Result) error {
|
||||
}
|
||||
return fmt.Errorf("agent %s (%s): %s", res.Status, res.StopReason, clip(detail, 2000))
|
||||
}
|
||||
if !a.ReadOnly {
|
||||
// repo.commit clears this when the stage commits changes.
|
||||
tc.BuildNoChanges = true
|
||||
}
|
||||
// Gatekeeping: the daemon reviews agent output before human delivery.
|
||||
if a.ReviewResult != nil {
|
||||
if err := a.ReviewResult(tc, res); err != nil {
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package workflow
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/agentrun"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
)
|
||||
|
||||
// noChangesTrees reports a fixed commit result and records whether anything
|
||||
// was pushed; the rest of the worktree API is never reached by these stages.
|
||||
type noChangesTrees struct {
|
||||
Trees
|
||||
changed bool
|
||||
pushed bool
|
||||
}
|
||||
|
||||
func (f *noChangesTrees) CommitAll(context.Context, string, string) (bool, error) {
|
||||
return f.changed, nil
|
||||
}
|
||||
|
||||
func (f *noChangesTrees) Push(context.Context, string, string) error {
|
||||
f.pushed = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func repoCommitNode(t *testing.T, ifEmpty string) yaml.Node {
|
||||
t.Helper()
|
||||
src := "message: fix it\n"
|
||||
if ifEmpty != "" {
|
||||
src += "if_empty: " + ifEmpty + "\n"
|
||||
}
|
||||
var doc yaml.Node
|
||||
if err := yaml.Unmarshal([]byte(src), &doc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return *doc.Content[0]
|
||||
}
|
||||
|
||||
// An empty commit is the workflow's decision, set by if_empty. The builder
|
||||
// passing with no changes does not choose the outcome on its own: unset, it
|
||||
// fails; complete closes the issue; skip moves on.
|
||||
func TestRepoCommitWithNoBuilderChangesFollowsIfEmpty(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
readOnly bool
|
||||
ifEmpty string
|
||||
wantErr bool
|
||||
wantPush bool
|
||||
wantState string
|
||||
}{
|
||||
{name: "unset fails when the builder passed with no changes", ifEmpty: "", wantErr: true},
|
||||
{name: "complete closes the issue", ifEmpty: "complete", wantState: StatusCompleted},
|
||||
{name: "skip moves on", ifEmpty: "skip"},
|
||||
{name: "read-only stage with no changes fails", readOnly: true, ifEmpty: "", wantErr: true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
trees := &noChangesTrees{changed: false}
|
||||
tc := &TaskContext{Task: &task.Task{ID: 1, Attempt: 1, Source: task.SourceTest}, Trees: trees, Dir: "/wt", Log: slog.Default()}
|
||||
|
||||
stage := AgentStage{Name: "build", ReadOnly: tt.readOnly}
|
||||
if err := stage.deliverResult(tc, agentrun.Result{Status: agentrun.StatusPassed}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
repo, err := newRepoCommitStage(repoCommitNode(t, tt.ifEmpty))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = repo.Run(context.Background(), tc)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Fatalf("err = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
if trees.pushed != tt.wantPush {
|
||||
t.Fatalf("pushed = %v, want %v", trees.pushed, tt.wantPush)
|
||||
}
|
||||
if tt.wantState != "" && tc.Outcome.Status != tt.wantState {
|
||||
t.Fatalf("outcome = %q, want %q", tc.Outcome.Status, tt.wantState)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,9 @@ func newRepoCommitStage(settings yaml.Node) (Stage, error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if changed {
|
||||
tc.BuildNoChanges = false
|
||||
}
|
||||
if !changed && !tc.BaselineFixed {
|
||||
switch s.IfEmpty {
|
||||
case "skip":
|
||||
|
||||
@@ -132,9 +132,9 @@ type TaskContext struct {
|
||||
workflowBranch 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 is set when a writable agent stage passes and is cleared
|
||||
// by repo.commit if it commits changes. While set, an empty commit with no
|
||||
// explicit if_empty closes the issue: the builder found nothing to do.
|
||||
BuildNoChanges bool
|
||||
// BaselineFixed is set when StageBaselineGate committed a fix, so
|
||||
// StageCommitPush pushes it even when the build changed nothing.
|
||||
|
||||
Reference in new issue
Block a user