mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-22 11:08:11 +00:00
Merge branch 'main' into feature/goals-souvenir-health
This commit is contained in:
@@ -780,27 +780,15 @@ describe("resolveResponsePrefixTemplate", () => {
|
||||
describe("extractShortModelName", () => {
|
||||
it("strips provider prefix", () => {
|
||||
expect(extractShortModelName("openai/gpt-5.2")).toBe("gpt-5.2");
|
||||
expect(extractShortModelName("anthropic/claude-opus-4-5")).toBe("claude-opus-4-5");
|
||||
expect(extractShortModelName("openai-codex/gpt-5.2-codex")).toBe("gpt-5.2-codex");
|
||||
});
|
||||
|
||||
it("strips date suffix", () => {
|
||||
expect(extractShortModelName("claude-opus-4-5-20251101")).toBe("claude-opus-4-5");
|
||||
expect(extractShortModelName("gpt-5.2-20250115")).toBe("gpt-5.2");
|
||||
});
|
||||
|
||||
it("strips -latest suffix", () => {
|
||||
expect(extractShortModelName("gpt-5.2-latest")).toBe("gpt-5.2");
|
||||
expect(extractShortModelName("claude-sonnet-latest")).toBe("claude-sonnet");
|
||||
});
|
||||
|
||||
it("handles model without provider", () => {
|
||||
expect(extractShortModelName("gpt-5.2")).toBe("gpt-5.2");
|
||||
expect(extractShortModelName("claude-opus-4-5")).toBe("claude-opus-4-5");
|
||||
});
|
||||
|
||||
it("handles full path with provider and date suffix", () => {
|
||||
expect(extractShortModelName("anthropic/claude-opus-4-5-20251101")).toBe("claude-opus-4-5");
|
||||
});
|
||||
|
||||
it("preserves version numbers that look like dates but are not", () => {
|
||||
@@ -811,28 +799,10 @@ describe("extractShortModelName", () => {
|
||||
});
|
||||
|
||||
describe("hasTemplateVariables", () => {
|
||||
it("returns false for undefined", () => {
|
||||
expect(hasTemplateVariables(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for empty string", () => {
|
||||
expect(hasTemplateVariables("")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for static prefix", () => {
|
||||
expect(hasTemplateVariables("[Claude]")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns true when template variables present", () => {
|
||||
expect(hasTemplateVariables("[{model}]")).toBe(true);
|
||||
expect(hasTemplateVariables("{provider}")).toBe(true);
|
||||
expect(hasTemplateVariables("prefix {thinkingLevel} suffix")).toBe(true);
|
||||
});
|
||||
|
||||
it("returns true for multiple variables", () => {
|
||||
expect(hasTemplateVariables("[{model} | {provider}]")).toBe(true);
|
||||
});
|
||||
|
||||
it("handles consecutive calls correctly (regex lastIndex reset)", () => {
|
||||
// First call
|
||||
expect(hasTemplateVariables("[{model}]")).toBe(true);
|
||||
|
||||
@@ -86,42 +86,6 @@ describe("Integration: saveSessionStore with pruning", () => {
|
||||
expect(loaded.fresh).toBeDefined();
|
||||
});
|
||||
|
||||
it("saveSessionStore rotates file when over size limit and creates .bak", async () => {
|
||||
mockLoadConfig.mockReturnValue({
|
||||
session: {
|
||||
maintenance: {
|
||||
mode: "enforce",
|
||||
pruneAfter: "30d",
|
||||
maxEntries: 500,
|
||||
rotateBytes: "100b",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const now = Date.now();
|
||||
const largeStore: Record<string, SessionEntry> = {};
|
||||
for (let i = 0; i < 50; i++) {
|
||||
largeStore[`agent:main:session-${crypto.randomUUID()}`] = makeEntry(now - i * 1000);
|
||||
}
|
||||
await fs.mkdir(path.dirname(storePath), { recursive: true });
|
||||
await fs.writeFile(storePath, JSON.stringify(largeStore, null, 2), "utf-8");
|
||||
|
||||
const statBefore = await fs.stat(storePath);
|
||||
expect(statBefore.size).toBeGreaterThan(100);
|
||||
|
||||
const smallStore: Record<string, SessionEntry> = {
|
||||
only: makeEntry(now),
|
||||
};
|
||||
await saveSessionStore(storePath, smallStore);
|
||||
|
||||
const files = await fs.readdir(testDir);
|
||||
const bakFiles = files.filter((f) => f.startsWith("sessions.json.bak."));
|
||||
expect(bakFiles.length).toBeGreaterThanOrEqual(1);
|
||||
|
||||
const loaded = loadSessionStore(storePath);
|
||||
expect(loaded.only).toBeDefined();
|
||||
});
|
||||
|
||||
it("saveSessionStore skips enforcement when maintenance mode is warn", async () => {
|
||||
mockLoadConfig.mockReturnValue({
|
||||
session: {
|
||||
|
||||
@@ -287,24 +287,6 @@ describe("resolveHeartbeatDeliveryTarget", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps WhatsApp group targets even with allowFrom set", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
channels: { whatsapp: { allowFrom: ["+1555"] } },
|
||||
};
|
||||
const entry = {
|
||||
...baseEntry,
|
||||
lastChannel: "whatsapp" as const,
|
||||
lastTo: "120363401234567890@g.us",
|
||||
};
|
||||
expect(resolveHeartbeatDeliveryTarget({ cfg, entry })).toEqual({
|
||||
channel: "whatsapp",
|
||||
to: "120363401234567890@g.us",
|
||||
accountId: undefined,
|
||||
lastChannel: "whatsapp",
|
||||
lastAccountId: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("normalizes prefixed WhatsApp group targets for heartbeat delivery", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
channels: { whatsapp: { allowFrom: ["+1555"] } },
|
||||
@@ -323,19 +305,6 @@ describe("resolveHeartbeatDeliveryTarget", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps explicit telegram targets", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: { defaults: { heartbeat: { target: "telegram", to: "123" } } },
|
||||
};
|
||||
expect(resolveHeartbeatDeliveryTarget({ cfg, entry: baseEntry })).toEqual({
|
||||
channel: "telegram",
|
||||
to: "123",
|
||||
accountId: undefined,
|
||||
lastChannel: undefined,
|
||||
lastAccountId: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("uses explicit heartbeat accountId when provided", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
@@ -1124,73 +1093,6 @@ describe("runHeartbeatOnce", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("does not skip hook-triggered heartbeat when HEARTBEAT.md is effectively empty", async () => {
|
||||
const tmpDir = await createCaseDir("openclaw-hb");
|
||||
const storePath = path.join(tmpDir, "sessions.json");
|
||||
const workspaceDir = path.join(tmpDir, "workspace");
|
||||
const replySpy = vi.spyOn(replyModule, "getReplyFromConfig");
|
||||
try {
|
||||
await fs.mkdir(workspaceDir, { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(workspaceDir, "HEARTBEAT.md"),
|
||||
"# HEARTBEAT.md\n\n## Tasks\n\n",
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
defaults: {
|
||||
workspace: workspaceDir,
|
||||
heartbeat: { every: "5m", target: "whatsapp" },
|
||||
},
|
||||
},
|
||||
channels: { whatsapp: { allowFrom: ["*"] } },
|
||||
session: { store: storePath },
|
||||
};
|
||||
const sessionKey = resolveMainSessionKey(cfg);
|
||||
|
||||
await fs.writeFile(
|
||||
storePath,
|
||||
JSON.stringify(
|
||||
{
|
||||
[sessionKey]: {
|
||||
sessionId: "sid",
|
||||
updatedAt: Date.now(),
|
||||
lastChannel: "whatsapp",
|
||||
lastTo: "+1555",
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
|
||||
replySpy.mockResolvedValue({ text: "hook event processed" });
|
||||
const sendWhatsApp = vi.fn().mockResolvedValue({
|
||||
messageId: "m1",
|
||||
toJid: "jid",
|
||||
});
|
||||
|
||||
const res = await runHeartbeatOnce({
|
||||
cfg,
|
||||
reason: "hook:wake",
|
||||
deps: {
|
||||
sendWhatsApp,
|
||||
getQueueSize: () => 0,
|
||||
nowMs: () => 0,
|
||||
webAuthExists: async () => true,
|
||||
hasActiveWebListener: () => true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.status).toBe("ran");
|
||||
expect(replySpy).toHaveBeenCalled();
|
||||
expect(sendWhatsApp).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
replySpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("runs heartbeat when HEARTBEAT.md has actionable content", async () => {
|
||||
const tmpDir = await createCaseDir("openclaw-hb");
|
||||
const storePath = path.join(tmpDir, "sessions.json");
|
||||
|
||||
Reference in New Issue
Block a user