From c6f358ffca0e7ba9702aa8644779648d7d72f029 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sun, 3 Aug 2025 11:43:21 +0800 Subject: [PATCH] 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 * 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 --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> --- examples/game/llk/main.go | 9 +++++++++ examples/game/llk/main_test.go | 18 ++---------------- uixt/ai/ai_test.go | 24 ++---------------------- 3 files changed, 13 insertions(+), 38 deletions(-) diff --git a/examples/game/llk/main.go b/examples/game/llk/main.go index 2e0bfafa..c8e5f201 100644 --- a/examples/game/llk/main.go +++ b/examples/game/llk/main.go @@ -34,6 +34,15 @@ type Dimensions struct { type Element struct { Type string `json:"type"` // Element type/name 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 diff --git a/examples/game/llk/main_test.go b/examples/game/llk/main_test.go index d55667ed..74421801 100644 --- a/examples/game/llk/main_test.go +++ b/examples/game/llk/main_test.go @@ -1,10 +1,11 @@ +//go:build localtest + package llk import ( "context" "encoding/json" "fmt" - "os" "testing" "github.com/stretchr/testify/assert" @@ -97,18 +98,6 @@ func convertToGameElementFromQueryResult(result *ai.QueryResult) (*GameElement, 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 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 func TestLLKGameBot_AnalyzeGameInterface(t *testing.T) { - if !hasRequiredEnvVars() { - t.Skip("Skipping test: required environment variables not set") - } t.Run("AnalyzeWithTestImage", func(t *testing.T) { // Create test bot and load test image diff --git a/uixt/ai/ai_test.go b/uixt/ai/ai_test.go index 2035c047..0a387784 100644 --- a/uixt/ai/ai_test.go +++ b/uixt/ai/ai_test.go @@ -1,8 +1,9 @@ +//go:build localtest + package ai import ( "context" - "os" "testing" "github.com/httprunner/httprunner/v5/internal/builtin" @@ -11,24 +12,7 @@ import ( "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) { - // Skip test if required environment variables are not set - if !hasRequiredEnvVars() { - t.Skip("Skipping test: required environment variables not set") - } // Create LLM service service, err := NewLLMService(option.OPENAI_GPT_4O) @@ -96,10 +80,6 @@ func TestILLMServiceQuery(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 service, err := NewLLMService(option.OPENAI_GPT_4O)