diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 047d8809..034c083f 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -1089,7 +1089,7 @@ port 3000 errMsg := err.Error() assert.Contains(t, errMsg, "line", "Error should mention line number") // Our improved format includes "column" explicitly when ParseError is detected - assert.True(t, strings.Contains(errMsg, "column") || strings.Contains(errMsg, "line 2"), + assert.Regexp(t, `\bcolumn\b|\bline\s+2\b`, errMsg, "Error should mention column or line position, got: %s", errMsg) } diff --git a/internal/config/expand_raw_json_test.go b/internal/config/expand_raw_json_test.go index 74b08ead..eb5f3cf4 100644 --- a/internal/config/expand_raw_json_test.go +++ b/internal/config/expand_raw_json_test.go @@ -1,7 +1,6 @@ package config import ( - "strings" "testing" "github.com/stretchr/testify/assert" @@ -566,7 +565,7 @@ func TestValidateMounts(t *testing.T) { if tt.shouldErr { require.Error(t, err, "Expected an error but got none") if tt.errMsg != "" { - assert.True(t, strings.Contains(err.Error(), tt.errMsg), + assert.Contains(t, err.Error(), tt.errMsg, "Error message %q should contain %q", err.Error(), tt.errMsg) } } else { diff --git a/internal/config/fetch_and_fix_schema_test.go b/internal/config/fetch_and_fix_schema_test.go index 29544982..638c317a 100644 --- a/internal/config/fetch_and_fix_schema_test.go +++ b/internal/config/fetch_and_fix_schema_test.go @@ -245,7 +245,10 @@ func TestFixSchemaBytes_AddRegistryAndGuardPoliciesToStdioConfig(t *testing.T) { require.True(t, hasGuardPolicies, "guard-policies field should be added to stdioServerConfig.properties") gpMap := guardPolicies.(map[string]interface{}) assert.Equal(t, "object", gpMap["type"], "guard-policies.type should be 'object'") - assert.Equal(t, true, gpMap["additionalProperties"], "guard-policies.additionalProperties should be true") + additionalProperties, hasAdditionalProperties := gpMap["additionalProperties"] + require.True(t, hasAdditionalProperties, "guard-policies.additionalProperties should be present") + require.IsType(t, true, additionalProperties, "guard-policies.additionalProperties should be a bool") + assert.True(t, additionalProperties.(bool), "guard-policies.additionalProperties should be true") } // TestFixSchemaBytes_AddRegistryAndGuardPoliciesToHttpConfig covers the injection diff --git a/internal/config/rules/rules_test.go b/internal/config/rules/rules_test.go index 0f9cc37f..6616a3dc 100644 --- a/internal/config/rules/rules_test.go +++ b/internal/config/rules/rules_test.go @@ -9,6 +9,13 @@ import ( "github.com/stretchr/testify/require" ) +func validationErrAsError(err *ValidationError) error { + if err == nil { + return nil + } + return err +} + func TestPortRange(t *testing.T) { tests := []struct { name string @@ -74,7 +81,7 @@ func TestPortRange(t *testing.T) { assert.Contains(t, err.Message, tt.errMsg, "Error message should contain expected text") assert.Equal(t, tt.jsonPath, err.JSONPath, "JSONPath should match") } else { - require.Nil(t, err, "Unexpected validation error") + require.NoError(t, validationErrAsError(err), "Unexpected validation error") } }) } @@ -138,7 +145,7 @@ func TestTimeoutPositive(t *testing.T) { assert.Equal(t, tt.jsonPath, err.JSONPath, "JSONPath should match") assert.Equal(t, tt.fieldName, err.Field, "Field name should match") } else { - require.Nil(t, err, "Unexpected validation error") + require.NoError(t, validationErrAsError(err), "Unexpected validation error") } }) } @@ -295,7 +302,7 @@ func TestMountFormat(t *testing.T) { assert.Contains(t, err.Message, tt.errMsg, "Error message should contain expected text") assert.Equal(t, fmt.Sprintf("%s.mounts[%d]", tt.jsonPath, tt.index), err.JSONPath, "JSONPath should match expected pattern") } else { - require.Nil(t, err, "Unexpected validation error") + require.NoError(t, validationErrAsError(err), "Unexpected validation error") } }) } @@ -899,7 +906,7 @@ func TestNonEmptyString(t *testing.T) { assert.Contains(t, err.Error(), tt.errMsg) assert.Contains(t, err.Error(), tt.jsonPath) } else { - require.Nil(t, err, "Unexpected validation error") + require.NoError(t, validationErrAsError(err), "Unexpected validation error") } }) } @@ -1039,7 +1046,7 @@ func TestAbsolutePath(t *testing.T) { assert.Contains(t, err.Error(), tt.errMsg) assert.Contains(t, err.Error(), tt.jsonPath) } else { - require.Nil(t, err, "Unexpected validation error") + require.NoError(t, validationErrAsError(err), "Unexpected validation error") } }) } diff --git a/internal/difc/labels_test.go b/internal/difc/labels_test.go index d3968d4b..e5ff9039 100644 --- a/internal/difc/labels_test.go +++ b/internal/difc/labels_test.go @@ -1,7 +1,6 @@ package difc import ( - "strings" "testing" "github.com/stretchr/testify/assert" @@ -590,11 +589,11 @@ func TestViolationError_Error(t *testing.T) { msg := tt.err.Error() assert.NotEmpty(t, msg) for _, want := range tt.wantContains { - assert.True(t, strings.Contains(msg, want), + assert.Contains(t, msg, want, "expected %q in error message %q", want, msg) } for _, absent := range tt.wantAbsent { - assert.False(t, strings.Contains(msg, absent), + assert.NotContains(t, msg, absent, "expected %q NOT to be in error message %q", absent, msg) } }) @@ -616,7 +615,7 @@ func TestViolationError_Detailed(t *testing.T) { base := err.Error() // Detailed should contain the base error message - assert.True(t, strings.Contains(detailed, base), "detailed should include base error") + assert.Contains(t, detailed, base, "detailed should include base error") // Detailed should include agent and resource tag context assert.Contains(t, detailed, "Agent") diff --git a/internal/mcp/tool_result_test.go b/internal/mcp/tool_result_test.go index 29650ffe..f0e670f7 100644 --- a/internal/mcp/tool_result_test.go +++ b/internal/mcp/tool_result_test.go @@ -268,7 +268,9 @@ func TestParseToolArguments(t *testing.T) { require.NotNil(t, args) assert.Equal(t, "search term", args["query"]) assert.Equal(t, float64(10), args["limit"]) - assert.Equal(t, true, args["active"]) + active, ok := args["active"].(bool) + require.True(t, ok, "expected active to be a bool") + assert.True(t, active) }) t.Run("nested object arguments are parsed correctly", func(t *testing.T) { diff --git a/internal/mcp/unmarshal_params_test.go b/internal/mcp/unmarshal_params_test.go index 0c2cb8b3..e308729d 100644 --- a/internal/mcp/unmarshal_params_test.go +++ b/internal/mcp/unmarshal_params_test.go @@ -153,7 +153,9 @@ func TestUnmarshalParams(t *testing.T) { // JSON unmarshal converts numbers to float64 by default assert.Equal(t, float64(42), target["int_val"]) assert.Equal(t, 3.14, target["float_val"]) - assert.Equal(t, true, target["bool_val"]) + boolVal, ok := target["bool_val"].(bool) + require.True(t, ok, "bool_val should be a bool") + assert.True(t, boolVal) assert.Len(t, target["array_val"], 3) assert.NotNil(t, target["object_val"]) assert.Nil(t, target["null_val"]) diff --git a/internal/middleware/jqschema_integration_test.go b/internal/middleware/jqschema_integration_test.go index e69a24c4..f2199102 100644 --- a/internal/middleware/jqschema_integration_test.go +++ b/internal/middleware/jqschema_integration_test.go @@ -195,7 +195,7 @@ func TestMiddlewareWithLargePayload(t *testing.T) { // Verify preview truncation in Content field (preview ends with ... when truncated) previewInContent := contentMap["payloadPreview"].(string) if strings.HasSuffix(previewInContent, "...") { - assert.True(t, len(previewInContent) <= 503, "Preview in Content should be truncated") + assert.LessOrEqual(t, len(previewInContent), 503, "Preview in Content should be truncated") } // Also check data return value @@ -204,7 +204,7 @@ func TestMiddlewareWithLargePayload(t *testing.T) { // Verify preview truncation (check if it ends with ...) preview := dataMap["payloadPreview"].(string) if strings.HasSuffix(preview, "...") { - assert.True(t, len(preview) <= 503, "Preview should be truncated") + assert.LessOrEqual(t, len(preview), 503, "Preview should be truncated") } // Verify payload file has complete data diff --git a/internal/proxy/proxy_test.go b/internal/proxy/proxy_test.go index 2861020c..70a46d8c 100644 --- a/internal/proxy/proxy_test.go +++ b/internal/proxy/proxy_test.go @@ -682,7 +682,11 @@ func TestRewrapSearchResponse(t *testing.T) { result := rewrapSearchResponse(original, filtered) m := result.(map[string]interface{}) assert.Equal(t, float64(2), m["total_count"]) - assert.Equal(t, false, m["incomplete_results"]) + incompleteResults, ok := m["incomplete_results"] + require.True(t, ok) + incompleteResultsBool, ok := incompleteResults.(bool) + require.True(t, ok) + assert.False(t, incompleteResultsBool) assert.Len(t, m["items"].([]interface{}), 2) }) diff --git a/internal/proxy/rest_backend_caller_tool_test.go b/internal/proxy/rest_backend_caller_tool_test.go index 48c9da8e..8c498783 100644 --- a/internal/proxy/rest_backend_caller_tool_test.go +++ b/internal/proxy/rest_backend_caller_tool_test.go @@ -6,7 +6,6 @@ import ( "fmt" "net/http" "net/http/httptest" - "strings" "testing" "github.com/stretchr/testify/assert" @@ -574,5 +573,5 @@ func TestRestBackendCaller_IssueRead_ResponseFormat(t *testing.T) { text, ok := content[0]["text"].(string) require.True(t, ok) - assert.True(t, strings.Contains(text, "Bug report"), "response text should contain the issue title") + assert.Contains(t, text, "Bug report", "response text should contain the issue title") } diff --git a/internal/server/call_backend_tool_test.go b/internal/server/call_backend_tool_test.go index 268a7a3f..7a60b585 100644 --- a/internal/server/call_backend_tool_test.go +++ b/internal/server/call_backend_tool_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "net/http" "net/http/httptest" - "strings" "testing" "time" @@ -482,8 +481,8 @@ func TestCallBackendTool_AllowedToolsError_MessageFormat(t *testing.T) { require.True(result.IsError) require.Len(result.Content, 1) text := result.Content[0].(*sdk.TextContent).Text - assert.True(t, strings.Contains(text, `"blocked"`), "error message should include tool name: %s", text) - assert.True(t, strings.Contains(text, "allowed-tools"), "error message should mention allowed-tools: %s", text) + assert.Contains(t, text, `"blocked"`, "error message should include tool name: %s", text) + assert.Contains(t, text, "allowed-tools", "error message should mention allowed-tools: %s", text) } // TestCallBackendTool_ToolTimeoutEnforcedViaContext verifies that the configured diff --git a/test/integration/large_payload_test.go b/test/integration/large_payload_test.go index 19ad1b1c..77067084 100644 --- a/test/integration/large_payload_test.go +++ b/test/integration/large_payload_test.go @@ -10,7 +10,6 @@ import ( "os" "os/exec" "path/filepath" - "strings" "testing" "time" @@ -698,5 +697,5 @@ func TestLargePayload_PayloadPathStructure(t *testing.T) { // This test documents the expected behavior assert.Equal(t, "{payloadDir}/{sessionID}/{queryID}/payload.json", expectedStructure) - assert.True(t, strings.Contains(expectedStructure, "sessionID"), "Structure should include sessionID for isolation") + assert.Contains(t, expectedStructure, "sessionID", "Structure should include sessionID for isolation") }