Files
harness-sync/internal/adapter/common/mcp_test.go
T
lukaszraczylo bde3128dba fix(zed): switch to language_models.openai_compatible for Agent panel visibility
The Zed Agent panel (new ACP-based UI) only discovers providers registered
under language_models.openai_compatible.<name>, not language_models.openai.
Each named entry appears as its own provider in the LLM Providers list.

- language_models.openai_compatible.harness-sync-gateway holds gateway URL + models
- agent.default_model.provider = 'harness-sync-gateway' (was 'openai')
- Model entries include capabilities {tools,images,parallel_tool_calls}
- Export common.GatewayProviderID so zed.go can reference it
- Fix staticcheck QF1001 (De Morgan's law) in io.go
- Fix struct field alignment in File (80→72 bytes)
- gofmt remaining files
2026-05-23 21:12:47 +01:00

114 lines
4.0 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"}})
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"])
// Claude's actual entry shape uses "type" (defaults to stdio when no URL).
assert.Equal(t, "stdio", e["type"])
assert.NotContains(t, e, "transport")
}
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.Equal(t, "http", 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)
// Zed 1.3.x serde bug: "enabled" and "source" must NOT be present.
assert.NotContains(t, e, "enabled")
assert.NotContains(t, 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)
// Zed 1.3.x serde bug: "enabled" must NOT be present.
assert.NotContains(t, 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)
}