Skip to content

Commit e0dd50d

Browse files
authored
chore(cli): fix test flake in TestExpMcpServer (#17772)
Test was failing inside a Coder workspace.
1 parent ea2cae0 commit e0dd50d

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

cli/exp_mcp_test.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,29 @@ func TestExpMcpServer(t *testing.T) {
133133
require.Equal(t, 1.0, initializeResponse["id"])
134134
require.NotNil(t, initializeResponse["result"])
135135
})
136+
}
136137

137-
t.Run("NoCredentials", func(t *testing.T) {
138-
t.Parallel()
138+
func TestExpMcpServerNoCredentials(t *testing.T) {
139+
// Ensure that no credentials are set from the environment.
140+
t.Setenv("CODER_AGENT_TOKEN", "")
141+
t.Setenv("CODER_AGENT_TOKEN_FILE", "")
142+
t.Setenv("CODER_SESSION_TOKEN", "")
139143

140-
ctx := testutil.Context(t, testutil.WaitShort)
141-
cancelCtx, cancel := context.WithCancel(ctx)
142-
t.Cleanup(cancel)
144+
ctx := testutil.Context(t, testutil.WaitShort)
145+
cancelCtx, cancel := context.WithCancel(ctx)
146+
t.Cleanup(cancel)
143147

144-
client := coderdtest.New(t, nil)
145-
inv, root := clitest.New(t, "exp", "mcp", "server")
146-
inv = inv.WithContext(cancelCtx)
148+
client := coderdtest.New(t, nil)
149+
inv, root := clitest.New(t, "exp", "mcp", "server")
150+
inv = inv.WithContext(cancelCtx)
147151

148-
pty := ptytest.New(t)
149-
inv.Stdin = pty.Input()
150-
inv.Stdout = pty.Output()
151-
clitest.SetupConfig(t, client, root)
152+
pty := ptytest.New(t)
153+
inv.Stdin = pty.Input()
154+
inv.Stdout = pty.Output()
155+
clitest.SetupConfig(t, client, root)
152156

153-
err := inv.Run()
154-
assert.ErrorContains(t, err, "are not logged in")
155-
})
157+
err := inv.Run()
158+
assert.ErrorContains(t, err, "are not logged in")
156159
}
157160

158161
//nolint:tparallel,paralleltest

0 commit comments

Comments
 (0)