mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:38:27 +00:00
fix: normalize session keys and outbound mirroring
This commit is contained in:
@@ -8,7 +8,6 @@ import { createMessageTool } from "./message-tool.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
runMessageAction: vi.fn(),
|
||||
appendAssistantMessageToSessionTranscript: vi.fn(async () => ({ ok: true, sessionFile: "x" })),
|
||||
}));
|
||||
|
||||
vi.mock("../../infra/outbound/message-action-runner.js", async () => {
|
||||
@@ -21,47 +20,9 @@ vi.mock("../../infra/outbound/message-action-runner.js", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../../config/sessions.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../../config/sessions.js")>(
|
||||
"../../config/sessions.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
appendAssistantMessageToSessionTranscript: mocks.appendAssistantMessageToSessionTranscript,
|
||||
};
|
||||
});
|
||||
|
||||
describe("message tool mirroring", () => {
|
||||
it("mirrors media filename for plugin-handled sends", async () => {
|
||||
mocks.appendAssistantMessageToSessionTranscript.mockClear();
|
||||
mocks.runMessageAction.mockResolvedValue({
|
||||
kind: "send",
|
||||
action: "send",
|
||||
channel: "telegram",
|
||||
handledBy: "plugin",
|
||||
payload: {},
|
||||
dryRun: false,
|
||||
} satisfies MessageActionRunResult);
|
||||
|
||||
const tool = createMessageTool({
|
||||
agentSessionKey: "agent:main:main",
|
||||
config: {} as never,
|
||||
});
|
||||
|
||||
await tool.execute("1", {
|
||||
action: "send",
|
||||
target: "telegram:123",
|
||||
message: "",
|
||||
media: "https://example.com/files/report.pdf?sig=1",
|
||||
});
|
||||
|
||||
expect(mocks.appendAssistantMessageToSessionTranscript).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ text: "report.pdf" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("does not mirror on dry-run", async () => {
|
||||
mocks.appendAssistantMessageToSessionTranscript.mockClear();
|
||||
describe("message tool agent routing", () => {
|
||||
it("derives agentId from the session key", async () => {
|
||||
mocks.runMessageAction.mockClear();
|
||||
mocks.runMessageAction.mockResolvedValue({
|
||||
kind: "send",
|
||||
action: "send",
|
||||
@@ -72,7 +33,7 @@ describe("message tool mirroring", () => {
|
||||
} satisfies MessageActionRunResult);
|
||||
|
||||
const tool = createMessageTool({
|
||||
agentSessionKey: "agent:main:main",
|
||||
agentSessionKey: "agent:alpha:main",
|
||||
config: {} as never,
|
||||
});
|
||||
|
||||
@@ -82,7 +43,9 @@ describe("message tool mirroring", () => {
|
||||
message: "hi",
|
||||
});
|
||||
|
||||
expect(mocks.appendAssistantMessageToSessionTranscript).not.toHaveBeenCalled();
|
||||
const call = mocks.runMessageAction.mock.calls[0]?.[0];
|
||||
expect(call?.agentId).toBe("alpha");
|
||||
expect(call?.sessionKey).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user