refactor: centralize history context wrapping
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
appendHistoryEntry,
|
||||
buildHistoryContext,
|
||||
buildHistoryContextFromEntries,
|
||||
buildHistoryContextFromMap,
|
||||
HISTORY_CONTEXT_MARKER,
|
||||
} from "./history.js";
|
||||
import { CURRENT_MESSAGE_MARKER } from "./mentions.js";
|
||||
@@ -60,4 +61,31 @@ describe("history helpers", () => {
|
||||
"three",
|
||||
]);
|
||||
});
|
||||
|
||||
it("builds context from map and appends entry", () => {
|
||||
const historyMap = new Map<string, { sender: string; body: string }[]>();
|
||||
historyMap.set("room", [
|
||||
{ sender: "A", body: "one" },
|
||||
{ sender: "B", body: "two" },
|
||||
]);
|
||||
|
||||
const result = buildHistoryContextFromMap({
|
||||
historyMap,
|
||||
historyKey: "room",
|
||||
limit: 3,
|
||||
entry: { sender: "C", body: "three" },
|
||||
currentMessage: "current",
|
||||
formatEntry: (entry) => `${entry.sender}: ${entry.body}`,
|
||||
});
|
||||
|
||||
expect(historyMap.get("room")?.map((entry) => entry.body)).toEqual([
|
||||
"one",
|
||||
"two",
|
||||
"three",
|
||||
]);
|
||||
expect(result).toContain(HISTORY_CONTEXT_MARKER);
|
||||
expect(result).toContain("A: one");
|
||||
expect(result).toContain("B: two");
|
||||
expect(result).not.toContain("C: three");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user