File size: 3,031 Bytes
3d700dd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | import { describe, expect, it } from "vitest";
import { QueryClient } from "@tanstack/react-query";
import {
updateConversationExecutionStatusInCache,
updateConversationLlmModelInCache,
} from "./conversation-mutation-utils";
import { ExecutionStatus } from "#/types/agent-server/core/base/common";
import { AppConversation } from "#/api/conversation-service/agent-server-conversation-service.types";
const createConversation = (): AppConversation => ({
id: "conversation-1",
created_by_user_id: null,
selected_repository: null,
selected_branch: null,
git_provider: null,
title: "Test conversation",
trigger: null,
pr_number: [],
llm_model: null,
metrics: null,
created_at: "2026-04-16T00:00:00Z",
updated_at: "2026-04-16T00:00:00Z",
execution_status: ExecutionStatus.RUNNING,
conversation_url: "http://localhost:3000/api/conversations/conversation-1",
session_api_key: "session-key",
sandbox_id: null,
sub_conversation_ids: [],
});
describe("updateConversationExecutionStatusInCache", () => {
it("updates the active conversation execution_status field", () => {
const queryClient = new QueryClient();
const conversation = createConversation();
queryClient.setQueryData(
["user", "conversation", conversation.id],
conversation,
);
updateConversationExecutionStatusInCache(
queryClient,
conversation.id,
ExecutionStatus.PAUSED,
);
expect(
queryClient.getQueryData<AppConversation | null>([
"user",
"conversation",
conversation.id,
]),
).toMatchObject({
execution_status: ExecutionStatus.PAUSED,
});
});
});
describe("updateConversationLlmModelInCache", () => {
it("updates active conversation and list cache entries", () => {
const queryClient = new QueryClient();
const conversation = createConversation();
const otherConversation = { ...createConversation(), id: "conversation-2" };
queryClient.setQueryData(
["user", "conversation", conversation.id, "backend-1", null],
conversation,
);
queryClient.setQueryData(["user", "conversations"], {
pages: [
{
items: [conversation, otherConversation],
},
],
});
updateConversationLlmModelInCache(
queryClient,
conversation.id,
"anthropic/claude-haiku-4-5",
);
expect(
queryClient.getQueryData<AppConversation | null>([
"user",
"conversation",
conversation.id,
"backend-1",
null,
]),
).toMatchObject({
llm_model: "anthropic/claude-haiku-4-5",
});
expect(
queryClient.getQueryData<{
pages: Array<{ items: AppConversation[] }>;
}>(["user", "conversations"])?.pages[0].items,
).toEqual([
expect.objectContaining({
id: conversation.id,
llm_model: "anthropic/claude-haiku-4-5",
}),
expect.objectContaining({
id: otherConversation.id,
llm_model: null,
}),
]);
});
});
|