package chattools import ( "encoding/json" "strings" "testing" ) func TestValidateArgumentsRefusesUnknownAndMistypedFields(t *testing.T) { cases := []struct { tool, args, want string }{ {ToolShowFile, `{"path":"a.txt"}`, ""}, {ToolShowFile, `{"path":"a.txt","replace":"shown_1","title":"x"}`, ""}, {ToolShowFile, `{"file":"a.txt"}`, `unknown argument "file"; show_file takes path (required), replace, title`}, {ToolShowFile, `{}`, "path is required"}, {ToolShowFile, `{"path":3}`, "path must be a string"}, {ToolShowFile, `[1]`, "must be a JSON object"}, {ToolShowImage, `{"url":"https://x/y.png"}`, `unknown argument "url"; show_image takes url_or_path (required), alt, replace, title`}, {ToolShowHTML, `{"html":"

","height_hint":"200"}`, "height_hint must be an integer"}, {ToolShowHTML, `{"html":"

","height_hint":200.5}`, "height_hint must be an integer"}, {ToolShowDiff, `{"paths":"a.go"}`, "paths must be an array of strings"}, {ToolShowDiff, `{"paths":["a.go"],"head":"main","committed_only":true}`, ""}, {ToolShowDiff, `{"committed_only":"yes"}`, "committed_only must be true or false"}, {ToolShowRun, `{"run_id":12}`, ""}, {ToolShowRun, `{"id":12}`, `unknown argument "id"`}, {ToolNotify, `{"title":"t","message":"m","priority":"urgent"}`, "priority must be one of low, default, high"}, {ToolScheduleFollowup, `{"message":"m","after_minutes":5}`, ""}, {ToolScheduleFollowup, `{"message":"m","in_minutes":5,"delay":1}`, `unknown arguments "delay", "in_minutes"`}, } for _, c := range cases { err := ValidateArguments(c.tool, json.RawMessage(c.args)) switch { case c.want == "" && err != nil: t.Errorf("%s %s: unexpected %v", c.tool, c.args, err) case c.want != "" && (err == nil || !strings.Contains(err.Error(), c.want)): t.Errorf("%s %s: got %v, want %q", c.tool, c.args, err, c.want) } } } func TestEveryListedToolIsATool(t *testing.T) { for _, definition := range definitions() { if !IsTool(definition.Name) { t.Errorf("%s is listed but not a tool", definition.Name) } if definition.InputSchema["additionalProperties"] != false { t.Errorf("%s schema allows additional properties", definition.Name) } } }