@@ -6,6 +6,7 @@ import * as path from "path";
66import { SessionManager , type SessionMessage } from "../session" ;
77
88const originalFetch = globalThis . fetch ;
9+ const originalConsoleWarn = console . warn ;
910const originalHome = process . env . HOME ;
1011const originalUserProfile = process . env . USERPROFILE ;
1112const tempDirs : string [ ] = [ ] ;
@@ -20,6 +21,7 @@ function setHomeDir(dir: string): void {
2021
2122afterEach ( ( ) => {
2223 globalThis . fetch = originalFetch ;
24+ console . warn = originalConsoleWarn ;
2325 if ( originalHome === undefined ) {
2426 delete process . env . HOME ;
2527 } else {
@@ -688,6 +690,7 @@ test("createSession reports a new prompt with the machineId token", async () =>
688690 assert . equal ( fetchCalls . length , 1 ) ;
689691 assert . equal ( String ( fetchCalls [ 0 ] . input ) , "https://deepcode.vegamo.cn/api/plugin/new" ) ;
690692 assert . equal ( fetchCalls [ 0 ] . init ?. method , "POST" ) ;
693+ assert . ok ( fetchCalls [ 0 ] . init ?. signal instanceof AbortSignal ) ;
691694 assert . deepEqual ( JSON . parse ( String ( fetchCalls [ 0 ] . init ?. body ) ) , { } ) ;
692695 assert . equal ( ( fetchCalls [ 0 ] . init ?. headers as Record < string , string > ) . Token , "machine-id-123" ) ;
693696} ) ;
@@ -719,10 +722,33 @@ test("replySession reports a new prompt with the machineId token", async () => {
719722 assert . equal ( fetchCalls . length , 1 ) ;
720723 assert . equal ( String ( fetchCalls [ 0 ] . input ) , "https://deepcode.vegamo.cn/api/plugin/new" ) ;
721724 assert . equal ( fetchCalls [ 0 ] . init ?. method , "POST" ) ;
725+ assert . ok ( fetchCalls [ 0 ] . init ?. signal instanceof AbortSignal ) ;
722726 assert . deepEqual ( JSON . parse ( String ( fetchCalls [ 0 ] . init ?. body ) ) , { } ) ;
723727 assert . equal ( ( fetchCalls [ 0 ] . init ?. headers as Record < string , string > ) . Token , "machine-id-456" ) ;
724728} ) ;
725729
730+ test ( "reporting a new prompt does not warn when the background request fails" , async ( ) => {
731+ const workspace = createTempDir ( "deepcode-report-failure-workspace-" ) ;
732+ const home = createTempDir ( "deepcode-report-failure-home-" ) ;
733+ setHomeDir ( home ) ;
734+
735+ const warnings : unknown [ ] [ ] = [ ] ;
736+ console . warn = ( ...args : unknown [ ] ) => {
737+ warnings . push ( args ) ;
738+ } ;
739+ globalThis . fetch = ( async ( ) => {
740+ throw new Error ( "fetch failed" ) ;
741+ } ) as typeof fetch ;
742+
743+ const manager = createSessionManager ( workspace , "machine-id-failure" ) ;
744+ ( manager as any ) . activateSession = async ( ) => { } ;
745+
746+ await manager . createSession ( { text : "hello world" } ) ;
747+ await flushPromises ( ) ;
748+
749+ assert . deepEqual ( warnings , [ ] ) ;
750+ } ) ;
751+
726752test ( "replySession continues without appending /continue as a user message" , async ( ) => {
727753 const workspace = createTempDir ( "deepcode-continue-workspace-" ) ;
728754 const home = createTempDir ( "deepcode-continue-home-" ) ;
0 commit comments