mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-06 20:32:44 +08:00
refactor: streamline AI assertion result handling by consolidating error management and improving result structure
This commit is contained in:
@@ -1 +1 @@
|
||||
v5.0.0-beta-2506242254
|
||||
v5.0.0-beta-2506242310
|
||||
|
||||
2
step.go
2
step.go
@@ -65,7 +65,7 @@ type ActionResult struct {
|
||||
Error string `json:"error,omitempty"` // action execution result
|
||||
Plannings []*uixt.PlanningExecutionResult `json:"plannings,omitempty"` // store planning results for start_to_goal actions, which contains multiple sub-actions
|
||||
AIResult *uixt.AIExecutionResult `json:"ai_result,omitempty"` // store unified AI execution result for ai_query/ai_action/ai_assert actions
|
||||
uixt.SessionData // store session data for other actions besides start_to_goal & ai_query
|
||||
uixt.SessionData // store session data for other actions besides start_to_goal
|
||||
}
|
||||
|
||||
// one testcase contains one or multiple steps
|
||||
|
||||
@@ -424,15 +424,17 @@ func (dExt *XTDriver) AIAssert(assertion string, opts ...option.ActionOption) (*
|
||||
return nil, err
|
||||
}
|
||||
|
||||
assertResult := &AIExecutionResult{
|
||||
Type: "assert",
|
||||
ScreenshotElapsed: screenshotElapsed,
|
||||
ImagePath: screenResult.ImagePath,
|
||||
Resolution: &screenResult.Resolution,
|
||||
}
|
||||
|
||||
screenShotBase64, size, err := dExt.GetScreenshotBase64WithSize()
|
||||
if err != nil {
|
||||
return &AIExecutionResult{
|
||||
Type: "assert",
|
||||
ScreenshotElapsed: screenshotElapsed,
|
||||
ImagePath: screenResult.ImagePath,
|
||||
Resolution: &screenResult.Resolution,
|
||||
Error: err.Error(),
|
||||
}, err
|
||||
assertResult.Error = err.Error()
|
||||
return assertResult, err
|
||||
}
|
||||
|
||||
// Step 2: Call model and measure time
|
||||
@@ -443,26 +445,18 @@ func (dExt *XTDriver) AIAssert(assertion string, opts ...option.ActionOption) (*
|
||||
Size: size,
|
||||
}
|
||||
result, err := dExt.LLMService.Assert(context.Background(), assertOpts)
|
||||
modelCallElapsed := time.Since(modelCallStartTime).Milliseconds()
|
||||
|
||||
aiResult := &AIExecutionResult{
|
||||
Type: "assert",
|
||||
ModelCallElapsed: modelCallElapsed,
|
||||
ScreenshotElapsed: screenshotElapsed,
|
||||
ImagePath: screenResult.ImagePath,
|
||||
Resolution: &screenResult.Resolution,
|
||||
AssertionResult: result,
|
||||
}
|
||||
assertResult.ModelCallElapsed = time.Since(modelCallStartTime).Milliseconds()
|
||||
assertResult.AssertionResult = result
|
||||
|
||||
if err != nil {
|
||||
aiResult.Error = err.Error()
|
||||
return aiResult, errors.Wrap(err, "AI assertion failed")
|
||||
assertResult.Error = err.Error()
|
||||
return assertResult, errors.Wrap(err, "AI assertion failed")
|
||||
}
|
||||
|
||||
if !result.Pass {
|
||||
aiResult.Error = result.Thought
|
||||
return aiResult, errors.New(result.Thought)
|
||||
assertResult.Error = result.Thought
|
||||
return assertResult, errors.New(result.Thought)
|
||||
}
|
||||
|
||||
return aiResult, nil
|
||||
return assertResult, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user