mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +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
|
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
|
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
|
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
|
// one testcase contains one or multiple steps
|
||||||
|
|||||||
@@ -424,15 +424,17 @@ func (dExt *XTDriver) AIAssert(assertion string, opts ...option.ActionOption) (*
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertResult := &AIExecutionResult{
|
||||||
|
Type: "assert",
|
||||||
|
ScreenshotElapsed: screenshotElapsed,
|
||||||
|
ImagePath: screenResult.ImagePath,
|
||||||
|
Resolution: &screenResult.Resolution,
|
||||||
|
}
|
||||||
|
|
||||||
screenShotBase64, size, err := dExt.GetScreenshotBase64WithSize()
|
screenShotBase64, size, err := dExt.GetScreenshotBase64WithSize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &AIExecutionResult{
|
assertResult.Error = err.Error()
|
||||||
Type: "assert",
|
return assertResult, err
|
||||||
ScreenshotElapsed: screenshotElapsed,
|
|
||||||
ImagePath: screenResult.ImagePath,
|
|
||||||
Resolution: &screenResult.Resolution,
|
|
||||||
Error: err.Error(),
|
|
||||||
}, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2: Call model and measure time
|
// Step 2: Call model and measure time
|
||||||
@@ -443,26 +445,18 @@ func (dExt *XTDriver) AIAssert(assertion string, opts ...option.ActionOption) (*
|
|||||||
Size: size,
|
Size: size,
|
||||||
}
|
}
|
||||||
result, err := dExt.LLMService.Assert(context.Background(), assertOpts)
|
result, err := dExt.LLMService.Assert(context.Background(), assertOpts)
|
||||||
modelCallElapsed := time.Since(modelCallStartTime).Milliseconds()
|
assertResult.ModelCallElapsed = time.Since(modelCallStartTime).Milliseconds()
|
||||||
|
assertResult.AssertionResult = result
|
||||||
aiResult := &AIExecutionResult{
|
|
||||||
Type: "assert",
|
|
||||||
ModelCallElapsed: modelCallElapsed,
|
|
||||||
ScreenshotElapsed: screenshotElapsed,
|
|
||||||
ImagePath: screenResult.ImagePath,
|
|
||||||
Resolution: &screenResult.Resolution,
|
|
||||||
AssertionResult: result,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
aiResult.Error = err.Error()
|
assertResult.Error = err.Error()
|
||||||
return aiResult, errors.Wrap(err, "AI assertion failed")
|
return assertResult, errors.Wrap(err, "AI assertion failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !result.Pass {
|
if !result.Pass {
|
||||||
aiResult.Error = result.Thought
|
assertResult.Error = result.Thought
|
||||||
return aiResult, errors.New(result.Thought)
|
return assertResult, errors.New(result.Thought)
|
||||||
}
|
}
|
||||||
|
|
||||||
return aiResult, nil
|
return assertResult, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user