mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 04:17:27 +00:00
test(session): cover stale threadId fallback
This commit is contained in:
@@ -2,8 +2,8 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { buildModelAliasIndex } from "../../agents/model-selection.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { buildModelAliasIndex } from "../../agents/model-selection.js";
|
||||
import { saveSessionStore } from "../../config/sessions.js";
|
||||
import { formatZonedTimestamp } from "../../infra/format-time/format-datetime.ts";
|
||||
import { enqueueSystemEvent, resetSystemEventsForTest } from "../../infra/system-events.js";
|
||||
@@ -1294,6 +1294,54 @@ describe("persistSessionUsageUpdate", () => {
|
||||
});
|
||||
|
||||
describe("initSessionState stale threadId fallback", () => {
|
||||
async function seedSessionStore(params: {
|
||||
storePath: string;
|
||||
sessionKey: string;
|
||||
entry: Record<string, unknown>;
|
||||
}) {
|
||||
await fs.mkdir(path.dirname(params.storePath), { recursive: true });
|
||||
await fs.writeFile(
|
||||
params.storePath,
|
||||
JSON.stringify({ [params.sessionKey]: params.entry }, null, 2),
|
||||
"utf-8",
|
||||
);
|
||||
}
|
||||
|
||||
it("ignores persisted lastThreadId on main sessions for non-thread messages", async () => {
|
||||
const storePath = await createStorePath("stale-main-thread-");
|
||||
const sessionKey = "agent:main:main";
|
||||
await seedSessionStore({
|
||||
storePath,
|
||||
sessionKey,
|
||||
entry: {
|
||||
sessionId: "s1",
|
||||
updatedAt: Date.now(),
|
||||
lastChannel: "telegram",
|
||||
lastTo: "telegram:123",
|
||||
lastThreadId: 42,
|
||||
deliveryContext: {
|
||||
channel: "telegram",
|
||||
to: "telegram:123",
|
||||
threadId: 42,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const cfg = { session: { store: storePath } } as OpenClawConfig;
|
||||
|
||||
const result = await initSessionState({
|
||||
ctx: {
|
||||
Body: "hello from DM",
|
||||
SessionKey: sessionKey,
|
||||
},
|
||||
cfg,
|
||||
commandAuthorized: true,
|
||||
});
|
||||
|
||||
expect(result.sessionEntry.lastThreadId).toBeUndefined();
|
||||
expect(result.sessionEntry.deliveryContext?.threadId).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not inherit lastThreadId from a previous thread interaction in non-thread sessions", async () => {
|
||||
const storePath = await createStorePath("stale-thread-");
|
||||
const cfg = { session: { store: storePath } } as OpenClawConfig;
|
||||
|
||||
Reference in New Issue
Block a user