forked from github/github-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstructions_test.go
More file actions
166 lines (155 loc) · 3.71 KB
/
instructions_test.go
File metadata and controls
166 lines (155 loc) · 3.71 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
166
package github
import (
"os"
"testing"
)
func TestGenerateInstructions(t *testing.T) {
tests := []struct {
name string
enabledToolsets []string
expectedEmpty bool
}{
{
name: "empty toolsets",
enabledToolsets: []string{},
expectedEmpty: false,
},
{
name: "only context toolset",
enabledToolsets: []string{"context"},
expectedEmpty: false,
},
{
name: "pull requests toolset",
enabledToolsets: []string{"pull_requests"},
expectedEmpty: false,
},
{
name: "issues toolset",
enabledToolsets: []string{"issues"},
expectedEmpty: false,
},
{
name: "discussions toolset",
enabledToolsets: []string{"discussions"},
expectedEmpty: false,
},
{
name: "multiple toolsets (context + pull_requests)",
enabledToolsets: []string{"context", "pull_requests"},
expectedEmpty: false,
},
{
name: "multiple toolsets (issues + pull_requests)",
enabledToolsets: []string{"issues", "pull_requests"},
expectedEmpty: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := GenerateInstructions(tt.enabledToolsets)
if tt.expectedEmpty {
if result != "" {
t.Errorf("Expected empty instructions but got: %s", result)
}
} else {
if result == "" {
t.Errorf("Expected non-empty instructions but got empty result")
}
}
})
}
}
func TestGenerateInstructionsWithDisableFlag(t *testing.T) {
tests := []struct {
name string
disableEnvValue string
enabledToolsets []string
expectedEmpty bool
}{
{
name: "DISABLE_INSTRUCTIONS=true returns empty",
disableEnvValue: "true",
enabledToolsets: []string{"context", "issues", "pull_requests"},
expectedEmpty: true,
},
{
name: "DISABLE_INSTRUCTIONS=false returns normal instructions",
disableEnvValue: "false",
enabledToolsets: []string{"context"},
expectedEmpty: false,
},
{
name: "DISABLE_INSTRUCTIONS unset returns normal instructions",
disableEnvValue: "",
enabledToolsets: []string{"issues"},
expectedEmpty: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Save original env value
originalValue := os.Getenv("DISABLE_INSTRUCTIONS")
defer func() {
if originalValue == "" {
os.Unsetenv("DISABLE_INSTRUCTIONS")
} else {
os.Setenv("DISABLE_INSTRUCTIONS", originalValue)
}
}()
// Set test env value
if tt.disableEnvValue == "" {
os.Unsetenv("DISABLE_INSTRUCTIONS")
} else {
os.Setenv("DISABLE_INSTRUCTIONS", tt.disableEnvValue)
}
result := GenerateInstructions(tt.enabledToolsets)
if tt.expectedEmpty {
if result != "" {
t.Errorf("Expected empty instructions but got: %s", result)
}
} else {
if result == "" {
t.Errorf("Expected non-empty instructions but got empty result")
}
}
})
}
}
func TestGetToolsetInstructions(t *testing.T) {
tests := []struct {
toolset string
expectedEmpty bool
}{
{
toolset: "pull_requests",
expectedEmpty: false,
},
{
toolset: "issues",
expectedEmpty: false,
},
{
toolset: "discussions",
expectedEmpty: false,
},
{
toolset: "nonexistent",
expectedEmpty: true,
},
}
for _, tt := range tests {
t.Run(tt.toolset, func(t *testing.T) {
result := getToolsetInstructions(tt.toolset)
if tt.expectedEmpty {
if result != "" {
t.Errorf("Expected empty result for toolset '%s', but got: %s", tt.toolset, result)
}
} else {
if result == "" {
t.Errorf("Expected non-empty result for toolset '%s', but got empty", tt.toolset)
}
}
})
}
}