Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(coderd): address review notes on the oauth2 experiment deprecation
Trim the doc comment on the message constant to its purpose so it
cannot drift from the literal. Assert the deprecation warning by count
instead of an exact warn slice, which coupled the test to the safety
classification of an unrelated experiment, and check explicitly that no
unknown-experiment warning leaks.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
  • Loading branch information
BobbyHo and claude committed Sep 12, 2026
commit ee405a9a23e48a579dcdb7f9eebf9bfca4c0a071
5 changes: 2 additions & 3 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2578,9 +2578,8 @@ func (api *API) DERPMap() *tailcfg.DERPMap {
return api.BaseDERPMap
}

// oauth2ExperimentDeprecatedMessage is logged when the retired oauth2
// experiment is still configured. The OAuth2 provider is controlled by
// CODER_OAUTH2_PROVIDER_ENABLE, so the experiment value does nothing.
// oauth2ExperimentDeprecatedMessage is logged when a retired oauth2
// experiment value is still configured.
const oauth2ExperimentDeprecatedMessage = `CODER_EXPERIMENTS contains "oauth2", which is deprecated and has no effect. The OAuth2 provider is now generally available and disabled by default. Set CODER_OAUTH2_PROVIDER_ENABLE=true to enable it. The "oauth2" experiment value will be removed in a future release.`

// warnOAuth2ExperimentDeprecated limits the deprecation warning to once per
Expand Down
27 changes: 17 additions & 10 deletions coderd/experiments_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ func (s *logRecorder) messages(level slog.Level) []string {
return out
}

// count returns how many entries at level carry exactly msg.
func (s *logRecorder) count(level slog.Level, msg string) int {
var n int
for _, m := range s.messages(level) {
if m == msg {
n++
}
}
return n
}

func TestReadExperimentsDeprecatedOAuth2(t *testing.T) {
t.Parallel()

Expand All @@ -48,18 +59,14 @@ func TestReadExperimentsDeprecatedOAuth2(t *testing.T) {
got := parseExperiments(log, raw, &once)
require.Equal(t, codersdk.Experiments{codersdk.ExperimentMCPServerHTTP}, got,
"the oauth2 experiment must be dropped, not passed through")
require.Equal(t, []string{oauth2ExperimentDeprecatedMessage, "🐉 HERE BE DRAGONS: opting into hidden experiment"},
rec.messages(slog.LevelWarn))
require.Equal(t, 1, rec.count(slog.LevelWarn, oauth2ExperimentDeprecatedMessage))
require.NotContains(t, rec.messages(slog.LevelWarn), "ignoring unknown experiment",
"oauth2 must be matched before the unknown-experiment branch")

// A second read in the same process returns the same slice and does not
// A second read in the same process returns the same values and does not
// repeat the deprecation warning. Upper-case input is matched too.
got = parseExperiments(log, []string{"OAuth2", string(codersdk.ExperimentMCPServerHTTP)}, &once)
require.Equal(t, codersdk.Experiments{codersdk.ExperimentMCPServerHTTP}, got)
var deprecations int
for _, m := range rec.messages(slog.LevelWarn) {
if m == oauth2ExperimentDeprecatedMessage {
deprecations++
}
}
require.Equal(t, 1, deprecations, "deprecation warning must be logged once per process")
require.Equal(t, 1, rec.count(slog.LevelWarn, oauth2ExperimentDeprecatedMessage),
"deprecation warning must be logged once per process")
}
Loading