(t *testing.T)
| 4729 | } |
| 4730 | } |
| 4731 | func Test_GetFileBlame(t *testing.T) { |
| 4732 | // Verify tool definition once |
| 4733 | serverTool := GetFileBlame(translations.NullTranslationHelper) |
| 4734 | tool := serverTool.Tool |
| 4735 | require.NoError(t, toolsnaps.Test(tool.Name, tool)) |
| 4736 | |
| 4737 | // get_file_blame is gated so it is not advertised unless the feature flag |
| 4738 | // (or insiders mode) opts it in. |
| 4739 | assert.Equal(t, FeatureFlagFileBlame, serverTool.FeatureFlagEnable, "get_file_blame must be gated behind the file_blame feature flag") |
| 4740 | |
| 4741 | schema, ok := tool.InputSchema.(*jsonschema.Schema) |
| 4742 | require.True(t, ok, "InputSchema should be *jsonschema.Schema") |
| 4743 | assert.Equal(t, "get_file_blame", tool.Name) |
| 4744 | assert.NotEmpty(t, tool.Description) |
| 4745 | for _, key := range []string{"owner", "repo", "path", "ref", "start_line", "end_line", "perPage", "after"} { |
| 4746 | assert.Contains(t, schema.Properties, key, "schema missing property %q", key) |
| 4747 | } |
| 4748 | assert.NotContains(t, schema.Properties, "page") |
| 4749 | assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "path"}) |
| 4750 | require.NotNil(t, tool.Annotations) |
| 4751 | assert.True(t, tool.Annotations.ReadOnlyHint, "blame is read-only") |
| 4752 | |
| 4753 | // blameQueryShape is the GraphQL query shape used by all |
| 4754 | // network-touching subtests below. Defined once so changes to the wire |
| 4755 | // schema are made in a single place. |
| 4756 | type blameQueryShape = struct { |
| 4757 | Repository struct { |
| 4758 | DefaultBranchRef struct { |
| 4759 | Name githubv4.String |
| 4760 | } |
| 4761 | Object struct { |
| 4762 | Typename githubv4.String `graphql:"__typename"` |
| 4763 | Commit blameCommitFragment `graphql:"... on Commit"` |
| 4764 | Tag struct { |
| 4765 | Target struct { |
| 4766 | Typename githubv4.String `graphql:"__typename"` |
| 4767 | Commit blameCommitFragment `graphql:"... on Commit"` |
| 4768 | } |
| 4769 | } `graphql:"... on Tag"` |
| 4770 | } `graphql:"object(expression: $ref)"` |
| 4771 | } `graphql:"repository(owner: $owner, name: $repo)"` |
| 4772 | } |
| 4773 | |
| 4774 | makeBlameVars := func(owner, repo, ref, path string) map[string]any { |
| 4775 | return map[string]any{ |
| 4776 | "owner": githubv4.String(owner), |
| 4777 | "repo": githubv4.String(repo), |
| 4778 | "ref": githubv4.String(ref), |
| 4779 | "path": githubv4.String(path), |
| 4780 | } |
| 4781 | } |
| 4782 | |
| 4783 | tests := []struct { |
| 4784 | name string |
| 4785 | mockedClient *http.Client |
| 4786 | requestArgs map[string]any |
| 4787 | expectError bool |
| 4788 | expectedErrMsg string |
nothing calls this directly
no test coverage detected