| 106 | } |
| 107 | |
| 108 | func TestController_Fork_SrcSeqNotFound(t *testing.T) { |
| 109 | ctx := context.Background() |
| 110 | srcCID := "src-conv" |
| 111 | |
| 112 | log := &executortest.MemoryEventLog{} |
| 113 | log.AllEvents = []*proto.ConversationEvent{ |
| 114 | { |
| 115 | ConversationId: srcCID, |
| 116 | Seq: 1, |
| 117 | Messages: []*proto.Message{ |
| 118 | {Role: "user", Content: &proto.Content{Type: &proto.Content_Text{Text: &proto.TextContent{Text: "msg 1"}}}}, |
| 119 | }, |
| 120 | State: proto.State_STATE_COMPLETED, |
| 121 | }, |
| 122 | { |
| 123 | ConversationId: srcCID, |
| 124 | Seq: 2, |
| 125 | Messages: []*proto.Message{ |
| 126 | {Role: "assistant", Content: &proto.Content{Type: &proto.Content_Text{Text: &proto.TextContent{Text: "msg 2"}}}}, |
| 127 | }, |
| 128 | State: proto.State_STATE_COMPLETED, |
| 129 | }, |
| 130 | } |
| 131 | |
| 132 | c, err := New(ctx, Config{ |
| 133 | EventLogBuilder: func() (executor.EventLog, error) { |
| 134 | return log, nil |
| 135 | }, |
| 136 | PlannerBuilder: func(ctx context.Context, r *Registry) (agent.Agent, error) { |
| 137 | return &dummyAgent{}, nil |
| 138 | }, |
| 139 | }) |
| 140 | if err != nil { |
| 141 | t.Fatal(err) |
| 142 | } |
| 143 | defer c.Close() |
| 144 | |
| 145 | // Non-existent src_seq must error and write nothing. |
| 146 | if _, err := c.Fork(ctx, srcCID, 99, "dest-conv"); err == nil { |
| 147 | t.Fatal("expected error when src_seq does not exist, got nil") |
| 148 | } |
| 149 | events, err := log.Events(ctx, "dest-conv") |
| 150 | if err != nil { |
| 151 | t.Fatal(err) |
| 152 | } |
| 153 | if len(events) != 0 { |
| 154 | t.Fatalf("expected 0 events on failed fork, got %d", len(events)) |
| 155 | } |
| 156 | |
| 157 | // src_seq exactly at the max is valid and must succeed. |
| 158 | if _, err := c.Fork(ctx, srcCID, 2, "dest-conv-boundary"); err != nil { |
| 159 | t.Fatalf("unexpected error forking at boundary src_seq: %v", err) |
| 160 | } |
| 161 | } |