Serve the Pipelines chat tools over a loopback MCP endpoint and register it with Claude Code, Codex and OpenCode chats
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user