|
| 1 | +/** |
| 2 | + * Copyright 2026 GoodRx, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { buildProposedFileChanges } from '../fileChanges'; |
| 18 | + |
| 19 | +describe('buildProposedFileChanges', () => { |
| 20 | + it('keeps workspace edit approvals as before-and-after previews instead of fake diffs', () => { |
| 21 | + const [change] = buildProposedFileChanges({ |
| 22 | + toolCallId: 'tool-1', |
| 23 | + sourceTool: 'workspace.edit_file', |
| 24 | + input: { |
| 25 | + path: '/workspace/sample-service/app.js', |
| 26 | + oldText: 'before', |
| 27 | + newText: 'after', |
| 28 | + }, |
| 29 | + }); |
| 30 | + |
| 31 | + expect(change).toMatchObject({ |
| 32 | + id: 'tool-1:sample-service/app.js', |
| 33 | + toolCallId: 'tool-1', |
| 34 | + sourceTool: 'workspace.edit_file', |
| 35 | + path: '/workspace/sample-service/app.js', |
| 36 | + displayPath: 'sample-service/app.js', |
| 37 | + stage: 'awaiting-approval', |
| 38 | + unifiedDiff: null, |
| 39 | + beforeTextPreview: 'before', |
| 40 | + afterTextPreview: 'after', |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + it('keeps workspace writes as preview-only changes', () => { |
| 45 | + const [change] = buildProposedFileChanges({ |
| 46 | + toolCallId: 'tool-2', |
| 47 | + sourceTool: 'workspace.write_file', |
| 48 | + input: { |
| 49 | + path: '/workspace/sample-service/README.md', |
| 50 | + content: '# Sample service', |
| 51 | + }, |
| 52 | + }); |
| 53 | + |
| 54 | + expect(change).toMatchObject({ |
| 55 | + id: 'tool-2:sample-service/README.md', |
| 56 | + toolCallId: 'tool-2', |
| 57 | + sourceTool: 'workspace.write_file', |
| 58 | + path: '/workspace/sample-service/README.md', |
| 59 | + displayPath: 'sample-service/README.md', |
| 60 | + stage: 'awaiting-approval', |
| 61 | + unifiedDiff: null, |
| 62 | + beforeTextPreview: null, |
| 63 | + afterTextPreview: '# Sample service', |
| 64 | + }); |
| 65 | + }); |
| 66 | +}); |
0 commit comments