summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/edit.test.ts
diff options
context:
space:
mode:
authoranj-s <[email protected]>2025-06-05 06:48:03 -0700
committerGitHub <[email protected]>2025-06-05 06:48:03 -0700
commit78b2a28fb612994e84df67ef95e34fdd01241fac (patch)
tree76c8cb8eaa7fe05463d11c0982e87486609361c3 /packages/core/src/tools/edit.test.ts
parentaa386d135b4fbe46b6dca95f28f0450543ac7d7d (diff)
Checks for diff changes before displaying the code snippet (#751)
Diffstat (limited to 'packages/core/src/tools/edit.test.ts')
-rw-r--r--packages/core/src/tools/edit.test.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/packages/core/src/tools/edit.test.ts b/packages/core/src/tools/edit.test.ts
index 87ae3b6f..603128bc 100644
--- a/packages/core/src/tools/edit.test.ts
+++ b/packages/core/src/tools/edit.test.ts
@@ -547,4 +547,57 @@ describe('EditTool', () => {
);
});
});
+
+ describe('getDescription', () => {
+ it('should return "No file changes to..." if old_string and new_string are the same', () => {
+ const testFileName = 'test.txt';
+ const params: EditToolParams = {
+ file_path: path.join(rootDir, testFileName),
+ old_string: 'identical_string',
+ new_string: 'identical_string',
+ };
+ // shortenPath will be called internally, resulting in just the file name
+ expect(tool.getDescription(params)).toBe(
+ `No file changes to ${testFileName}`,
+ );
+ });
+
+ it('should return a snippet of old and new strings if they are different', () => {
+ const testFileName = 'test.txt';
+ const params: EditToolParams = {
+ file_path: path.join(rootDir, testFileName),
+ old_string: 'this is the old string value',
+ new_string: 'this is the new string value',
+ };
+ // shortenPath will be called internally, resulting in just the file name
+ // The snippets are truncated at 30 chars + '...'
+ expect(tool.getDescription(params)).toBe(
+ `${testFileName}: this is the old string value => this is the new string value`,
+ );
+ });
+
+ it('should handle very short strings correctly in the description', () => {
+ const testFileName = 'short.txt';
+ const params: EditToolParams = {
+ file_path: path.join(rootDir, testFileName),
+ old_string: 'old',
+ new_string: 'new',
+ };
+ expect(tool.getDescription(params)).toBe(`${testFileName}: old => new`);
+ });
+
+ it('should truncate long strings in the description', () => {
+ const testFileName = 'long.txt';
+ const params: EditToolParams = {
+ file_path: path.join(rootDir, testFileName),
+ old_string:
+ 'this is a very long old string that will definitely be truncated',
+ new_string:
+ 'this is a very long new string that will also be truncated',
+ };
+ expect(tool.getDescription(params)).toBe(
+ `${testFileName}: this is a very long old string... => this is a very long new string...`,
+ );
+ });
+ });
});