|
1 | 1 | package github |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "os" |
4 | 5 | "strings" |
5 | 6 | "testing" |
6 | 7 | ) |
@@ -104,6 +105,79 @@ func TestGenerateInstructions(t *testing.T) { |
104 | 105 | } |
105 | 106 | } |
106 | 107 |
|
| 108 | +func TestGenerateInstructionsWithDisableFlag(t *testing.T) { |
| 109 | + tests := []struct { |
| 110 | + name string |
| 111 | + disableEnvValue string |
| 112 | + enabledToolsets []string |
| 113 | + expectedEmpty bool |
| 114 | + expectedContains []string |
| 115 | + }{ |
| 116 | + { |
| 117 | + name: "DISABLE_INSTRUCTIONS=true returns empty", |
| 118 | + disableEnvValue: "true", |
| 119 | + enabledToolsets: []string{"context", "issues", "pull_requests"}, |
| 120 | + expectedEmpty: true, |
| 121 | + }, |
| 122 | + { |
| 123 | + name: "DISABLE_INSTRUCTIONS=false returns normal instructions", |
| 124 | + disableEnvValue: "false", |
| 125 | + enabledToolsets: []string{"context"}, |
| 126 | + expectedEmpty: false, |
| 127 | + expectedContains: []string{ |
| 128 | + "GitHub MCP Server provides GitHub API tools", |
| 129 | + "Always call 'get_me' first", |
| 130 | + }, |
| 131 | + }, |
| 132 | + { |
| 133 | + name: "DISABLE_INSTRUCTIONS unset returns normal instructions", |
| 134 | + disableEnvValue: "", |
| 135 | + enabledToolsets: []string{"issues"}, |
| 136 | + expectedEmpty: false, |
| 137 | + expectedContains: []string{ |
| 138 | + "GitHub MCP Server provides GitHub API tools", |
| 139 | + "search_issues", |
| 140 | + }, |
| 141 | + }, |
| 142 | + } |
| 143 | + |
| 144 | + for _, tt := range tests { |
| 145 | + t.Run(tt.name, func(t *testing.T) { |
| 146 | + // Save original env value |
| 147 | + originalValue := os.Getenv("DISABLE_INSTRUCTIONS") |
| 148 | + defer func() { |
| 149 | + if originalValue == "" { |
| 150 | + os.Unsetenv("DISABLE_INSTRUCTIONS") |
| 151 | + } else { |
| 152 | + os.Setenv("DISABLE_INSTRUCTIONS", originalValue) |
| 153 | + } |
| 154 | + }() |
| 155 | + |
| 156 | + // Set test env value |
| 157 | + if tt.disableEnvValue == "" { |
| 158 | + os.Unsetenv("DISABLE_INSTRUCTIONS") |
| 159 | + } else { |
| 160 | + os.Setenv("DISABLE_INSTRUCTIONS", tt.disableEnvValue) |
| 161 | + } |
| 162 | + |
| 163 | + result := GenerateInstructions(tt.enabledToolsets) |
| 164 | + |
| 165 | + if tt.expectedEmpty { |
| 166 | + if result != "" { |
| 167 | + t.Errorf("Expected empty instructions but got: %s", result) |
| 168 | + } |
| 169 | + return |
| 170 | + } |
| 171 | + |
| 172 | + for _, expectedContent := range tt.expectedContains { |
| 173 | + if !strings.Contains(result, expectedContent) { |
| 174 | + t.Errorf("Expected instructions to contain '%s', but got: %s", expectedContent, result) |
| 175 | + } |
| 176 | + } |
| 177 | + }) |
| 178 | + } |
| 179 | +} |
| 180 | + |
107 | 181 | func TestGetToolsetInstructions(t *testing.T) { |
108 | 182 | tests := []struct { |
109 | 183 | toolset string |
|
0 commit comments