重建会话记录逻辑

This commit is contained in:
2026-06-04 15:26:23 +08:00
parent 0ecb2babf3
commit 0188240d62
9 changed files with 375 additions and 42 deletions
+22
View File
@@ -2,6 +2,7 @@ import { describe, expect, it } from "bun:test";
import {
buildPromptWithLearningContext,
extractLatestFrontendTurn,
generateSessionTitle,
shouldGenerateSessionTitle,
} from "../../src/routes/chatSession.js";
@@ -161,3 +162,24 @@ describe("buildPromptWithLearningContext", () => {
expect(prompt).toBe("基于刚才结果继续分析");
});
});
describe("extractLatestFrontendTurn", () => {
it("extracts the latest valid frontend user and assistant turn", () => {
const turn = extractLatestFrontendTurn([
{ role: "user", content: "检查 DMA-2 漏损" },
{
role: "assistant",
content: "DMA-2 夜间最小流量持续抬升。",
progress: [{ id: "tool-dma", phase: "tool" }],
},
{ role: "user", content: "继续分析相邻分区" },
{ role: "assistant", content: "⚠️ **请求已中断**", isError: true },
]);
expect(turn).toEqual({
assistantMessage: "DMA-2 夜间最小流量持续抬升。",
toolCallCount: 1,
userMessage: "检查 DMA-2 漏损",
});
});
});