import { describe, expect, it } from "vitest"; import { buildSlackProgressDraftBlocks } from "./progress-blocks.js"; function progressLine(index: number) { return { kind: "tool" as const, icon: "๐Ÿ› ๏ธ", label: `Exec ${index}`, detail: `run ${index}`, text: `๐Ÿ› ๏ธ Exec ${index}: run ${index}`, }; } describe("buildSlackProgressDraftBlocks", () => { it("renders structured progress lines as compact Block Kit fields", () => { expect( buildSlackProgressDraftBlocks({ label: "Shelling...", lines: [ { kind: "tool", icon: "๐Ÿ› ๏ธ", label: "Exec", detail: "run tests", text: "๐Ÿ› ๏ธ Exec: run tests", toolName: "exec", }, ], }), ).toEqual([ { type: "section", text: { type: "mrkdwn", text: "*Shelling...*" }, }, { type: "section", fields: [ { type: "mrkdwn", text: "๐Ÿ› ๏ธ *Exec*" }, { type: "mrkdwn", text: "run tests" }, ], }, ]); }); it("compacts long rich details independently from the text fallback", () => { const blocks = buildSlackProgressDraftBlocks({ lines: [ { kind: "tool", icon: "๐Ÿ› ๏ธ", label: "Exec", detail: "run tests in /Users/example/Projects/openclaw/packages/very/deep/path/example", text: "๐Ÿ› ๏ธ Exec: run tests in /Users/example/Projects/openclaw/packages/very/deep/path/example", }, ], }); expect(blocks?.[0]).toEqual({ type: "section", fields: [ { type: "mrkdwn", text: "๐Ÿ› ๏ธ *Exec*" }, { type: "mrkdwn", text: "run tests in /Users/exโ€ฆes/very/deep/path/example" }, ], }); }); it("keeps newest rich progress lines when capping Slack blocks", () => { const blocksWithLabel = buildSlackProgressDraftBlocks({ label: "Shelling...", lines: Array.from({ length: 60 }, (_value, index) => progressLine(index)), }); expect(blocksWithLabel).toHaveLength(50); expect(blocksWithLabel?.[0]).toMatchObject({ type: "section", fields: [{ text: "๐Ÿ› ๏ธ *Exec 10*" }, { text: "run 10" }], }); expect(blocksWithLabel?.at(-1)).toMatchObject({ type: "section", fields: [{ text: "๐Ÿ› ๏ธ *Exec 59*" }, { text: "run 59" }], }); const blocksWithoutLabel = buildSlackProgressDraftBlocks({ lines: Array.from({ length: 60 }, (_value, index) => progressLine(index)), }); expect(blocksWithoutLabel).toHaveLength(50); expect(blocksWithoutLabel?.[0]).toMatchObject({ type: "section", fields: [{ text: "๐Ÿ› ๏ธ *Exec 10*" }, { text: "run 10" }], }); expect(blocksWithoutLabel?.at(-1)).toMatchObject({ type: "section", fields: [{ text: "๐Ÿ› ๏ธ *Exec 59*" }, { text: "run 59" }], }); }); });