mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:38:27 +00:00
refactor: move dmHistoryLimit to provider-level config
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
applyGoogleTurnOrderingFix,
|
||||
buildEmbeddedSandboxInfo,
|
||||
createSystemPromptOverride,
|
||||
getDmHistoryLimitFromSessionKey,
|
||||
limitHistoryTurns,
|
||||
runEmbeddedPiAgent,
|
||||
splitSdkTools,
|
||||
@@ -370,6 +371,68 @@ describe("limitHistoryTurns", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getDmHistoryLimitFromSessionKey", () => {
|
||||
it("returns undefined when sessionKey is undefined", () => {
|
||||
expect(getDmHistoryLimitFromSessionKey(undefined, {})).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns undefined when config is undefined", () => {
|
||||
expect(
|
||||
getDmHistoryLimitFromSessionKey("telegram:dm:123", undefined),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns dmHistoryLimit for telegram provider", () => {
|
||||
const config = { telegram: { dmHistoryLimit: 15 } } as ClawdbotConfig;
|
||||
expect(getDmHistoryLimitFromSessionKey("telegram:dm:123", config)).toBe(15);
|
||||
});
|
||||
|
||||
it("returns dmHistoryLimit for whatsapp provider", () => {
|
||||
const config = { whatsapp: { dmHistoryLimit: 20 } } as ClawdbotConfig;
|
||||
expect(getDmHistoryLimitFromSessionKey("whatsapp:dm:123", config)).toBe(20);
|
||||
});
|
||||
|
||||
it("returns dmHistoryLimit for agent-prefixed session keys", () => {
|
||||
const config = { telegram: { dmHistoryLimit: 10 } } as ClawdbotConfig;
|
||||
expect(
|
||||
getDmHistoryLimitFromSessionKey("agent:main:telegram:dm:123", config),
|
||||
).toBe(10);
|
||||
});
|
||||
|
||||
it("returns undefined for unknown provider", () => {
|
||||
const config = { telegram: { dmHistoryLimit: 15 } } as ClawdbotConfig;
|
||||
expect(
|
||||
getDmHistoryLimitFromSessionKey("unknown:dm:123", config),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns undefined when provider config has no dmHistoryLimit", () => {
|
||||
const config = { telegram: {} } as ClawdbotConfig;
|
||||
expect(
|
||||
getDmHistoryLimitFromSessionKey("telegram:dm:123", config),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("handles all supported providers", () => {
|
||||
const providers = [
|
||||
"telegram",
|
||||
"whatsapp",
|
||||
"discord",
|
||||
"slack",
|
||||
"signal",
|
||||
"imessage",
|
||||
"msteams",
|
||||
] as const;
|
||||
|
||||
for (const provider of providers) {
|
||||
const config = { [provider]: { dmHistoryLimit: 5 } } as ClawdbotConfig;
|
||||
expect(
|
||||
getDmHistoryLimitFromSessionKey(`${provider}:dm:123`, config),
|
||||
).toBe(5);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("runEmbeddedPiAgent", () => {
|
||||
it("writes models.json into the provided agentDir", async () => {
|
||||
const agentDir = await fs.mkdtemp(
|
||||
|
||||
Reference in New Issue
Block a user