64 lines
2.6 KiB
Go
64 lines
2.6 KiB
Go
package agenttask
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestReviewWarnCreatesFollowupAttempt(t *testing.T) {
|
|
snapshot := testSnapshot("project", "workspace", testUnit("work", WriteSetUnknown))
|
|
harness := newHarness(t, map[ProjectID]ProjectWorkflowSnapshot{"project": snapshot}, 1)
|
|
harness.reviewer.sequences["work"] = []ReviewVerdict{ReviewVerdictWarn, ReviewVerdictPass}
|
|
harness.start("project", "workspace", nil)
|
|
if err := harness.manager.Reconcile(context.Background()); err != nil {
|
|
t.Fatalf("Reconcile: %v", err)
|
|
}
|
|
work := harness.store.snapshot().Projects["project"].Works["work"]
|
|
if work.State != WorkStateCompleted || work.Attempt != 2 {
|
|
t.Fatalf("work state/attempt = %s/%d, want completed/2", work.State, work.Attempt)
|
|
}
|
|
if harness.invoker.callCount() != 2 || harness.reviewer.callCount() != 2 {
|
|
t.Fatalf(
|
|
"followup invoke/review = %d/%d, want 2/2",
|
|
harness.invoker.callCount(), harness.reviewer.callCount(),
|
|
)
|
|
}
|
|
}
|
|
|
|
func TestReviewFailCreatesFollowupAttempt(t *testing.T) {
|
|
snapshot := testSnapshot("project", "workspace", testUnit("work", WriteSetUnknown))
|
|
harness := newHarness(t, map[ProjectID]ProjectWorkflowSnapshot{"project": snapshot}, 1)
|
|
harness.reviewer.sequences["work"] = []ReviewVerdict{ReviewVerdictFail, ReviewVerdictPass}
|
|
harness.start("project", "workspace", nil)
|
|
if err := harness.manager.Reconcile(context.Background()); err != nil {
|
|
t.Fatalf("Reconcile: %v", err)
|
|
}
|
|
work := harness.store.snapshot().Projects["project"].Works["work"]
|
|
if work.State != WorkStateCompleted || work.Attempt != 2 {
|
|
t.Fatalf("work state/attempt = %s/%d, want completed/2", work.State, work.Attempt)
|
|
}
|
|
}
|
|
|
|
func TestReviewUserReviewDefersOnlyOneTask(t *testing.T) {
|
|
snapshot := testSnapshot(
|
|
"project", "workspace",
|
|
testUnit("needs-user", WriteSetUnknown),
|
|
testUnit("independent", WriteSetUnknown),
|
|
)
|
|
harness := newHarness(t, map[ProjectID]ProjectWorkflowSnapshot{"project": snapshot}, 2)
|
|
harness.reviewer.sequences["needs-user"] = []ReviewVerdict{ReviewVerdictUserReview}
|
|
harness.start("project", "workspace", nil)
|
|
if err := harness.manager.Reconcile(context.Background()); err != nil {
|
|
t.Fatalf("Reconcile: %v", err)
|
|
}
|
|
project := harness.store.snapshot().Projects["project"]
|
|
if project.Works["needs-user"].State != WorkStateTerminalDeferred {
|
|
t.Fatalf("user-review state = %s", project.Works["needs-user"].State)
|
|
}
|
|
if project.Works["independent"].State != WorkStateCompleted {
|
|
t.Fatalf("independent state = %s", project.Works["independent"].State)
|
|
}
|
|
if harness.integrator.callCount() != 1 {
|
|
t.Fatalf("integration calls = %d, want independent task only", harness.integrator.callCount())
|
|
}
|
|
}
|