mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:10:44 +00:00
test: share command delivery media fixture
This commit is contained in:
@@ -28,6 +28,7 @@ vi.mock("../../auto-reply/reply/reply-media-paths.runtime.js", () => ({
|
||||
|
||||
type NormalizeParams = Parameters<typeof normalizeAgentCommandReplyPayloads>[0];
|
||||
type RunResult = NormalizeParams["result"];
|
||||
type DeliverParams = Parameters<typeof deliverAgentCommandResult>[0];
|
||||
|
||||
const slackOutboundForTest: ChannelOutboundAdapter = {
|
||||
deliveryMode: "direct",
|
||||
@@ -64,6 +65,29 @@ function createResult(overrides: Partial<RunResult> = {}): RunResult {
|
||||
} as RunResult;
|
||||
}
|
||||
|
||||
async function deliverMediaReplyForTest(outboundSession: DeliverParams["outboundSession"]) {
|
||||
const runtime = { log: vi.fn(), error: vi.fn() };
|
||||
return await deliverAgentCommandResult({
|
||||
cfg: {
|
||||
agents: {
|
||||
list: [{ id: "tester", workspace: "/tmp/agent-workspace" }],
|
||||
},
|
||||
} as OpenClawConfig,
|
||||
deps: {} as CliDeps,
|
||||
runtime: runtime as never,
|
||||
opts: {
|
||||
message: "go",
|
||||
deliver: true,
|
||||
replyChannel: "slack",
|
||||
replyTo: "#general",
|
||||
} as AgentCommandOpts,
|
||||
outboundSession,
|
||||
sessionEntry: undefined,
|
||||
payloads: [{ text: "here you go", mediaUrls: ["./out/photo.png"] }],
|
||||
result: createResult(),
|
||||
});
|
||||
}
|
||||
|
||||
describe("normalizeAgentCommandReplyPayloads", () => {
|
||||
beforeEach(() => {
|
||||
setActivePluginRegistry(slackRegistry);
|
||||
@@ -157,7 +181,6 @@ describe("normalizeAgentCommandReplyPayloads", () => {
|
||||
});
|
||||
|
||||
it("normalizes reply-media paths before outbound delivery", async () => {
|
||||
const runtime = { log: vi.fn(), error: vi.fn() };
|
||||
const normalizerFn = vi.fn(
|
||||
async (payload: ReplyPayload): Promise<ReplyPayload> => ({
|
||||
...payload,
|
||||
@@ -168,28 +191,10 @@ describe("normalizeAgentCommandReplyPayloads", () => {
|
||||
createReplyMediaPathNormalizerMock.mockReturnValue(normalizerFn);
|
||||
deliverOutboundPayloadsMock.mockResolvedValue([]);
|
||||
|
||||
await deliverAgentCommandResult({
|
||||
cfg: {
|
||||
agents: {
|
||||
list: [{ id: "tester", workspace: "/tmp/agent-workspace" }],
|
||||
},
|
||||
} as OpenClawConfig,
|
||||
deps: {} as CliDeps,
|
||||
runtime: runtime as never,
|
||||
opts: {
|
||||
message: "go",
|
||||
deliver: true,
|
||||
replyChannel: "slack",
|
||||
replyTo: "#general",
|
||||
} as AgentCommandOpts,
|
||||
outboundSession: {
|
||||
key: "agent:tester:slack:direct:alice",
|
||||
agentId: "tester",
|
||||
} as never,
|
||||
sessionEntry: undefined,
|
||||
payloads: [{ text: "here you go", mediaUrls: ["./out/photo.png"] }],
|
||||
result: createResult(),
|
||||
});
|
||||
await deliverMediaReplyForTest({
|
||||
key: "agent:tester:slack:direct:alice",
|
||||
agentId: "tester",
|
||||
} as never);
|
||||
|
||||
expect(createReplyMediaPathNormalizerMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
@@ -211,29 +216,10 @@ describe("normalizeAgentCommandReplyPayloads", () => {
|
||||
});
|
||||
|
||||
it("threads agentId into the normalizer when sessionKey is unresolved", async () => {
|
||||
const runtime = { log: vi.fn(), error: vi.fn() };
|
||||
createReplyMediaPathNormalizerMock.mockReturnValue(async (payload: ReplyPayload) => payload);
|
||||
deliverOutboundPayloadsMock.mockResolvedValue([]);
|
||||
|
||||
await deliverAgentCommandResult({
|
||||
cfg: {
|
||||
agents: {
|
||||
list: [{ id: "tester", workspace: "/tmp/agent-workspace" }],
|
||||
},
|
||||
} as OpenClawConfig,
|
||||
deps: {} as CliDeps,
|
||||
runtime: runtime as never,
|
||||
opts: {
|
||||
message: "go",
|
||||
deliver: true,
|
||||
replyChannel: "slack",
|
||||
replyTo: "#general",
|
||||
} as AgentCommandOpts,
|
||||
outboundSession: { agentId: "tester" } as never,
|
||||
sessionEntry: undefined,
|
||||
payloads: [{ text: "here you go", mediaUrls: ["./out/photo.png"] }],
|
||||
result: createResult(),
|
||||
});
|
||||
await deliverMediaReplyForTest({ agentId: "tester" } as never);
|
||||
|
||||
expect(createReplyMediaPathNormalizerMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
|
||||
Reference in New Issue
Block a user