53 lines
1.8 KiB
Go
53 lines
1.8 KiB
Go
package opencode
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"testing"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/chattools"
|
|
)
|
|
|
|
type toolRegistry struct{}
|
|
|
|
func (toolRegistry) SessionURL(string) (string, error) { return "", errors.New("unused") }
|
|
func (toolRegistry) PendingURL() (string, func(string) error, error) {
|
|
return "", nil, errors.New("unused")
|
|
}
|
|
func (toolRegistry) InstanceURL(harness string) (string, error) {
|
|
return "http://127.0.0.1:9/mcp/chat/instance-" + harness, nil
|
|
}
|
|
|
|
func TestChatServiceConfigRegistersThePipelinesTools(t *testing.T) {
|
|
if got := withPipelinesTools(nil); got != nil {
|
|
t.Fatalf("no registry must add nothing: %v", got)
|
|
}
|
|
chattools.Configure(toolRegistry{})
|
|
t.Cleanup(func() { chattools.Configure(nil) })
|
|
|
|
content, err := configContent(`{"model":"x/y","mcp":{"mine":{"type":"local","command":["m"]}}}`, withPipelinesTools(nil))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var config struct {
|
|
Model string `json:"model"`
|
|
MCP map[string]map[string]any `json:"mcp"`
|
|
}
|
|
if err := json.Unmarshal([]byte(content), &config); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if config.Model != "x/y" || config.MCP["mine"] == nil {
|
|
t.Fatalf("the operator's config must be kept: %s", content)
|
|
}
|
|
if got := config.MCP["pipelines"]; got["type"] != "remote" || got["url"] != "http://127.0.0.1:9/mcp/chat/instance-opencode" || got["enabled"] != true {
|
|
t.Fatalf("pipelines mcp = %v", got)
|
|
}
|
|
|
|
// Chat overrides the operator set win, including their own "pipelines".
|
|
merged := withPipelinesTools(map[string]any{"mcp": map[string]any{"pipelines": map[string]any{"enabled": false}}, "limit": 1.0})
|
|
server := merged["mcp"].(map[string]any)["pipelines"].(map[string]any)
|
|
if server["enabled"] != false || server["url"] == nil || merged["limit"] != 1.0 {
|
|
t.Fatalf("merged = %v", merged)
|
|
}
|
|
}
|