@@ -225,29 +225,44 @@ describe("Server entry", () => {
225225 } ) ;
226226
227227 describe ( "runServer" , ( ) => {
228- it . each ( [ "--version" , "-v" ] ) (
229- "prints version for %s and exits before server startup" ,
230- async ( flag ) => {
231- process . env = {
232- ...originalEnv ,
233- HEVY_API_KEY : "test-api-key" ,
234- } ;
228+ it . each ( [
229+ [ "--version" , undefined ] ,
230+ [ "-v" , "" ] ,
231+ ] ) (
232+ "prints version for %s without an API key and exits before server startup" ,
233+ async ( flag , apiKey ) => {
234+ process . env = { ...originalEnv } ;
235+ if ( apiKey === undefined ) {
236+ delete process . env . HEVY_API_KEY ;
237+ } else {
238+ process . env . HEVY_API_KEY = apiKey ;
239+ }
235240 process . argv = [ ...originalArgv . slice ( 0 , 2 ) , flag ] ;
236241
237242 const logSpy = vi
238243 . spyOn ( console , "log" )
239244 . mockImplementation ( ( ) => undefined ) ;
245+ const errorSpy = vi
246+ . spyOn ( console , "error" )
247+ . mockImplementation ( ( ) => undefined ) ;
248+ const exitSpy = vi
249+ . spyOn ( process , "exit" )
250+ . mockImplementation ( ( ) => undefined as never ) ;
240251
241252 await runServer ( ) ;
242253
243- expect ( logSpy ) . toHaveBeenCalledWith ( "dev" ) ;
254+ expect ( errorSpy ) . toHaveBeenCalledExactlyOnceWith ( "hevy-mcp vdev" ) ;
255+ expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
256+ expect ( exitSpy ) . not . toHaveBeenCalled ( ) ;
244257 expect ( createClient ) . not . toHaveBeenCalled ( ) ;
245258 expect ( testDoubles . startActiveSpan ) . not . toHaveBeenCalled ( ) ;
246259
247260 const anyStdioModule = stdioModule as { __transports ?: unknown [ ] } ;
248261 expect ( anyStdioModule . __transports ) . toHaveLength ( 0 ) ;
249262
250263 logSpy . mockRestore ( ) ;
264+ errorSpy . mockRestore ( ) ;
265+ exitSpy . mockRestore ( ) ;
251266 } ,
252267 ) ;
253268
0 commit comments