mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-14 03:50:49 -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;
|
const length = comprehensiveHistory.length;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (i < length) {
|
while (i < length) {
|
||||||
if (comprehensiveHistory[i].role === 'user') {
|
const role = comprehensiveHistory[i].role;
|
||||||
const userMessage: Content = {
|
const parts: Part[] = [];
|
||||||
role: 'user',
|
let isValid = true;
|
||||||
parts: [...(comprehensiveHistory[i].parts || [])],
|
|
||||||
};
|
while (i < length && comprehensiveHistory[i].role === role) {
|
||||||
i++;
|
if (
|
||||||
while (i < length && comprehensiveHistory[i].role === 'user') {
|
isValid &&
|
||||||
userMessage.parts!.push(...(comprehensiveHistory[i].parts || []));
|
role === 'model' &&
|
||||||
i++;
|
!isValidContent(comprehensiveHistory[i])
|
||||||
|
) {
|
||||||
|
isValid = false;
|
||||||
}
|
}
|
||||||
curatedHistory.push(userMessage);
|
|
||||||
} else {
|
const entryParts = comprehensiveHistory[i].parts || [];
|
||||||
const modelOutput: Content[] = [];
|
for (const part of entryParts) {
|
||||||
let isValid = true;
|
if (
|
||||||
while (i < length && comprehensiveHistory[i].role === 'model') {
|
parts.length > 0 &&
|
||||||
modelOutput.push(comprehensiveHistory[i]);
|
parts[parts.length - 1].text !== undefined &&
|
||||||
if (isValid && !isValidContent(comprehensiveHistory[i])) {
|
part.text !== undefined
|
||||||
isValid = false;
|
) {
|
||||||
|
// 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;
|
return curatedHistory;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { fileURLToPath } from 'node:url';
|
|||||||
import { env } from 'node:process';
|
import { env } from 'node:process';
|
||||||
import { setTimeout as sleep } from 'node:timers/promises';
|
import { setTimeout as sleep } from 'node:timers/promises';
|
||||||
import {
|
import {
|
||||||
PREVIEW_GEMINI_FLASH_MODEL,
|
DEFAULT_GEMINI_FLASH_MODEL,
|
||||||
GEMINI_DIR,
|
GEMINI_DIR,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
export { GEMINI_DIR };
|
export { GEMINI_DIR };
|
||||||
@@ -460,7 +460,7 @@ export class TestRig {
|
|||||||
...(env['GEMINI_TEST_TYPE'] === 'integration'
|
...(env['GEMINI_TEST_TYPE'] === 'integration'
|
||||||
? {
|
? {
|
||||||
model: {
|
model: {
|
||||||
name: PREVIEW_GEMINI_FLASH_MODEL,
|
name: DEFAULT_GEMINI_FLASH_MODEL,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
|
|||||||
Reference in New Issue
Block a user