part.test.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { describe, expect, test } from "bun:test"
  2. import { expandTrackedPastedText, stripPromptPartIDs } from "../../src/prompt/part"
  3. describe("prompt part", () => {
  4. test("strips persisted IDs from reused parts", () => {
  5. expect(
  6. stripPromptPartIDs({
  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. ).toEqual({
  16. type: "file",
  17. mime: "image/png",
  18. filename: "tiny.png",
  19. url: "data:image/png;base64,abc",
  20. })
  21. })
  22. test("preserves wide characters around pasted text", () => {
  23. const marker = "[Pasted ~3 lines]"
  24. const prefix = "你好你好\n"
  25. expect(
  26. expandTrackedPastedText(prefix + marker + "\n阿斯顿法国红酒看来", [
  27. {
  28. start: Bun.stringWidth("你好你好") + 1,
  29. end: Bun.stringWidth("你好你好") + 1 + Bun.stringWidth(marker),
  30. text: "public:\n\tvoid ExecuteTask();\nprivate:",
  31. },
  32. ]),
  33. ).toBe("你好你好\npublic:\n\tvoid ExecuteTask();\nprivate:\n阿斯顿法国红酒看来")
  34. })
  35. test("only expands the tracked placeholder occurrence", () => {
  36. const marker = "[Pasted ~3 lines]"
  37. const prefix = `keep ${marker} then `
  38. expect(
  39. expandTrackedPastedText(prefix + marker + " tail", [
  40. {
  41. start: Bun.stringWidth(prefix),
  42. end: Bun.stringWidth(prefix + marker),
  43. text: "alpha\nbeta\ngamma",
  44. },
  45. ]),
  46. ).toBe(`keep ${marker} then alpha\nbeta\ngamma tail`)
  47. })
  48. })