(t *testing.T)
| 217 | } |
| 218 | |
| 219 | func TestTaskModelErrors(t *testing.T) { |
| 220 | for _, grace := range []bool{false, true} { |
| 221 | t.Run(strconv.FormatBool(grace), func(t *testing.T) { |
| 222 | task := testTask() |
| 223 | task.MaxRounds = 1 |
| 224 | requests := 0 |
| 225 | client := taskClient(func(context.Context, llm.ChatRequest) (*llm.ChatResponse, error) { |
| 226 | requests++ |
| 227 | if grace && requests == 1 { |
| 228 | return testTaskResponse("read_test_data", `{}`), nil |
| 229 | } |
| 230 | return nil, errors.New("model unavailable") |
| 231 | }) |
| 232 | history := session.New(t.TempDir(), "main", "fake", session.SessionOptions{}) |
| 233 | runner := NewRunner(Deps{LLMClient: client, Session: history}, task) |
| 234 | result, err := runner.Run(context.Background(), taskMessages(), "data") |
| 235 | if result.Completed || (err == nil) != grace { |
| 236 | t.Fatalf("Run = %+v, %v", result, err) |
| 237 | } |
| 238 | if grace && result.StopReason != StopMaxRounds { |
| 239 | t.Fatalf("grace stop = %v", result.StopReason) |
| 240 | } |
| 241 | records := history.GetOrCreateFileSession("data").TaskRecords[session.MainTask] |
| 242 | if records[len(records)-1].Error != "model unavailable" { |
| 243 | t.Fatal("model failure was not recorded") |
| 244 | } |
| 245 | }) |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | func TestTaskGraceOutcomes(t *testing.T) { |
| 250 | for _, scenario := range []string{"no_calls", "failed", "mixed", "no_tools", "cancelled"} { |
nothing calls this directly
no test coverage detected