-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathserver_test.go
More file actions
108 lines (101 loc) · 3.16 KB
/
server_test.go
File metadata and controls
108 lines (101 loc) · 3.16 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
package http
import (
"context"
"testing"
ghcontext "github.com/github/github-mcp-server/pkg/context"
"github.com/github/github-mcp-server/pkg/github"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCreateHTTPFeatureChecker(t *testing.T) {
checker := createHTTPFeatureChecker()
tests := []struct {
name string
flagName string
headerFeatures []string
insidersMode bool
wantEnabled bool
}{
{
name: "allowed issues_granular flag accepted from header",
flagName: github.FeatureFlagIssuesGranular,
headerFeatures: []string{github.FeatureFlagIssuesGranular},
wantEnabled: true,
},
{
name: "allowed pull_requests_granular flag accepted from header",
flagName: github.FeatureFlagPullRequestsGranular,
headerFeatures: []string{github.FeatureFlagPullRequestsGranular},
wantEnabled: true,
},
{
name: "MCP Apps flag accepted from header",
flagName: github.MCPAppsFeatureFlag,
headerFeatures: []string{github.MCPAppsFeatureFlag},
wantEnabled: true,
},
{
name: "unknown flag in header is ignored",
flagName: "unknown_flag",
headerFeatures: []string{"unknown_flag"},
wantEnabled: false,
},
{
name: "allowed flag not in header returns false",
flagName: github.FeatureFlagIssuesGranular,
headerFeatures: nil,
wantEnabled: false,
},
{
name: "allowed flag with different flag in header returns false",
flagName: github.FeatureFlagIssuesGranular,
headerFeatures: []string{github.FeatureFlagPullRequestsGranular},
wantEnabled: false,
},
{
name: "multiple allowed flags in header",
flagName: github.FeatureFlagIssuesGranular,
headerFeatures: []string{github.FeatureFlagIssuesGranular, github.FeatureFlagPullRequestsGranular},
wantEnabled: true,
},
{
name: "empty header features",
flagName: github.FeatureFlagIssuesGranular,
headerFeatures: []string{},
wantEnabled: false,
},
{
name: "insiders mode enables MCP Apps without header",
flagName: github.MCPAppsFeatureFlag,
insidersMode: true,
wantEnabled: true,
},
{
name: "insiders mode does not enable granular flags",
flagName: github.FeatureFlagIssuesGranular,
insidersMode: true,
wantEnabled: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.Background()
if len(tt.headerFeatures) > 0 {
ctx = ghcontext.WithHeaderFeatures(ctx, tt.headerFeatures)
}
if tt.insidersMode {
ctx = ghcontext.WithInsidersMode(ctx, true)
}
enabled, err := checker(ctx, tt.flagName)
require.NoError(t, err)
assert.Equal(t, tt.wantEnabled, enabled)
})
}
}
func TestHeaderAllowedFeatureFlagsMatchesAllowed(t *testing.T) {
// Ensure HeaderAllowedFeatureFlags delegates to AllowedFeatureFlags
allowed := github.HeaderAllowedFeatureFlags()
assert.Equal(t, github.AllowedFeatureFlags, allowed,
"HeaderAllowedFeatureFlags() should match AllowedFeatureFlags")
assert.NotEmpty(t, allowed, "AllowedFeatureFlags should not be empty")
}