MCPcopy Create free account
hub / github.com/alibaba/open-code-review / TestTaskModelErrors

Function TestTaskModelErrors

internal/llmloop/task_test.go:219–267  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

217}
218
219func TestTaskModelErrors(t *testing.T) {
220 unavailable := errors.New("model unavailable")
221 for _, fixture := range []struct {
222 name string
223 maxRounds int
224 tokenBudget int64
225 reportErrors bool
226 stop MainLoopStop
227 wantErr error
228 }{
229 {"main request", 1, 1, true, StopNone, unavailable},
230 {"round limit", 1, 0, false, StopMaxRounds, nil},
231 {"round limit error", 1, 0, true, StopMaxRounds, unavailable},
232 {"token limit", 5, 1, true, StopTokenBudget, unavailable},
233 {"best effort final submission", 5, 1, false, StopTokenBudget, nil},
234 {"cancelled final submission", 5, 1, true, StopTokenBudget, context.Canceled},
235 } {
236 t.Run(fixture.name, func(t *testing.T) {
237 ctx, cancel := context.WithCancel(t.Context())
238 defer cancel()
239 task := testTask()
240 task.MaxRounds = fixture.maxRounds
241 task.Grace.ReportErrors = fixture.reportErrors
242 requestErr := unavailable
243 requests := 0
244 client := taskClient(func(context.Context, llm.ChatRequest) (*llm.ChatResponse, error) {
245 requests++
246 if fixture.stop != StopNone && requests == 1 {
247 return testTaskResponse("read_test_data", `{}`), nil
248 }
249 if fixture.wantErr == context.Canceled {
250 cancel()
251 requestErr = ctx.Err()
252 }
253 return nil, requestErr
254 })
255 history := session.New(t.TempDir(), "main", "fake", session.SessionOptions{})
256 runner := NewRunner(Deps{LLMClient: client, Session: history, MaxTokensBudget: fixture.tokenBudget}, task)
257 result, err := runner.Run(ctx, taskMessages(), "data")
258 if result.Completed || !errors.Is(err, fixture.wantErr) || result.StopReason != fixture.stop {
259 t.Fatalf("Run = %+v, %v", result, err)
260 }
261 records := history.GetOrCreateFileSession("data").TaskRecords[session.MainTask]
262 if records[len(records)-1].Error != requestErr.Error() {
263 t.Fatal("model failure was not recorded")
264 }
265 })
266 }
267}
268
269func TestTaskGraceOutcomes(t *testing.T) {
270 for _, scenario := range []string{"no_calls", "failed", "mixed", "no_tools", "cancelled"} {

Callers

nothing calls this directly

Calls 11

RunMethod · 0.95
NewFunction · 0.92
testTaskFunction · 0.85
taskClientFuncType · 0.85
testTaskResponseFunction · 0.85
taskMessagesFunction · 0.85
NewRunnerFunction · 0.70
RunMethod · 0.65
ErrMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected