integration.test.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { describe, test, expect } from "bun:test"
  2. import { Patch } from "../../src/patch"
  3. describe("Patch integration", () => {
  4. test("should be compatible with existing tool system", () => {
  5. // Test that our Patch namespace can be imported and used
  6. expect(Patch).toBeDefined()
  7. expect(Patch.parsePatch).toBeDefined()
  8. expect(Patch.applyPatch).toBeDefined()
  9. expect(Patch.maybeParseApplyPatch).toBeDefined()
  10. expect(Patch.PatchSchema).toBeDefined()
  11. })
  12. test("should parse patch format compatible with existing tool", () => {
  13. const patchText = `*** Begin Patch
  14. *** Add File: test-integration.txt
  15. +Integration test content
  16. *** End Patch`
  17. const result = Patch.parsePatch(patchText)
  18. expect(result.hunks).toHaveLength(1)
  19. expect(result.hunks[0].type).toBe("add")
  20. expect(result.hunks[0].path).toBe("test-integration.txt")
  21. if (result.hunks[0].type === "add") {
  22. expect(result.hunks[0].contents).toBe("Integration test content")
  23. }
  24. })
  25. test("should handle complex patch with multiple operations", () => {
  26. const patchText = `*** Begin Patch
  27. *** Add File: new-file.txt
  28. +This is a new file
  29. +with multiple lines
  30. *** Update File: existing.txt
  31. @@
  32. old content
  33. -line to remove
  34. +line to add
  35. more content
  36. *** Delete File: old-file.txt
  37. *** End Patch`
  38. const result = Patch.parsePatch(patchText)
  39. expect(result.hunks).toHaveLength(3)
  40. // Check add operation
  41. expect(result.hunks[0].type).toBe("add")
  42. if (result.hunks[0].type === "add") {
  43. expect(result.hunks[0].contents).toBe("This is a new file\nwith multiple lines")
  44. }
  45. // Check update operation
  46. expect(result.hunks[1].type).toBe("update")
  47. if (result.hunks[1].type === "update") {
  48. expect(result.hunks[1].path).toBe("existing.txt")
  49. expect(result.hunks[1].chunks).toHaveLength(1)
  50. expect(result.hunks[1].chunks[0].old_lines).toEqual(["old content", "line to remove", "more content"])
  51. expect(result.hunks[1].chunks[0].new_lines).toEqual(["old content", "line to add", "more content"])
  52. expect(result.hunks[1].chunks[0].change_context).toBeUndefined()
  53. }
  54. // Check delete operation
  55. expect(result.hunks[2].type).toBe("delete")
  56. expect(result.hunks[2].path).toBe("old-file.txt")
  57. })
  58. })