mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 20:05:46 -06:00
73bba03e4c
* refactor: canonicalize session delivery state * test: canonicalize reply persistence fixtures * test: canonicalize talk delivery fixtures * test: canonicalize voice session routes * test: canonicalize attachment delivery fixtures * test: migrate gateway delivery fixtures * fix: skip invalid session delivery rows * test: align delivery SDK surface gates * fix: preserve legacy delivery precedence * test: canonicalize heartbeat delivery fixtures * fix: preserve delivery route prompt identity * test: canonicalize session delivery fixtures * fix: preserve recoverable legacy delivery routes * fix: canonicalize remaining session state * fix: preserve canonical session classification * style: format delivery state changes * test: refresh plugin SDK delivery baseline * test: avoid mutating session fixture input * style: simplify delivery identity check * style: simplify delivery origin spread * fix: preserve fresh delivery route metadata * test: assert canonical surface route switch * fix: canonicalize doctor file-store imports * fix: preserve transitional delivery migration state * fix: satisfy canonical delivery CI gates * ci: scope GitHub App token permissions * test: infer canonical delivery projections * test: canonicalize ACP requester delivery fixtures * test: canonicalize harness rollback fixture * style: apply pinned formatter
132 lines
4.0 KiB
TypeScript
132 lines
4.0 KiB
TypeScript
// Telegram plugin module implements bot message context.session recreate support behavior.
|
|
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
import {
|
|
clearRuntimeConfigSnapshot,
|
|
setRuntimeConfigSnapshot,
|
|
} from "openclaw/plugin-sdk/runtime-config-snapshot";
|
|
import {
|
|
deleteSessionEntry,
|
|
normalizeSessionDeliveryState,
|
|
getSessionEntry,
|
|
upsertSessionEntry,
|
|
} from "openclaw/plugin-sdk/session-store-runtime";
|
|
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
|
|
import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
import { buildTelegramMessageContextForTest } from "./bot-message-context.test-harness.js";
|
|
|
|
const TELEGRAM_DIRECT_KEY = "agent:main:telegram:direct:7463849194";
|
|
|
|
function createSuiteTempRootTracker(params: { prefix: string }) {
|
|
let root: string | undefined;
|
|
const children: string[] = [];
|
|
return {
|
|
async setup() {
|
|
root = await fs.mkdtemp(path.join(resolvePreferredOpenClawTmpDir(), params.prefix));
|
|
},
|
|
async make(name: string) {
|
|
if (!root) {
|
|
throw new Error("temp root not initialized");
|
|
}
|
|
const child = path.join(root, name);
|
|
await fs.mkdir(child, { recursive: true });
|
|
children.push(child);
|
|
return child;
|
|
},
|
|
async cleanup() {
|
|
await Promise.all(
|
|
children.splice(0).map((child) => fs.rm(child, { force: true, recursive: true })),
|
|
);
|
|
if (root) {
|
|
await fs.rm(root, { force: true, recursive: true });
|
|
root = undefined;
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("Telegram direct session recreation after delete", () => {
|
|
const suiteRootTracker = createSuiteTempRootTracker({
|
|
prefix: "openclaw-telegram-context-recreate-",
|
|
});
|
|
|
|
beforeAll(async () => {
|
|
await suiteRootTracker.setup();
|
|
});
|
|
|
|
afterEach(() => {
|
|
clearRuntimeConfigSnapshot();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await suiteRootTracker.cleanup();
|
|
});
|
|
|
|
it("records a deleted direct session again when the next DM is processed", async () => {
|
|
const tempDir = await suiteRootTracker.make("direct");
|
|
const storePath = path.join(tempDir, "sessions.json");
|
|
const cfg = {
|
|
agents: {
|
|
defaults: {
|
|
model: "openai/gpt-5.4",
|
|
workspace: "/tmp/openclaw",
|
|
},
|
|
},
|
|
channels: { telegram: {} },
|
|
messages: { groupChat: { mentionPatterns: [] } },
|
|
session: {
|
|
dmScope: "per-channel-peer" as const,
|
|
store: storePath,
|
|
},
|
|
};
|
|
setRuntimeConfigSnapshot(cfg as never);
|
|
await upsertSessionEntry({
|
|
storePath,
|
|
sessionKey: TELEGRAM_DIRECT_KEY,
|
|
entry: {
|
|
sessionId: "old-session",
|
|
updatedAt: 1_700_000_000_000,
|
|
chatType: "direct",
|
|
delivery: normalizeSessionDeliveryState({ context: { channel: "telegram" } }),
|
|
},
|
|
});
|
|
await deleteSessionEntry({ storePath, sessionKey: TELEGRAM_DIRECT_KEY });
|
|
|
|
const context = await buildTelegramMessageContextForTest({
|
|
cfg,
|
|
message: {
|
|
message_id: 2,
|
|
chat: { id: 7463849194, type: "private" },
|
|
date: 1_700_000_001,
|
|
text: "hello again",
|
|
from: { id: 7463849194, first_name: "Alice" },
|
|
},
|
|
sessionRuntime: null,
|
|
});
|
|
expect(context).not.toBeNull();
|
|
await context?.turn.recordInboundSession({
|
|
storePath: context.turn.storePath,
|
|
sessionKey: context.ctxPayload.SessionKey,
|
|
ctx: context.ctxPayload as never,
|
|
updateLastRoute: context.turn.record.updateLastRoute,
|
|
onRecordError: context.turn.record.onRecordError,
|
|
});
|
|
|
|
const entry = getSessionEntry({ storePath, sessionKey: TELEGRAM_DIRECT_KEY });
|
|
expect(context?.ctxPayload?.SessionKey).toBe(TELEGRAM_DIRECT_KEY);
|
|
expect(entry?.delivery).toEqual(
|
|
expect.objectContaining({
|
|
kind: "external",
|
|
context: expect.objectContaining({
|
|
channel: "telegram",
|
|
to: "telegram:7463849194",
|
|
}),
|
|
origin: expect.objectContaining({
|
|
provider: "telegram",
|
|
chatType: "direct",
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
});
|