fix(core): improve history merging logic and switch to stable flash for e2e tests

This commit is contained in:
Sehoon Shon
2026-03-31 15:54:42 -04:00
parent 4b72b7f846
commit 4bb389efb7
2 changed files with 34 additions and 23 deletions
+32 -21
View File
@@ -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;
+2 -2
View File
@@ -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,
},
}
: {}),