fix(chat): handle truncated diff headers
This commit is contained in:
@@ -2,7 +2,7 @@ import { describe, expect, test } from 'bun:test';
|
||||
|
||||
import { getStreamingOutputAppend, getToolOutput, renderTerminalOutput } from './toolOutput';
|
||||
import { readTaskTagSessionIdFromOutput } from './taskSessionIdParser';
|
||||
import { tryParseJsonOutput } from '../toolRenderers';
|
||||
import { parseDiffToUnified, tryParseJsonOutput } from '../toolRenderers';
|
||||
import { getStreamingThrottleText } from '../../hooks/useStreamingTextThrottle';
|
||||
import { getToolDescriptionFallback } from './toolRenderUtils';
|
||||
|
||||
@@ -42,6 +42,29 @@ describe('getToolOutput', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseDiffToUnified', () => {
|
||||
test('handles a streamed diff with a bare Index header', () => {
|
||||
expect(parseDiffToUnified('Index:')).toEqual([]);
|
||||
expect(parseDiffToUnified('Index:\n@@ -1,1 +1,1 @@\n-old\n+new')).toEqual([
|
||||
{
|
||||
file: 'file',
|
||||
oldStart: 1,
|
||||
newStart: 1,
|
||||
lines: [
|
||||
{ type: 'removed', lineNumber: 1, content: 'old' },
|
||||
{ type: 'added', lineNumber: 1, content: 'new' },
|
||||
],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('preserves spaces when extracting the indexed filename', () => {
|
||||
const [hunk] = parseDiffToUnified('Index: src/my file.ts\n@@ -1,1 +1,1 @@\n-old\n+new');
|
||||
|
||||
expect(hunk?.file).toBe('my file.ts');
|
||||
});
|
||||
});
|
||||
|
||||
describe('renderTerminalOutput', () => {
|
||||
test('renders carriage-return progress updates as their latest value', () => {
|
||||
expect(renderTerminalOutput('Downloading 10%\r\u001B[2KDownloading 90%')).toBe('Downloading 90%');
|
||||
|
||||
@@ -575,7 +575,7 @@ export const parseDiffToUnified = (diffText: string): UnifiedDiffHunk[] => {
|
||||
|
||||
if (line.startsWith('Index:') || line.startsWith('===') || line.startsWith('---') || line.startsWith('+++')) {
|
||||
if (line.startsWith('Index:')) {
|
||||
currentFile = line.split(' ')[1].split('/').pop() || 'file';
|
||||
currentFile = line.slice('Index:'.length).trim().split('/').pop() || 'file';
|
||||
}
|
||||
i++;
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user