feat(agents): add unarchive agent support (#22579)

This commit is contained in:
Danielle Maywood
2026-03-04 14:08:12 +00:00
committed by GitHub
parent 8c09df52f9
commit 90f686d684
10 changed files with 270 additions and 32 deletions
+89
View File
@@ -1292,6 +1292,95 @@ func TestArchiveChat(t *testing.T) {
})
}
func TestUnarchiveChat(t *testing.T) {
t.Parallel()
t.Run("Success", func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitLong)
client := newChatClient(t)
_ = coderdtest.CreateFirstUser(t, client)
_ = createChatModelConfig(t, client)
chat, err := client.CreateChat(ctx, codersdk.CreateChatRequest{
Content: []codersdk.ChatInputPart{
{
Type: codersdk.ChatInputPartTypeText,
Text: "archive then unarchive me",
},
},
})
require.NoError(t, err)
// Archive the chat first.
err = client.ArchiveChat(ctx, chat.ID)
require.NoError(t, err)
// Verify it's archived.
archivedChats, err := client.ListChats(ctx, &codersdk.ListChatsOptions{
Archived: ptr.Ref(true),
})
require.NoError(t, err)
require.Len(t, archivedChats, 1)
require.True(t, archivedChats[0].Archived)
// Unarchive the chat.
err = client.UnarchiveChat(ctx, chat.ID)
require.NoError(t, err)
// Verify it's no longer archived.
activeChats, err := client.ListChats(ctx, &codersdk.ListChatsOptions{
Archived: ptr.Ref(false),
})
require.NoError(t, err)
require.Len(t, activeChats, 1)
require.Equal(t, chat.ID, activeChats[0].ID)
require.False(t, activeChats[0].Archived)
// No archived chats remain.
archivedChats, err = client.ListChats(ctx, &codersdk.ListChatsOptions{
Archived: ptr.Ref(true),
})
require.NoError(t, err)
require.Empty(t, archivedChats)
})
t.Run("NotArchived", func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitLong)
client := newChatClient(t)
_ = coderdtest.CreateFirstUser(t, client)
_ = createChatModelConfig(t, client)
chat, err := client.CreateChat(ctx, codersdk.CreateChatRequest{
Content: []codersdk.ChatInputPart{
{
Type: codersdk.ChatInputPartTypeText,
Text: "not archived",
},
},
})
require.NoError(t, err)
// Trying to unarchive a non-archived chat should fail.
err = client.UnarchiveChat(ctx, chat.ID)
requireSDKError(t, err, http.StatusBadRequest)
})
t.Run("NotFound", func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitLong)
client := newChatClient(t)
_ = coderdtest.CreateFirstUser(t, client)
err := client.UnarchiveChat(ctx, uuid.New())
requireSDKError(t, err, http.StatusNotFound)
})
}
func TestPostChatMessages(t *testing.T) {
t.Parallel()