Files
Jyotisha/frontend/tests/consultation-session-history.test.ts
T
Jesse_Chen b6989c3eea
Independent Staging Quality Gate / validate (push) Has been cancelled
Independent Staging Quality Gate / publish (push) Has been cancelled
fix(chat): make the server the only writer of session messages
List GET no longer ships transcripts; consult appends questions after reserve and ignores client history so dual-tab last-write-wins cannot erase messages.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-01 19:51:19 +08:00

32 lines
1.2 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { consultationHistoryFromStoredMessages } from "../src/lib/consultation-session-history.ts";
test("stored consultation history keeps the last 12 role/text pairs and clips text", () => {
const history = consultationHistoryFromStoredMessages([
{ role: "system", text: "ignore" },
{ role: "user", text: "first" },
...Array.from({ length: 12 }, (_, index) => ({
role: index % 2 === 0 ? "assistant" : "user",
text: `keep-${index}`,
requestId: `req-${index}`,
})),
{ role: "assistant", text: "x".repeat(4001), thinkingText: "secret" },
]);
assert.equal(history.length, 12);
assert.equal(history[0]?.text, "keep-1");
assert.equal(history.at(-1)?.text.length, 4000);
assert.deepEqual(history.at(-2), { role: "user", text: "keep-11" });
});
test("stored consultation history can skip the in-flight request id", () => {
const history = consultationHistoryFromStoredMessages([
{ role: "user", text: "old", requestId: "keep" },
{ role: "user", text: "current", requestId: "skip" },
], { excludeRequestId: "skip" });
assert.deepEqual(history, [{ role: "user", text: "old" }]);
});