Merge pull request #1354 from trheyi/main

Refactor stress test and i18n translations for improved clarity and c…
This commit is contained in:
Max 2025-11-28 19:37:50 +08:00 committed by GitHub
commit 506e6bf88e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 40 deletions

View file

@ -82,7 +82,7 @@ func TestRealWorldMCPScenarios(t *testing.T) {
// Detailed validation // Detailed validation
assert.NotNil(t, response) assert.NotNil(t, response)
assert.NotEmpty(t, response.Messages) assert.NotEmpty(t, response.Messages)
// Check if metadata exists // Check if metadata exists
if response.Metadata == nil { if response.Metadata == nil {
t.Logf("⚠ Metadata is nil - checking messages content") t.Logf("⚠ Metadata is nil - checking messages content")
@ -90,20 +90,20 @@ func TestRealWorldMCPScenarios(t *testing.T) {
messageContent := "" messageContent := ""
for _, msg := range response.Messages { for _, msg := range response.Messages {
if content, ok := msg.Content.(string); ok { if content, ok := msg.Content.(string); ok {
messageContent += content + "\n" messageContent += content + "\n"
} }
} }
assert.Contains(t, messageContent, "Health", "Message should mention health") assert.Contains(t, messageContent, "Health", "Message should mention health")
assert.Contains(t, messageContent, "Tools", "Message should mention tools") assert.Contains(t, messageContent, "Tools", "Message should mention tools")
t.Logf("✓ MCP Health executed (verified via message content)") t.Logf("✓ MCP Health executed (verified via message content)")
} else { } else {
assert.Equal(t, "mcp_health", response.Metadata["scenario"]) assert.Equal(t, "mcp_health", response.Metadata["scenario"])
// Verify metadata contains MCP results // Verify metadata contains MCP results
if toolsCount, ok := response.Metadata["tools_count"]; ok { if toolsCount, ok := response.Metadata["tools_count"]; ok {
count := int(toolsCount.(float64)) count := int(toolsCount.(float64))
assert.Greater(t, count, 0, "Should have tools from MCP") assert.Greater(t, count, 0, "Should have tools from MCP")
t.Logf("✓ MCP Health: %d tools, health data: %v", t.Logf("✓ MCP Health: %d tools, health data: %v",
count, response.Metadata["health_data"]) count, response.Metadata["health_data"])
} }
} }
@ -126,7 +126,7 @@ func TestRealWorldMCPScenarios(t *testing.T) {
// Detailed validation // Detailed validation
assert.NotNil(t, response) assert.NotNil(t, response)
assert.NotEmpty(t, response.Messages) assert.NotEmpty(t, response.Messages)
// Check if metadata exists // Check if metadata exists
if response.Metadata == nil { if response.Metadata == nil {
t.Logf("⚠ Metadata is nil - checking messages content") t.Logf("⚠ Metadata is nil - checking messages content")
@ -134,20 +134,20 @@ func TestRealWorldMCPScenarios(t *testing.T) {
messageContent := "" messageContent := ""
for _, msg := range response.Messages { for _, msg := range response.Messages {
if content, ok := msg.Content.(string); ok { if content, ok := msg.Content.(string); ok {
messageContent += content + "\n" messageContent += content + "\n"
} }
} }
assert.Contains(t, messageContent, "Tools", "Message should mention tools") assert.Contains(t, messageContent, "Tools", "Message should mention tools")
assert.Contains(t, messageContent, "Ping", "Message should mention ping") assert.Contains(t, messageContent, "Ping", "Message should mention ping")
t.Logf("✓ MCP Tools executed (verified via message content)") t.Logf("✓ MCP Tools executed (verified via message content)")
} else { } else {
assert.Equal(t, "mcp_tools", response.Metadata["scenario"]) assert.Equal(t, "mcp_tools", response.Metadata["scenario"])
// Verify tools were called // Verify tools were called
if toolsCount, ok := response.Metadata["tools_count"]; ok { if toolsCount, ok := response.Metadata["tools_count"]; ok {
count := int(toolsCount.(float64)) count := int(toolsCount.(float64))
assert.Greater(t, count, 0, "Should have tools from MCP") assert.Greater(t, count, 0, "Should have tools from MCP")
// Verify operations list // Verify operations list
if operations, ok := response.Metadata["operations"].([]interface{}); ok { if operations, ok := response.Metadata["operations"].([]interface{}); ok {
assert.Len(t, operations, 2, "Should execute 2 operations: ping, status") assert.Len(t, operations, 2, "Should execute 2 operations: ping, status")
@ -161,7 +161,7 @@ func TestRealWorldMCPScenarios(t *testing.T) {
t.Run("Full Workflow", func(t *testing.T) { t.Run("Full Workflow", func(t *testing.T) {
ctx := newRealWorldContext("test-full-workflow", "tests.realworld") ctx := newRealWorldContext("test-full-workflow", "tests.realworld")
// Initialize stack for trace // Initialize stack for trace
stack, _, done := context.EnterStack(ctx, "tests.realworld", context.RefererAPI) stack, _, done := context.EnterStack(ctx, "tests.realworld", context.RefererAPI)
defer done() defer done()
@ -179,7 +179,7 @@ func TestRealWorldMCPScenarios(t *testing.T) {
// Detailed validation // Detailed validation
assert.NotNil(t, response) assert.NotNil(t, response)
assert.NotEmpty(t, response.Messages) assert.NotEmpty(t, response.Messages)
// Check if metadata exists // Check if metadata exists
if response.Metadata == nil { if response.Metadata == nil {
t.Logf("⚠ Metadata is nil - checking messages content") t.Logf("⚠ Metadata is nil - checking messages content")
@ -187,8 +187,8 @@ func TestRealWorldMCPScenarios(t *testing.T) {
messageContent := "" messageContent := ""
for _, msg := range response.Messages { for _, msg := range response.Messages {
if content, ok := msg.Content.(string); ok { if content, ok := msg.Content.(string); ok {
messageContent += content + "\n" messageContent += content + "\n"
} }
} }
assert.Contains(t, messageContent, "Workflow", "Message should mention workflow") assert.Contains(t, messageContent, "Workflow", "Message should mention workflow")
assert.Contains(t, messageContent, "Tools", "Message should mention tools") assert.Contains(t, messageContent, "Tools", "Message should mention tools")
@ -196,22 +196,22 @@ func TestRealWorldMCPScenarios(t *testing.T) {
t.Logf("✓ Full Workflow executed (verified via message content)") t.Logf("✓ Full Workflow executed (verified via message content)")
} else { } else {
assert.Equal(t, "full_workflow", response.Metadata["scenario"]) assert.Equal(t, "full_workflow", response.Metadata["scenario"])
// Verify all phases completed // Verify all phases completed
if phasesCompleted, ok := response.Metadata["phases_completed"]; ok { if phasesCompleted, ok := response.Metadata["phases_completed"]; ok {
phases := int(phasesCompleted.(float64)) phases := int(phasesCompleted.(float64))
assert.Equal(t, 4, phases, "Should complete 4 phases") assert.Equal(t, 4, phases, "Should complete 4 phases")
// Verify MCP tools // Verify MCP tools
if mcpTools, ok := response.Metadata["mcp_tools"]; ok { if mcpTools, ok := response.Metadata["mcp_tools"]; ok {
tools := int(mcpTools.(float64)) tools := int(mcpTools.(float64))
assert.Greater(t, tools, 0, "Should have MCP tools") assert.Greater(t, tools, 0, "Should have MCP tools")
// Verify DB records // Verify DB records
if dbRecords, ok := response.Metadata["db_records"]; ok { if dbRecords, ok := response.Metadata["db_records"]; ok {
records := int(dbRecords.(float64)) records := int(dbRecords.(float64))
assert.GreaterOrEqual(t, records, 0, "Should have DB query result") assert.GreaterOrEqual(t, records, 0, "Should have DB query result")
t.Logf("✓ Full Workflow: %d phases, %d MCP tools, %d DB records", t.Logf("✓ Full Workflow: %d phases, %d MCP tools, %d DB records",
phases, tools, records) phases, tools, records)
} }
@ -462,7 +462,7 @@ func TestRealWorldStressConcurrent(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
errors := make(chan error, goroutines*iterationsPerGoroutine) errors := make(chan error, goroutines*iterationsPerGoroutine)
// Track results for validation // Track results for validation
type Result struct { type Result struct {
goroutineID int goroutineID int
@ -499,7 +499,7 @@ func TestRealWorldStressConcurrent(t *testing.T) {
ctx.Release() ctx.Release()
return return
} }
// Validate response // Validate response
if response == nil { if response == nil {
errors <- fmt.Errorf("goroutine %d iteration %d (%s): nil response", goroutineID, i, scenario) errors <- fmt.Errorf("goroutine %d iteration %d (%s): nil response", goroutineID, i, scenario)
@ -507,7 +507,7 @@ func TestRealWorldStressConcurrent(t *testing.T) {
ctx.Release() ctx.Release()
return return
} }
if len(response.Messages) == 0 { if len(response.Messages) == 0 {
errors <- fmt.Errorf("goroutine %d iteration %d (%s): empty messages", goroutineID, i, scenario) errors <- fmt.Errorf("goroutine %d iteration %d (%s): empty messages", goroutineID, i, scenario)
done() done()
@ -546,15 +546,15 @@ func TestRealWorldStressConcurrent(t *testing.T) {
} }
assert.Equal(t, 0, errorCount, "No errors should occur in concurrent operations") assert.Equal(t, 0, errorCount, "No errors should occur in concurrent operations")
// Validate results // Validate results
scenarioCounts := make(map[string]int) scenarioCounts := make(map[string]int)
validResults := 0 validResults := 0
for result := range results { for result := range results {
validResults++ validResults++
scenarioCounts[result.scenario]++ scenarioCounts[result.scenario]++
// Validate metadata exists and has expected scenario // Validate metadata exists and has expected scenario
if result.metadata != nil { if result.metadata != nil {
if scenario, ok := result.metadata["scenario"].(string); ok { if scenario, ok := result.metadata["scenario"].(string); ok {
@ -568,7 +568,7 @@ func TestRealWorldStressConcurrent(t *testing.T) {
totalOperations := goroutines * iterationsPerGoroutine totalOperations := goroutines * iterationsPerGoroutine
assert.Equal(t, totalOperations, validResults, "All operations should return valid results") assert.Equal(t, totalOperations, validResults, "All operations should return valid results")
avgTime := duration / time.Duration(totalOperations) avgTime := duration / time.Duration(totalOperations)
t.Logf("✓ Concurrent stress: %d operations (goroutines: %d, iterations: %d)", t.Logf("✓ Concurrent stress: %d operations (goroutines: %d, iterations: %d)",
@ -716,4 +716,3 @@ func getMemStats() uint64 {
runtime.ReadMemStats(&m) runtime.ReadMemStats(&m)
return m.Alloc return m.Alloc
} }

View file

@ -72,13 +72,13 @@ func init() {
"mcp.read_resource.description": "Read resource '%s' from MCP client '%s'", "mcp.read_resource.description": "Read resource '%s' from MCP client '%s'",
// MCP: context/mcp.go - Tool operations // MCP: context/mcp.go - Tool operations
"mcp.list_tools.label": "MCP: List Tools", "mcp.list_tools.label": "MCP: List Tools",
"mcp.list_tools.description": "List tools from MCP client '%s'", "mcp.list_tools.description": "List tools from MCP client '%s'",
"mcp.call_tool.label": "MCP: Call Tool", "mcp.call_tool.label": "MCP: Call Tool",
"mcp.call_tool.description": "Call tool '%s' from MCP client '%s'", "mcp.call_tool.description": "Call tool '%s' from MCP client '%s'",
"mcp.call_tools.label": "MCP: Call Tools", "mcp.call_tools.label": "MCP: Call Tools",
"mcp.call_tools.description": "Call %d tools sequentially from MCP client '%s'", "mcp.call_tools.description": "Call %d tools sequentially from MCP client '%s'",
"mcp.call_tools_parallel.label": "MCP: Call Tools (Parallel)", "mcp.call_tools_parallel.label": "MCP: Call Tools (Parallel)",
"mcp.call_tools_parallel.description": "Call %d tools in parallel from MCP client '%s'", "mcp.call_tools_parallel.description": "Call %d tools in parallel from MCP client '%s'",
// MCP: context/mcp.go - Prompt operations // MCP: context/mcp.go - Prompt operations
@ -220,13 +220,13 @@ func init() {
"mcp.read_resource.description": "从 MCP 客户端 '%s' 读取资源 '%s'", "mcp.read_resource.description": "从 MCP 客户端 '%s' 读取资源 '%s'",
// MCP: context/mcp.go - Tool operations // MCP: context/mcp.go - Tool operations
"mcp.list_tools.label": "MCP: 列出工具", "mcp.list_tools.label": "MCP: 列出工具",
"mcp.list_tools.description": "从 MCP 客户端 '%s' 列出工具", "mcp.list_tools.description": "从 MCP 客户端 '%s' 列出工具",
"mcp.call_tool.label": "MCP: 调用工具", "mcp.call_tool.label": "MCP: 调用工具",
"mcp.call_tool.description": "从 MCP 客户端 '%s' 调用工具 '%s'", "mcp.call_tool.description": "从 MCP 客户端 '%s' 调用工具 '%s'",
"mcp.call_tools.label": "MCP: 调用工具", "mcp.call_tools.label": "MCP: 调用工具",
"mcp.call_tools.description": "从 MCP 客户端 '%s' 顺序调用 %d 个工具", "mcp.call_tools.description": "从 MCP 客户端 '%s' 顺序调用 %d 个工具",
"mcp.call_tools_parallel.label": "MCP: 调用工具(并行)", "mcp.call_tools_parallel.label": "MCP: 调用工具(并行)",
"mcp.call_tools_parallel.description": "从 MCP 客户端 '%s' 并行调用 %d 个工具", "mcp.call_tools_parallel.description": "从 MCP 客户端 '%s' 并行调用 %d 个工具",
// MCP: context/mcp.go - Prompt operations // MCP: context/mcp.go - Prompt operations