Skip to content

chore(cli): fix test flake in TestExpMcpServer #17772

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

Merged
merged 2 commits into from
May 12, 2025
Merged
Changes from all commits
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
33 changes: 18 additions & 15 deletions cli/exp_mcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,29 @@ func TestExpMcpServer(t *testing.T) {
require.Equal(t, 1.0, initializeResponse["id"])
require.NotNil(t, initializeResponse["result"])
})
}

t.Run("NoCredentials", func(t *testing.T) {
t.Parallel()
func TestExpMcpServerNoCredentials(t *testing.T) {
// Ensure that no credentials are set from the environment.
t.Setenv("CODER_AGENT_TOKEN", "")
t.Setenv("CODER_AGENT_TOKEN_FILE", "")
t.Setenv("CODER_SESSION_TOKEN", "")

ctx := testutil.Context(t, testutil.WaitShort)
cancelCtx, cancel := context.WithCancel(ctx)
t.Cleanup(cancel)
ctx := testutil.Context(t, testutil.WaitShort)
cancelCtx, cancel := context.WithCancel(ctx)
t.Cleanup(cancel)

client := coderdtest.New(t, nil)
inv, root := clitest.New(t, "exp", "mcp", "server")
inv = inv.WithContext(cancelCtx)
client := coderdtest.New(t, nil)
inv, root := clitest.New(t, "exp", "mcp", "server")
inv = inv.WithContext(cancelCtx)

pty := ptytest.New(t)
inv.Stdin = pty.Input()
inv.Stdout = pty.Output()
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t)
inv.Stdin = pty.Input()
inv.Stdout = pty.Output()
clitest.SetupConfig(t, client, root)

err := inv.Run()
assert.ErrorContains(t, err, "are not logged in")
})
err := inv.Run()
assert.ErrorContains(t, err, "are not logged in")
}

//nolint:tparallel,paralleltest
Expand Down
Loading