@@ -432,6 +432,47 @@ describe("VsCodeLmHandler", () => {
432432 expect . anything ( ) ,
433433 )
434434 } )
435+
436+ it ( "should throw a Zoo Code branded error when request is cancelled" , async ( ) => {
437+ const systemPrompt = "You are a helpful assistant"
438+ const messages : Anthropic . Messages . MessageParam [ ] = [
439+ {
440+ role : "user" as const ,
441+ content : "Hello" ,
442+ } ,
443+ ]
444+
445+ mockLanguageModelChat . sendRequest . mockRejectedValueOnce ( new vscode . CancellationError ( ) )
446+
447+ await expect ( handler . createMessage ( systemPrompt , messages ) . next ( ) ) . rejects . toThrow (
448+ "Zoo Code <Language Model API>: Request cancelled by user" ,
449+ )
450+ } )
451+
452+ it ( "should throw a Zoo Code branded error on stream error with error-like object" , async ( ) => {
453+ const systemPrompt = "You are a helpful assistant"
454+ const messages : Anthropic . Messages . MessageParam [ ] = [
455+ {
456+ role : "user" as const ,
457+ content : "Hello" ,
458+ } ,
459+ ]
460+
461+ const consoleErrorSpy = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
462+
463+ mockLanguageModelChat . sendRequest . mockRejectedValueOnce ( { code : "STREAM_ERROR" , details : "broken" } )
464+
465+ await expect ( handler . createMessage ( systemPrompt , messages ) . next ( ) ) . rejects . toThrow (
466+ "Zoo Code <Language Model API>: Response stream error:" ,
467+ )
468+
469+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
470+ "Zoo Code <Language Model API>: Stream error object:" ,
471+ expect . stringContaining ( "STREAM_ERROR" ) ,
472+ )
473+
474+ consoleErrorSpy . mockRestore ( )
475+ } )
435476 } )
436477
437478 describe ( "initializeClient" , ( ) => {
@@ -461,11 +502,18 @@ describe("VsCodeLmHandler", () => {
461502 } )
462503
463504 it ( "should return fallback model info when no client exists" , ( ) => {
505+ const consoleDebugSpy = vi . spyOn ( console , "debug" ) . mockImplementation ( ( ) => { } )
506+
464507 // Clear the client first
465508 handler [ "client" ] = null
466509 const model = handler . getModel ( )
467510 expect ( model . id ) . toBe ( "test-vendor/test-family" )
468511 expect ( model . info ) . toBeDefined ( )
512+ expect ( consoleDebugSpy ) . toHaveBeenCalledWith (
513+ "Zoo Code <Language Model API>: No client available, using fallback model info" ,
514+ )
515+
516+ consoleDebugSpy . mockRestore ( )
469517 } )
470518
471519 it ( "should return basic model info when client exists" , async ( ) => {
@@ -609,10 +657,17 @@ describe("VsCodeLmHandler", () => {
609657 handler [ "client" ] = null
610658 handler [ "currentRequestCancellation" ] = null
611659
660+ const consoleWarnSpy = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } )
661+
612662 const content : Anthropic . Messages . ContentBlockParam [ ] = [ { type : "text" , text : "Hello" } ]
613663 const result = await handler . countTokens ( content )
614664
615665 expect ( result ) . toBe ( 0 )
666+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
667+ "Zoo Code <Language Model API>: No client available for token counting" ,
668+ )
669+
670+ consoleWarnSpy . mockRestore ( )
616671 } )
617672
618673 it ( "should handle image blocks with placeholder" , async ( ) => {
0 commit comments