Files
pipelines/internal/chattools/validate_test.go
T
alan d275ffe643 Chat tools: follow-up ids, cancel_followup, run-triggered follow-ups, show_html warnings
- schedule_followup returns the follow-up id and lists pending follow-ups;
  count-then-queue is serialised so the 3-pending bound holds under
  concurrent calls.
- cancel_followup {id} removes one of the chat's undelivered follow-ups.
- schedule_followup {run_id, on: finished|attention} queues a durable
  follow-up (7-day deadline) that is released with the run's state when the
  run ends or waits on a human; run must exist and not already meet the
  condition; watches are re-armed from the restored queue after a restart.
- show_html results warn about scripts, remote resources (blocked by the
  sandbox) and missing dark-mode support.
- The ambiguous-call error advice fits each tool instead of always
  suggesting a different title.
- references/chat.md and the SKILL.md chat paragraph document the above, and
  questions are no longer described as Claude-only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:24:12 +00:00

56 lines
2.4 KiB
Go

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":"<p>","height_hint":"200"}`, "height_hint must be an integer"},
{ToolShowHTML, `{"html":"<p>","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"`},
{ToolScheduleFollowup, `{"message":"m","run_id":7,"on":"attention"}`, ""},
{ToolScheduleFollowup, `{"message":"m","run_id":7,"on":"done"}`, "on must be one of finished, attention"},
{ToolCancelFollowup, `{"id":"followup-1"}`, ""},
{ToolCancelFollowup, `{}`, "id is required"},
}
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)
}
}
}