FinishActiveChatForTest exposes the unexported cleanup TX so tests can drive the post-run state machine deterministically. Returns the resulting chat, the promoted message (if any), the synthetic tool-result rows the cleanup TX inserted (if any), and the cleanup error. The lastError string is encode
( ctx context.Context, server *Server, chat database.Chat, status database.ChatStatus, lastError string, )
| 18 | // the same way runChat does, so callers do not need to know about |
| 19 | // the structured-error wrapper. |
| 20 | func FinishActiveChatForTest( |
| 21 | ctx context.Context, |
| 22 | server *Server, |
| 23 | chat database.Chat, |
| 24 | status database.ChatStatus, |
| 25 | lastError string, |
| 26 | ) (database.Chat, *database.ChatMessage, []database.ChatMessage, error) { |
| 27 | logger := server.logger.With(slog.F("chat_id", chat.ID)) |
| 28 | var encoded pqtype.NullRawMessage |
| 29 | if lastError != "" { |
| 30 | var err error |
| 31 | encoded, err = encodeChatLastErrorPayload(&codersdk.ChatError{ |
| 32 | Message: lastError, |
| 33 | }) |
| 34 | if err != nil { |
| 35 | return database.Chat{}, nil, nil, err |
| 36 | } |
| 37 | } |
| 38 | result, err := server.finishActiveChat(ctx, logger, chat, status, encoded) |
| 39 | if err != nil { |
| 40 | return database.Chat{}, nil, nil, err |
| 41 | } |
| 42 | return result.updatedChat, result.promotedMessage, result.syntheticToolResults, nil |
| 43 | } |
| 44 | |
| 45 | // RecoverStaleChatsForTest exposes the unexported stale-recovery loop |
| 46 | // so tests can assert the recovery state machine without waiting for |
no test coverage detected