2026-01-14 01:08:15 +00:00
|
|
|
import fs from "node:fs/promises";
|
2026-02-23 13:30:47 +00:00
|
|
|
import { tmpdir } from "node:os";
|
2026-01-14 01:08:15 +00:00
|
|
|
import { join } from "node:path";
|
2026-02-22 09:32:41 +00:00
|
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
2026-02-17 14:32:18 +09:00
|
|
|
import type { OpenClawConfig } from "../config/config.js";
|
2026-02-23 13:30:47 +00:00
|
|
|
import { loadSessionStore, resolveSessionKey } from "../config/sessions.js";
|
2026-02-14 18:31:21 +00:00
|
|
|
import {
|
|
|
|
|
getAbortEmbeddedPiRunMock,
|
2026-02-23 13:30:47 +00:00
|
|
|
getCompactEmbeddedPiSessionMock,
|
2026-02-14 18:31:21 +00:00
|
|
|
getRunEmbeddedPiAgentMock,
|
|
|
|
|
installTriggerHandlingE2eTestHooks,
|
|
|
|
|
MAIN_SESSION_KEY,
|
|
|
|
|
makeCfg,
|
2026-02-23 13:30:47 +00:00
|
|
|
mockRunEmbeddedPiAgentOk,
|
|
|
|
|
requireSessionStorePath,
|
2026-02-14 18:31:21 +00:00
|
|
|
withTempHome,
|
|
|
|
|
} from "./reply.triggers.trigger-handling.test-harness.js";
|
2026-02-01 10:03:47 +09:00
|
|
|
import { enqueueFollowupRun, getFollowupQueueDepth, type FollowupRun } from "./reply/queue.js";
|
2026-02-23 13:30:47 +00:00
|
|
|
import { HEARTBEAT_TOKEN } from "./tokens.js";
|
2026-01-14 01:08:15 +00:00
|
|
|
|
2026-02-14 21:57:24 +01:00
|
|
|
let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig;
|
2026-02-22 09:32:41 +00:00
|
|
|
let previousFastTestEnv: string | undefined;
|
2026-02-14 21:57:24 +01:00
|
|
|
beforeAll(async () => {
|
2026-02-22 09:32:41 +00:00
|
|
|
previousFastTestEnv = process.env.OPENCLAW_TEST_FAST;
|
|
|
|
|
process.env.OPENCLAW_TEST_FAST = "1";
|
2026-02-14 21:57:24 +01:00
|
|
|
({ getReplyFromConfig } = await import("./reply.js"));
|
|
|
|
|
});
|
2026-02-22 09:32:41 +00:00
|
|
|
afterAll(() => {
|
|
|
|
|
if (previousFastTestEnv === undefined) {
|
|
|
|
|
delete process.env.OPENCLAW_TEST_FAST;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
process.env.OPENCLAW_TEST_FAST = previousFastTestEnv;
|
|
|
|
|
});
|
2026-02-14 21:57:24 +01:00
|
|
|
|
2026-02-14 18:31:21 +00:00
|
|
|
installTriggerHandlingE2eTestHooks();
|
2026-01-14 01:08:15 +00:00
|
|
|
|
2026-02-23 13:30:47 +00:00
|
|
|
const BASE_MESSAGE = {
|
|
|
|
|
Body: "hello",
|
|
|
|
|
From: "+1002",
|
|
|
|
|
To: "+2000",
|
|
|
|
|
} as const;
|
2026-02-23 12:50:08 +00:00
|
|
|
|
2026-02-23 13:30:47 +00:00
|
|
|
function maybeReplyText(reply: Awaited<ReturnType<typeof getReplyFromConfig>>) {
|
|
|
|
|
return Array.isArray(reply) ? reply[0]?.text : reply?.text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mockEmbeddedOkPayload() {
|
|
|
|
|
return mockRunEmbeddedPiAgentOk("ok");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function writeStoredModelOverride(cfg: ReturnType<typeof makeCfg>): Promise<void> {
|
|
|
|
|
await fs.writeFile(
|
|
|
|
|
requireSessionStorePath(cfg),
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
[MAIN_SESSION_KEY]: {
|
|
|
|
|
sessionId: "main",
|
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
|
providerOverride: "openai",
|
|
|
|
|
modelOverride: "gpt-5.2",
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
"utf-8",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mockSuccessfulCompaction() {
|
|
|
|
|
getCompactEmbeddedPiSessionMock().mockResolvedValue({
|
|
|
|
|
ok: true,
|
|
|
|
|
compacted: true,
|
|
|
|
|
result: {
|
|
|
|
|
summary: "summary",
|
|
|
|
|
firstKeptEntryId: "x",
|
|
|
|
|
tokensBefore: 12000,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-14 01:08:15 +00:00
|
|
|
describe("trigger handling", () => {
|
2026-02-23 13:30:47 +00:00
|
|
|
it("includes the error cause when the embedded agent throws", async () => {
|
|
|
|
|
await withTempHome(async (home) => {
|
|
|
|
|
const runEmbeddedPiAgentMock = getRunEmbeddedPiAgentMock();
|
|
|
|
|
runEmbeddedPiAgentMock.mockRejectedValue(new Error("sandbox is not defined."));
|
|
|
|
|
|
|
|
|
|
const res = await getReplyFromConfig(BASE_MESSAGE, {}, makeCfg(home));
|
|
|
|
|
|
|
|
|
|
expect(maybeReplyText(res)).toBe(
|
|
|
|
|
"⚠️ Agent failed before reply: sandbox is not defined.\nLogs: openclaw logs --follow",
|
|
|
|
|
);
|
|
|
|
|
expect(runEmbeddedPiAgentMock).toHaveBeenCalledOnce();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("uses heartbeat model override for heartbeat runs", async () => {
|
2026-02-23 12:50:08 +00:00
|
|
|
await withTempHome(async (home) => {
|
2026-02-23 13:30:47 +00:00
|
|
|
const runEmbeddedPiAgentMock = mockEmbeddedOkPayload();
|
|
|
|
|
const cfg = makeCfg(home);
|
|
|
|
|
await writeStoredModelOverride(cfg);
|
|
|
|
|
cfg.agents = {
|
|
|
|
|
...cfg.agents,
|
|
|
|
|
defaults: {
|
|
|
|
|
...cfg.agents?.defaults,
|
|
|
|
|
heartbeat: { model: "anthropic/claude-haiku-4-5-20251001" },
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await getReplyFromConfig(BASE_MESSAGE, { isHeartbeat: true }, cfg);
|
|
|
|
|
|
|
|
|
|
const call = runEmbeddedPiAgentMock.mock.calls[0]?.[0];
|
|
|
|
|
expect(call?.provider).toBe("anthropic");
|
|
|
|
|
expect(call?.model).toBe("claude-haiku-4-5-20251001");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("keeps stored model override for heartbeat runs when heartbeat model is not configured", async () => {
|
|
|
|
|
await withTempHome(async (home) => {
|
|
|
|
|
const runEmbeddedPiAgentMock = mockEmbeddedOkPayload();
|
|
|
|
|
const cfg = makeCfg(home);
|
|
|
|
|
await writeStoredModelOverride(cfg);
|
|
|
|
|
await getReplyFromConfig(BASE_MESSAGE, { isHeartbeat: true }, cfg);
|
|
|
|
|
|
|
|
|
|
const call = runEmbeddedPiAgentMock.mock.calls[0]?.[0];
|
|
|
|
|
expect(call?.provider).toBe("openai");
|
|
|
|
|
expect(call?.model).toBe("gpt-5.2");
|
2026-02-23 12:50:08 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-23 13:30:47 +00:00
|
|
|
it("suppresses HEARTBEAT_OK replies outside heartbeat runs", async () => {
|
2026-02-23 12:50:08 +00:00
|
|
|
await withTempHome(async (home) => {
|
2026-02-23 13:30:47 +00:00
|
|
|
const runEmbeddedPiAgentMock = getRunEmbeddedPiAgentMock();
|
|
|
|
|
runEmbeddedPiAgentMock.mockResolvedValue({
|
|
|
|
|
payloads: [{ text: HEARTBEAT_TOKEN }],
|
|
|
|
|
meta: {
|
|
|
|
|
durationMs: 1,
|
|
|
|
|
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const res = await getReplyFromConfig(BASE_MESSAGE, {}, makeCfg(home));
|
|
|
|
|
|
|
|
|
|
expect(res).toBeUndefined();
|
|
|
|
|
expect(runEmbeddedPiAgentMock).toHaveBeenCalledOnce();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("strips HEARTBEAT_OK at edges outside heartbeat runs", async () => {
|
|
|
|
|
await withTempHome(async (home) => {
|
|
|
|
|
const runEmbeddedPiAgentMock = getRunEmbeddedPiAgentMock();
|
|
|
|
|
runEmbeddedPiAgentMock.mockResolvedValue({
|
|
|
|
|
payloads: [{ text: `${HEARTBEAT_TOKEN} hello` }],
|
|
|
|
|
meta: {
|
|
|
|
|
durationMs: 1,
|
|
|
|
|
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const res = await getReplyFromConfig(BASE_MESSAGE, {}, makeCfg(home));
|
|
|
|
|
|
|
|
|
|
expect(maybeReplyText(res)).toBe("hello");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("updates group activation when the owner sends /activation", async () => {
|
|
|
|
|
await withTempHome(async (home) => {
|
|
|
|
|
const runEmbeddedPiAgentMock = getRunEmbeddedPiAgentMock();
|
|
|
|
|
const cfg = makeCfg(home);
|
|
|
|
|
const res = await getReplyFromConfig(
|
|
|
|
|
{
|
|
|
|
|
Body: "/activation always",
|
|
|
|
|
From: "123@g.us",
|
|
|
|
|
To: "+2000",
|
|
|
|
|
ChatType: "group",
|
|
|
|
|
Provider: "whatsapp",
|
|
|
|
|
SenderE164: "+2000",
|
|
|
|
|
CommandAuthorized: true,
|
|
|
|
|
},
|
|
|
|
|
{},
|
|
|
|
|
cfg,
|
|
|
|
|
);
|
|
|
|
|
expect(maybeReplyText(res)).toContain("Group activation set to always");
|
|
|
|
|
const store = JSON.parse(await fs.readFile(requireSessionStorePath(cfg), "utf-8")) as Record<
|
|
|
|
|
string,
|
|
|
|
|
{ groupActivation?: string }
|
|
|
|
|
>;
|
|
|
|
|
expect(store["agent:main:whatsapp:group:123@g.us"]?.groupActivation).toBe("always");
|
|
|
|
|
expect(runEmbeddedPiAgentMock).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("runs /compact as a gated command", async () => {
|
|
|
|
|
await withTempHome(async (home) => {
|
|
|
|
|
const storePath = join(tmpdir(), `openclaw-session-test-${Date.now()}.json`);
|
|
|
|
|
const cfg = makeCfg(home);
|
|
|
|
|
cfg.session = { ...cfg.session, store: storePath };
|
|
|
|
|
mockSuccessfulCompaction();
|
|
|
|
|
|
|
|
|
|
const request = {
|
|
|
|
|
Body: "/compact focus on decisions",
|
|
|
|
|
From: "+1003",
|
|
|
|
|
To: "+2000",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = await getReplyFromConfig(
|
|
|
|
|
{
|
|
|
|
|
...request,
|
|
|
|
|
CommandAuthorized: true,
|
|
|
|
|
},
|
|
|
|
|
{},
|
|
|
|
|
cfg,
|
|
|
|
|
);
|
|
|
|
|
const text = maybeReplyText(res);
|
|
|
|
|
expect(text?.startsWith("⚙️ Compacted")).toBe(true);
|
|
|
|
|
expect(getCompactEmbeddedPiSessionMock()).toHaveBeenCalledOnce();
|
|
|
|
|
expect(getRunEmbeddedPiAgentMock()).not.toHaveBeenCalled();
|
|
|
|
|
const store = loadSessionStore(storePath);
|
|
|
|
|
const sessionKey = resolveSessionKey("per-sender", request);
|
|
|
|
|
expect(store[sessionKey]?.compactionCount).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("runs /compact for non-default agents without transcript path validation failures", async () => {
|
|
|
|
|
await withTempHome(async (home) => {
|
|
|
|
|
getCompactEmbeddedPiSessionMock().mockClear();
|
|
|
|
|
mockSuccessfulCompaction();
|
|
|
|
|
|
|
|
|
|
const res = await getReplyFromConfig(
|
|
|
|
|
{
|
|
|
|
|
Body: "/compact",
|
|
|
|
|
From: "+1004",
|
|
|
|
|
To: "+2000",
|
|
|
|
|
SessionKey: "agent:worker1:telegram:12345",
|
|
|
|
|
CommandAuthorized: true,
|
|
|
|
|
},
|
|
|
|
|
{},
|
|
|
|
|
makeCfg(home),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const text = maybeReplyText(res);
|
|
|
|
|
expect(text?.startsWith("⚙️ Compacted")).toBe(true);
|
|
|
|
|
expect(getCompactEmbeddedPiSessionMock()).toHaveBeenCalledOnce();
|
|
|
|
|
expect(getCompactEmbeddedPiSessionMock().mock.calls[0]?.[0]?.sessionFile).toContain(
|
|
|
|
|
join("agents", "worker1", "sessions"),
|
|
|
|
|
);
|
|
|
|
|
expect(getRunEmbeddedPiAgentMock()).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("ignores think directives that only appear in the context wrapper", async () => {
|
|
|
|
|
await withTempHome(async (home) => {
|
|
|
|
|
mockRunEmbeddedPiAgentOk();
|
|
|
|
|
|
|
|
|
|
const res = await getReplyFromConfig(
|
|
|
|
|
{
|
|
|
|
|
Body: [
|
|
|
|
|
"[Chat messages since your last reply - for context]",
|
|
|
|
|
"Peter: /thinking high [2025-12-05T21:45:00.000Z]",
|
|
|
|
|
"",
|
|
|
|
|
"[Current message - respond to this]",
|
|
|
|
|
"Give me the status",
|
|
|
|
|
].join("\n"),
|
|
|
|
|
From: "+1002",
|
|
|
|
|
To: "+2000",
|
|
|
|
|
},
|
|
|
|
|
{},
|
|
|
|
|
makeCfg(home),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(maybeReplyText(res)).toBe("ok");
|
|
|
|
|
expect(getRunEmbeddedPiAgentMock()).toHaveBeenCalledOnce();
|
|
|
|
|
const prompt = getRunEmbeddedPiAgentMock().mock.calls[0]?.[0]?.prompt ?? "";
|
|
|
|
|
expect(prompt).toContain("Give me the status");
|
|
|
|
|
expect(prompt).not.toContain("/thinking high");
|
|
|
|
|
expect(prompt).not.toContain("/think high");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("does not emit directive acks for heartbeats with /think", async () => {
|
|
|
|
|
await withTempHome(async (home) => {
|
|
|
|
|
mockRunEmbeddedPiAgentOk();
|
|
|
|
|
|
|
|
|
|
const res = await getReplyFromConfig(
|
|
|
|
|
{
|
|
|
|
|
Body: "HEARTBEAT /think:high",
|
|
|
|
|
From: "+1003",
|
|
|
|
|
To: "+1003",
|
|
|
|
|
},
|
|
|
|
|
{ isHeartbeat: true },
|
|
|
|
|
makeCfg(home),
|
|
|
|
|
);
|
2026-02-23 12:50:08 +00:00
|
|
|
|
2026-02-23 13:30:47 +00:00
|
|
|
const text = maybeReplyText(res);
|
|
|
|
|
expect(text).toBe("ok");
|
|
|
|
|
expect(text).not.toMatch(/Thinking level set/i);
|
|
|
|
|
expect(getRunEmbeddedPiAgentMock()).toHaveBeenCalledOnce();
|
2026-02-23 12:50:08 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-14 01:08:15 +00:00
|
|
|
it("targets the active session for native /stop", async () => {
|
|
|
|
|
await withTempHome(async (home) => {
|
|
|
|
|
const cfg = makeCfg(home);
|
2026-02-17 14:32:18 +09:00
|
|
|
const storePath = cfg.session?.store;
|
|
|
|
|
if (!storePath) {
|
|
|
|
|
throw new Error("missing session store path");
|
|
|
|
|
}
|
2026-01-14 01:08:15 +00:00
|
|
|
const targetSessionKey = "agent:main:telegram:group:123";
|
|
|
|
|
const targetSessionId = "session-target";
|
|
|
|
|
await fs.writeFile(
|
2026-02-17 14:32:18 +09:00
|
|
|
storePath,
|
2026-02-22 09:32:41 +00:00
|
|
|
JSON.stringify({
|
|
|
|
|
[targetSessionKey]: {
|
|
|
|
|
sessionId: targetSessionId,
|
|
|
|
|
updatedAt: Date.now(),
|
2026-01-14 01:08:15 +00:00
|
|
|
},
|
2026-02-22 09:32:41 +00:00
|
|
|
}),
|
2026-01-14 01:08:15 +00:00
|
|
|
);
|
2026-01-16 21:15:25 +00:00
|
|
|
const followupRun: FollowupRun = {
|
|
|
|
|
prompt: "queued",
|
|
|
|
|
enqueuedAt: Date.now(),
|
|
|
|
|
run: {
|
|
|
|
|
agentId: "main",
|
|
|
|
|
agentDir: join(home, "agent"),
|
|
|
|
|
sessionId: targetSessionId,
|
|
|
|
|
sessionKey: targetSessionKey,
|
|
|
|
|
messageProvider: "telegram",
|
|
|
|
|
agentAccountId: "acct",
|
|
|
|
|
sessionFile: join(home, "session.jsonl"),
|
|
|
|
|
workspaceDir: join(home, "workspace"),
|
|
|
|
|
config: cfg,
|
|
|
|
|
provider: "anthropic",
|
|
|
|
|
model: "claude-opus-4-5",
|
2026-02-22 09:32:41 +00:00
|
|
|
timeoutMs: 10,
|
2026-01-16 21:15:25 +00:00
|
|
|
blockReplyBreak: "text_end",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
enqueueFollowupRun(
|
|
|
|
|
targetSessionKey,
|
|
|
|
|
followupRun,
|
|
|
|
|
{ mode: "collect", debounceMs: 0, cap: 20, dropPolicy: "summarize" },
|
|
|
|
|
"none",
|
|
|
|
|
);
|
|
|
|
|
expect(getFollowupQueueDepth(targetSessionKey)).toBe(1);
|
2026-01-14 01:08:15 +00:00
|
|
|
|
|
|
|
|
const res = await getReplyFromConfig(
|
|
|
|
|
{
|
|
|
|
|
Body: "/stop",
|
|
|
|
|
From: "telegram:111",
|
|
|
|
|
To: "telegram:111",
|
|
|
|
|
ChatType: "direct",
|
|
|
|
|
Provider: "telegram",
|
|
|
|
|
Surface: "telegram",
|
|
|
|
|
SessionKey: "telegram:slash:111",
|
|
|
|
|
CommandSource: "native",
|
|
|
|
|
CommandTargetSessionKey: targetSessionKey,
|
|
|
|
|
CommandAuthorized: true,
|
|
|
|
|
},
|
|
|
|
|
{},
|
|
|
|
|
cfg,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
2026-01-16 21:41:55 +00:00
|
|
|
expect(text).toBe("⚙️ Agent was aborted.");
|
2026-02-14 18:31:21 +00:00
|
|
|
expect(getAbortEmbeddedPiRunMock()).toHaveBeenCalledWith(targetSessionId);
|
2026-02-17 14:32:18 +09:00
|
|
|
const store = loadSessionStore(storePath);
|
2026-01-14 01:08:15 +00:00
|
|
|
expect(store[targetSessionKey]?.abortedLastRun).toBe(true);
|
2026-01-16 21:15:25 +00:00
|
|
|
expect(getFollowupQueueDepth(targetSessionKey)).toBe(0);
|
2026-01-14 01:08:15 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it("applies native /model to the target session", async () => {
|
|
|
|
|
await withTempHome(async (home) => {
|
|
|
|
|
const cfg = makeCfg(home);
|
2026-02-17 14:32:18 +09:00
|
|
|
const storePath = cfg.session?.store;
|
|
|
|
|
if (!storePath) {
|
|
|
|
|
throw new Error("missing session store path");
|
|
|
|
|
}
|
2026-01-14 01:08:15 +00:00
|
|
|
const slashSessionKey = "telegram:slash:111";
|
|
|
|
|
const targetSessionKey = MAIN_SESSION_KEY;
|
|
|
|
|
|
|
|
|
|
// Seed the target session to ensure the native command mutates it.
|
|
|
|
|
await fs.writeFile(
|
2026-02-17 14:32:18 +09:00
|
|
|
storePath,
|
2026-02-22 09:32:41 +00:00
|
|
|
JSON.stringify({
|
|
|
|
|
[targetSessionKey]: {
|
|
|
|
|
sessionId: "session-target",
|
|
|
|
|
updatedAt: Date.now(),
|
2026-01-14 01:08:15 +00:00
|
|
|
},
|
2026-02-22 09:32:41 +00:00
|
|
|
}),
|
2026-01-14 01:08:15 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const res = await getReplyFromConfig(
|
|
|
|
|
{
|
|
|
|
|
Body: "/model openai/gpt-4.1-mini",
|
|
|
|
|
From: "telegram:111",
|
|
|
|
|
To: "telegram:111",
|
|
|
|
|
ChatType: "direct",
|
|
|
|
|
Provider: "telegram",
|
|
|
|
|
Surface: "telegram",
|
|
|
|
|
SessionKey: slashSessionKey,
|
|
|
|
|
CommandSource: "native",
|
|
|
|
|
CommandTargetSessionKey: targetSessionKey,
|
|
|
|
|
CommandAuthorized: true,
|
|
|
|
|
},
|
|
|
|
|
{},
|
|
|
|
|
cfg,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
|
|
|
|
expect(text).toContain("Model set to openai/gpt-4.1-mini");
|
|
|
|
|
|
2026-02-17 14:32:18 +09:00
|
|
|
const store = loadSessionStore(storePath);
|
2026-01-14 01:08:15 +00:00
|
|
|
expect(store[targetSessionKey]?.providerOverride).toBe("openai");
|
|
|
|
|
expect(store[targetSessionKey]?.modelOverride).toBe("gpt-4.1-mini");
|
|
|
|
|
expect(store[slashSessionKey]).toBeUndefined();
|
|
|
|
|
|
2026-02-14 18:31:21 +00:00
|
|
|
getRunEmbeddedPiAgentMock().mockResolvedValue({
|
2026-01-14 01:08:15 +00:00
|
|
|
payloads: [{ text: "ok" }],
|
|
|
|
|
meta: {
|
|
|
|
|
durationMs: 5,
|
|
|
|
|
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await getReplyFromConfig(
|
|
|
|
|
{
|
|
|
|
|
Body: "hi",
|
|
|
|
|
From: "telegram:111",
|
|
|
|
|
To: "telegram:111",
|
|
|
|
|
ChatType: "direct",
|
|
|
|
|
Provider: "telegram",
|
|
|
|
|
Surface: "telegram",
|
|
|
|
|
},
|
|
|
|
|
{},
|
|
|
|
|
cfg,
|
|
|
|
|
);
|
|
|
|
|
|
2026-02-14 18:31:21 +00:00
|
|
|
expect(getRunEmbeddedPiAgentMock()).toHaveBeenCalledOnce();
|
|
|
|
|
expect(getRunEmbeddedPiAgentMock().mock.calls[0]?.[0]).toEqual(
|
2026-01-14 01:08:15 +00:00
|
|
|
expect.objectContaining({
|
|
|
|
|
provider: "openai",
|
|
|
|
|
model: "gpt-4.1-mini",
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-01-20 19:04:25 +00:00
|
|
|
|
|
|
|
|
it("uses the target agent model for native /status", async () => {
|
|
|
|
|
await withTempHome(async (home) => {
|
2026-02-22 12:41:37 +00:00
|
|
|
const cfg = makeCfg(home) as unknown as OpenClawConfig;
|
|
|
|
|
cfg.agents = {
|
|
|
|
|
...cfg.agents,
|
|
|
|
|
list: [{ id: "coding", model: "minimax/MiniMax-M2.1" }],
|
|
|
|
|
};
|
|
|
|
|
cfg.channels = {
|
|
|
|
|
...cfg.channels,
|
|
|
|
|
telegram: {
|
|
|
|
|
allowFrom: ["*"],
|
2026-01-20 19:04:25 +00:00
|
|
|
},
|
2026-02-22 12:41:37 +00:00
|
|
|
};
|
2026-01-20 19:04:25 +00:00
|
|
|
|
|
|
|
|
const res = await getReplyFromConfig(
|
|
|
|
|
{
|
|
|
|
|
Body: "/status",
|
|
|
|
|
From: "telegram:111",
|
|
|
|
|
To: "telegram:111",
|
|
|
|
|
ChatType: "group",
|
|
|
|
|
Provider: "telegram",
|
|
|
|
|
Surface: "telegram",
|
|
|
|
|
SessionKey: "telegram:slash:111",
|
|
|
|
|
CommandSource: "native",
|
|
|
|
|
CommandTargetSessionKey: "agent:coding:telegram:group:123",
|
|
|
|
|
CommandAuthorized: true,
|
|
|
|
|
},
|
|
|
|
|
{},
|
|
|
|
|
cfg,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
|
|
|
|
expect(text).toContain("minimax/MiniMax-M2.1");
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-01-14 01:08:15 +00:00
|
|
|
});
|