fix: scope history injection to pending-only

This commit is contained in:
Peter Steinberger
2026-01-16 23:52:14 +00:00
parent 56ed5cc2d9
commit e31251293b
21 changed files with 278 additions and 175 deletions

View File

@@ -4,6 +4,7 @@ import {
buildHistoryContext,
buildHistoryContextFromEntries,
buildHistoryContextFromMap,
buildPendingHistoryContextFromMap,
HISTORY_CONTEXT_MARKER,
} from "./history.js";
import { CURRENT_MESSAGE_MARKER } from "./mentions.js";
@@ -81,4 +82,27 @@ describe("history helpers", () => {
expect(result).toContain("B: two");
expect(result).not.toContain("C: three");
});
it("builds context from pending map without appending", () => {
const historyMap = new Map<string, { sender: string; body: string }[]>();
historyMap.set("room", [
{ sender: "A", body: "one" },
{ sender: "B", body: "two" },
]);
const result = buildPendingHistoryContextFromMap({
historyMap,
historyKey: "room",
limit: 3,
currentMessage: "current",
formatEntry: (entry) => `${entry.sender}: ${entry.body}`,
});
expect(historyMap.get("room")?.map((entry) => entry.body)).toEqual(["one", "two"]);
expect(result).toContain(HISTORY_CONTEXT_MARKER);
expect(result).toContain("A: one");
expect(result).toContain("B: two");
expect(result).toContain(CURRENT_MESSAGE_MARKER);
expect(result).toContain("current");
});
});