zcodeProtocolV4AttachmentSource.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. userInputRowSchema,
  4. v4AttachmentReadResultSchema,
  5. PROTOCOL_V4_LIMITS,
  6. } from "../src/zcode-protocol-v4/index.js";
  7. describe("V4 attachment source across row transport", () => {
  8. it("accepts text preview responses and keeps the text attachment size limit", () => {
  9. const response = {
  10. dataBase64: "aGk=",
  11. mediaType: "text/plain; charset=utf-8",
  12. totalBytes: 2,
  13. nextOffset: null,
  14. };
  15. expect(v4AttachmentReadResultSchema.parse(response)).toEqual(response);
  16. expect(() =>
  17. v4AttachmentReadResultSchema.parse({
  18. ...response,
  19. totalBytes: PROTOCOL_V4_LIMITS.attachmentMaxBytes + 1,
  20. }),
  21. ).toThrow();
  22. expect(() =>
  23. v4AttachmentReadResultSchema.parse({ ...response, mediaType: "text/html" }),
  24. ).toThrow();
  25. });
  26. it.each(["clipboard-text", "topic-history"])(
  27. "preserves %s on the executed user row",
  28. (sourceKind) => {
  29. const attachment = {
  30. ref: "zcode-artifact://history",
  31. fileName: "history.txt",
  32. mime: "text/plain",
  33. bytes: 84,
  34. sourceKind,
  35. messageCount: 1,
  36. };
  37. const row = userInputRowSchema.parse({
  38. rowId: 1,
  39. turnId: "turn-1",
  40. createdAt: 1,
  41. createdAtSeq: 1,
  42. kind: "userInput",
  43. origin: "realUser",
  44. text: "request",
  45. attachments: [attachment],
  46. });
  47. expect(row.attachments).toEqual([attachment]);
  48. },
  49. );
  50. });