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

Function TestServer_HandleRequest_MessageSend

pkg/a2a/server_test.go:82–137  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

80}
81
82func TestServer_HandleRequest_MessageSend(t *testing.T) {
83 // 创建 Actor 系统
84 system := actor.NewSystem("test-a2a")
85 defer system.Shutdown()
86
87 // 创建 A2A 服务器
88 taskStore := NewInMemoryTaskStore()
89 server := NewServer(system, taskStore)
90
91 // 创建测试 Agent
92 agentID := "test-agent"
93 mockAgent := &MockAgentActor{responses: []string{"Hello from agent"}}
94 system.Spawn(mockAgent, agentID)
95
96 // 构造 message/send 请求
97 params := MessageSendParams{
98 Message: Message{
99 MessageID: "msg-1",
100 Role: "user",
101 Parts: []Part{{Kind: "text", Text: "Hello"}},
102 },
103 ContextID: "context-1",
104 }
105 paramsJSON, _ := json.Marshal(params)
106
107 req := &JSONRPCRequest{
108 JSONRPC: "2.0",
109 ID: "req-1",
110 Method: "message/send",
111 Params: json.RawMessage(paramsJSON),
112 }
113
114 // 处理请求
115 ctx := context.Background()
116 resp := server.HandleRequest(ctx, agentID, req)
117
118 // 验证响应
119 require.NotNil(t, resp)
120 assert.Equal(t, "2.0", resp.JSONRPC)
121 assert.Equal(t, "req-1", resp.ID)
122 assert.Nil(t, resp.Error)
123 assert.NotNil(t, resp.Result)
124
125 // 验证任务已创建
126 var result MessageSendResult
127 resultBytes, _ := json.Marshal(resp.Result)
128 err := json.Unmarshal(resultBytes, &result)
129 require.NoError(t, err)
130 assert.NotEmpty(t, result.TaskID)
131
132 // 验证任务存储中的任务
133 task, err := taskStore.Load(agentID, result.TaskID)
134 require.NoError(t, err)
135 assert.Equal(t, TaskStateCompleted, task.Status.State)
136 assert.Len(t, task.History, 2) // 用户消息 + Agent 响应
137}
138
139func TestServer_HandleRequest_TasksGet(t *testing.T) {

Callers

nothing calls this directly

Calls 8

ShutdownMethod · 0.95
SpawnMethod · 0.95
HandleRequestMethod · 0.95
LoadMethod · 0.95
NewSystemFunction · 0.92
NewInMemoryTaskStoreFunction · 0.85
NewServerFunction · 0.85
LenMethod · 0.65

Tested by

no test coverage detected