Skip to content

Commit bcfd993

Browse files
Copilotlpcox
andauthored
test: address review feedback for safe type assertions
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/5e78a2b2-2590-435f-9662-ff17be3389fd Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
1 parent 98d7334 commit bcfd993

5 files changed

Lines changed: 16 additions & 5 deletions

File tree

internal/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ port 3000
10891089
errMsg := err.Error()
10901090
assert.Contains(t, errMsg, "line", "Error should mention line number")
10911091
// Our improved format includes "column" explicitly when ParseError is detected
1092-
assert.Regexp(t, `column|line 2`, errMsg,
1092+
assert.Regexp(t, `\bcolumn\b|\bline\s+2\b`, errMsg,
10931093
"Error should mention column or line position, got: %s", errMsg)
10941094
}
10951095

internal/config/fetch_and_fix_schema_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,10 @@ func TestFixSchemaBytes_AddRegistryAndGuardPoliciesToStdioConfig(t *testing.T) {
245245
require.True(t, hasGuardPolicies, "guard-policies field should be added to stdioServerConfig.properties")
246246
gpMap := guardPolicies.(map[string]interface{})
247247
assert.Equal(t, "object", gpMap["type"], "guard-policies.type should be 'object'")
248-
assert.True(t, gpMap["additionalProperties"].(bool), "guard-policies.additionalProperties should be true")
248+
additionalProperties, hasAdditionalProperties := gpMap["additionalProperties"]
249+
require.True(t, hasAdditionalProperties, "guard-policies.additionalProperties should be present")
250+
require.IsType(t, true, additionalProperties, "guard-policies.additionalProperties should be a bool")
251+
assert.True(t, additionalProperties.(bool), "guard-policies.additionalProperties should be true")
249252
}
250253

251254
// TestFixSchemaBytes_AddRegistryAndGuardPoliciesToHttpConfig covers the injection

internal/mcp/tool_result_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ func TestParseToolArguments(t *testing.T) {
268268
require.NotNil(t, args)
269269
assert.Equal(t, "search term", args["query"])
270270
assert.Equal(t, float64(10), args["limit"])
271-
assert.True(t, args["active"].(bool))
271+
active, ok := args["active"].(bool)
272+
require.True(t, ok, "expected active to be a bool")
273+
assert.True(t, active)
272274
})
273275

274276
t.Run("nested object arguments are parsed correctly", func(t *testing.T) {

internal/mcp/unmarshal_params_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ func TestUnmarshalParams(t *testing.T) {
153153
// JSON unmarshal converts numbers to float64 by default
154154
assert.Equal(t, float64(42), target["int_val"])
155155
assert.Equal(t, 3.14, target["float_val"])
156-
assert.True(t, target["bool_val"].(bool))
156+
boolVal, ok := target["bool_val"].(bool)
157+
require.True(t, ok, "bool_val should be a bool")
158+
assert.True(t, boolVal)
157159
assert.Len(t, target["array_val"], 3)
158160
assert.NotNil(t, target["object_val"])
159161
assert.Nil(t, target["null_val"])

internal/proxy/proxy_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,11 @@ func TestRewrapSearchResponse(t *testing.T) {
682682
result := rewrapSearchResponse(original, filtered)
683683
m := result.(map[string]interface{})
684684
assert.Equal(t, float64(2), m["total_count"])
685-
assert.False(t, m["incomplete_results"].(bool))
685+
incompleteResults, ok := m["incomplete_results"]
686+
require.True(t, ok)
687+
incompleteResultsBool, ok := incompleteResults.(bool)
688+
require.True(t, ok)
689+
assert.False(t, incompleteResultsBool)
686690
assert.Len(t, m["items"].([]interface{}), 2)
687691
})
688692

0 commit comments

Comments
 (0)