实现会话记录项目隔离
This commit is contained in:
@@ -42,6 +42,39 @@ describe("chatStorage backend-only persistence", () => {
|
||||
expect(loaded.title).toBe("已存在会话");
|
||||
});
|
||||
|
||||
it("loads the active remote session from the current project's storage key", async () => {
|
||||
window.localStorage.setItem(
|
||||
"tjwater_agent_active_session_id_v2:project-a",
|
||||
"chat-project-a",
|
||||
);
|
||||
window.localStorage.setItem(
|
||||
"tjwater_agent_active_session_id_v2:project-b",
|
||||
"chat-project-b",
|
||||
);
|
||||
|
||||
apiFetch.mockImplementation(async (url: string) => {
|
||||
if (url.endsWith("/api/v1/agent/chat/session/chat-project-b")) {
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
id: "chat-project-b",
|
||||
title: "项目 B 会话",
|
||||
is_title_manually_edited: false,
|
||||
session_id: "chat-project-b",
|
||||
messages: [],
|
||||
branch_groups: [],
|
||||
}),
|
||||
} as Response;
|
||||
}
|
||||
throw new Error(`Unexpected request ${url}`);
|
||||
});
|
||||
|
||||
const loaded = await loadActiveChatState("project-b");
|
||||
|
||||
expect(loaded.storageSessionId).toBe("chat-project-b");
|
||||
expect(loaded.title).toBe("项目 B 会话");
|
||||
});
|
||||
|
||||
it("creates a backend conversation when saving the first non-empty state", async () => {
|
||||
apiFetch.mockImplementation(async (url: string, init?: RequestInit) => {
|
||||
if (url.endsWith("/api/v1/agent/chat/session")) {
|
||||
@@ -67,26 +100,29 @@ describe("chatStorage backend-only persistence", () => {
|
||||
throw new Error(`Unexpected request ${url}`);
|
||||
});
|
||||
|
||||
const savedSessionId = await saveActiveChatState({
|
||||
storageSessionId: undefined,
|
||||
title: "新对话",
|
||||
isTitleManuallyEdited: false,
|
||||
messages: [
|
||||
{
|
||||
id: "message-2",
|
||||
role: "user",
|
||||
content: "第一条消息",
|
||||
branchRootId: "message-2",
|
||||
},
|
||||
],
|
||||
sessionId: undefined,
|
||||
branchGroups: [],
|
||||
});
|
||||
const savedSessionId = await saveActiveChatState(
|
||||
{
|
||||
storageSessionId: undefined,
|
||||
title: "新对话",
|
||||
isTitleManuallyEdited: false,
|
||||
messages: [
|
||||
{
|
||||
id: "message-2",
|
||||
role: "user",
|
||||
content: "第一条消息",
|
||||
branchRootId: "message-2",
|
||||
},
|
||||
],
|
||||
sessionId: undefined,
|
||||
branchGroups: [],
|
||||
},
|
||||
"project-a",
|
||||
);
|
||||
|
||||
expect(savedSessionId).toBe("chat-new-1");
|
||||
expect(window.localStorage.getItem("tjwater_agent_active_session_id_v2")).toBe(
|
||||
"chat-new-1",
|
||||
);
|
||||
expect(
|
||||
window.localStorage.getItem("tjwater_agent_active_session_id_v2:project-a"),
|
||||
).toBe("chat-new-1");
|
||||
});
|
||||
|
||||
it("does not persist a blank new session before there is chat content", async () => {
|
||||
|
||||
Reference in New Issue
Block a user