dd239d8443
* initial logging stack for http * add metrics adapter * fix linter issues * make log fields generic * Update pkg/github/server_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove unused SlogMetrics adapter The slog-based metrics adapter was never used — OSS always uses NoopMetrics and the remote server has its own DataDog-backed adapter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update pkg/github/dependencies.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fmt * change to use slog * address feedback * rename noop adapter to noop sink * Update pkg/http/server.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * [WIP] [WIP] Address feedback on OSS logging adapter for http implementation (#2264) * Initial plan * Fix BaseDeps.Logger and BaseDeps.Metrics to return safe defaults when Obsv is nil Agent-Logs-Url: https://github.com/github/github-mcp-server/sessions/53221b0b-abb4-4138-a147-3ce9e13b379a Co-authored-by: mattdholloway <918573+mattdholloway@users.noreply.github.com> * Fix nil metrics in server.go by passing metrics.NewNoopMetrics() to NewExporters Agent-Logs-Url: https://github.com/github/github-mcp-server/sessions/53221b0b-abb4-4138-a147-3ce9e13b379a Co-authored-by: mattdholloway <918573+mattdholloway@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mattdholloway <918573+mattdholloway@users.noreply.github.com> Co-authored-by: Matt Holloway <mattdholloway@github.com> * replace nil with stubs --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
121 lines
3.1 KiB
Go
121 lines
3.1 KiB
Go
package github_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log/slog"
|
|
"testing"
|
|
|
|
"github.com/github/github-mcp-server/pkg/github"
|
|
"github.com/github/github-mcp-server/pkg/observability"
|
|
"github.com/github/github-mcp-server/pkg/observability/metrics"
|
|
"github.com/github/github-mcp-server/pkg/translations"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func testExporters() observability.Exporters {
|
|
obs, _ := observability.NewExporters(slog.New(slog.DiscardHandler), metrics.NewNoopMetrics())
|
|
return obs
|
|
}
|
|
|
|
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
|
|
testExporters(),
|
|
)
|
|
|
|
// 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)
|
|
testExporters(),
|
|
)
|
|
|
|
// 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
|
|
testExporters(),
|
|
)
|
|
|
|
// 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
|
|
testExporters(),
|
|
)
|
|
|
|
// 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")
|
|
}
|