Skip to content

Commit 9c77d56

Browse files
committed
test: make mcp serve-agents e2e deterministic
1 parent c3cce6d commit 9c77d56

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

go/test/e2e/mcp_serve_agents_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ import (
1717
)
1818

1919
func TestE2EInvokeAgentThroughMCPServeAgents(t *testing.T) {
20+
// Setup mock server (so agent responses are deterministic and don't hit real LLMs)
21+
baseURL, stopServer := setupMockServer(t, "mocks/invoke_mcp_serve_agents.json")
22+
defer stopServer()
23+
24+
// Setup Kubernetes resources for a known-good agent
25+
cli := setupK8sClient(t, false)
26+
modelCfg := setupModelConfig(t, cli, baseURL)
27+
agent := setupAgentWithOptions(t, cli, modelCfg.Name, nil, AgentOptions{
28+
Name: "kebab-agent",
29+
})
30+
2031
kagentURL := os.Getenv("KAGENT_URL")
2132
if kagentURL == "" {
2233
kagentURL = "http://localhost:8083"
@@ -123,9 +134,9 @@ func TestE2EInvokeAgentThroughMCPServeAgents(t *testing.T) {
123134
}
124135
require.NoError(t, json.Unmarshal(agentsResult, &callResult), string(agentsResult))
125136
require.NotEmpty(t, callResult.Content)
126-
require.Contains(t, callResult.Content[0].Text, "kebab-agent")
137+
require.Contains(t, callResult.Content[0].Text, agent.Namespace+"/"+agent.Name)
127138

128-
writeLine(`{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"invoke_agent","arguments":{"agent":"kebab-agent","task":"What can you do?"}}}`)
139+
writeLine(fmt.Sprintf(`{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"invoke_agent","arguments":{"agent":%q,"task":"What can you do?"}}}`, agent.Name))
129140
invokeResult := readResponse(4)
130141
require.NoError(t, json.Unmarshal(invokeResult, &callResult), string(invokeResult))
131142
require.NotEmpty(t, callResult.Content)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"openai": [
3+
{
4+
"name": "serve_agents_request",
5+
"match": {
6+
"match_type": "contains",
7+
"message": {
8+
"content": "What can you do?",
9+
"role": "user"
10+
}
11+
},
12+
"response": {
13+
"id": "chatcmpl-1",
14+
"object": "chat.completion",
15+
"created": 1677652288,
16+
"model": "gpt-4.1-mini",
17+
"choices": [
18+
{
19+
"index": 0,
20+
"role": "assistant",
21+
"message": {
22+
"content": "I can answer questions and help you with tasks. Also: kebab.",
23+
"role": "assistant"
24+
},
25+
"finish_reason": "stop"
26+
}
27+
]
28+
}
29+
}
30+
]
31+
}

0 commit comments

Comments
 (0)