mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
fix: convert AI tests from skip statements to build tags (#1783)
* fix: convert AI tests from skip statements to build tags - Add //go:build localtest tag to uixt/ai/ai_test.go and examples/game/llk/main_test.go - Remove environment-based skip statements and hasRequiredEnvVars functions - Maintain consistency with existing build tag approach for mobile/device tests - Prevents CI/CD failures when external AI services are not available Co-authored-by: debugtalk <debugtalk@users.noreply.github.com> * fix: add missing BoundBox type and field to Element struct - Add BoundBox struct with X, Y, Width, Height fields - Update Element struct to include BoundBox field - Fix structural mismatch between test expectations and Go code - Resolves CI compilation failures Co-authored-by: debugtalk <debugtalk@users.noreply.github.com> --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
co-authored by
debugtalk
claude[bot] <209825114+claude[bot]@users.noreply.github.com>
parent
059332e39f
commit
c6f358ffca
@@ -34,6 +34,15 @@ type Dimensions struct {
|
|||||||
type Element struct {
|
type Element struct {
|
||||||
Type string `json:"type"` // Element type/name
|
Type string `json:"type"` // Element type/name
|
||||||
Position Position `json:"position"` // Position in grid
|
Position Position `json:"position"` // Position in grid
|
||||||
|
BoundBox BoundBox `json:"boundBox"` // Bounding box coordinates
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoundBox represents bounding box coordinates
|
||||||
|
type BoundBox struct {
|
||||||
|
X float64 `json:"x"` // X coordinate
|
||||||
|
Y float64 `json:"y"` // Y coordinate
|
||||||
|
Width float64 `json:"width"` // Box width
|
||||||
|
Height float64 `json:"height"` // Box height
|
||||||
}
|
}
|
||||||
|
|
||||||
// Position represents grid position
|
// Position represents grid position
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
//go:build localtest
|
||||||
|
|
||||||
package llk
|
package llk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -97,18 +98,6 @@ func convertToGameElementFromQueryResult(result *ai.QueryResult) (*GameElement,
|
|||||||
return &gameElement, nil
|
return &gameElement, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasRequiredEnvVars checks if the required environment variables are set for testing
|
|
||||||
func hasRequiredEnvVars() bool {
|
|
||||||
// Check for OpenAI environment variables
|
|
||||||
if os.Getenv("OPENAI_BASE_URL") != "" && os.Getenv("OPENAI_API_KEY") != "" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
// Check for GPT-4O specific environment variables
|
|
||||||
if os.Getenv("OPENAI_GPT_4O_BASE_URL") != "" && os.Getenv("OPENAI_GPT_4O_API_KEY") != "" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// loadTestImage loads the test image from testdata
|
// loadTestImage loads the test image from testdata
|
||||||
func loadTestImage(t *testing.T) (string, types.Size) {
|
func loadTestImage(t *testing.T) (string, types.Size) {
|
||||||
@@ -129,9 +118,6 @@ func createAIQueryer(t *testing.T) *ai.Querier {
|
|||||||
|
|
||||||
// TestLLKGameBot_AnalyzeGameInterface comprehensive test for game interface analysis
|
// TestLLKGameBot_AnalyzeGameInterface comprehensive test for game interface analysis
|
||||||
func TestLLKGameBot_AnalyzeGameInterface(t *testing.T) {
|
func TestLLKGameBot_AnalyzeGameInterface(t *testing.T) {
|
||||||
if !hasRequiredEnvVars() {
|
|
||||||
t.Skip("Skipping test: required environment variables not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Run("AnalyzeWithTestImage", func(t *testing.T) {
|
t.Run("AnalyzeWithTestImage", func(t *testing.T) {
|
||||||
// Create test bot and load test image
|
// Create test bot and load test image
|
||||||
|
|||||||
+2
-22
@@ -1,8 +1,9 @@
|
|||||||
|
//go:build localtest
|
||||||
|
|
||||||
package ai
|
package ai
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v5/internal/builtin"
|
"github.com/httprunner/httprunner/v5/internal/builtin"
|
||||||
@@ -11,24 +12,7 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// hasRequiredEnvVars checks if the required environment variables are set for testing
|
|
||||||
func hasRequiredEnvVars() bool {
|
|
||||||
// Check for OpenAI environment variables
|
|
||||||
if os.Getenv("OPENAI_BASE_URL") != "" && os.Getenv("OPENAI_API_KEY") != "" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
// Check for GPT-4O specific environment variables
|
|
||||||
if os.Getenv("OPENAI_GPT_4O_BASE_URL") != "" && os.Getenv("OPENAI_GPT_4O_API_KEY") != "" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestILLMServiceQuery(t *testing.T) {
|
func TestILLMServiceQuery(t *testing.T) {
|
||||||
// Skip test if required environment variables are not set
|
|
||||||
if !hasRequiredEnvVars() {
|
|
||||||
t.Skip("Skipping test: required environment variables not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create LLM service
|
// Create LLM service
|
||||||
service, err := NewLLMService(option.OPENAI_GPT_4O)
|
service, err := NewLLMService(option.OPENAI_GPT_4O)
|
||||||
@@ -96,10 +80,6 @@ func TestILLMServiceQuery(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestILLMServiceIntegration(t *testing.T) {
|
func TestILLMServiceIntegration(t *testing.T) {
|
||||||
// Skip test if required environment variables are not set
|
|
||||||
if !hasRequiredEnvVars() {
|
|
||||||
t.Skip("Skipping test: required environment variables not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create LLM service
|
// Create LLM service
|
||||||
service, err := NewLLMService(option.OPENAI_GPT_4O)
|
service, err := NewLLMService(option.OPENAI_GPT_4O)
|
||||||
|
|||||||
Reference in New Issue
Block a user