mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-08-18 05:04:45 +00:00
fix(web-shell): prefer raw file diffs in tool output (#5992)
Co-authored-by: ytahdn <ytahdn@gmail.com>
This commit is contained in:
parent
23830a180b
commit
b737364892
2 changed files with 33 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ vi.mock('../../App', async () => {
|
|||
|
||||
const {
|
||||
buildUnifiedDiff,
|
||||
extractDiff,
|
||||
formatToolGroupSummary,
|
||||
getActiveTool,
|
||||
getRawFileDiff,
|
||||
|
|
@ -184,6 +185,32 @@ describe('tool output logic', () => {
|
|||
).toBe('');
|
||||
});
|
||||
|
||||
it('prefers raw fileDiff over content old/new text', () => {
|
||||
const fileDiff =
|
||||
'Index: file.ts\n@@ -10,1 +10,2 @@\n old context\n+precise line';
|
||||
|
||||
expect(
|
||||
extractDiff(
|
||||
makeTool({
|
||||
toolName: 'edit',
|
||||
content: [
|
||||
{
|
||||
type: 'diff',
|
||||
oldText: 'full old text',
|
||||
newText: 'full new text',
|
||||
},
|
||||
],
|
||||
rawOutput: {
|
||||
fileDiff,
|
||||
fileName: 'file.ts',
|
||||
originalContent: 'full old text',
|
||||
newContent: 'full new text',
|
||||
},
|
||||
}),
|
||||
),
|
||||
).toBe(fileDiff);
|
||||
});
|
||||
|
||||
it('builds a unified diff for changed content blocks', () => {
|
||||
expect(buildUnifiedDiff('same\nold', 'same\nnew')).toBe(
|
||||
' same\n-old\n+new',
|
||||
|
|
|
|||
|
|
@ -110,14 +110,18 @@ function hasEditContent(tool: ACPToolCall): boolean {
|
|||
return hasDiffContent(tool) || !!extractText(tool);
|
||||
}
|
||||
|
||||
function extractDiff(tool: ACPToolCall): string {
|
||||
export function extractDiff(tool: ACPToolCall): string {
|
||||
const rawFileDiff = getRawFileDiff(tool);
|
||||
if (rawFileDiff) return rawFileDiff;
|
||||
|
||||
if (tool.content) {
|
||||
const diffBlock = tool.content.find((b) => b.type === 'diff');
|
||||
if (diffBlock && diffBlock.type === 'diff') {
|
||||
return buildUnifiedDiff(diffBlock.oldText || '', diffBlock.newText || '');
|
||||
}
|
||||
}
|
||||
return getRawFileDiff(tool);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
export function getRawFileDiff(tool: ACPToolCall): string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue