MCPcopy Create free account
hub / github.com/docker/model-test / runAgentTest

Method runAgentTest

services/test_runner.go:116–172  ·  view source on GitHub ↗

runAgentTest executes a single test case using the agent loop

(ctx context.Context, testCase models.TestCase)

Source from the content-addressed store, hash-verified

114
115// runAgentTest executes a single test case using the agent loop
116func (tr *TestRunner) runAgentTest(ctx context.Context, testCase models.TestCase) models.AgentTestResult {
117 startTime := time.Now()
118
119 // Generate a unique session ID for this test
120 sessionID := fmt.Sprintf("test_%s_%d", testCase.Name, time.Now().UnixNano())
121
122 // Create a session for the test
123 session := &models.ChatSession{
124 SessionID: sessionID,
125 Messages: []models.ChatMessage{},
126 CreatedAt: time.Now(),
127 UpdatedAt: time.Now(),
128 }
129
130 // Initialize cart state if specified in the test case
131 if testCase.InitialCartState != nil {
132 err := tr.openaiService.InitializeCartForTest(sessionID, testCase.InitialCartState)
133 if err != nil {
134 return models.AgentTestResult{
135 TestCase: testCase,
136 ModelName: tr.getModelName(),
137 Success: false,
138 ErrorMessage: fmt.Sprintf("Failed to initialize cart state: %v", err),
139 Timestamp: time.Now(),
140 ResponseTime: time.Since(startTime),
141 }
142 }
143 }
144
145 // Execute the test using the agent loop
146 response, err := tr.openaiService.ProcessChatMessage(ctx, testCase.Prompt, session, testCase.Name)
147 responseTime := time.Since(startTime)
148
149 if err != nil {
150 return models.AgentTestResult{
151 TestCase: testCase,
152 ModelName: tr.getModelName(),
153 Success: false,
154 ErrorMessage: err.Error(),
155 Timestamp: time.Now(),
156 ResponseTime: responseTime,
157 }
158 }
159
160 // Evaluate if the test was successful by checking tool calls
161 success, matchedPath := tr.evaluateAgentResponse(testCase, response)
162
163 return models.AgentTestResult{
164 TestCase: testCase,
165 ModelName: tr.getModelName(),
166 Response: response,
167 Success: success,
168 MatchedPath: matchedPath,
169 Timestamp: time.Now(),
170 ResponseTime: responseTime,
171 }
172}
173

Callers 1

RunAgentTestSuiteMethod · 0.95

Calls 4

getModelNameMethod · 0.95
evaluateAgentResponseMethod · 0.95
InitializeCartForTestMethod · 0.80
ProcessChatMessageMethod · 0.80

Tested by

no test coverage detected