fix(slack): scope attachment extraction to forwarded shares

This commit is contained in:
Sebastian
2026-02-16 20:36:55 -05:00
parent fb996031bc
commit 67250f059a
4 changed files with 171 additions and 9 deletions

View File

@@ -1,16 +1,16 @@
import type { App } from "@slack/bolt";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import type { App } from "@slack/bolt";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import { expectInboundContextContract } from "../../../../test/helpers/inbound-contract.js";
import type { OpenClawConfig } from "../../../config/config.js";
import { resolveAgentRoute } from "../../../routing/resolve-route.js";
import { resolveThreadSessionKeys } from "../../../routing/session-key.js";
import type { RuntimeEnv } from "../../../runtime.js";
import type { ResolvedSlackAccount } from "../../accounts.js";
import type { SlackMessageEvent } from "../../types.js";
import type { SlackMonitorContext } from "../context.js";
import { expectInboundContextContract } from "../../../../test/helpers/inbound-contract.js";
import { resolveAgentRoute } from "../../../routing/resolve-route.js";
import { resolveThreadSessionKeys } from "../../../routing/session-key.js";
import { createSlackMonitorContext } from "../context.js";
import { prepareSlackMessage } from "./prepare.js";
@@ -184,6 +184,30 @@ describe("slack prepareSlackMessage inbound contract", () => {
expectInboundContextContract(prepared!.ctxPayload as any);
});
it("includes forwarded shared attachment text in raw body", async () => {
const prepared = await prepareWithDefaultCtx(
createSlackMessage({
text: "",
attachments: [{ is_share: true, author_name: "Bob", text: "Forwarded hello" }],
}),
);
expect(prepared).toBeTruthy();
expect(prepared!.ctxPayload.RawBody).toContain("[Forwarded message from Bob]\nForwarded hello");
});
it("ignores non-forward attachments when no direct text/files are present", async () => {
const prepared = await prepareWithDefaultCtx(
createSlackMessage({
text: "",
files: [],
attachments: [{ is_msg_unfurl: true, text: "link unfurl text" }],
}),
);
expect(prepared).toBeNull();
});
it("keeps channel metadata out of GroupSystemPrompt", async () => {
const slackCtx = createInboundSlackCtx({
cfg: {