mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 14:04:41 -07:00
Fix number of lines being reported in rewind confirmation dialog (#18675)
This commit is contained in:
@@ -41,7 +41,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
debug: vi.fn(),
|
||||
},
|
||||
getFileDiffFromResultDisplay: vi.fn(),
|
||||
computeAddedAndRemovedLines: vi.fn(),
|
||||
computeModelAddedAndRemovedLines: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -68,7 +68,7 @@ describe('rewindFileOps', () => {
|
||||
});
|
||||
|
||||
it('calculates stats for single turn correctly', async () => {
|
||||
const { getFileDiffFromResultDisplay, computeAddedAndRemovedLines } =
|
||||
const { getFileDiffFromResultDisplay, computeModelAddedAndRemovedLines } =
|
||||
await import('@google/gemini-cli-core');
|
||||
vi.mocked(getFileDiffFromResultDisplay).mockReturnValue({
|
||||
filePath: 'test.ts',
|
||||
@@ -88,7 +88,7 @@ describe('rewindFileOps', () => {
|
||||
},
|
||||
fileDiff: 'diff',
|
||||
});
|
||||
vi.mocked(computeAddedAndRemovedLines).mockReturnValue({
|
||||
vi.mocked(computeModelAddedAndRemovedLines).mockReturnValue({
|
||||
addedLines: 3,
|
||||
removedLines: 3,
|
||||
});
|
||||
@@ -124,7 +124,7 @@ describe('rewindFileOps', () => {
|
||||
|
||||
describe('calculateRewindImpact', () => {
|
||||
it('calculates cumulative stats across multiple turns', async () => {
|
||||
const { getFileDiffFromResultDisplay, computeAddedAndRemovedLines } =
|
||||
const { getFileDiffFromResultDisplay, computeModelAddedAndRemovedLines } =
|
||||
await import('@google/gemini-cli-core');
|
||||
vi.mocked(getFileDiffFromResultDisplay)
|
||||
.mockReturnValueOnce({
|
||||
@@ -164,7 +164,7 @@ describe('rewindFileOps', () => {
|
||||
fileDiff: 'diff2',
|
||||
});
|
||||
|
||||
vi.mocked(computeAddedAndRemovedLines)
|
||||
vi.mocked(computeModelAddedAndRemovedLines)
|
||||
.mockReturnValueOnce({ addedLines: 5, removedLines: 3 })
|
||||
.mockReturnValueOnce({ addedLines: 4, removedLines: 0 });
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
coreEvents,
|
||||
debugLogger,
|
||||
getFileDiffFromResultDisplay,
|
||||
computeAddedAndRemovedLines,
|
||||
computeModelAddedAndRemovedLines,
|
||||
} from '@google/gemini-cli-core';
|
||||
|
||||
export interface FileChangeDetail {
|
||||
@@ -61,7 +61,7 @@ export function calculateTurnStats(
|
||||
if (fileDiff) {
|
||||
hasEdits = true;
|
||||
const stats = fileDiff.diffStat;
|
||||
const calculations = computeAddedAndRemovedLines(stats);
|
||||
const calculations = computeModelAddedAndRemovedLines(stats);
|
||||
addedLines += calculations.addedLines;
|
||||
removedLines += calculations.removedLines;
|
||||
|
||||
@@ -112,7 +112,7 @@ export function calculateRewindImpact(
|
||||
if (fileDiff) {
|
||||
hasEdits = true;
|
||||
const stats = fileDiff.diffStat;
|
||||
const calculations = computeAddedAndRemovedLines(stats);
|
||||
const calculations = computeModelAddedAndRemovedLines(stats);
|
||||
addedLines += calculations.addedLines;
|
||||
removedLines += calculations.removedLines;
|
||||
files.add(fileDiff.fileName);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
getFileDiffFromResultDisplay,
|
||||
computeAddedAndRemovedLines,
|
||||
computeModelAddedAndRemovedLines,
|
||||
} from './fileDiffUtils.js';
|
||||
import type { FileDiff, ToolResultDisplay } from '../tools/tools.js';
|
||||
|
||||
@@ -57,7 +57,7 @@ describe('fileDiffUtils', () => {
|
||||
|
||||
describe('computeAddedAndRemovedLines', () => {
|
||||
it('returns 0 added and 0 removed if stats is undefined', () => {
|
||||
expect(computeAddedAndRemovedLines(undefined)).toEqual({
|
||||
expect(computeModelAddedAndRemovedLines(undefined)).toEqual({
|
||||
addedLines: 0,
|
||||
removedLines: 0,
|
||||
});
|
||||
@@ -75,10 +75,10 @@ describe('fileDiffUtils', () => {
|
||||
user_removed_chars: 10,
|
||||
};
|
||||
|
||||
const result = computeAddedAndRemovedLines(stats);
|
||||
const result = computeModelAddedAndRemovedLines(stats);
|
||||
expect(result).toEqual({
|
||||
addedLines: 12, // 10 + 2
|
||||
removedLines: 6, // 5 + 1
|
||||
addedLines: 10,
|
||||
removedLines: 5,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -94,7 +94,7 @@ describe('fileDiffUtils', () => {
|
||||
user_removed_chars: 0,
|
||||
};
|
||||
|
||||
const result = computeAddedAndRemovedLines(stats);
|
||||
const result = computeModelAddedAndRemovedLines(stats);
|
||||
expect(result).toEqual({
|
||||
addedLines: 0,
|
||||
removedLines: 0,
|
||||
|
||||
@@ -31,7 +31,7 @@ export function getFileDiffFromResultDisplay(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function computeAddedAndRemovedLines(
|
||||
export function computeModelAddedAndRemovedLines(
|
||||
stats: FileDiff['diffStat'] | undefined,
|
||||
): {
|
||||
addedLines: number;
|
||||
@@ -44,7 +44,7 @@ export function computeAddedAndRemovedLines(
|
||||
};
|
||||
}
|
||||
return {
|
||||
addedLines: stats.model_added_lines + stats.user_added_lines,
|
||||
removedLines: stats.model_removed_lines + stats.user_removed_lines,
|
||||
addedLines: stats.model_added_lines,
|
||||
removedLines: stats.model_removed_lines,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user