topicHistoryAttachment.test.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { describe, expect, it } from "vitest";
  2. import { createTopicHistoryAttachment } from "../src/bots/topicHistoryAttachment.js";
  3. describe("topic history text material", () => {
  4. const batch = {
  5. checkpoint: "om_current",
  6. hasGap: false,
  7. messages: [
  8. {
  9. id: "om_a",
  10. chatId: "oc_a",
  11. threadId: "omt_a",
  12. senderId: "ou_alice",
  13. senderName: "Alice",
  14. senderType: "user" as const,
  15. createdAt: 1000,
  16. kind: "post",
  17. text: "line one\nline two",
  18. attachments: [{ name: "diagram.png", kind: "image" }],
  19. },
  20. ],
  21. };
  22. it("keeps sender identity and original lines, and scopes resource indexes to this snapshot", () => {
  23. const result = createTopicHistoryAttachment(batch, "input-a", "Design");
  24. expect(result).toMatchObject({ sourceKind: "topic-history", messageCount: 1 });
  25. for (const text of [
  26. "Alice",
  27. "ou_alice",
  28. "line one\nline two",
  29. "input-a",
  30. "diagram.png",
  31. "A1",
  32. "M1",
  33. "UTC",
  34. ])
  35. expect(result!.textContent).toContain(text);
  36. expect(result!.textContent).not.toContain("bot_topic_context");
  37. expect(createTopicHistoryAttachment(batch, "input-b", "Design")!.filename).not.toBe(
  38. result!.filename,
  39. );
  40. });
  41. it("does not duplicate empty history; preserves unavailable coverage as a file", () => {
  42. expect(
  43. createTopicHistoryAttachment({ ...batch, messages: [] }, "empty", "Design"),
  44. ).toBeUndefined();
  45. expect(
  46. createTopicHistoryAttachment({ ...batch, messages: [], hasGap: true }, "gap", "Design")
  47. ?.textContent,
  48. ).toContain("incomplete");
  49. });
  50. });