Files
harness-sync/internal/adapter/common/common_test.go
T
lukaszraczylo 6483eb8044 refactor: remove dead code, deduplicate defaultHome, simplify mcpEntry + kilo render
Dead code removed:
- BuildProviders, buildModels, ProviderEntry (no production callers)
- ZedLanguageModels (shadowed by adapter-local version, wrong schema)
- GatewayProviderID deprecated constant (zero references)
- Corresponding dead tests for BuildProviders

Deduplication:
- Extract common.DefaultHome() to internal/adapter/common/home.go
- All 7 adapters call common.DefaultHome() instead of local copies (-49 lines)

Simplification:
- mcp.go: merge MCPClaudeStyle/MCPCrushStyle branches (identical URL path,
  one-line difference in stdio path) — clearer intent, fewer lines
- kilo.go: extract opencode.jsonc merge to mergeOpenCodeJSONC() helper,
  Render() drops from 92 to ~55 lines
- goose.go: strings.IndexByte → strings.Cut in splitProviderModel
2026-05-23 21:22:49 +01:00

67 lines
1.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 TestBuildMCPMap(t *testing.T) {
reg := &canonical.MCPRegistry{Servers: []canonical.MCPServer{
{Name: "filepuff", Command: "/bin/x", Transport: "stdio"},
}}
out := BuildMCPMap(reg)
assert.Contains(t, out, "filepuff")
entry := out["filepuff"].(map[string]any)
assert.Equal(t, "/bin/x", entry["command"])
}
func TestBuildMCPMapNil(t *testing.T) {
out := BuildMCPMap(nil)
assert.NotNil(t, out)
assert.Len(t, out, 0)
}
func TestStripJSONComments(t *testing.T) {
s := "// hi\n{\"a\":1, /* x */ \"b\":2}"
assert.Equal(t, `{"a":1, "b":2}`, StripJSONComments(s))
}
func TestParseFrontmatter(t *testing.T) {
body := []byte("---\nname: foo\ndescription: bar\n---\nbody")
name, desc := ParseFrontmatter(body)
assert.Equal(t, "foo", name)
assert.Equal(t, "bar", desc)
}
func TestParseFrontmatterMissing(t *testing.T) {
name, desc := ParseFrontmatter([]byte("no frontmatter"))
assert.Empty(t, name)
assert.Empty(t, desc)
}
func TestImportMarkdownTreeMissingDir(t *testing.T) {
docs, err := ImportMarkdownTree("/nonexistent/path", "")
require.NoError(t, err)
assert.Empty(t, docs)
}
func TestParseMCPFromJSON(t *testing.T) {
body := []byte(`{"mcpServers": {"filepuff": {"command": "/bin/fp", "args": ["--flag"]}}}`)
servers, err := ParseMCPFromJSON(body, "mcpServers")
require.NoError(t, err)
require.Len(t, servers, 1)
assert.Equal(t, "filepuff", servers[0].Name)
assert.Equal(t, "/bin/fp", servers[0].Command)
}
func TestParseMCPFromJSONMissingKey(t *testing.T) {
body := []byte(`{"other": {}}`)
servers, err := ParseMCPFromJSON(body, "mcpServers")
require.NoError(t, err)
assert.Nil(t, servers)
}