| 1 | package team |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestBugReleaseCannotRetryTaskOutcome(t *testing.T) { |
| 6 | for _, outcome := range []string{"refusal", "receipt", "artifact", "complete"} { |
| 7 | t.Run(outcome, func(t *testing.T) { |
| 8 | e := newEnv(t) |
| 9 | spec := softwareSpec(SoftwareSteps(false)) |
| 10 | spec.Evidence.RequireBugFreeze = true |
| 11 | _, scope := e.createJob(spec) |
| 12 | h := e.claim(scope, "reproduce", "runner", "workspace") |
| 13 | reason := WaitRunnerUnavailable |
| 14 | switch outcome { |
| 15 | case "refusal": |
| 16 | reason = WaitProviderLimit |
| 17 | case "receipt": |
| 18 | id, err := e.store.Intend(e.ctx, scope, h, intent("turn", Usage{})) |
| 19 | must(t, err) |
| 20 | _, err = e.store.Admit(e.ctx, scope, id) |
| 21 | must(t, err) |
| 22 | must(t, e.store.Record(e.ctx, scope, id, Receipt{ID: "failed", Outcome: OutcomeFailure})) |
| 23 | case "artifact": |
| 24 | _, err := e.store.Register(e.ctx, scope, h, reproSpec(h)) |
| 25 | must(t, err) |
| 26 | } |
| 27 | if outcome == "complete" { |
| 28 | must(t, e.store.Complete(e.ctx, scope, h, AttemptResult{Outcome: OutcomeFailure, Detail: "runner.identity"})) |
| 29 | } else { |
| 30 | must(t, e.store.Release(e.ctx, scope, h, reason, "task outcome")) |
| 31 | } |
| 32 | must(t, e.store.Contain(e.ctx, scope, h.Attempt, "contained")) |
| 33 | if j := e.job(scope); j.State != JobFailed { |
| 34 | t.Fatalf("task outcome remains retryable: %s", j.State) |
| 35 | } |
| 36 | if _, err := e.store.Claim(e.ctx, scope, "reproduce", "runner", "new-workspace"); err == nil { |
| 37 | t.Fatal("task outcome received another attempt") |
| 38 | } |
| 39 | }) |
| 40 | } |
| 41 | } |
| 42 | func TestBugInfrastructureReleaseHasBoundedRetry(t *testing.T) { |
| 43 | e := newEnv(t) |
| 44 | spec := softwareSpec(SoftwareSteps(false)) |
| 45 | spec.Evidence.RequireBugFreeze = true |
| 46 | spec.Policy.MaxAttemptsPerStep = 2 |
| 47 | _, scope := e.createJob(spec) |
| 48 | for i := 0; i < 2; i++ { |
| 49 | h := e.claim(scope, "reproduce", "runner", "workspace-"+itoa(i)) |
| 50 | must(t, e.store.Release(e.ctx, scope, h, WaitRunnerUnavailable, "transport")) |
| 51 | if i == 0 { |
| 52 | if _, err := e.store.Claim(e.ctx, scope, "reproduce", "runner", "too-early"); err == nil { |
| 53 | t.Fatal("retry before containment") |
| 54 | } |
| 55 | } |
| 56 | must(t, e.store.Contain(e.ctx, scope, h.Attempt, "contained")) |
| 57 | } |
| 58 | if j := e.job(scope); j.State != JobFailed { |
| 59 | t.Fatalf("exhausted infrastructure retries left job %s", j.State) |
| 60 | } |
| 61 | } |
| 62 | |