mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-12 00:45:22 +00:00
- common/mcp.go: MCPStyle enum + BuildMCPMapStyled for claude/crush/opencode/zed dialects - common/jsonmerge.go: MergeJSONKeys (JSON-first, JSONC fallback) preserves user keys; fix: try plain json.Unmarshal before StripJSONComments to avoid mangling URLs with // - common/yamlmerge.go: MergeYAMLKeys for YAML configs (goose) - common/blocks.go: add ProvidersAsMap for opencode map-shaped provider key - claudecode: merge settings.json (preserves hooks/permissions/env); MCPClaudeStyle (no type field) - crush: fix mcp key (was mcpServers); MCPCrushStyle entries include type field; merge crush.json; fix import key mcp - kilo: drop providers key (kilo has none); MCPOpencodeStyle (local/remote); merge kilo.json - opencode: fix provider (singular map) + model (not default_model); MCPOpencodeStyle; merge jsonc; fix import key mcp - goose: new adapter — YAML merge, extensions map, splitProviderModel, import reconstructs MCP from extensions - cagent: new adapter — renders starter default.yaml, import returns empty - zed: new adapter — merge settings.json, context_servers (MCPZedStyle) + agent.default_model - docs: append Grounded harness schemas section to design spec
111 lines
3.8 KiB
Go
111 lines
3.8 KiB
Go
package common
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/lukaszraczylo/harness-sync/internal/canonical"
|
|
)
|
|
|
|
func reg(servers ...canonical.MCPServer) *canonical.MCPRegistry {
|
|
return &canonical.MCPRegistry{Servers: servers}
|
|
}
|
|
|
|
func TestBuildMCPMapStyledClaudeStyle(t *testing.T) {
|
|
r := reg(canonical.MCPServer{Name: "fp", Command: "/bin/fp", Args: []string{"--flag"}, Transport: "stdio"})
|
|
out := BuildMCPMapStyled(r, MCPClaudeStyle)
|
|
require.Contains(t, out, "fp")
|
|
e := out["fp"].(map[string]any)
|
|
assert.Equal(t, "/bin/fp", e["command"])
|
|
assert.Equal(t, []string{"--flag"}, e["args"])
|
|
assert.Equal(t, "stdio", e["transport"])
|
|
assert.NotContains(t, e, "type")
|
|
}
|
|
|
|
func TestBuildMCPMapStyledClaudeStyleURL(t *testing.T) {
|
|
r := reg(canonical.MCPServer{Name: "remote", URL: "https://example.com"})
|
|
out := BuildMCPMapStyled(r, MCPClaudeStyle)
|
|
e := out["remote"].(map[string]any)
|
|
assert.Equal(t, "https://example.com", e["url"])
|
|
assert.NotContains(t, e, "type")
|
|
}
|
|
|
|
func TestBuildMCPMapStyledCrushStdio(t *testing.T) {
|
|
r := reg(canonical.MCPServer{Name: "fp", Command: "/bin/fp", Args: []string{"-x"}})
|
|
out := BuildMCPMapStyled(r, MCPCrushStyle)
|
|
e := out["fp"].(map[string]any)
|
|
assert.Equal(t, "stdio", e["type"])
|
|
assert.Equal(t, "/bin/fp", e["command"])
|
|
assert.Equal(t, []string{"-x"}, e["args"])
|
|
}
|
|
|
|
func TestBuildMCPMapStyledCrushHTTP(t *testing.T) {
|
|
r := reg(canonical.MCPServer{Name: "remote", URL: "https://example.com", Transport: "sse"})
|
|
out := BuildMCPMapStyled(r, MCPCrushStyle)
|
|
e := out["remote"].(map[string]any)
|
|
assert.Equal(t, "sse", e["type"])
|
|
assert.Equal(t, "https://example.com", e["url"])
|
|
}
|
|
|
|
func TestBuildMCPMapStyledCrushHTTPDefaultType(t *testing.T) {
|
|
// No transport set → default to "http"
|
|
r := reg(canonical.MCPServer{Name: "remote", URL: "https://example.com"})
|
|
out := BuildMCPMapStyled(r, MCPCrushStyle)
|
|
e := out["remote"].(map[string]any)
|
|
assert.Equal(t, "http", e["type"])
|
|
}
|
|
|
|
func TestBuildMCPMapStyledOpencodeLocal(t *testing.T) {
|
|
r := reg(canonical.MCPServer{Name: "fp", Command: "/bin/fp", Args: []string{"--flag"}})
|
|
out := BuildMCPMapStyled(r, MCPOpencodeStyle)
|
|
e := out["fp"].(map[string]any)
|
|
assert.Equal(t, "local", e["type"])
|
|
assert.Equal(t, true, e["enabled"])
|
|
cmd := e["command"].([]string)
|
|
assert.Equal(t, []string{"/bin/fp", "--flag"}, cmd)
|
|
assert.NotContains(t, e, "environment")
|
|
}
|
|
|
|
func TestBuildMCPMapStyledOpencodeRemote(t *testing.T) {
|
|
r := reg(canonical.MCPServer{Name: "r", URL: "https://example.com"})
|
|
out := BuildMCPMapStyled(r, MCPOpencodeStyle)
|
|
e := out["r"].(map[string]any)
|
|
assert.Equal(t, "remote", e["type"])
|
|
assert.Equal(t, true, e["enabled"])
|
|
assert.Equal(t, "https://example.com", e["url"])
|
|
}
|
|
|
|
func TestBuildMCPMapStyledOpencodeEnv(t *testing.T) {
|
|
r := reg(canonical.MCPServer{Name: "fp", Command: "/bin/fp", Env: map[string]string{"K": "V"}})
|
|
out := BuildMCPMapStyled(r, MCPOpencodeStyle)
|
|
e := out["fp"].(map[string]any)
|
|
assert.Equal(t, map[string]string{"K": "V"}, e["environment"])
|
|
}
|
|
|
|
func TestBuildMCPMapStyledZedStdio(t *testing.T) {
|
|
r := reg(canonical.MCPServer{Name: "fp", Command: "/bin/fp", Args: []string{"-x"}})
|
|
out := BuildMCPMapStyled(r, MCPZedStyle)
|
|
e := out["fp"].(map[string]any)
|
|
assert.Equal(t, true, e["enabled"])
|
|
assert.Equal(t, "custom", e["source"])
|
|
assert.Equal(t, "/bin/fp", e["command"])
|
|
assert.Equal(t, []string{"-x"}, e["args"])
|
|
}
|
|
|
|
func TestBuildMCPMapStyledZedURL(t *testing.T) {
|
|
r := reg(canonical.MCPServer{Name: "r", URL: "https://example.com"})
|
|
out := BuildMCPMapStyled(r, MCPZedStyle)
|
|
e := out["r"].(map[string]any)
|
|
assert.Equal(t, true, e["enabled"])
|
|
assert.Equal(t, "https://example.com", e["url"])
|
|
assert.NotContains(t, e, "source")
|
|
}
|
|
|
|
func TestBuildMCPMapStyledNilReg(t *testing.T) {
|
|
out := BuildMCPMapStyled(nil, MCPClaudeStyle)
|
|
assert.NotNil(t, out)
|
|
assert.Len(t, out, 0)
|
|
}
|