From 57afd5415641e1848c5d4751bb14087f2a0382e6 Mon Sep 17 00:00:00 2001 From: Hugo Dutka Date: Wed, 26 Aug 2026 06:57:33 +0000 Subject: [PATCH] test(cli): wait for expected GitHub auth state The GitHub OAuth server test accepted the first successful AuthMethods response after restart, even when it still exposed the prior server's semantic state on macOS. Wait until the full GitHub authentication method matches the expected configuration before asserting it. Closes https://linear.app/codercom/issue/ENG-3285/flake-testserveroauth2githubdefaultprovidernewdeployment Generated by Coder Agents. --- cli/server_test.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cli/server_test.go b/cli/server_test.go index 572af9a72bcdc..b5ca20e70b613 100644 --- a/cli/server_test.go +++ b/cli/server_test.go @@ -397,15 +397,15 @@ func TestServer(t *testing.T) { createUserPostRestart bool } - waitAuthMethods := func(t *testing.T, ctx context.Context, client *codersdk.Client) codersdk.AuthMethods { + waitAuthMethods := func(t *testing.T, ctx context.Context, client *codersdk.Client, expected codersdk.GithubAuthMethod) codersdk.AuthMethods { t.Helper() var authMethods codersdk.AuthMethods testutil.Eventually(ctx, t, func(ctx context.Context) bool { var err error authMethods, err = client.AuthMethods(ctx) - return err == nil - }, testutil.IntervalFast, "failed to get auth methods") + return err == nil && authMethods.Github == expected + }, testutil.IntervalFast, "github auth method did not reach expected state: %+v", expected) return authMethods } @@ -463,9 +463,12 @@ func TestServer(t *testing.T) { } client := codersdk.New(accessURL) - authMethods := waitAuthMethods(t, ctx, client) - require.Equal(t, tc.expectGithubEnabled, authMethods.Github.Enabled) - require.Equal(t, tc.expectGithubDefaultProviderConfigured, authMethods.Github.DefaultProviderConfigured) + expectedGithubAuthMethod := codersdk.GithubAuthMethod{ + Enabled: tc.expectGithubEnabled, + DefaultProviderConfigured: tc.expectGithubDefaultProviderConfigured, + } + authMethods := waitAuthMethods(t, ctx, client, expectedGithubAuthMethod) + require.Equal(t, expectedGithubAuthMethod, authMethods.Github) cancelFunc() select { @@ -486,9 +489,8 @@ func TestServer(t *testing.T) { client = codersdk.New(accessURL) ctx = testutil.Context(t, testutil.WaitLong) - authMethods = waitAuthMethods(t, ctx, client) - require.Equal(t, tc.expectGithubEnabled, authMethods.Github.Enabled) - require.Equal(t, tc.expectGithubDefaultProviderConfigured, authMethods.Github.DefaultProviderConfigured) + authMethods = waitAuthMethods(t, ctx, client, expectedGithubAuthMethod) + require.Equal(t, expectedGithubAuthMethod, authMethods.Github) } for _, tc := range []testCase{