mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-10 16:51:13 +00:00
* fix: pass agentId in CLI message command to enable session transcript writes The CLI `openclaw message send` command was not passing `agentId` to `runMessageAction()`, causing the outbound session route resolution to be skipped (it's gated on `agentId && !dryRun`). Without a route, the `mirror` object is never constructed, and `appendAssistantMessageToSessionTranscript()` is never called. This fix resolves the agent ID from the config (defaulting to "main") and passes it through, enabling transcript mirroring for all channels when using the CLI. Closes #54186 * fix: format message.ts with oxfmt * fix: use resolveDefaultAgentId instead of cfg.agent * fix: restore CLI message transcript mirroring (#54187) (thanks @KevInTheCloud5617) --------- Co-authored-by: Ayaan Zaidi <hi@obviy.us>
82 lines
1.9 KiB
TypeScript
82 lines
1.9 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { CliDeps } from "../cli/outbound-send-deps.js";
|
|
import type { RuntimeEnv } from "../runtime.js";
|
|
|
|
let testConfig: Record<string, unknown> = {};
|
|
|
|
const resolveCommandSecretRefsViaGateway = vi.hoisted(() =>
|
|
vi.fn(async ({ config }: { config: unknown }) => ({
|
|
resolvedConfig: config,
|
|
diagnostics: [] as string[],
|
|
})),
|
|
);
|
|
const runMessageAction = vi.hoisted(() =>
|
|
vi.fn(async () => ({
|
|
kind: "send" as const,
|
|
channel: "telegram" as const,
|
|
action: "send" as const,
|
|
to: "123456",
|
|
handledBy: "core" as const,
|
|
payload: { ok: true },
|
|
dryRun: false,
|
|
})),
|
|
);
|
|
|
|
vi.mock("../config/config.js", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("../config/config.js")>();
|
|
return {
|
|
...actual,
|
|
loadConfig: () => testConfig,
|
|
};
|
|
});
|
|
|
|
vi.mock("../cli/command-secret-gateway.js", () => ({
|
|
resolveCommandSecretRefsViaGateway,
|
|
}));
|
|
|
|
vi.mock("../infra/outbound/message-action-runner.js", () => ({
|
|
runMessageAction,
|
|
}));
|
|
|
|
describe("messageCommand agent routing", () => {
|
|
beforeEach(() => {
|
|
testConfig = {};
|
|
resolveCommandSecretRefsViaGateway.mockClear();
|
|
runMessageAction.mockClear();
|
|
});
|
|
|
|
it("passes the resolved default agent id to the outbound runner", async () => {
|
|
testConfig = {
|
|
agents: {
|
|
list: [{ id: "alpha" }, { id: "ops", default: true }],
|
|
},
|
|
};
|
|
|
|
const runtime: RuntimeEnv = {
|
|
log: vi.fn(),
|
|
error: vi.fn(),
|
|
exit: vi.fn(),
|
|
};
|
|
|
|
const { messageCommand } = await import("./message.js");
|
|
|
|
await messageCommand(
|
|
{
|
|
action: "send",
|
|
channel: "telegram",
|
|
target: "123456",
|
|
message: "hi",
|
|
json: true,
|
|
},
|
|
{} as CliDeps,
|
|
runtime,
|
|
);
|
|
|
|
expect(runMessageAction).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
agentId: "ops",
|
|
}),
|
|
);
|
|
});
|
|
});
|