@@ -2059,6 +2059,35 @@ describe('runCopilotLifecycle', () => {
20592059 )
20602060 } )
20612061
2062+ it ( 'explains an error terminal that arrives without a reason as an already-ended run' , async ( ) => {
2063+ mockRunStreamLoop . mockImplementationOnce (
2064+ async ( _url : string , _init : RequestInit , context : StreamingContext ) : Promise < void > => {
2065+ context . completionStatus = MothershipStreamV1CompletionStatus . error
2066+ }
2067+ )
2068+
2069+ const result = await runWithStreamAbort ( new AbortController ( ) )
2070+
2071+ expect ( result . success ) . toBe ( false )
2072+ expect ( result . cancelled ) . toBe ( false )
2073+ expect ( result . error ) . toEqual ( expect . stringContaining ( 'already ended' ) )
2074+ } )
2075+
2076+ it ( 'keeps a Stop a cancellation when the error terminal carries no reason' , async ( ) => {
2077+ const abortController = new AbortController ( )
2078+ mockRunStreamLoop . mockImplementationOnce (
2079+ async ( _url : string , _init : RequestInit , context : StreamingContext ) : Promise < void > => {
2080+ context . completionStatus = MothershipStreamV1CompletionStatus . error
2081+ abortController . abort ( )
2082+ }
2083+ )
2084+
2085+ const result = await runWithStreamAbort ( abortController )
2086+
2087+ expect ( result . cancelled ) . toBe ( true )
2088+ expect ( result . error ) . toBeUndefined ( )
2089+ } )
2090+
20622091 it ( 'keeps a Stop a cancellation when a replay refusal follows it' , async ( ) => {
20632092 const abortController = new AbortController ( )
20642093 mockRunStreamLoop . mockImplementationOnce (
@@ -3352,78 +3381,6 @@ describe('runCopilotLifecycle', () => {
33523381 expect ( result . errors ) . toEqual ( [ 'The provider is overloaded' ] )
33533382 } )
33543383
3355- it ( 'explains an error terminal that arrives without a reason as an already-ended run' , async ( ) => {
3356- const executionContext : ExecutionContext = {
3357- userId : 'user-1' ,
3358- workflowId : '' ,
3359- workspaceId : 'ws-1' ,
3360- chatId : 'chat-1' ,
3361- }
3362-
3363- mockRunStreamLoop . mockImplementationOnce (
3364- async (
3365- _fetchUrl : string ,
3366- _fetchOptions : RequestInit ,
3367- context : StreamingContext
3368- ) : Promise < void > => {
3369- context . completionStatus = MothershipStreamV1CompletionStatus . error
3370- }
3371- )
3372-
3373- const result = await runCopilotLifecycle (
3374- { message : 'hello' , messageId : 'stream-1' } ,
3375- {
3376- userId : 'user-1' ,
3377- workspaceId : 'ws-1' ,
3378- chatId : 'chat-1' ,
3379- executionId : 'exec-1' ,
3380- runId : 'run-1' ,
3381- executionContext,
3382- }
3383- )
3384-
3385- expect ( result . success ) . toBe ( false )
3386- expect ( result . cancelled ) . toBe ( false )
3387- expect ( result . error ) . toEqual ( expect . stringContaining ( 'already ended' ) )
3388- } )
3389-
3390- it ( 'keeps a Stop a cancellation when the error terminal carries no reason' , async ( ) => {
3391- const executionContext : ExecutionContext = {
3392- userId : 'user-1' ,
3393- workflowId : '' ,
3394- workspaceId : 'ws-1' ,
3395- chatId : 'chat-1' ,
3396- }
3397- const abortController = new AbortController ( )
3398-
3399- mockRunStreamLoop . mockImplementationOnce (
3400- async (
3401- _fetchUrl : string ,
3402- _fetchOptions : RequestInit ,
3403- context : StreamingContext
3404- ) : Promise < void > => {
3405- context . completionStatus = MothershipStreamV1CompletionStatus . error
3406- abortController . abort ( )
3407- }
3408- )
3409-
3410- const result = await runCopilotLifecycle (
3411- { message : 'hello' , messageId : 'stream-1' } ,
3412- {
3413- userId : 'user-1' ,
3414- workspaceId : 'ws-1' ,
3415- chatId : 'chat-1' ,
3416- executionId : 'exec-1' ,
3417- runId : 'run-1' ,
3418- executionContext,
3419- abortSignal : abortController . signal ,
3420- }
3421- )
3422-
3423- expect ( result . cancelled ) . toBe ( true )
3424- expect ( result . error ) . toBeUndefined ( )
3425- } )
3426-
34273384 it ( 'force-fails a hung tool promise and resumes with an error result instead of wedging' , async ( ) => {
34283385 vi . useFakeTimers ( )
34293386 try {
0 commit comments