v4TopicInputMessages.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { describe, expect, it } from "vitest";
  2. import type { UserInputRow } from "@zcode/shared/zcode-protocol-v4";
  3. import { expandTopicInputMessages } from "@/v4/topicInputMessages.js";
  4. describe("topic input presentation", () => {
  5. it("keeps original senders and attachment ownership while showing history only once", () => {
  6. const row = {
  7. kind: "userInput",
  8. rowId: 1,
  9. entityId: "input",
  10. text: "combined model text",
  11. attachments: [{ ref: "file-a" }, { ref: "file-b" }, { ref: "history" }],
  12. botGroupSource: {
  13. provider: "feishu",
  14. botId: "bot",
  15. chatId: "chat",
  16. threadId: "topic",
  17. senderId: "b",
  18. senderName: "B",
  19. messageId: "b",
  20. messages: [
  21. {
  22. messageId: "a",
  23. senderId: "a",
  24. senderName: "A",
  25. text: "first",
  26. attachmentIndexes: [0],
  27. conversationQuotes: [{ text: "root" }],
  28. },
  29. {
  30. messageId: "b",
  31. senderId: "b",
  32. senderName: "B",
  33. text: "second",
  34. attachmentIndexes: [1],
  35. },
  36. ],
  37. },
  38. } as UserInputRow;
  39. const rows = expandTopicInputMessages(row);
  40. expect(rows.map((r) => [r.text, r.botGroupSource?.senderName])).toEqual([
  41. ["first", "A"],
  42. ["second", "B"],
  43. ]);
  44. expect(rows.map((r) => r.attachments?.map((a) => a.ref))).toEqual([
  45. ["file-a", "history"],
  46. ["file-b"],
  47. ]);
  48. expect(rows[0]?.conversationQuotes).toEqual([{ text: "root" }]);
  49. expect(rows[1]?.conversationQuotes).toEqual([]);
  50. expect(row.text).toBe("combined model text");
  51. });
  52. it("preserves normal user input identity", () => {
  53. const row = { kind: "userInput", text: "normal" } as UserInputRow;
  54. expect(expandTopicInputMessages(row)).toEqual([row]);
  55. expect(expandTopicInputMessages(row)[0]).toBe(row);
  56. });
  57. });