Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 1 addition & 2 deletions internal/config/expand_raw_json_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion internal/config/fetch_and_fix_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions internal/config/rules/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
})
}
Expand Down Expand Up @@ -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")
}
})
}
Expand Down Expand Up @@ -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")
}
})
}
Expand Down Expand Up @@ -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")
}
})
}
Expand Down Expand Up @@ -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")
}
})
}
Expand Down
7 changes: 3 additions & 4 deletions internal/difc/labels_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package difc

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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)
}
})
Expand All @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion internal/mcp/tool_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion internal/mcp/unmarshal_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
4 changes: 2 additions & 2 deletions internal/middleware/jqschema_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion internal/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
3 changes: 1 addition & 2 deletions internal/proxy/rest_backend_caller_tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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")
}
5 changes: 2 additions & 3 deletions internal/server/call_backend_tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/integration/large_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -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")
}
Loading