@@ -76,7 +76,7 @@ func TestResult_MCPServers(t *testing.T) {
7676 tests := []struct {
7777 name string
7878 result Result
79- want [ ]mcp.MCPServerConfig
79+ want map [ string ]mcp.MCPServerConfig
8080 }{
8181 {
8282 name : "no MCP servers" ,
@@ -87,20 +87,22 @@ func TestResult_MCPServers(t *testing.T) {
8787 FrontMatter : markdown.TaskFrontMatter {},
8888 },
8989 },
90- want : [ ]mcp.MCPServerConfig {},
90+ want : map [ string ]mcp.MCPServerConfig {},
9191 },
9292 {
93- name : "MCP servers from rules only " ,
93+ name : "MCP servers from rules with IDs " ,
9494 result : Result {
9595 Name : "test-task" ,
9696 Rules : []markdown.Markdown [markdown.RuleFrontMatter ]{
9797 {
9898 FrontMatter : markdown.RuleFrontMatter {
99+ ID : "jira-server" ,
99100 MCPServer : mcp.MCPServerConfig {Type : mcp .TransportTypeStdio , Command : "jira" },
100101 },
101102 },
102103 {
103104 FrontMatter : markdown.RuleFrontMatter {
105+ ID : "api-server" ,
104106 MCPServer : mcp.MCPServerConfig {Type : mcp .TransportTypeHTTP , URL : "https://api.example.com" },
105107 },
106108 },
@@ -109,9 +111,35 @@ func TestResult_MCPServers(t *testing.T) {
109111 FrontMatter : markdown.TaskFrontMatter {},
110112 },
111113 },
112- want : []mcp.MCPServerConfig {
113- {Type : mcp .TransportTypeStdio , Command : "jira" },
114- {Type : mcp .TransportTypeHTTP , URL : "https://api.example.com" },
114+ want : map [string ]mcp.MCPServerConfig {
115+ "jira-server" : {Type : mcp .TransportTypeStdio , Command : "jira" },
116+ "api-server" : {Type : mcp .TransportTypeHTTP , URL : "https://api.example.com" },
117+ },
118+ },
119+ {
120+ name : "MCP servers from rules without explicit IDs in frontmatter" ,
121+ result : Result {
122+ Rules : []markdown.Markdown [markdown.RuleFrontMatter ]{
123+ {
124+ FrontMatter : markdown.RuleFrontMatter {
125+ ID : "rule-file-1" , // ID is auto-set to filename during loading
126+ MCPServer : mcp.MCPServerConfig {Type : mcp .TransportTypeStdio , Command : "server1" },
127+ },
128+ },
129+ {
130+ FrontMatter : markdown.RuleFrontMatter {
131+ ID : "rule-file-2" , // ID is auto-set to filename during loading
132+ MCPServer : mcp.MCPServerConfig {Type : mcp .TransportTypeStdio , Command : "server2" },
133+ },
134+ },
135+ },
136+ Task : markdown.Markdown [markdown.TaskFrontMatter ]{
137+ FrontMatter : markdown.TaskFrontMatter {},
138+ },
139+ },
140+ want : map [string ]mcp.MCPServerConfig {
141+ "rule-file-1" : {Type : mcp .TransportTypeStdio , Command : "server1" },
142+ "rule-file-2" : {Type : mcp .TransportTypeStdio , Command : "server2" },
115143 },
116144 },
117145 {
@@ -121,25 +149,29 @@ func TestResult_MCPServers(t *testing.T) {
121149 Rules : []markdown.Markdown [markdown.RuleFrontMatter ]{
122150 {
123151 FrontMatter : markdown.RuleFrontMatter {
152+ ID : "server1-id" ,
124153 MCPServer : mcp.MCPServerConfig {Type : mcp .TransportTypeStdio , Command : "server1" },
125154 },
126155 },
127156 {
128157 FrontMatter : markdown.RuleFrontMatter {
158+ ID : "server2-id" ,
129159 MCPServer : mcp.MCPServerConfig {Type : mcp .TransportTypeStdio , Command : "server2" },
130160 },
131161 },
132162 {
133- FrontMatter : markdown.RuleFrontMatter {},
163+ FrontMatter : markdown.RuleFrontMatter {
164+ ID : "empty-rule" ,
165+ },
134166 },
135167 },
136168 Task : markdown.Markdown [markdown.TaskFrontMatter ]{
137169 FrontMatter : markdown.TaskFrontMatter {},
138170 },
139171 },
140- want : [ ]mcp.MCPServerConfig {
141- {Type : mcp .TransportTypeStdio , Command : "server1" },
142- {Type : mcp .TransportTypeStdio , Command : "server2" },
172+ want : map [ string ]mcp.MCPServerConfig {
173+ "server1-id" : {Type : mcp .TransportTypeStdio , Command : "server1" },
174+ "server2-id" : {Type : mcp .TransportTypeStdio , Command : "server2" },
143175 // Empty rule MCP server is filtered out
144176 },
145177 },
@@ -149,17 +181,52 @@ func TestResult_MCPServers(t *testing.T) {
149181 Name : "test-task" ,
150182 Rules : []markdown.Markdown [markdown.RuleFrontMatter ]{
151183 {
152- FrontMatter : markdown.RuleFrontMatter {},
184+ FrontMatter : markdown.RuleFrontMatter {
185+ ID : "no-server-rule" ,
186+ },
153187 },
154188 },
155189 Task : markdown.Markdown [markdown.TaskFrontMatter ]{
156190 FrontMatter : markdown.TaskFrontMatter {},
157191 },
158192 },
159- want : [ ]mcp.MCPServerConfig {
193+ want : map [ string ]mcp.MCPServerConfig {
160194 // Empty rule MCP server is filtered out
161195 },
162196 },
197+ {
198+ name : "mixed rules with explicit and auto-generated IDs" ,
199+ result : Result {
200+ Rules : []markdown.Markdown [markdown.RuleFrontMatter ]{
201+ {
202+ FrontMatter : markdown.RuleFrontMatter {
203+ ID : "explicit-id" , // Explicit ID in frontmatter
204+ MCPServer : mcp.MCPServerConfig {Type : mcp .TransportTypeStdio , Command : "server1" },
205+ },
206+ },
207+ {
208+ FrontMatter : markdown.RuleFrontMatter {
209+ ID : "some-rule" , // ID auto-set to filename during loading
210+ MCPServer : mcp.MCPServerConfig {Type : mcp .TransportTypeStdio , Command : "server2" },
211+ },
212+ },
213+ {
214+ FrontMatter : markdown.RuleFrontMatter {
215+ ID : "another-id" , // Explicit ID in frontmatter
216+ MCPServer : mcp.MCPServerConfig {Type : mcp .TransportTypeHTTP , URL : "https://example.com" },
217+ },
218+ },
219+ },
220+ Task : markdown.Markdown [markdown.TaskFrontMatter ]{
221+ FrontMatter : markdown.TaskFrontMatter {},
222+ },
223+ },
224+ want : map [string ]mcp.MCPServerConfig {
225+ "explicit-id" : {Type : mcp .TransportTypeStdio , Command : "server1" },
226+ "some-rule" : {Type : mcp .TransportTypeStdio , Command : "server2" },
227+ "another-id" : {Type : mcp .TransportTypeHTTP , URL : "https://example.com" },
228+ },
229+ },
163230 }
164231
165232 for _ , tt := range tests {
@@ -168,22 +235,37 @@ func TestResult_MCPServers(t *testing.T) {
168235
169236 if len (got ) != len (tt .want ) {
170237 t .Errorf ("MCPServers() returned %d servers, want %d" , len (got ), len (tt .want ))
238+ t .Logf ("Got keys: %v" , mapKeys (got ))
239+ t .Logf ("Want keys: %v" , mapKeys (tt .want ))
171240 return
172241 }
173242
174- for i , wantServer := range tt .want {
175- gotServer := got [i ]
243+ for key , wantServer := range tt .want {
244+ gotServer , ok := got [key ]
245+ if ! ok {
246+ t .Errorf ("MCPServers() missing key %q" , key )
247+ continue
248+ }
176249
177250 if gotServer .Type != wantServer .Type {
178- t .Errorf ("MCPServers()[%d ].Type = %v, want %v" , i , gotServer .Type , wantServer .Type )
251+ t .Errorf ("MCPServers()[%q ].Type = %v, want %v" , key , gotServer .Type , wantServer .Type )
179252 }
180253 if gotServer .Command != wantServer .Command {
181- t .Errorf ("MCPServers()[%d ].Command = %q, want %q" , i , gotServer .Command , wantServer .Command )
254+ t .Errorf ("MCPServers()[%q ].Command = %q, want %q" , key , gotServer .Command , wantServer .Command )
182255 }
183256 if gotServer .URL != wantServer .URL {
184- t .Errorf ("MCPServers()[%d ].URL = %q, want %q" , i , gotServer .URL , wantServer .URL )
257+ t .Errorf ("MCPServers()[%q ].URL = %q, want %q" , key , gotServer .URL , wantServer .URL )
185258 }
186259 }
187260 })
188261 }
189262}
263+
264+ // Helper function to get map keys for debugging
265+ func mapKeys (m map [string ]mcp.MCPServerConfig ) []string {
266+ keys := make ([]string , 0 , len (m ))
267+ for k := range m {
268+ keys = append (keys , k )
269+ }
270+ return keys
271+ }
0 commit comments