@@ -621,3 +621,85 @@ describe("unknown event type", () => {
621621 expect ( events ) . toHaveLength ( 0 ) ;
622622 } ) ;
623623} ) ;
624+
625+ // ---------------------------------------------------------------------------
626+ // user.message
627+ // ---------------------------------------------------------------------------
628+
629+ describe ( "user.message" , ( ) => {
630+ it ( "emits message.user event with content when data.content is present" , ( ) => {
631+ const state = makeState ( ) ;
632+ const event = { type : "user.message" , data : { content : "Hello from user" } } as SessionEvent ;
633+ const events = collect ( mapCopilotEvent ( event , state ) ) as { type : string ; text ?: string } [ ] ;
634+ expect ( events ) . toHaveLength ( 1 ) ;
635+ expect ( events [ 0 ] ) . toEqual ( { type : "message.user" , text : "Hello from user" } ) ;
636+ } ) ;
637+
638+ it ( "emits no events when data.content is empty string" , ( ) => {
639+ const state = makeState ( ) ;
640+ const event = { type : "user.message" , data : { content : "" } } as SessionEvent ;
641+ const events = collect ( mapCopilotEvent ( event , state ) ) ;
642+ expect ( events ) . toHaveLength ( 0 ) ;
643+ } ) ;
644+
645+ it ( "emits no events when data.content is undefined (falsy)" , ( ) => {
646+ const state = makeState ( ) ;
647+ const event = { type : "user.message" , data : { } } as SessionEvent ;
648+ const events = collect ( mapCopilotEvent ( event , state ) ) ;
649+ expect ( events ) . toHaveLength ( 0 ) ;
650+ } ) ;
651+ } ) ;
652+
653+ // ---------------------------------------------------------------------------
654+ // normalizeCopilotTool field remapping
655+ // ---------------------------------------------------------------------------
656+
657+ describe ( "normalizeCopilotTool field remapping" , ( ) => {
658+ it ( "write: remaps path → file_path and file_text → content in block input" , ( ) => {
659+ const state = makeState ( { turnOpen : true } ) ;
660+ const event = {
661+ type : "assistant.message" ,
662+ data : {
663+ toolRequests : [ { toolCallId : "tw1" , name : "write" , arguments : { path : "/tmp/f.ts" , file_text : "hello" } } ] ,
664+ } ,
665+ } as SessionEvent ;
666+ const events = collect ( mapCopilotEvent ( event , state ) ) as {
667+ type : string ;
668+ block ?: { type : string ; name : string ; input : Record < string , unknown > } ;
669+ } [ ] ;
670+ const toolStart = events . find ( ( e ) => e . type === "block.start" && e . block ?. type === "tool_use" ) ;
671+ expect ( toolStart ?. block ?. input ) . toMatchObject ( { file_path : "/tmp/f.ts" , content : "hello" } ) ;
672+ } ) ;
673+
674+ it ( "edit: remaps path → file_path, old_str → old_string, new_str → new_string in block input" , ( ) => {
675+ const state = makeState ( { turnOpen : true } ) ;
676+ const event = {
677+ type : "assistant.message" ,
678+ data : {
679+ toolRequests : [ { toolCallId : "te1" , name : "edit" , arguments : { path : "/tmp/f.ts" , old_str : "a" , new_str : "b" } } ] ,
680+ } ,
681+ } as SessionEvent ;
682+ const events = collect ( mapCopilotEvent ( event , state ) ) as {
683+ type : string ;
684+ block ?: { type : string ; name : string ; input : Record < string , unknown > } ;
685+ } [ ] ;
686+ const toolStart = events . find ( ( e ) => e . type === "block.start" && e . block ?. type === "tool_use" ) ;
687+ expect ( toolStart ?. block ?. input ) . toMatchObject ( { file_path : "/tmp/f.ts" , old_string : "a" , new_string : "b" } ) ;
688+ } ) ;
689+
690+ it ( "read: remaps path → file_path in block input" , ( ) => {
691+ const state = makeState ( { turnOpen : true } ) ;
692+ const event = {
693+ type : "assistant.message" ,
694+ data : {
695+ toolRequests : [ { toolCallId : "tr1" , name : "read" , arguments : { path : "/tmp/f.ts" } } ] ,
696+ } ,
697+ } as SessionEvent ;
698+ const events = collect ( mapCopilotEvent ( event , state ) ) as {
699+ type : string ;
700+ block ?: { type : string ; name : string ; input : Record < string , unknown > } ;
701+ } [ ] ;
702+ const toolStart = events . find ( ( e ) => e . type === "block.start" && e . block ?. type === "tool_use" ) ;
703+ expect ( toolStart ?. block ?. input ) . toMatchObject ( { file_path : "/tmp/f.ts" } ) ;
704+ } ) ;
705+ } ) ;
0 commit comments