Files
openclaw/extensions/telegram/src/session-transcript-context.test.ts
mikasa ec7a548062 fix #95378: https://github.com/openclaw/openclaw/issues/95378 (#95390)
* fix(telegram): use session transcript for direct context

* fix(telegram): account for proof and SDK checks

* fix(telegram): address review findings

* fix(telegram): tighten session transcript context

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
2026-06-22 04:29:44 +05:30

85 lines
2.5 KiB
TypeScript

import { readRecentUserAssistantTextForSession } from "openclaw/plugin-sdk/session-store-runtime";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { buildTelegramSessionTranscriptPromptMessages } from "./session-transcript-context.js";
vi.mock("openclaw/plugin-sdk/session-store-runtime", () => ({
readRecentUserAssistantTextForSession: vi.fn(),
}));
const readRecentUserAssistantTextForSessionMock = vi.mocked(readRecentUserAssistantTextForSession);
describe("buildTelegramSessionTranscriptPromptMessages", () => {
beforeEach(() => {
readRecentUserAssistantTextForSessionMock.mockReset();
});
it("maps shared session turns into chronological Telegram prompt messages", async () => {
readRecentUserAssistantTextForSessionMock.mockResolvedValue([
{
id: "u1",
role: "user",
text: "Analyze this chart",
timestamp: 1_000,
sourceChannel: "gateway",
},
{
id: "a1",
role: "assistant",
text: "The chart is range-bound; want an alert?",
timestamp: 2_000,
},
]);
await expect(
buildTelegramSessionTranscriptPromptMessages({
agentId: "main",
sessionKey: "agent:main:main",
storePath: "/tmp/sessions.json",
beforeTimestampMs: 3_000,
limit: 10,
}),
).resolves.toEqual([
{
message_id: "session:u1",
sender: "User (gateway)",
timestamp_ms: 1_000,
body: "Analyze this chart",
source_channel: "gateway",
},
{
message_id: "session:a1",
sender: "OpenClaw",
timestamp_ms: 2_000,
body: "The chart is range-bound; want an alert?",
},
]);
expect(readRecentUserAssistantTextForSessionMock).toHaveBeenCalledWith({
agentId: "main",
sessionKey: "agent:main:main",
storePath: "/tmp/sessions.json",
limit: 10,
beforeTimestampMs: 3_000,
});
});
it("forwards topic-enabled DM session keys unchanged to the SDK reader", async () => {
readRecentUserAssistantTextForSessionMock.mockResolvedValue([]);
await buildTelegramSessionTranscriptPromptMessages({
agentId: "main",
sessionKey: "agent:main:main:thread:1234:42",
storePath: "/tmp/sessions.json",
beforeTimestampMs: 5_000,
limit: 10,
});
expect(readRecentUserAssistantTextForSessionMock).toHaveBeenCalledWith({
agentId: "main",
sessionKey: "agent:main:main:thread:1234:42",
storePath: "/tmp/sessions.json",
limit: 10,
beforeTimestampMs: 5_000,
});
});
});