4cddfcf2f3
Backend Tests / Tests (other) (push) Failing after 1s
Backend Tests / Static Checks (push) Failing after 2s
Backend Tests / Tests (internal) (push) Failing after 2s
Backend Tests / Tests (server) (push) Failing after 1s
Backend Tests / Tests (store) (push) Failing after 1s
Build Canary Image / build-frontend (push) Failing after 1s
Frontend Tests / Lint (push) Failing after 1s
Build Canary Image / build-push (linux/amd64) (push) Has been skipped
Build Canary Image / build-push (linux/arm64) (push) Has been skipped
Build Canary Image / merge (push) Has been skipped
Frontend Tests / Build (push) Failing after 1s
Release Please / release-please (push) Failing after 0s
Proto Linter / Lint Protos (push) Failing after 2s
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package mcp
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestValidateToolArgumentsRejectsUnknownArguments(t *testing.T) {
|
|
schema := jsonSchema{
|
|
"type": "object",
|
|
"properties": map[string]any{
|
|
"pageSize": map[string]any{"type": "integer"},
|
|
},
|
|
"additionalProperties": false,
|
|
}
|
|
|
|
err := validateToolArguments(schema, map[string]any{"unexpected": true})
|
|
require.ErrorContains(t, err, `unknown argument "unexpected"`)
|
|
}
|
|
|
|
func TestValidateToolArgumentsRejectsMissingRequiredArguments(t *testing.T) {
|
|
schema := jsonSchema{
|
|
"type": "object",
|
|
"properties": map[string]any{
|
|
"memo": map[string]any{"type": "string"},
|
|
},
|
|
"required": []string{"memo"},
|
|
"additionalProperties": false,
|
|
}
|
|
|
|
err := validateToolArguments(schema, map[string]any{})
|
|
require.ErrorContains(t, err, `missing required argument "memo"`)
|
|
}
|
|
|
|
func TestValidateToolArgumentsRejectsWrongPrimitiveTypes(t *testing.T) {
|
|
schema := jsonSchema{
|
|
"type": "object",
|
|
"properties": map[string]any{
|
|
"pageSize": map[string]any{"type": "integer"},
|
|
},
|
|
"additionalProperties": false,
|
|
}
|
|
|
|
err := validateToolArguments(schema, map[string]any{"pageSize": "ten"})
|
|
require.ErrorContains(t, err, `argument "pageSize" must be integer`)
|
|
}
|
|
|
|
func TestValidateToolArgumentsUsesJSONSchemaValidation(t *testing.T) {
|
|
schema := jsonSchema{
|
|
"type": "object",
|
|
"properties": map[string]any{
|
|
"state": map[string]any{
|
|
"type": "string",
|
|
"enum": []any{"NORMAL", "ARCHIVED"},
|
|
},
|
|
},
|
|
"additionalProperties": false,
|
|
}
|
|
|
|
err := validateToolArguments(schema, map[string]any{"state": "DELETED"})
|
|
require.ErrorContains(t, err, "MCP tool arguments do not match input schema")
|
|
}
|