(t *testing.T)
| 1544 | } |
| 1545 | |
| 1546 | func TestArchiveChatMovesPendingChatToWaiting(t *testing.T) { |
| 1547 | t.Parallel() |
| 1548 | |
| 1549 | db, ps := dbtestutil.NewDB(t) |
| 1550 | replica := newTestServer(t, db, ps, uuid.New()) |
| 1551 | |
| 1552 | ctx := testutil.Context(t, testutil.WaitLong) |
| 1553 | user, org, model := seedChatDependencies(t, db) |
| 1554 | |
| 1555 | chat, err := replica.CreateChat(ctx, chatd.CreateOptions{ |
| 1556 | OwnerID: user.ID, |
| 1557 | OrganizationID: org.ID, |
| 1558 | Title: "archive-pending", |
| 1559 | ModelConfigID: model.ID, |
| 1560 | InitialUserContent: []codersdk.ChatMessagePart{codersdk.ChatMessageText("hello")}, |
| 1561 | }) |
| 1562 | require.NoError(t, err) |
| 1563 | |
| 1564 | chat, err = db.UpdateChatStatus(ctx, database.UpdateChatStatusParams{ |
| 1565 | ID: chat.ID, |
| 1566 | Status: database.ChatStatusPending, |
| 1567 | WorkerID: uuid.NullUUID{}, |
| 1568 | StartedAt: sql.NullTime{}, |
| 1569 | HeartbeatAt: sql.NullTime{}, |
| 1570 | LastError: pqtype.NullRawMessage{}, |
| 1571 | }) |
| 1572 | require.NoError(t, err) |
| 1573 | |
| 1574 | err = replica.ArchiveChat(ctx, chat) |
| 1575 | require.NoError(t, err) |
| 1576 | |
| 1577 | fromDB, err := db.GetChatByID(ctx, chat.ID) |
| 1578 | require.NoError(t, err) |
| 1579 | require.Equal(t, database.ChatStatusWaiting, fromDB.Status) |
| 1580 | require.False(t, fromDB.WorkerID.Valid) |
| 1581 | require.False(t, fromDB.StartedAt.Valid) |
| 1582 | require.False(t, fromDB.HeartbeatAt.Valid) |
| 1583 | require.True(t, fromDB.Archived) |
| 1584 | require.Zero(t, fromDB.PinOrder) |
| 1585 | } |
| 1586 | |
| 1587 | // TestUnarchiveChildChat covers the deterministic branches of the |
| 1588 | // Server.UnarchiveChat child path: happy path, archived-parent reject, |
nothing calls this directly
no test coverage detected