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.
87 lines
2.5 KiB
Go
87 lines
2.5 KiB
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|