-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathsteps_test.go
More file actions
671 lines (608 loc) · 19.7 KB
/
Copy pathsteps_test.go
File metadata and controls
671 lines (608 loc) · 19.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
package flow
import (
"context"
"errors"
"testing"
"time"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/store"
)
// appendStep returns a step that appends its name to the carried data,
// so a run's path is visible in the final State.
func appendStep(name string) Step {
return Step{Name: name, Run: func(_ context.Context, in State) (State, error) {
s := in.String()
if s != "" {
s += ","
}
in.Data = []byte(s + name)
return in, nil
}}
}
func TestFlowStepsRunInOrder(t *testing.T) {
f := New("seq",
WithCheckpoint(StoreCheckpoint(store.NewMemoryStore(), "seq")),
Steps(appendStep("a"), appendStep("b"), appendStep("c")),
)
if err := f.Execute(context.Background(), ""); err != nil {
t.Fatalf("Execute: %v", err)
}
res := f.Results()
if len(res) != 1 || res[0].Answer != "a,b,c" {
t.Fatalf("steps ran out of order: %+v", res)
}
}
// A run that fails mid-way is persisted at the failing step and resumes
// there — without re-running the completed steps.
func TestFlowCheckpointResume(t *testing.T) {
mem := store.NewMemoryStore()
var firstCalls, fixed int
steps := []Step{
{Name: "first", Run: func(_ context.Context, in State) (State, error) {
firstCalls++
in.Data = []byte("first-done")
return in, nil
}},
{Name: "flaky", Run: func(_ context.Context, in State) (State, error) {
if fixed == 0 {
return in, errors.New("dependency unavailable")
}
in.Data = []byte("flaky-done")
return in, nil
}},
}
f := New("resumable", WithCheckpoint(StoreCheckpoint(mem, "resumable")), Steps(steps...))
// First run fails at "flaky".
if err := f.Execute(context.Background(), "start"); err == nil {
t.Fatal("expected the run to fail at the flaky step")
}
pend, _ := f.Pending(context.Background())
if len(pend) != 1 {
t.Fatalf("expected 1 pending run, got %d", len(pend))
}
if pend[0].State.Stage != "flaky" {
t.Fatalf("run should be checkpointed at the flaky step, got stage %q", pend[0].State.Stage)
}
runID := pend[0].ID
// The dependency recovers; resume continues from where it stopped.
fixed = 1
if err := f.Resume(context.Background(), runID); err != nil {
t.Fatalf("Resume: %v", err)
}
if firstCalls != 1 {
t.Errorf("completed step should not re-run on resume; first called %d times", firstCalls)
}
if pend, _ := f.Pending(context.Background()); len(pend) != 0 {
t.Errorf("expected no pending runs after a successful resume, got %d", len(pend))
}
}
func TestFlowAwaitAndResumeWith(t *testing.T) {
mem := store.NewMemoryStore()
var firstCalls int
var secondInput string
steps := []Step{
{Name: "first", Run: func(_ context.Context, in State) (State, error) {
firstCalls++
in.Data = []byte("first-done")
return in, nil
}},
AwaitStep("approval", "approve", "Approve to continue?"),
{Name: "second", Run: func(_ context.Context, in State) (State, error) {
secondInput = in.String()
in.Data = []byte("second-done")
return in, nil
}},
}
f := New("hitl", WithCheckpoint(StoreCheckpoint(mem, "hitl")), Steps(steps...))
// Execute suspends at the await step — a clean return, not an error.
if err := f.Execute(context.Background(), "start"); err != nil {
t.Fatalf("Execute should suspend cleanly, got %v", err)
}
if firstCalls != 1 {
t.Fatalf("first step calls = %d, want 1", firstCalls)
}
// A waiting run is not pending (restart), it needs input.
if pend, _ := f.Pending(context.Background()); len(pend) != 0 {
t.Errorf("a waiting run must not be pending, got %d", len(pend))
}
waiting, err := f.Waiting(context.Background())
if err != nil {
t.Fatal(err)
}
if len(waiting) != 1 {
t.Fatalf("waiting runs = %d, want 1", len(waiting))
}
w := waiting[0]
if w.Status != "waiting" || w.Await == nil || w.Await.Key != "approve" ||
w.Await.Prompt != "Approve to continue?" || w.Await.Step != "approval" {
t.Fatalf("await metadata = %+v (status %q)", w.Await, w.Status)
}
if w.State.Stage != "approval" {
t.Fatalf("waiting stage = %q, want approval", w.State.Stage)
}
// Injecting input completes the awaited step and runs the rest.
if err := f.ResumeWith(context.Background(), w.ID, "approved"); err != nil {
t.Fatalf("ResumeWith: %v", err)
}
if firstCalls != 1 {
t.Errorf("completed step re-ran on resume; first calls = %d", firstCalls)
}
if secondInput != "approved" {
t.Errorf("second step input = %q, want the injected 'approved'", secondInput)
}
if wr, _ := f.Waiting(context.Background()); len(wr) != 0 {
t.Errorf("no waiting runs after resume, got %d", len(wr))
}
runs, _ := StoreCheckpoint(mem, "hitl").List(context.Background())
if len(runs) != 1 || runs[0].Status != "done" {
t.Fatalf("run should be done after resume, got %+v", runs)
}
if runs[0].Await != nil {
t.Errorf("await metadata should be cleared after resume, got %+v", runs[0].Await)
}
}
func TestFlowResumeWithRejectsNonWaiting(t *testing.T) {
mem := store.NewMemoryStore()
f := New("hitl2", WithCheckpoint(StoreCheckpoint(mem, "hitl2")),
Steps(Step{Name: "only", Run: func(_ context.Context, in State) (State, error) { return in, nil }}))
if err := f.Execute(context.Background(), "x"); err != nil {
t.Fatalf("Execute: %v", err)
}
runs, _ := StoreCheckpoint(mem, "hitl2").List(context.Background())
if len(runs) != 1 {
t.Fatalf("runs = %d", len(runs))
}
if err := f.ResumeWith(context.Background(), runs[0].ID, "input"); err == nil {
t.Error("ResumeWith on a completed (non-waiting) run should error")
}
}
func TestFlowStepContextIncludesRunInfo(t *testing.T) {
var got ai.RunInfo
step := Step{Name: "inspect", Run: func(ctx context.Context, in State) (State, error) {
var ok bool
got, ok = ai.RunInfoFrom(ctx)
if !ok {
t.Fatal("RunInfo missing from step context")
}
in.Data = []byte("ok")
return in, nil
}}
mem := store.NewMemoryStore()
f := New("correlated",
WithCheckpoint(StoreCheckpoint(mem, "correlated")),
Steps(step),
)
ctx := ai.WithRunInfo(context.Background(), ai.RunInfo{RunID: "agent-run-1", Agent: "planner"})
if err := f.Execute(ctx, "start"); err != nil {
t.Fatalf("Execute: %v", err)
}
if got.Agent != "correlated" {
t.Fatalf("RunInfo.Agent = %q, want correlated", got.Agent)
}
if got.RunID == "" {
t.Fatal("RunInfo.RunID is empty")
}
if got.Flow != "correlated" {
t.Fatalf("RunInfo.Flow = %q, want correlated", got.Flow)
}
if got.ParentID != "agent-run-1" {
t.Fatalf("RunInfo.ParentID = %q, want agent-run-1", got.ParentID)
}
if got.Step != "inspect" {
t.Fatalf("RunInfo.Step = %q, want inspect", got.Step)
}
runs, err := StoreCheckpoint(mem, "correlated").List(context.Background())
if err != nil {
t.Fatalf("List: %v", err)
}
if len(runs) != 1 || runs[0].ParentID != "agent-run-1" {
t.Fatalf("persisted parent id = %+v, want agent-run-1", runs)
}
}
func TestFlowResumePendingResumesOldestRunsUntilFailure(t *testing.T) {
mem := store.NewMemoryStore()
ctx := context.Background()
var calls int
step := Step{Name: "work", Run: func(_ context.Context, in State) (State, error) {
calls++
if in.String() == "block" {
return in, errors.New("still blocked")
}
in.Data = []byte(in.String() + "-done")
return in, nil
}}
f := New("resume-pending", WithCheckpoint(StoreCheckpoint(mem, "resume-pending")), Steps(step))
base := time.Date(2026, 6, 24, 12, 0, 0, 0, time.UTC)
runs := []Run{
{
ID: "run-ok",
Flow: "resume-pending",
State: State{Stage: "work", Data: []byte("ok")},
Steps: []StepRecord{{Name: "work", Status: "failed", Error: "temporary"}},
Status: "failed",
Started: base,
},
{
ID: "run-blocked",
Flow: "resume-pending",
State: State{Stage: "work", Data: []byte("block")},
Steps: []StepRecord{{Name: "work", Status: "failed", Error: "temporary"}},
Status: "failed",
Started: base.Add(time.Minute),
},
{
ID: "run-later",
Flow: "resume-pending",
State: State{Stage: "work", Data: []byte("later")},
Steps: []StepRecord{{Name: "work", Status: "failed", Error: "temporary"}},
Status: "failed",
Started: base.Add(2 * time.Minute),
},
}
for _, run := range runs {
if err := f.checkpoint.Save(ctx, run); err != nil {
t.Fatalf("Save(%s): %v", run.ID, err)
}
}
failedRun, err := f.ResumePending(ctx)
if err == nil {
t.Fatal("expected ResumePending to stop at the blocked run")
}
if failedRun != "run-blocked" {
t.Fatalf("failed run = %q, want run-blocked", failedRun)
}
if calls != 2 {
t.Fatalf("ResumePending should stop before later runs; got %d calls", calls)
}
run, ok, err := f.checkpoint.Load(ctx, "run-ok")
if err != nil || !ok {
t.Fatalf("Load(run-ok) ok=%v err=%v", ok, err)
}
if run.Status != "done" || run.State.String() != "ok-done" {
t.Fatalf("run-ok not resumed successfully: %+v", run)
}
run, ok, err = f.checkpoint.Load(ctx, "run-later")
if err != nil || !ok {
t.Fatalf("Load(run-later) ok=%v err=%v", ok, err)
}
if run.Status != "failed" {
t.Fatalf("run-later should not be resumed after a failure, got %+v", run)
}
}
// A flow-level Retry re-runs a failing step until it succeeds.
func TestFlowStepRetry(t *testing.T) {
var attempts int
step := Step{Name: "transient", Run: func(_ context.Context, in State) (State, error) {
attempts++
if attempts < 3 {
return in, errors.New("transient")
}
in.Data = []byte("ok")
return in, nil
}}
f := New("retrying",
WithCheckpoint(StoreCheckpoint(store.NewMemoryStore(), "retrying")),
Retry(2), // up to 3 tries
Steps(step),
)
if err := f.Execute(context.Background(), ""); err != nil {
t.Fatalf("Execute: %v", err)
}
if attempts != 3 {
t.Errorf("want 3 attempts with Retry(2), got %d", attempts)
}
}
// A per-step Retry overrides the flow default.
func TestFlowStepRetryOverride(t *testing.T) {
var attempts int
step := Step{Name: "capped", Retry: 1, Run: func(_ context.Context, in State) (State, error) {
attempts++
return in, errors.New("always fails")
}}
f := New("override",
WithCheckpoint(StoreCheckpoint(store.NewMemoryStore(), "override")),
Retry(5), // would be 6 tries; the step's Retry:1 caps it at 2
Steps(step),
)
_ = f.Execute(context.Background(), "")
if attempts != 2 {
t.Errorf("per-step Retry(1) should cap tries at 2, got %d", attempts)
}
}
func TestFlowStepRetryBackoffWaitsBetweenAttempts(t *testing.T) {
var attempts int
step := Step{Name: "transient", Run: func(_ context.Context, in State) (State, error) {
attempts++
if attempts == 1 {
return in, errors.New("transient")
}
in.Data = []byte("ok")
return in, nil
}}
f := New("retry-backoff",
WithCheckpoint(StoreCheckpoint(store.NewMemoryStore(), "retry-backoff")),
Retry(1),
RetryBackoff(10*time.Millisecond),
Steps(step),
)
start := time.Now()
if err := f.Execute(context.Background(), ""); err != nil {
t.Fatalf("Execute: %v", err)
}
if attempts != 2 {
t.Fatalf("want 2 attempts, got %d", attempts)
}
if elapsed := time.Since(start); elapsed < 10*time.Millisecond {
t.Fatalf("retry backoff was not observed; elapsed %s", elapsed)
}
}
func TestFlowTimeoutStopsRetryBackoff(t *testing.T) {
var attempts int
step := Step{Name: "slow", Run: func(_ context.Context, in State) (State, error) {
attempts++
return in, errors.New("transient")
}}
f := New("timeout-backoff",
WithCheckpoint(StoreCheckpoint(store.NewMemoryStore(), "timeout-backoff")),
Timeout(20*time.Millisecond),
Retry(1),
RetryBackoff(time.Hour),
Steps(step),
)
err := f.Execute(context.Background(), "")
if err == nil {
t.Fatal("expected the timed-out run to fail")
}
if !errors.Is(err, context.DeadlineExceeded) {
t.Errorf("want a context deadline error, got %v", err)
}
if attempts != 1 {
t.Errorf("timeout should stop during backoff before retrying, got %d attempts", attempts)
}
}
func TestFlowTimeoutRespectsExistingDeadline(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
defer cancel()
f := New("existing-deadline", Timeout(time.Millisecond))
got, stop := f.withTimeout(ctx)
defer stop()
wantDeadline, _ := ctx.Deadline()
gotDeadline, ok := got.Deadline()
if !ok {
t.Fatal("expected the existing deadline to remain set")
}
if !gotDeadline.Equal(wantDeadline) {
t.Fatalf("deadline = %v, want existing deadline %v", gotDeadline, wantDeadline)
}
}
func TestFlowStepRetryBackoffStopsOnCancel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
var attempts int
step := Step{Name: "cancelbackoff", Run: func(_ context.Context, in State) (State, error) {
attempts++
cancel()
return in, errors.New("transient")
}}
f := New("cancel-backoff",
WithCheckpoint(StoreCheckpoint(store.NewMemoryStore(), "cancel-backoff")),
Retry(1),
RetryBackoff(time.Hour),
Steps(step),
)
err := f.Execute(ctx, "")
if err == nil {
t.Fatal("expected the canceled run to fail")
}
if !errors.Is(err, context.Canceled) {
t.Errorf("want a context.Canceled error, got %v", err)
}
if attempts != 1 {
t.Errorf("cancellation should stop during backoff before retrying, got %d attempts", attempts)
}
}
// A canceled run stops retrying immediately instead of burning the whole
// retry budget, and surfaces the context error.
func TestFlowStepRetryStopsOnCancel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
var attempts int
step := Step{Name: "cancelaware", Run: func(_ context.Context, in State) (State, error) {
attempts++
cancel() // the run is canceled while this step is in flight
return in, errors.New("transient")
}}
f := New("cancelretry",
WithCheckpoint(StoreCheckpoint(store.NewMemoryStore(), "cancelretry")),
Retry(5), // would be 6 tries without the cancellation check
Steps(step),
)
err := f.Execute(ctx, "")
if err == nil {
t.Fatal("expected the canceled run to fail")
}
if !errors.Is(err, context.Canceled) {
t.Errorf("want a context.Canceled error, got %v", err)
}
if attempts != 1 {
t.Errorf("cancellation should stop retries after the first attempt, got %d", attempts)
}
}
func TestFlowStepNamesMustBeUnique(t *testing.T) {
step := Step{Name: "work", Run: func(_ context.Context, in State) (State, error) {
return in, nil
}}
f := New("duplicate-steps",
WithCheckpoint(StoreCheckpoint(store.NewMemoryStore(), "duplicate-steps")),
Steps(step, step),
)
err := f.Execute(context.Background(), "")
if err == nil {
t.Fatal("expected duplicate step names to fail validation")
}
if got, want := err.Error(), `flow: duplicate step name "work"`; got != want {
t.Fatalf("error = %q, want %q", got, want)
}
}
func TestFlowStepNamesMustBeNonEmpty(t *testing.T) {
f := New("empty-step-name",
WithCheckpoint(StoreCheckpoint(store.NewMemoryStore(), "empty-step-name")),
Steps(Step{Name: "", Run: func(_ context.Context, in State) (State, error) {
return in, nil
}}),
)
err := f.Execute(context.Background(), "")
if err == nil {
t.Fatal("expected an empty step name to fail validation")
}
if got, want := err.Error(), "flow: step 0 has an empty name"; got != want {
t.Fatalf("error = %q, want %q", got, want)
}
}
// A step with no Run function is reported as a configuration error rather
// than panicking the run.
func TestFlowStepNilRun(t *testing.T) {
f := New("nilstep",
WithCheckpoint(StoreCheckpoint(store.NewMemoryStore(), "nilstep")),
Steps(Step{Name: "missing"}),
)
err := f.Execute(context.Background(), "")
if err == nil {
t.Fatal("expected an error for a step with no Run function")
}
}
func TestStoreCheckpointListReturnsRunsInStartedOrder(t *testing.T) {
cp := StoreCheckpoint(store.NewMemoryStore(), "ordered")
ctx := context.Background()
base := time.Date(2026, 6, 24, 12, 0, 0, 0, time.UTC)
runs := []Run{
{ID: "run-c", Flow: "ordered", Status: "failed", Started: base.Add(2 * time.Minute)},
{ID: "run-a", Flow: "ordered", Status: "failed", Started: base},
{ID: "run-b", Flow: "ordered", Status: "failed", Started: base.Add(time.Minute)},
}
for _, run := range runs {
if err := cp.Save(ctx, run); err != nil {
t.Fatalf("Save(%s): %v", run.ID, err)
}
}
got, err := cp.List(ctx)
if err != nil {
t.Fatalf("List: %v", err)
}
if len(got) != 3 {
t.Fatalf("List returned %d runs, want 3", len(got))
}
want := []string{"run-a", "run-b", "run-c"}
for i, id := range want {
if got[i].ID != id {
t.Fatalf("run %d = %q, want %q (all runs: %+v)", i, got[i].ID, id, got)
}
}
}
func TestStoreCheckpointHonorsCanceledContext(t *testing.T) {
cp := StoreCheckpoint(store.NewMemoryStore(), "canceled")
ctx, cancel := context.WithCancel(context.Background())
cancel()
run := Run{ID: "canceled", Started: time.Now()}
if err := cp.Save(ctx, run); !errors.Is(err, context.Canceled) {
t.Fatalf("Save error = %v, want context.Canceled", err)
}
if _, ok, err := cp.Load(ctx, run.ID); !errors.Is(err, context.Canceled) || ok {
t.Fatalf("Load ok, error = %v, %v; want false, context.Canceled", ok, err)
}
if err := cp.Delete(ctx, run.ID); !errors.Is(err, context.Canceled) {
t.Fatalf("Delete error = %v, want context.Canceled", err)
}
if _, err := cp.List(ctx); !errors.Is(err, context.Canceled) {
t.Fatalf("List error = %v, want context.Canceled", err)
}
}
type failingCheckpoint struct {
err error
}
func (c failingCheckpoint) Save(context.Context, Run) error { return c.err }
func (c failingCheckpoint) Load(context.Context, string) (Run, bool, error) {
return Run{}, false, c.err
}
func (c failingCheckpoint) Delete(context.Context, string) error { return c.err }
func (c failingCheckpoint) List(context.Context) ([]Run, error) { return nil, c.err }
func TestFlowCheckpointSaveFailureStopsRun(t *testing.T) {
checkpointErr := errors.New("checkpoint unavailable")
var ran bool
f := New("checkpoint-fails",
WithCheckpoint(failingCheckpoint{err: checkpointErr}),
Steps(Step{Name: "work", Run: func(_ context.Context, in State) (State, error) {
ran = true
return in, nil
}}),
)
err := f.Execute(context.Background(), "start")
if !errors.Is(err, checkpointErr) {
t.Fatalf("Execute error = %v, want checkpoint error", err)
}
if ran {
t.Fatal("step ran even though the in-progress checkpoint failed")
}
}
func TestFlowDeleteOnSuccessFailureIsReturned(t *testing.T) {
checkpointErr := errors.New("delete unavailable")
cp := &deleteFailCheckpoint{Checkpoint: StoreCheckpoint(store.NewMemoryStore(), "delete-fails"), err: checkpointErr}
f := New("delete-fails",
WithCheckpoint(cp),
DeleteOnSuccess(),
Steps(appendStep("work")),
)
err := f.Execute(context.Background(), "")
if !errors.Is(err, checkpointErr) {
t.Fatalf("Execute error = %v, want delete error", err)
}
}
type deleteFailCheckpoint struct {
Checkpoint
err error
}
func (c *deleteFailCheckpoint) Delete(context.Context, string) error { return c.err }
func TestStateSetScan(t *testing.T) {
var s State
type payload struct {
Email string `json:"email"`
}
if err := s.Set(payload{Email: "a@b.com"}); err != nil {
t.Fatalf("Set: %v", err)
}
var got payload
if err := s.Scan(&got); err != nil {
t.Fatalf("Scan: %v", err)
}
if got.Email != "a@b.com" {
t.Errorf("round-trip failed: %+v", got)
}
}
func TestFlowFailureRecordsErrorKind(t *testing.T) {
cp := StoreCheckpoint(store.NewMemoryStore(), "failure-kind")
f := New("failure-kind",
WithCheckpoint(cp),
Steps(Step{Name: "limited", Run: func(_ context.Context, in State) (State, error) {
return in, errors.New("rate limit exceeded")
}}),
)
err := f.Execute(context.Background(), "payload")
if err == nil {
t.Fatal("Execute error = nil, want failure")
}
runs, listErr := cp.List(context.Background())
if listErr != nil {
t.Fatalf("List: %v", listErr)
}
if len(runs) != 1 {
t.Fatalf("runs = %d, want 1", len(runs))
}
if got := runs[0].Steps[0].ErrorKind; got != string(ai.ErrorKindRateLimited) {
t.Fatalf("step error kind = %q, want %q", got, ai.ErrorKindRateLimited)
}
results := f.Results()
if len(results) != 1 {
t.Fatalf("results = %d, want 1", len(results))
}
if got := results[0].ErrorKind; got != string(ai.ErrorKindRateLimited) {
t.Fatalf("result error kind = %q, want %q", got, ai.ErrorKindRateLimited)
}
}