mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-16 14:53:19 -07:00
fix(core): improve history merging logic and switch to stable flash for e2e tests
This commit is contained in:
@@ -166,30 +166,41 @@ function extractCuratedHistory(comprehensiveHistory: Content[]): Content[] {
|
||||
const length = comprehensiveHistory.length;
|
||||
let i = 0;
|
||||
while (i < length) {
|
||||
if (comprehensiveHistory[i].role === 'user') {
|
||||
const userMessage: Content = {
|
||||
role: 'user',
|
||||
parts: [...(comprehensiveHistory[i].parts || [])],
|
||||
};
|
||||
i++;
|
||||
while (i < length && comprehensiveHistory[i].role === 'user') {
|
||||
userMessage.parts!.push(...(comprehensiveHistory[i].parts || []));
|
||||
i++;
|
||||
const role = comprehensiveHistory[i].role;
|
||||
const parts: Part[] = [];
|
||||
let isValid = true;
|
||||
|
||||
while (i < length && comprehensiveHistory[i].role === role) {
|
||||
if (
|
||||
isValid &&
|
||||
role === 'model' &&
|
||||
!isValidContent(comprehensiveHistory[i])
|
||||
) {
|
||||
isValid = false;
|
||||
}
|
||||
curatedHistory.push(userMessage);
|
||||
} else {
|
||||
const modelOutput: Content[] = [];
|
||||
let isValid = true;
|
||||
while (i < length && comprehensiveHistory[i].role === 'model') {
|
||||
modelOutput.push(comprehensiveHistory[i]);
|
||||
if (isValid && !isValidContent(comprehensiveHistory[i])) {
|
||||
isValid = false;
|
||||
|
||||
const entryParts = comprehensiveHistory[i].parts || [];
|
||||
for (const part of entryParts) {
|
||||
if (
|
||||
parts.length > 0 &&
|
||||
parts[parts.length - 1].text !== undefined &&
|
||||
part.text !== undefined
|
||||
) {
|
||||
// Merge consecutive text parts using a new object to avoid corruption
|
||||
parts[parts.length - 1] = {
|
||||
...parts[parts.length - 1],
|
||||
text: parts[parts.length - 1].text + '\n' + part.text,
|
||||
};
|
||||
} else {
|
||||
// Deep copy the part to avoid reference issues
|
||||
parts.push({ ...part });
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (isValid) {
|
||||
curatedHistory.push(...modelOutput);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (isValid && parts.length > 0) {
|
||||
curatedHistory.push({ role, parts });
|
||||
}
|
||||
}
|
||||
return curatedHistory;
|
||||
|
||||
@@ -12,7 +12,7 @@ import { fileURLToPath } from 'node:url';
|
||||
import { env } from 'node:process';
|
||||
import { setTimeout as sleep } from 'node:timers/promises';
|
||||
import {
|
||||
PREVIEW_GEMINI_FLASH_MODEL,
|
||||
DEFAULT_GEMINI_FLASH_MODEL,
|
||||
GEMINI_DIR,
|
||||
} from '@google/gemini-cli-core';
|
||||
export { GEMINI_DIR };
|
||||
@@ -460,7 +460,7 @@ export class TestRig {
|
||||
...(env['GEMINI_TEST_TYPE'] === 'integration'
|
||||
? {
|
||||
model: {
|
||||
name: PREVIEW_GEMINI_FLASH_MODEL,
|
||||
name: DEFAULT_GEMINI_FLASH_MODEL,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
|
||||
Reference in New Issue
Block a user