prompt-part.test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { describe, expect, test } from "bun:test"
  2. import type { PromptInfo } from "../../../../src/cli/cmd/tui/component/prompt/history"
  3. import { assign, strip } from "../../../../src/cli/cmd/tui/component/prompt/part"
  4. describe("prompt part", () => {
  5. test("strip removes persisted ids from reused file parts", () => {
  6. const part = {
  7. id: "prt_old",
  8. sessionID: "ses_old",
  9. messageID: "msg_old",
  10. type: "file" as const,
  11. mime: "image/png",
  12. filename: "tiny.png",
  13. url: "data:image/png;base64,abc",
  14. }
  15. expect(strip(part)).toEqual({
  16. type: "file",
  17. mime: "image/png",
  18. filename: "tiny.png",
  19. url: "data:image/png;base64,abc",
  20. })
  21. })
  22. test("assign overwrites stale runtime ids", () => {
  23. const part = {
  24. id: "prt_old",
  25. sessionID: "ses_old",
  26. messageID: "msg_old",
  27. type: "file" as const,
  28. mime: "image/png",
  29. filename: "tiny.png",
  30. url: "data:image/png;base64,abc",
  31. } as PromptInfo["parts"][number]
  32. const next = assign(part)
  33. expect(next.id).not.toBe("prt_old")
  34. expect(next.id.startsWith("prt_")).toBe(true)
  35. expect(next).toMatchObject({
  36. type: "file",
  37. mime: "image/png",
  38. filename: "tiny.png",
  39. url: "data:image/png;base64,abc",
  40. })
  41. })
  42. })