@@ -133,35 +133,29 @@ func TestExpMcpServer(t *testing.T) {
133
133
require .Equal (t , 1.0 , initializeResponse ["id" ])
134
134
require .NotNil (t , initializeResponse ["result" ])
135
135
})
136
+ }
136
137
137
- t .Run ("NoCredentials" , func (t * testing.T ) {
138
- t .Parallel ()
139
-
140
- ctx := testutil .Context (t , testutil .WaitShort )
141
- cancelCtx , cancel := context .WithCancel (ctx )
142
- t .Cleanup (cancel )
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" , "" )
143
143
144
- client := coderdtest . New (t , nil )
145
- inv , root := clitest . New ( t , "exp" , "mcp" , "server" )
146
- inv = inv . WithContext ( cancelCtx )
144
+ ctx := testutil . Context (t , testutil . WaitShort )
145
+ cancelCtx , cancel := context . WithCancel ( ctx )
146
+ t . Cleanup ( cancel )
147
147
148
- pty := ptytest .New (t )
149
- inv .Stdin = pty .Input ()
150
- inv .Stdout = pty .Output ()
151
- inv .Stderr = pty .Output ()
152
- clitest .SetupConfig (t , client , root )
148
+ client := coderdtest .New (t , nil )
149
+ inv , root := clitest .New (t , "exp" , "mcp" , "server" )
150
+ inv = inv .WithContext (cancelCtx )
153
151
154
- cmdDone := make (chan struct {})
155
- go func () {
156
- defer close (cmdDone )
157
- err := inv .Run ()
158
- assert .NoError (t , err )
159
- }()
152
+ pty := ptytest .New (t )
153
+ inv .Stdin = pty .Input ()
154
+ inv .Stdout = pty .Output ()
155
+ clitest .SetupConfig (t , client , root )
160
156
161
- pty .ExpectRegexMatch (`(?is)Authentication\s+:\s+None` )
162
- cancel ()
163
- <- cmdDone
164
- })
157
+ err := inv .Run ()
158
+ assert .ErrorContains (t , err , "are not logged in" )
165
159
}
166
160
167
161
//nolint:tparallel,paralleltest
0 commit comments