|
| 1 | +package github |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/github/github-mcp-server/pkg/inventory" |
| 8 | + "github.com/github/github-mcp-server/pkg/translations" |
| 9 | + "github.com/google/jsonschema-go/jsonschema" |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | +) |
| 13 | + |
| 14 | +func TestRepositoryInstructionsExplainSymlinkWriteSemantics(t *testing.T) { |
| 15 | + t.Setenv("DISABLE_INSTRUCTIONS", "false") |
| 16 | + |
| 17 | + reposInventory, err := inventory.NewBuilder(). |
| 18 | + SetTools([]inventory.ServerTool{{Toolset: ToolsetMetadataRepos}}). |
| 19 | + WithToolsets([]string{"repos"}). |
| 20 | + WithServerInstructions(). |
| 21 | + Build() |
| 22 | + require.NoError(t, err) |
| 23 | + |
| 24 | + instructions := strings.ToLower(reposInventory.Instructions()) |
| 25 | + assert.Contains(t, instructions, "## repository file writes") |
| 26 | + assert.Contains(t, instructions, "may return the target contents") |
| 27 | + assert.Contains(t, instructions, "do not follow symbolic links") |
| 28 | + |
| 29 | + defaultInventory, err := inventory.NewBuilder(). |
| 30 | + SetTools([]inventory.ServerTool{ |
| 31 | + {Toolset: ToolsetMetadataContext}, |
| 32 | + {Toolset: ToolsetMetadataRepos}, |
| 33 | + }). |
| 34 | + WithToolsets([]string{"default"}). |
| 35 | + WithServerInstructions(). |
| 36 | + Build() |
| 37 | + require.NoError(t, err) |
| 38 | + assert.Contains(t, strings.ToLower(defaultInventory.Instructions()), "## repository file writes") |
| 39 | + |
| 40 | + contextInventory, err := inventory.NewBuilder(). |
| 41 | + SetTools([]inventory.ServerTool{{Toolset: ToolsetMetadataContext}}). |
| 42 | + WithToolsets([]string{"context"}). |
| 43 | + WithServerInstructions(). |
| 44 | + Build() |
| 45 | + require.NoError(t, err) |
| 46 | + assert.NotContains(t, strings.ToLower(contextInventory.Instructions()), "## repository file writes") |
| 47 | +} |
| 48 | + |
| 49 | +func TestFileWritePathsExplainSymlinkWriteSemantics(t *testing.T) { |
| 50 | + createSchema, ok := CreateOrUpdateFile(translations.NullTranslationHelper).Tool.InputSchema.(*jsonschema.Schema) |
| 51 | + require.True(t, ok) |
| 52 | + pushSchema, ok := PushFiles(translations.NullTranslationHelper).Tool.InputSchema.(*jsonschema.Schema) |
| 53 | + require.True(t, ok) |
| 54 | + createPath := createSchema.Properties["path"] |
| 55 | + require.NotNil(t, createPath) |
| 56 | + pushFiles := pushSchema.Properties["files"] |
| 57 | + require.NotNil(t, pushFiles) |
| 58 | + require.NotNil(t, pushFiles.Items) |
| 59 | + pushPath := pushFiles.Items.Properties["path"] |
| 60 | + require.NotNil(t, pushPath) |
| 61 | + |
| 62 | + tools := []struct { |
| 63 | + name string |
| 64 | + description string |
| 65 | + expectedBehavior string |
| 66 | + }{ |
| 67 | + { |
| 68 | + name: "create_or_update_file", |
| 69 | + description: createPath.Description, |
| 70 | + expectedBehavior: "rewrites the symbolic link's target path", |
| 71 | + }, |
| 72 | + { |
| 73 | + name: "push_files", |
| 74 | + description: pushPath.Description, |
| 75 | + expectedBehavior: "replaces the link with a regular file", |
| 76 | + }, |
| 77 | + } |
| 78 | + |
| 79 | + for _, tool := range tools { |
| 80 | + t.Run(tool.name, func(t *testing.T) { |
| 81 | + description := strings.ToLower(tool.description) |
| 82 | + assert.Contains(t, description, "exact git path") |
| 83 | + assert.Contains(t, description, tool.expectedBehavior) |
| 84 | + }) |
| 85 | + } |
| 86 | +} |
0 commit comments