-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfrontmatter_rule_test.go
More file actions
165 lines (158 loc) · 3.86 KB
/
frontmatter_rule_test.go
File metadata and controls
165 lines (158 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package markdown
import (
"testing"
"github.com/kitproj/coding-context-cli/pkg/codingcontext/mcp"
"gopkg.in/yaml.v3"
)
func TestRuleFrontMatter_Marshal(t *testing.T) {
tests := []struct {
name string
rule RuleFrontMatter
want string
}{
{
name: "minimal rule",
rule: RuleFrontMatter{},
want: "{}\n",
},
{
name: "rule with standard id, name, description",
rule: RuleFrontMatter{
BaseFrontMatter: BaseFrontMatter{
Name: "Standard Rule",
Description: "This is a standard rule with metadata",
},
},
want: "{}\n",
},
{
name: "rule with task_names",
rule: RuleFrontMatter{
TaskNames: []string{"implement-feature"},
Languages: []string{"go"},
},
want: "task_names:\n - implement-feature\nlanguages:\n - go\n",
},
{
name: "rule with multiple task_names",
rule: RuleFrontMatter{
TaskNames: []string{"fix-bug", "implement-feature"},
Languages: []string{"go"},
Agent: "cursor",
},
want: "task_names:\n - fix-bug\n - implement-feature\nlanguages:\n - go\nagent: cursor\n",
},
{
name: "rule with all fields",
rule: RuleFrontMatter{
BaseFrontMatter: BaseFrontMatter{
Name: "Complete Rule",
Description: "A rule with all fields",
},
TaskNames: []string{"test-task"},
Languages: []string{"go", "python"},
Agent: "copilot",
MCPServer: mcp.MCPServerConfig{
Type: mcp.TransportTypeStdio,
Command: "database-server",
Args: []string{"--port", "5432"},
},
},
want: "task_names:\n - test-task\nlanguages:\n - go\n - python\nagent: copilot\nmcp_server:\n type: stdio\n command: database-server\n args:\n - --port\n - \"5432\"\n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := yaml.Marshal(&tt.rule)
if err != nil {
t.Fatalf("Marshal() error = %v", err)
}
if string(got) != tt.want {
t.Errorf("Marshal() = %q, want %q", string(got), tt.want)
}
})
}
}
func TestRuleFrontMatter_Unmarshal(t *testing.T) {
tests := []struct {
name string
yaml string
want RuleFrontMatter
wantErr bool
}{
{
name: "rule with standard id, name, description",
yaml: `id: urn:agents:rule:named
name: Named Rule
description: A rule with standard fields
`,
want: RuleFrontMatter{
BaseFrontMatter: BaseFrontMatter{
Name: "Named Rule",
Description: "A rule with standard fields",
Content: map[string]any{"id": "urn:agents:rule:named"},
},
},
},
{
name: "rule with task_names and languages",
yaml: `task_names:
- implement-feature
languages:
- go
agent: cursor
`,
want: RuleFrontMatter{
TaskNames: []string{"implement-feature"},
Languages: []string{"go"},
Agent: "",
},
},
{
name: "rule with multiple task_names",
yaml: `task_names:
- fix-bug
- implement-feature
languages:
- go
`,
want: RuleFrontMatter{
TaskNames: []string{"fix-bug", "implement-feature"},
Languages: []string{"go"},
},
},
{
name: "rule with multiple languages",
yaml: `languages:
- go
- python
- javascript
`,
want: RuleFrontMatter{
Languages: []string{"go", "python", "javascript"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var got RuleFrontMatter
err := yaml.Unmarshal([]byte(tt.yaml), &got)
if (err != nil) != tt.wantErr {
t.Fatalf("Unmarshal() error = %v, wantErr %v", err, tt.wantErr)
}
if err != nil {
return
}
// Compare fields individually
if got.Name != tt.want.Name {
t.Errorf("Name = %q, want %q", got.Name, tt.want.Name)
}
if got.Description != tt.want.Description {
t.Errorf("Description = %q, want %q", got.Description, tt.want.Description)
}
if got.Agent != tt.want.Agent {
t.Errorf("Agent = %q, want %q", got.Agent, tt.want.Agent)
}
})
}
}