@@ -5,6 +5,8 @@ import { useHumanInTheLoop } from "../use-human-in-the-loop";
55import { ReactHumanInTheLoop } from "@/types" ;
66import { ToolCallStatus } from "@copilotkitnext/core" ;
77import { CopilotChat } from "@/components/chat/CopilotChat" ;
8+ import CopilotChatToolCallsView from "@/components/chat/CopilotChatToolCallsView" ;
9+ import { AssistantMessage , Message } from "@ag-ui/core" ;
810import {
911 MockStepwiseAgent ,
1012 renderWithCopilotKit ,
@@ -573,4 +575,77 @@ describe("useHumanInTheLoop E2E - HITL Tool Rendering", () => {
573575 agent . complete ( ) ;
574576 } ) ;
575577 } ) ;
578+
579+ describe ( "useHumanInTheLoop dependencies" , ( ) => {
580+ it ( "updates HITL renderer when optional deps change" , async ( ) => {
581+ const DependencyDrivenHITLComponent : React . FC = ( ) => {
582+ const [ version , setVersion ] = useState ( 0 ) ;
583+
584+ const hitlTool : ReactHumanInTheLoop < { message : string } > = {
585+ name : "dependencyHitlTool" ,
586+ description : "Dependency-driven HITL tool" ,
587+ parameters : z . object ( { message : z . string ( ) } ) ,
588+ render : ( { args } ) => (
589+ < div data-testid = "dependency-hitl-render" >
590+ { args . message } (v{ version } )
591+ </ div >
592+ ) ,
593+ } ;
594+
595+ useHumanInTheLoop ( hitlTool , [ version ] ) ;
596+
597+ const toolCallId = testId ( "hitl_dep_tc" ) ;
598+ const assistantMessage : AssistantMessage = {
599+ id : testId ( "hitl_dep_a" ) ,
600+ role : "assistant" ,
601+ content : "" ,
602+ toolCalls : [
603+ {
604+ id : toolCallId ,
605+ type : "function" ,
606+ function : {
607+ name : "dependencyHitlTool" ,
608+ arguments : JSON . stringify ( { message : "hello" } ) ,
609+ } ,
610+ } as any ,
611+ ] ,
612+ } as any ;
613+ const messages : Message [ ] = [ ] ;
614+
615+ return (
616+ < >
617+ < button
618+ data-testid = "hitl-bump-version"
619+ type = "button"
620+ onClick = { ( ) => setVersion ( ( v ) => v + 1 ) }
621+ >
622+ Bump
623+ </ button >
624+ < CopilotChatToolCallsView
625+ message = { assistantMessage }
626+ messages = { messages }
627+ />
628+ </ >
629+ ) ;
630+ } ;
631+
632+ renderWithCopilotKit ( {
633+ children : < DependencyDrivenHITLComponent /> ,
634+ } ) ;
635+
636+ await waitFor ( ( ) => {
637+ const el = screen . getByTestId ( "dependency-hitl-render" ) ;
638+ expect ( el ) . toBeDefined ( ) ;
639+ expect ( el . textContent ) . toContain ( "hello" ) ;
640+ expect ( el . textContent ) . toContain ( "(v0)" ) ;
641+ } ) ;
642+
643+ fireEvent . click ( screen . getByTestId ( "hitl-bump-version" ) ) ;
644+
645+ await waitFor ( ( ) => {
646+ const el = screen . getByTestId ( "dependency-hitl-render" ) ;
647+ expect ( el . textContent ) . toContain ( "(v1)" ) ;
648+ } ) ;
649+ } ) ;
650+ } ) ;
576651} ) ;
0 commit comments