69 lines
2.2 KiB
Go
69 lines
2.2 KiB
Go
package claude
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"slices"
|
|
"testing"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/chattools"
|
|
)
|
|
|
|
type toolRegistry struct{ fail bool }
|
|
|
|
func (r toolRegistry) SessionURL(id string) (string, error) {
|
|
if r.fail {
|
|
return "", errors.New("no store")
|
|
}
|
|
return "http://127.0.0.1:9/mcp/chat/token-" + id, nil
|
|
}
|
|
func (toolRegistry) PendingURL() (string, func(string) error, error) {
|
|
return "", nil, errors.New("unused")
|
|
}
|
|
func (toolRegistry) InstanceURL(string) (string, error) { return "", errors.New("unused") }
|
|
|
|
func TestCLIArgsRegisterThePipelinesToolsPerSession(t *testing.T) {
|
|
chat := &Chat{sessions: map[string]*session{}}
|
|
s := chat.sessionFor("id-1", "/fixture")
|
|
args, _ := s.cliArgs(false)
|
|
if slices.Contains(args, "--mcp-config") {
|
|
t.Fatalf("no registry must add no MCP config: %q", args)
|
|
}
|
|
|
|
chattools.Configure(toolRegistry{})
|
|
t.Cleanup(func() { chattools.Configure(nil) })
|
|
args, _ = s.cliArgs(true)
|
|
var config struct {
|
|
MCPServers map[string]struct {
|
|
Type string `json:"type"`
|
|
URL string `json:"url"`
|
|
} `json:"mcpServers"`
|
|
}
|
|
if err := json.Unmarshal([]byte(argValue(args, "--mcp-config")), &config); err != nil {
|
|
t.Fatalf("--mcp-config is not JSON: %q", args)
|
|
}
|
|
if got := config.MCPServers["pipelines"]; got.Type != "http" || got.URL != "http://127.0.0.1:9/mcp/chat/token-id-1" {
|
|
t.Fatalf("mcp config = %+v", config)
|
|
}
|
|
if argValue(args, "--allowedTools") != "mcp__pipelines" || argValue(args, "--resume") != "id-1" {
|
|
t.Fatalf("args = %q", args)
|
|
}
|
|
|
|
// A start that failed with the tools retries once without them.
|
|
if !s.disableTools(errors.New("unknown option --mcp-config")) {
|
|
t.Fatal("the first failure must ask for a retry without the tools")
|
|
}
|
|
if s.disableTools(errors.New("again")) {
|
|
t.Fatal("a chat already without the tools must not retry again")
|
|
}
|
|
if args, _ = s.cliArgs(true); slices.Contains(args, "--mcp-config") {
|
|
t.Fatalf("a chat whose start refused the tools must start without them: %q", args)
|
|
}
|
|
|
|
chattools.Configure(toolRegistry{fail: true})
|
|
other := chat.sessionFor("id-2", "/fixture")
|
|
if args, _ = other.cliArgs(false); slices.Contains(args, "--mcp-config") {
|
|
t.Fatalf("an unissued endpoint must start without the tools: %q", args)
|
|
}
|
|
}
|