(t *testing.T)
| 9602 | } |
| 9603 | |
| 9604 | func TestAcquireChatsSkipsArchivedPendingChat(t *testing.T) { |
| 9605 | t.Parallel() |
| 9606 | |
| 9607 | db, ps := dbtestutil.NewDB(t) |
| 9608 | _ = newTestServer(t, db, ps, uuid.New()) |
| 9609 | |
| 9610 | ctx := testutil.Context(t, testutil.WaitLong) |
| 9611 | user, org, model := seedChatDependencies(t, db) |
| 9612 | |
| 9613 | archivedChat := dbgen.Chat(t, db, database.Chat{ |
| 9614 | OwnerID: user.ID, |
| 9615 | OrganizationID: org.ID, |
| 9616 | Title: "acquire-skip-archived", |
| 9617 | LastModelConfigID: model.ID, |
| 9618 | }) |
| 9619 | |
| 9620 | // Archive the chat, then force it to pending. |
| 9621 | _, err := db.ArchiveChatByID(ctx, archivedChat.ID) |
| 9622 | require.NoError(t, err) |
| 9623 | |
| 9624 | _, err = db.UpdateChatStatus(ctx, database.UpdateChatStatusParams{ |
| 9625 | ID: archivedChat.ID, |
| 9626 | Status: database.ChatStatusPending, |
| 9627 | }) |
| 9628 | require.NoError(t, err) |
| 9629 | |
| 9630 | // Insert a second, non-archived pending chat so the result |
| 9631 | // slice is non-empty and the assertion is not vacuously true. |
| 9632 | activeChat := dbgen.Chat(t, db, database.Chat{ |
| 9633 | OwnerID: user.ID, |
| 9634 | OrganizationID: org.ID, |
| 9635 | Title: "acquire-active", |
| 9636 | LastModelConfigID: model.ID, |
| 9637 | Status: database.ChatStatusPending, |
| 9638 | }) |
| 9639 | |
| 9640 | now := time.Now() |
| 9641 | acquired, err := db.AcquireChats(ctx, database.AcquireChatsParams{ |
| 9642 | WorkerID: uuid.New(), |
| 9643 | StartedAt: now, |
| 9644 | NumChats: 10, |
| 9645 | }) |
| 9646 | require.NoError(t, err) |
| 9647 | require.Len(t, acquired, 1, "only the non-archived chat should be acquired") |
| 9648 | require.Equal(t, activeChat.ID, acquired[0].ID) |
| 9649 | } |
| 9650 | |
| 9651 | func TestAdvisorGating_Disabled(t *testing.T) { |
| 9652 | t.Parallel() |
nothing calls this directly
no test coverage detected