|
4 | 4 | "testing" |
5 | 5 | "time" |
6 | 6 |
|
| 7 | + "github.com/smart-mcp-proxy/mcpproxy-go/internal/config" |
7 | 8 | "github.com/stretchr/testify/assert" |
8 | 9 | "github.com/stretchr/testify/require" |
9 | 10 | ) |
@@ -84,6 +85,58 @@ func TestConvertGenericServersToTyped_EmptyOAuth(t *testing.T) { |
84 | 85 | assert.Empty(t, servers[0].OAuth.ClientID) |
85 | 86 | } |
86 | 87 |
|
| 88 | +// TestConvertGenericServersToTyped_SourceRegistry verifies registry provenance |
| 89 | +// (MCP-901) is carried through the generic-map fallback projection so the |
| 90 | +// approval/quarantine view can show a server's origin. |
| 91 | +func TestConvertGenericServersToTyped_SourceRegistry(t *testing.T) { |
| 92 | + genericServers := []map[string]interface{}{ |
| 93 | + { |
| 94 | + "id": "everything", |
| 95 | + "name": "everything", |
| 96 | + "enabled": true, |
| 97 | + "source_registry_id": "modelcontextprotocol", |
| 98 | + "source_registry_provenance": "custom/unverified", |
| 99 | + }, |
| 100 | + { |
| 101 | + // Manually-configured server: both fields absent → empty. |
| 102 | + "id": "manual", |
| 103 | + "name": "manual", |
| 104 | + "enabled": true, |
| 105 | + }, |
| 106 | + } |
| 107 | + |
| 108 | + servers := ConvertGenericServersToTyped(genericServers) |
| 109 | + require.Len(t, servers, 2) |
| 110 | + |
| 111 | + assert.Equal(t, "modelcontextprotocol", servers[0].SourceRegistryID) |
| 112 | + assert.Equal(t, "custom/unverified", servers[0].SourceRegistryProvenance) |
| 113 | + |
| 114 | + assert.Empty(t, servers[1].SourceRegistryID, "manual server carries no registry id") |
| 115 | + assert.Empty(t, servers[1].SourceRegistryProvenance) |
| 116 | +} |
| 117 | + |
| 118 | +// TestConvertServerConfig_SourceRegistry verifies the direct config→contracts |
| 119 | +// mapper populates registry provenance (MCP-901). |
| 120 | +func TestConvertServerConfig_SourceRegistry(t *testing.T) { |
| 121 | + cfg := &config.ServerConfig{ |
| 122 | + Name: "everything", |
| 123 | + Protocol: "stdio", |
| 124 | + Enabled: true, |
| 125 | + SourceRegistryID: "modelcontextprotocol", |
| 126 | + SourceRegistryProvenance: config.RegistryProvenanceCustom, |
| 127 | + } |
| 128 | + |
| 129 | + server := ConvertServerConfig(cfg, "ready", true, 3, false) |
| 130 | + require.NotNil(t, server) |
| 131 | + assert.Equal(t, "modelcontextprotocol", server.SourceRegistryID) |
| 132 | + assert.Equal(t, config.RegistryProvenanceCustom, server.SourceRegistryProvenance) |
| 133 | + |
| 134 | + // Manual server (no source registry) leaves both empty. |
| 135 | + manual := ConvertServerConfig(&config.ServerConfig{Name: "manual", Enabled: true}, "ready", true, 0, false) |
| 136 | + assert.Empty(t, manual.SourceRegistryID) |
| 137 | + assert.Empty(t, manual.SourceRegistryProvenance) |
| 138 | +} |
| 139 | + |
87 | 140 | // TestConvertGenericServersToTyped_NoOAuth verifies servers without OAuth have nil OAuth field |
88 | 141 | func TestConvertGenericServersToTyped_NoOAuth(t *testing.T) { |
89 | 142 | genericServers := []map[string]interface{}{ |
|
0 commit comments