MCPcopy Create free account
hub / github.com/astercloud/aster / testBasicWorkflow

Function testBasicWorkflow

examples/workflow_complete/main.go:40–77  ·  view source on GitHub ↗

测试 1: 基础 Workflow

(ctx context.Context)

Source from the content-addressed store, hash-verified

38
39// 测试 1: 基础 Workflow
40func testBasicWorkflow(ctx context.Context) {
41 wf := workflow.New("BasicTest").WithStream()
42
43 wf.AddStep(workflow.NewFunctionStep("step1", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
44 return &workflow.StepOutput{
45 Content: "Step 1 完成",
46 Metadata: make(map[string]any),
47 }, nil
48 }))
49
50 wf.AddStep(workflow.NewFunctionStep("step2", func(ctx context.Context, input *workflow.StepInput) (*workflow.StepOutput, error) {
51 return &workflow.StepOutput{
52 Content: fmt.Sprintf("Step 2 接收: %v", input.PreviousStepContent),
53 Metadata: make(map[string]any),
54 }, nil
55 }))
56
57 if err := wf.Validate(); err != nil {
58 fmt.Printf(" ❌ 验证失败: %v\n", err)
59 return
60 }
61
62 input := &workflow.WorkflowInput{Input: "测试输入"}
63 reader := wf.Execute(ctx, input)
64 for {
65 event, err := reader.Recv()
66 if err != nil {
67 if errors.Is(err, io.EOF) {
68 break
69 }
70 fmt.Printf(" ❌ 错误: %v\n", err)
71 continue
72 }
73 if event.Type == workflow.EventWorkflowCompleted {
74 fmt.Printf(" ✅ 成功: %v\n", event.Data.(map[string]any)["output"])
75 }
76 }
77}
78
79// 测试 2: 所有步骤类型
80func testAllStepTypes(ctx context.Context) {

Callers 1

mainFunction · 0.85

Calls 8

NewFunction · 0.92
NewFunctionStepFunction · 0.92
WithStreamMethod · 0.80
PrintfMethod · 0.80
RecvMethod · 0.80
ValidateMethod · 0.65
ExecuteMethod · 0.65
AddStepMethod · 0.45

Tested by

no test coverage detected