TestWaitForActiveChatStop and TestWaitForActiveChatStop_WaitsForReplacementRun were removed along with the process-local activeChats mechanism. Debug cleanup is now best-effort; stale finalization handles orphaned rows. TestArchiveChatWaitsForActiveChatStop and TestArchiveChatWaitsForEveryInterrupte
(t *testing.T)
| 693 | // best-effort; stale finalization handles any orphaned rows. |
| 694 | |
| 695 | func TestRenameChatTitle(t *testing.T) { |
| 696 | t.Parallel() |
| 697 | |
| 698 | setupRealWorkerLock := func( |
| 699 | db *dbmock.MockStore, |
| 700 | chatID uuid.UUID, |
| 701 | lockedChat database.Chat, |
| 702 | ) { |
| 703 | lockTx := dbmock.NewMockStore(gomock.NewController(t)) |
| 704 | unlockTx := dbmock.NewMockStore(gomock.NewController(t)) |
| 705 | gomock.InOrder( |
| 706 | db.EXPECT().InTx(gomock.Any(), database.DefaultTXOptions().WithID("chat_title_regenerate_lock")).DoAndReturn( |
| 707 | func(fn func(database.Store) error, _ *database.TxOptions) error { |
| 708 | return fn(lockTx) |
| 709 | }, |
| 710 | ), |
| 711 | db.EXPECT().InTx(gomock.Any(), database.DefaultTXOptions().WithID("chat_title_regenerate_unlock")).DoAndReturn( |
| 712 | func(fn func(database.Store) error, _ *database.TxOptions) error { |
| 713 | return fn(unlockTx) |
| 714 | }, |
| 715 | ), |
| 716 | ) |
| 717 | lockTx.EXPECT().GetChatByIDForUpdate(gomock.Any(), chatID).Return(lockedChat, nil) |
| 718 | unlockTx.EXPECT().GetChatByIDForUpdate(gomock.Any(), chatID).Return(lockedChat, nil) |
| 719 | } |
| 720 | |
| 721 | t.Run("WritesAndReturnsWroteTrue", func(t *testing.T) { |
| 722 | t.Parallel() |
| 723 | |
| 724 | ctx := testutil.Context(t, testutil.WaitShort) |
| 725 | ctrl := gomock.NewController(t) |
| 726 | db := dbmock.NewMockStore(ctrl) |
| 727 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) |
| 728 | |
| 729 | chatID := uuid.New() |
| 730 | workerID := uuid.New() |
| 731 | stored := database.Chat{ |
| 732 | ID: chatID, |
| 733 | Status: database.ChatStatusRunning, |
| 734 | WorkerID: uuid.NullUUID{UUID: workerID, Valid: true}, |
| 735 | Title: "original", |
| 736 | } |
| 737 | updated := stored |
| 738 | updated.Title = "renamed" |
| 739 | |
| 740 | server := &Server{db: db, logger: logger} |
| 741 | |
| 742 | setupRealWorkerLock(db, chatID, stored) |
| 743 | db.EXPECT().GetChatByID(gomock.Any(), chatID).Return(stored, nil) |
| 744 | db.EXPECT().UpdateChatTitleByID(gomock.Any(), database.UpdateChatTitleByIDParams{ |
| 745 | ID: chatID, |
| 746 | Title: "renamed", |
| 747 | }).Return(updated, nil) |
| 748 | |
| 749 | got, wrote, err := server.RenameChatTitle(ctx, stored, "renamed") |
| 750 | require.NoError(t, err) |
| 751 | require.True(t, wrote, "fresh rename must report wrote=true") |
| 752 | require.Equal(t, updated, got) |
nothing calls this directly
no test coverage detected