From 894b443d6a9d214dfd70332ad73f3122091266e4 Mon Sep 17 00:00:00 2001 From: waleedcodes <110061477+waleedcodes@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:24:05 +0500 Subject: [PATCH 1/3] test(diff): scaffold diff parser test suite --- tests/diffParser.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/diffParser.test.ts diff --git a/tests/diffParser.test.ts b/tests/diffParser.test.ts new file mode 100644 index 0000000..5fce140 --- /dev/null +++ b/tests/diffParser.test.ts @@ -0,0 +1,19 @@ +import { describe, expect, it } from 'vitest'; +import { DiffParser } from '../src/git/diffParser'; + +describe('DiffParser', () => { + it('should parse an empty diff without error', () => { + const result = DiffParser.parse('', '/test/root'); + expect(result.files).toHaveLength(0); + expect(result.totalFilesChanged).toBe(0); + expect(result.totalInsertions).toBe(0); + expect(result.totalDeletions).toBe(0); + }); + + it('should parse a standard unified diff with additions and deletions', () => { + const sampleDiff = `diff --git a/src/user.ts b/src/user.ts +index e69de29..49e29a1 100644 +--- a/src/user.ts ++++ b/src/user.ts +@@ -10,3 +10,5 @@ export function getUser(id: string) { +- return db.user.find(id); From 05cd1881e47cb15347ab65383d1e56a44b23b6f5 Mon Sep 17 00:00:00 2001 From: waleedcodes <110061477+waleedcodes@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:24:05 +0500 Subject: [PATCH 2/3] test(diff): test single file added and deleted line extraction --- tests/diffParser.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/diffParser.test.ts b/tests/diffParser.test.ts index 5fce140..d7e071d 100644 --- a/tests/diffParser.test.ts +++ b/tests/diffParser.test.ts @@ -17,3 +17,25 @@ index e69de29..49e29a1 100644 +++ b/src/user.ts @@ -10,3 +10,5 @@ export function getUser(id: string) { - return db.user.find(id); ++ const user = await db.user.findUnique({ where: { id } }); ++ return user; + } ++export function deleteUser() {} +`; + + const result = DiffParser.parse(sampleDiff, '/workspace'); + expect(result.files).toHaveLength(1); + const file = result.files[0]; + expect(file.newPath).toBe('src/user.ts'); + expect(file.addedLines).toEqual([10, 11, 13]); + expect(file.deletedLines).toEqual([10]); + expect(file.modifiedLineRanges).toEqual([ + { start: 10, end: 11 }, + { start: 13, end: 13 } + ]); + }); + + it('should identify new files correctly', () => { + const newFileDiff = `diff --git a/src/new-route.ts b/src/new-route.ts +new file mode 100644 +index 0000000..49e29a1 From ecc325008989485546a2c3f44b97f71f239a98e3 Mon Sep 17 00:00:00 2001 From: waleedcodes <110061477+waleedcodes@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:24:05 +0500 Subject: [PATCH 3/3] test(diff): test multi-file diff parsing and empty diff edge cases --- tests/diffParser.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/diffParser.test.ts b/tests/diffParser.test.ts index d7e071d..8a69cda 100644 --- a/tests/diffParser.test.ts +++ b/tests/diffParser.test.ts @@ -39,3 +39,17 @@ index e69de29..49e29a1 100644 const newFileDiff = `diff --git a/src/new-route.ts b/src/new-route.ts new file mode 100644 index 0000000..49e29a1 +--- /dev/null ++++ b/src/new-route.ts +@@ -0,0 +1,3 @@ ++export async function GET() { ++ return Response.json({ status: 'ok' }); ++} +`; + + const result = DiffParser.parse(newFileDiff, '/workspace'); + expect(result.files).toHaveLength(1); + expect(result.files[0].isNew).toBe(true); + expect(result.files[0].addedLines).toEqual([1, 2, 3]); + }); +});