|
| 1 | +package github |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/github/github-mcp-server/pkg/translations" |
| 8 | + "github.com/github/github-mcp-server/pkg/utils" |
| 9 | + "github.com/google/jsonschema-go/jsonschema" |
| 10 | + "github.com/stretchr/testify/require" |
| 11 | +) |
| 12 | + |
| 13 | +func Test_SearchModeNaturalLanguageAndSyntax(t *testing.T) { |
| 14 | + for _, q := range []string{ |
| 15 | + "login does not work after password reset", "connecting to postgres and redis", "should I use hooks or plugins", |
| 16 | + `why does "this AND that" fail`, `explain "foo OR bar"`, `why "NOT ready" appears`, |
| 17 | + `explain "label:bug" text`, `why "escaped \" AND operator" fails`, |
| 18 | + } { |
| 19 | + t.Run(q, func(t *testing.T) { |
| 20 | + got, err := resolveIssuesSearchMode(searchModeSemantic, map[string]any{"query": q}) |
| 21 | + require.NoError(t, err) |
| 22 | + require.Equal(t, searchModeSemantic, got) |
| 23 | + }) |
| 24 | + } |
| 25 | + for _, q := range []string{"foo AND bar", "foo OR bar", "foo NOT bar", "foo AND(bar OR baz)", `label:"needs triage"`, `repo:owner/repo`, `-author:bot`, `(label:bug OR label:critical)`} { |
| 26 | + t.Run(q, func(t *testing.T) { |
| 27 | + got, err := resolveIssuesSearchMode(searchModeSemantic, map[string]any{"query": q}) |
| 28 | + require.NoError(t, err) |
| 29 | + require.Equal(t, searchModeLexical, got) |
| 30 | + got, err = resolveIssuesSearchMode(searchModeSemantic, map[string]any{"query": q, "search_type": "semantic"}) |
| 31 | + require.NoError(t, err) |
| 32 | + require.Equal(t, searchModeSemantic, got) |
| 33 | + }) |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +func Test_SearchIssuesGHESRejectsSemanticOverride(t *testing.T) { |
| 38 | + got, err := resolveIssuesSearchMode(searchModeLexical, map[string]any{"query": "question", "search_type": "semantic"}) |
| 39 | + require.ErrorContains(t, err, "not supported") |
| 40 | + require.NotEqual(t, searchModeSemantic, got) |
| 41 | + tool := SearchIssues(translations.NullTranslationHelper, WithHost(utils.HostTypeGHES)) |
| 42 | + require.Equal(t, []any{"lexical"}, tool.Tool.InputSchema.(*jsonschema.Schema).Properties["search_type"].Enum) |
| 43 | + // No client: the capability error must be returned before attempting a request. |
| 44 | + deps := &BaseDeps{} |
| 45 | + request := createMCPRequest(map[string]any{"query": "question", "search_type": "semantic"}) |
| 46 | + result, err := tool.Handler(deps)(ContextWithDeps(context.Background(), deps), &request) |
| 47 | + require.NoError(t, err) |
| 48 | + require.True(t, result.IsError) |
| 49 | +} |
0 commit comments