-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Skip large diffs when generating context for the LLM
This skips diffs larger than 1000 characters when generating input for @WELCOME and @review. Large diffs are replaced with a message, for example diff --git a/file2.txt b/file2.txt [Change of size 2078] Fixes #2173
- Loading branch information
1 parent
355d931
commit abaf705
Showing
4 changed files
with
187 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { mkdir, writeFile } from 'fs/promises'; | ||
import { join } from 'path'; | ||
import tmp from 'tmp-promise'; | ||
import { findRepository } from '../../../src/lib/git'; | ||
|
||
import { findRepository, processPatchset } from '../../../src/lib/git'; | ||
|
||
describe('git.ts', () => { | ||
test.each([ | ||
|
@@ -38,6 +39,159 @@ describe('git.ts', () => { | |
{ unsafeCleanup: true } | ||
); | ||
}); | ||
|
||
describe('processPatchset', () => { | ||
it('should handle patchset with small diffs correctly', () => { | ||
const patchset = `diff --git a/file1.txt b/file1.txt | ||
index 83db48f..f735c4e 100644 | ||
--- a/file1.txt | ||
+++ b/file1.txt | ||
@@ -1,3 +1,3 @@ | ||
-Hello World | ||
+Hello AppMap | ||
This is a test file.`; | ||
|
||
const result = processPatchset(patchset, 1000); | ||
expect(result).toContain('Hello AppMap'); | ||
}); | ||
|
||
it('should have the correct output format', () => { | ||
const largeDiff = 'a'.repeat(2000); | ||
const patchset = `Here's some header. | ||
diff --git a/file1.txt b/file1.txt | ||
index 83db48f..f735c4e 100644 | ||
--- a/file1.txt | ||
+++ b/file1.txt | ||
@@ -1,3 +1,3 @@ | ||
-Hello World | ||
+Hello AppMap | ||
This is a test file. | ||
diff --git a/file2.txt b/file2.txt | ||
index 83db48f..f735c4e 100644 | ||
--- a/file2.txt | ||
+++ b/file2.txt | ||
@@ -1,3 +1,3 @@ | ||
${largeDiff} | ||
diff --git a/file3.txt b/file3.txt | ||
index 83db48f..f735c4e 100644 | ||
--- a/file3.txt | ||
+++ b/file3.txt | ||
@@ -1,3 +1,3 @@ | ||
-Hello World | ||
+Hello AppMap | ||
This is another test file.`; | ||
|
||
const result = processPatchset(patchset, 1000); | ||
expect(result).toMatchInlineSnapshot(` | ||
"Here's some header. | ||
diff --git a/file1.txt b/file1.txt | ||
index 83db48f..f735c4e 100644 | ||
--- a/file1.txt | ||
+++ b/file1.txt | ||
@@ -1,3 +1,3 @@ | ||
-Hello World | ||
+Hello AppMap | ||
This is a test file. | ||
diff --git a/file2.txt b/file2.txt | ||
[Change of size 2078] | ||
diff --git a/file3.txt b/file3.txt | ||
index 83db48f..f735c4e 100644 | ||
--- a/file3.txt | ||
+++ b/file3.txt | ||
@@ -1,3 +1,3 @@ | ||
-Hello World | ||
+Hello AppMap | ||
This is another test file." | ||
`); | ||
}); | ||
|
||
it('should handle patchsets with multiple commit headers like from git log', () => { | ||
const patchset = `commit 1 | ||
Author: John Doe <[email protected]> | ||
Date: Mon Jan 1 12:00:00 2023 +0000 | ||
Initial commit | ||
diff --git a/file1.txt b/file1.txt | ||
index 83db48f..f735c4e 100644 | ||
--- a/file1.txt | ||
+++ b/file1.txt | ||
@@ -1,3 +1,3 @@ | ||
-Hello World | ||
+Hello AppMap | ||
This is a test file. | ||
commit 2 | ||
Author: Jane Doe <[email protected]> | ||
Date: Tue Jan 2 12:00:00 2023 +0000 | ||
Second commit | ||
diff --git a/file2.txt b/file2.txt | ||
index 83db48f..f735c4e 100644 | ||
--- a/file2.txt | ||
+++ b/file2.txt | ||
@@ -1,3 +1,3 @@ | ||
-Hello World | ||
+Hello AppMap | ||
This is another test file.`; | ||
|
||
const result = processPatchset(patchset, 10); | ||
expect(result).toMatchInlineSnapshot(` | ||
"commit 1 | ||
Author: John Doe <[email protected]> | ||
Date: Mon Jan 1 12:00:00 2023 +0000 | ||
Initial commit | ||
diff --git a/file1.txt b/file1.txt | ||
[Change of size 126] | ||
commit 2 | ||
Author: Jane Doe <[email protected]> | ||
Date: Tue Jan 2 12:00:00 2023 +0000 | ||
Second commit | ||
diff --git a/file2.txt b/file2.txt | ||
[Change of size 132] | ||
" | ||
`); | ||
}); | ||
|
||
it('should handle patchset with large diffs correctly', () => { | ||
const largeDiff = 'a'.repeat(2000); | ||
const patchset = `diff --git a/file2.txt b/file2.txt | ||
index 83db48f..f735c4e 100644 | ||
--- a/file2.txt | ||
+++ b/file2.txt | ||
@@ -1,3 +1,3 @@ | ||
${largeDiff}`; | ||
|
||
const result = processPatchset(patchset, 1000); | ||
expect(result).toContain('[Change of size 2078]'); | ||
}); | ||
|
||
it('should handle patchset with mixed diff sizes correctly', () => { | ||
const largeDiff = 'a'.repeat(2000); | ||
const smallDiff = 'b'.repeat(500); | ||
const patchset = `diff --git a/file3.txt b/file3.txt | ||
index 83db48f..f735c4e 100644 | ||
--- a/file3.txt | ||
+++ b/file3.txt | ||
@@ -1,3 +1,3 @@ | ||
${largeDiff} | ||
diff --git a/file4.txt b/file4.txt | ||
index 83db48f..f735c4e 100644 | ||
--- a/file4.txt | ||
+++ b/file4.txt | ||
@@ -1,3 +1,3 @@ | ||
${smallDiff}`; | ||
|
||
const result = processPatchset(patchset, 1000); | ||
expect(result).toContain('[Change of size 2078]'); | ||
expect(result).toContain(smallDiff); | ||
}); | ||
}); | ||
}); | ||
|
||
function unindent(str: string) { | ||
|