@@ -582,6 +582,172 @@ describe("matchFixture — sequenceIndex", () => {
582582 } ) ;
583583} ) ;
584584
585+ // ---------------------------------------------------------------------------
586+ // matchFixture — turnIndex
587+ // ---------------------------------------------------------------------------
588+
589+ describe ( "matchFixture — turnIndex" , ( ) => {
590+ it ( "matches when assistant message count equals turnIndex" , ( ) => {
591+ const fixture = makeFixture ( { userMessage : "hello" , turnIndex : 1 } ) ;
592+ const req = makeReq ( {
593+ messages : [
594+ { role : "system" , content : "you are helpful" } ,
595+ { role : "user" , content : "hello" } ,
596+ { role : "assistant" , content : "hi there" } ,
597+ { role : "user" , content : "hello" } ,
598+ ] ,
599+ } ) ;
600+ expect ( matchFixture ( [ fixture ] , req ) ) . toBe ( fixture ) ;
601+ } ) ;
602+
603+ it ( "skips when assistant message count does not equal turnIndex" , ( ) => {
604+ const fixture = makeFixture ( { userMessage : "hello" , turnIndex : 2 } ) ;
605+ const req = makeReq ( {
606+ messages : [
607+ { role : "user" , content : "hello" } ,
608+ { role : "assistant" , content : "hi there" } ,
609+ { role : "user" , content : "hello" } ,
610+ ] ,
611+ } ) ;
612+ expect ( matchFixture ( [ fixture ] , req ) ) . toBeNull ( ) ;
613+ } ) ;
614+
615+ it ( "turnIndex 0 matches when no assistant messages present" , ( ) => {
616+ const fixture = makeFixture ( { userMessage : "hello" , turnIndex : 0 } ) ;
617+ const req = makeReq ( {
618+ messages : [
619+ { role : "system" , content : "you are helpful" } ,
620+ { role : "user" , content : "hello" } ,
621+ ] ,
622+ } ) ;
623+ expect ( matchFixture ( [ fixture ] , req ) ) . toBe ( fixture ) ;
624+ } ) ;
625+
626+ it ( "selects correct fixture from turnIndex sequence" , ( ) => {
627+ const turn0 = makeFixture ( { userMessage : "hello" , turnIndex : 0 } , { content : "turn-0" } ) ;
628+ const turn1 = makeFixture ( { userMessage : "hello" , turnIndex : 1 } , { content : "turn-1" } ) ;
629+ const turn2 = makeFixture ( { userMessage : "hello" , turnIndex : 2 } , { content : "turn-2" } ) ;
630+
631+ const req0 = makeReq ( {
632+ messages : [ { role : "user" , content : "hello" } ] ,
633+ } ) ;
634+ expect ( matchFixture ( [ turn0 , turn1 , turn2 ] , req0 ) ) . toBe ( turn0 ) ;
635+
636+ const req1 = makeReq ( {
637+ messages : [
638+ { role : "user" , content : "hello" } ,
639+ { role : "assistant" , content : "reply" } ,
640+ { role : "user" , content : "hello" } ,
641+ ] ,
642+ } ) ;
643+ expect ( matchFixture ( [ turn0 , turn1 , turn2 ] , req1 ) ) . toBe ( turn1 ) ;
644+
645+ const req2 = makeReq ( {
646+ messages : [
647+ { role : "user" , content : "hello" } ,
648+ { role : "assistant" , content : "reply1" } ,
649+ { role : "user" , content : "hello" } ,
650+ { role : "assistant" , content : "reply2" } ,
651+ { role : "user" , content : "hello" } ,
652+ ] ,
653+ } ) ;
654+ expect ( matchFixture ( [ turn0 , turn1 , turn2 ] , req2 ) ) . toBe ( turn2 ) ;
655+ } ) ;
656+
657+ it ( "falls through to non-turnIndex fixture when no turnIndex matches" , ( ) => {
658+ const turnOnly = makeFixture ( { userMessage : "hello" , turnIndex : 0 } , { content : "turn-0" } ) ;
659+ const fallback = makeFixture ( { userMessage : "hello" } , { content : "fallback" } ) ;
660+ const req = makeReq ( {
661+ messages : [
662+ { role : "user" , content : "hello" } ,
663+ { role : "assistant" , content : "reply1" } ,
664+ { role : "user" , content : "hello" } ,
665+ { role : "assistant" , content : "reply2" } ,
666+ { role : "user" , content : "hello" } ,
667+ ] ,
668+ } ) ;
669+ expect ( matchFixture ( [ turnOnly , fallback ] , req ) ) . toBe ( fallback ) ;
670+ } ) ;
671+ } ) ;
672+
673+ // ---------------------------------------------------------------------------
674+ // matchFixture — hasToolResult
675+ // ---------------------------------------------------------------------------
676+
677+ describe ( "matchFixture — hasToolResult" , ( ) => {
678+ it ( "matches hasToolResult: true when tool messages present" , ( ) => {
679+ const fixture = makeFixture ( { userMessage : "hello" , hasToolResult : true } ) ;
680+ const req = makeReq ( {
681+ messages : [
682+ { role : "user" , content : "hello" } ,
683+ { role : "assistant" , content : "calling tool" } ,
684+ { role : "tool" , content : "tool output" } ,
685+ { role : "user" , content : "hello" } ,
686+ ] ,
687+ } ) ;
688+ expect ( matchFixture ( [ fixture ] , req ) ) . toBe ( fixture ) ;
689+ } ) ;
690+
691+ it ( "skips hasToolResult: true when no tool messages present" , ( ) => {
692+ const fixture = makeFixture ( { userMessage : "hello" , hasToolResult : true } ) ;
693+ const req = makeReq ( {
694+ messages : [
695+ { role : "user" , content : "hello" } ,
696+ { role : "assistant" , content : "reply" } ,
697+ { role : "user" , content : "hello" } ,
698+ ] ,
699+ } ) ;
700+ expect ( matchFixture ( [ fixture ] , req ) ) . toBeNull ( ) ;
701+ } ) ;
702+
703+ it ( "matches hasToolResult: false when no tool messages present" , ( ) => {
704+ const fixture = makeFixture ( { userMessage : "hello" , hasToolResult : false } ) ;
705+ const req = makeReq ( {
706+ messages : [ { role : "user" , content : "hello" } ] ,
707+ } ) ;
708+ expect ( matchFixture ( [ fixture ] , req ) ) . toBe ( fixture ) ;
709+ } ) ;
710+
711+ it ( "skips hasToolResult: false when tool messages present" , ( ) => {
712+ const fixture = makeFixture ( { userMessage : "hello" , hasToolResult : false } ) ;
713+ const req = makeReq ( {
714+ messages : [
715+ { role : "user" , content : "hello" } ,
716+ { role : "assistant" , content : "calling tool" } ,
717+ { role : "tool" , content : "tool output" } ,
718+ { role : "user" , content : "hello" } ,
719+ ] ,
720+ } ) ;
721+ expect ( matchFixture ( [ fixture ] , req ) ) . toBeNull ( ) ;
722+ } ) ;
723+
724+ it ( "discriminates 2-step HITL flow with hasToolResult" , ( ) => {
725+ const beforeTool = makeFixture (
726+ { userMessage : "hello" , hasToolResult : false } ,
727+ { content : "before-tool" } ,
728+ ) ;
729+ const afterTool = makeFixture (
730+ { userMessage : "hello" , hasToolResult : true } ,
731+ { content : "after-tool" } ,
732+ ) ;
733+
734+ const reqBefore = makeReq ( {
735+ messages : [ { role : "user" , content : "hello" } ] ,
736+ } ) ;
737+ expect ( matchFixture ( [ beforeTool , afterTool ] , reqBefore ) ) . toBe ( beforeTool ) ;
738+
739+ const reqAfter = makeReq ( {
740+ messages : [
741+ { role : "user" , content : "hello" } ,
742+ { role : "assistant" , content : "calling tool" } ,
743+ { role : "tool" , content : "result" } ,
744+ { role : "user" , content : "hello" } ,
745+ ] ,
746+ } ) ;
747+ expect ( matchFixture ( [ beforeTool , afterTool ] , reqAfter ) ) . toBe ( afterTool ) ;
748+ } ) ;
749+ } ) ;
750+
585751// ---------------------------------------------------------------------------
586752// matchFixture — first-match-wins
587753// ---------------------------------------------------------------------------
0 commit comments