File size: 1,625 Bytes
d197cf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { describe, expect, it } from "vitest";
import { normalizeMessagePresentation, renderMessagePresentationFallbackText } from "./payload.js";

describe("presentation payload controls", () => {
  it("keeps typed select commands actionable without exposing callback values", () => {
    expect(
      renderMessagePresentationFallbackText({
        presentation: {
          blocks: [
            {
              type: "select",
              placeholder: "Environment",
              options: [
                { label: "Canary", action: { type: "command", command: "/deploy canary" } },
                {
                  label: "Production",
                  action: { type: "command", command: "/deploy production" },
                },
                { label: "Opaque", action: { type: "callback", value: "private-callback-token" } },
              ],
            },
          ],
        },
      }),
    ).toBe(
      "Environment:\n- Canary: `/deploy canary`\n- Production: `/deploy production`\n- Opaque",
    );
  });

  it("normalizes only the known custom-input question intent", () => {
    const action = {
      type: "question" as const,
      questionId: "ask_0123456789abcdef0123456789abcdef",
    };
    const presentation = (intent: string) => ({
      blocks: [
        { type: "buttons" as const, buttons: [{ label: "Other…", action: { ...action, intent } }] },
      ],
    });

    expect(normalizeMessagePresentation(presentation("custom-input"))).toEqual(
      presentation("custom-input"),
    );
    expect(normalizeMessagePresentation(presentation("unknown"))).toBeUndefined();
  });
});