@@ -784,26 +784,70 @@ describe("OpenCodeAdapterV2", () => {
784784 error : "Command failed" ,
785785 time : { start : 3 , end : 4 } ,
786786 } ,
787+ {
788+ status : "error" ,
789+ input : { command : "sleep 60" } ,
790+ error : "Interrupted" ,
791+ metadata : { interrupted : true } ,
792+ time : { start : 5 , end : 6 } ,
793+ } ,
794+ // OpenCode 1.3 reports a stopped tool only through this message.
795+ {
796+ status : "error" ,
797+ input : { command : "sleep 90" } ,
798+ error : "Tool execution aborted" ,
799+ time : { start : 6 , end : 7 } ,
800+ } ,
787801 ] satisfies ReadonlyArray < ToolPart [ "state" ] > ;
788802 for ( const state of states ) {
803+ const callID =
804+ state . status === "error" ? `call-ended-${ state . time . start } ` : "call-working" ;
789805 yield * Effect . promise ( ( ) =>
790806 nativeEvents . push ( {
791807 type : "message.part.updated" ,
792808 properties : {
793809 sessionID : nativeSessionId ,
794810 part : {
795- id : state . status === "error" ? " part-failed" : "part-working" ,
811+ id : ` part-${ callID } ` ,
796812 sessionID : nativeSessionId ,
797813 messageID : "late-assistant" ,
798814 type : "tool" ,
799- callID : state . status === "error" ? "call-failed" : "call-working" ,
815+ callID,
800816 tool : "bash" ,
801817 state,
802818 } ,
803819 } ,
804820 } ) ,
805821 ) ;
806822 }
823+ for ( const error of [ "Task cancelled" , "Task failed" ] ) {
824+ yield * Effect . promise ( ( ) =>
825+ nativeEvents . push ( {
826+ type : "message.part.updated" ,
827+ properties : {
828+ sessionID : nativeSessionId ,
829+ part : {
830+ id : `part-${ error } ` ,
831+ sessionID : nativeSessionId ,
832+ messageID : "late-assistant" ,
833+ type : "tool" ,
834+ callID : `call-${ error } ` ,
835+ tool : "task" ,
836+ state : {
837+ status : "error" ,
838+ input : {
839+ description : "Sleep task" ,
840+ prompt : "sleep 120" ,
841+ subagent_type : "general" ,
842+ } ,
843+ error,
844+ time : { start : 7 , end : 8 } ,
845+ } ,
846+ } ,
847+ } ,
848+ } ) ,
849+ ) ;
850+ }
807851 yield * Effect . promise ( ( ) =>
808852 nativeEvents . push ( {
809853 type : "message.part.updated" ,
@@ -902,21 +946,31 @@ describe("OpenCodeAdapterV2", () => {
902946 const commands = items . filter ( ( item ) => item . type === "command_execution" ) ;
903947 assert . deepEqual (
904948 commands . map ( ( item ) => item . status ) ,
905- [ "pending" , "running" , "completed" , "failed" , "failed" ] ,
949+ [ "pending" , "running" , "completed" , "failed" , "interrupted" , "interrupted" , " failed"] ,
906950 ) ;
907951 assert . deepEqual (
908952 commands . map ( ( item ) => item . input ) ,
909- [ "pwd" , "pwd" , "pwd" , "pwd" , "vp test" ] ,
953+ [ "pwd" , "pwd" , "pwd" , "pwd" , "sleep 60" , "sleep 90" , " vp test"] ,
910954 ) ;
911955 assert . equal ( commands [ 2 ] ?. output , "/repo\n" ) ;
912956 assert . equal ( commands [ 3 ] ?. output , "Command failed" ) ;
913- assert . equal ( commands [ 4 ] ?. exitCode , 1 ) ;
957+ assert . equal ( commands [ 6 ] ?. exitCode , 1 ) ;
914958 assert . equal (
915959 events
916960 . flatMap ( ( event ) => ( event . type === "node.updated" ? [ event . node ] : [ ] ) )
917- . findLast ( ( node ) => node . id === commands [ 4 ] ?. nodeId ) ?. status ,
961+ . findLast ( ( node ) => node . id === commands [ 6 ] ?. nodeId ) ?. status ,
918962 "failed" ,
919963 ) ;
964+ assert . deepEqual (
965+ items . filter ( ( item ) => item . type === "subagent" ) . map ( ( item ) => item . status ) ,
966+ [ "interrupted" , "failed" ] ,
967+ ) ;
968+ assert . deepEqual (
969+ events . flatMap ( ( event ) =>
970+ event . type === "subagent.updated" ? [ event . subagent . status ] : [ ] ,
971+ ) ,
972+ [ "interrupted" , "failed" ] ,
973+ ) ;
920974 assert . isTrue (
921975 events . some (
922976 ( event ) =>
0 commit comments