-
Notifications
You must be signed in to change notification settings - Fork 3.4k
adding feature flag on dependency level #1801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tonytrg
wants to merge
10
commits into
main
Choose a base branch
from
tonytrg/add-ff-dep
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+366
−7
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
58829a7
wip injecting ff function into tool as dep
tonytrg de1b271
remove debug
tonytrg bb5d7d7
Merge branch 'main' into tonytrg/add-ff-dep
tonytrg 03f7909
fix linter
tonytrg baaab83
add better test
tonytrg fa0aa8c
adding compile time check
tonytrg 15c037a
move experimental to seperate config/ff value
tonytrg b54e64e
adding test var
tonytrg 42a8cbc
fixing test
tonytrg 5d8561f
adding flag and possibility to call feature checker
tonytrg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package github_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/github/github-mcp-server/pkg/github" | ||
| "github.com/github/github-mcp-server/pkg/translations" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestIsFeatureEnabled_WithEnabledFlag(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Create a feature checker that returns true for "test_flag" | ||
| checker := func(_ context.Context, flagName string) (bool, error) { | ||
| return flagName == "test_flag", nil | ||
| } | ||
|
|
||
| // Create deps with the checker using NewBaseDeps | ||
| deps := github.NewBaseDeps( | ||
| nil, // client | ||
| nil, // gqlClient | ||
| nil, // rawClient | ||
| nil, // repoAccessCache | ||
| translations.NullTranslationHelper, | ||
| github.FeatureFlags{}, | ||
| 0, // contentWindowSize | ||
| checker, // featureChecker | ||
| ) | ||
|
|
||
| // Test enabled flag | ||
| result := deps.IsFeatureEnabled(context.Background(), "test_flag") | ||
| assert.True(t, result, "Expected test_flag to be enabled") | ||
|
|
||
| // Test disabled flag | ||
| result = deps.IsFeatureEnabled(context.Background(), "other_flag") | ||
| assert.False(t, result, "Expected other_flag to be disabled") | ||
| } | ||
|
|
||
| func TestIsFeatureEnabled_WithoutChecker(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Create deps without feature checker (nil) | ||
| deps := github.NewBaseDeps( | ||
| nil, // client | ||
| nil, // gqlClient | ||
| nil, // rawClient | ||
| nil, // repoAccessCache | ||
| translations.NullTranslationHelper, | ||
| github.FeatureFlags{}, | ||
| 0, // contentWindowSize | ||
| nil, // featureChecker (nil) | ||
| ) | ||
|
|
||
| // Should return false when checker is nil | ||
| result := deps.IsFeatureEnabled(context.Background(), "any_flag") | ||
| assert.False(t, result, "Expected false when checker is nil") | ||
| } | ||
|
|
||
| func TestIsFeatureEnabled_EmptyFlagName(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Create a feature checker | ||
| checker := func(_ context.Context, _ string) (bool, error) { | ||
| return true, nil | ||
| } | ||
|
|
||
| deps := github.NewBaseDeps( | ||
| nil, // client | ||
| nil, // gqlClient | ||
| nil, // rawClient | ||
| nil, // repoAccessCache | ||
| translations.NullTranslationHelper, | ||
| github.FeatureFlags{}, | ||
| 0, // contentWindowSize | ||
| checker, // featureChecker | ||
| ) | ||
|
|
||
| // Should return false for empty flag name | ||
| result := deps.IsFeatureEnabled(context.Background(), "") | ||
| assert.False(t, result, "Expected false for empty flag name") | ||
| } | ||
|
|
||
| func TestIsFeatureEnabled_CheckerError(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Create a feature checker that returns an error | ||
| checker := func(_ context.Context, _ string) (bool, error) { | ||
| return false, errors.New("checker error") | ||
| } | ||
|
|
||
| deps := github.NewBaseDeps( | ||
| nil, // client | ||
| nil, // gqlClient | ||
| nil, // rawClient | ||
| nil, // repoAccessCache | ||
| translations.NullTranslationHelper, | ||
| github.FeatureFlags{}, | ||
| 0, // contentWindowSize | ||
| checker, // featureChecker | ||
| ) | ||
|
|
||
| // Should return false and log error (not crash) | ||
| result := deps.IsFeatureEnabled(context.Background(), "error_flag") | ||
| assert.False(t, result, "Expected false when checker returns error") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error logging uses fmt.Fprintf to os.Stderr directly instead of using the project's logging infrastructure (pkg/log). This is inconsistent with how errors are logged elsewhere in the codebase. Consider using the established logging package for consistent error handling and formatting.