| 25 | ) |
| 26 | |
| 27 | func TestController_Fork(t *testing.T) { |
| 28 | ctx := context.Background() |
| 29 | srcCID := "src-conv" |
| 30 | destCID := "dest-conv" |
| 31 | |
| 32 | log := &executortest.MemoryEventLog{} |
| 33 | // Pre-populate history |
| 34 | log.AllEvents = []*proto.ConversationEvent{ |
| 35 | { |
| 36 | ConversationId: srcCID, |
| 37 | Seq: 1, |
| 38 | Messages: []*proto.Message{ |
| 39 | {Role: "user", Content: &proto.Content{Type: &proto.Content_Text{Text: &proto.TextContent{Text: "msg 1"}}}}, |
| 40 | }, |
| 41 | State: proto.State_STATE_COMPLETED, |
| 42 | }, |
| 43 | { |
| 44 | ConversationId: srcCID, |
| 45 | Seq: 2, |
| 46 | Messages: []*proto.Message{ |
| 47 | {Role: "assistant", Content: &proto.Content{Type: &proto.Content_Text{Text: &proto.TextContent{Text: "msg 2"}}}}, |
| 48 | }, |
| 49 | State: proto.State_STATE_COMPLETED, |
| 50 | }, |
| 51 | } |
| 52 | |
| 53 | c, err := New(ctx, Config{ |
| 54 | EventLogBuilder: func() (executor.EventLog, error) { |
| 55 | return log, nil |
| 56 | }, |
| 57 | PlannerBuilder: func(ctx context.Context, r *Registry) (agent.Agent, error) { |
| 58 | return &dummyAgent{}, nil |
| 59 | }, |
| 60 | }) |
| 61 | if err != nil { |
| 62 | t.Fatal(err) |
| 63 | } |
| 64 | defer c.Close() |
| 65 | |
| 66 | // Case 1: Fork without seq (should copy all) |
| 67 | forkedID, err := c.Fork(ctx, srcCID, 0, destCID) |
| 68 | if err != nil { |
| 69 | t.Fatal(err) |
| 70 | } |
| 71 | if forkedID != destCID { |
| 72 | t.Fatalf("expected destCID %s, got %s", destCID, forkedID) |
| 73 | } |
| 74 | |
| 75 | events, err := log.Events(ctx, destCID) |
| 76 | if err != nil { |
| 77 | t.Fatal(err) |
| 78 | } |
| 79 | if len(events) != 2 { |
| 80 | t.Fatalf("expected 2 events, got %d", len(events)) |
| 81 | } |
| 82 | if events[0].Seq != 1 || events[1].Seq != 2 { |
| 83 | t.Errorf("sequences mismatch") |
| 84 | } |