mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-15 12:30:32 -07:00
cleanup continue
This commit is contained in:
@@ -72,7 +72,7 @@ export class SimulationHarness {
|
||||
mockTempDir,
|
||||
mockTempDir,
|
||||
this.tracer,
|
||||
4, // 4 chars per token average
|
||||
1, // 1 char per token average
|
||||
this.eventBus,
|
||||
new InMemoryFileSystem(),
|
||||
new DeterministicIdGenerator(),
|
||||
|
||||
+148
-10
@@ -133,30 +133,168 @@ exports[`System Lifecycle Golden Tests > Scenario 1: Organic Growth with Huge To
|
||||
],
|
||||
"tokenTrajectory": [
|
||||
{
|
||||
"tokensAfterBackground": 14,
|
||||
"tokensBeforeBackground": 14,
|
||||
"tokensAfterBackground": 34,
|
||||
"tokensBeforeBackground": 34,
|
||||
"turnIndex": 0,
|
||||
},
|
||||
{
|
||||
"tokensAfterBackground": 29,
|
||||
"tokensBeforeBackground": 29,
|
||||
"tokensAfterBackground": 70,
|
||||
"tokensBeforeBackground": 70,
|
||||
"turnIndex": 1,
|
||||
},
|
||||
{
|
||||
"tokensAfterBackground": 10137,
|
||||
"tokensBeforeBackground": 10137,
|
||||
"tokensAfterBackground": 25370,
|
||||
"tokensBeforeBackground": 25370,
|
||||
"turnIndex": 2,
|
||||
},
|
||||
{
|
||||
"tokensAfterBackground": 13422,
|
||||
"tokensBeforeBackground": 13422,
|
||||
"tokensAfterBackground": 28692,
|
||||
"tokensBeforeBackground": 28692,
|
||||
"turnIndex": 3,
|
||||
},
|
||||
{
|
||||
"tokensAfterBackground": 13438,
|
||||
"tokensBeforeBackground": 13438,
|
||||
"tokensAfterBackground": 28731,
|
||||
"tokensBeforeBackground": 28731,
|
||||
"turnIndex": 4,
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`System Lifecycle Golden Tests > Scenario 2: Under Budget (No Modifications) 1`] = `
|
||||
{
|
||||
"finalProjection": [
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "System Instructions",
|
||||
},
|
||||
],
|
||||
"role": "user",
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "Ack.",
|
||||
},
|
||||
{
|
||||
"text": "Yield",
|
||||
},
|
||||
],
|
||||
"role": "model",
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "Hello!",
|
||||
},
|
||||
],
|
||||
"role": "user",
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "Hi, how can I help?",
|
||||
},
|
||||
{
|
||||
"text": "Yield",
|
||||
},
|
||||
],
|
||||
"role": "model",
|
||||
},
|
||||
],
|
||||
"tokenTrajectory": [
|
||||
{
|
||||
"tokensAfterBackground": 34,
|
||||
"tokensBeforeBackground": 34,
|
||||
"turnIndex": 0,
|
||||
},
|
||||
{
|
||||
"tokensAfterBackground": 70,
|
||||
"tokensBeforeBackground": 70,
|
||||
"turnIndex": 1,
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`System Lifecycle Golden Tests > Scenario 3: Worker-Driven Background GC 1`] = `
|
||||
{
|
||||
"finalProjection": [
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
||||
},
|
||||
],
|
||||
"role": "user",
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
|
||||
},
|
||||
{
|
||||
"text": "Yield",
|
||||
},
|
||||
],
|
||||
"role": "model",
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
|
||||
},
|
||||
],
|
||||
"role": "user",
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD",
|
||||
},
|
||||
{
|
||||
"text": "Yield",
|
||||
},
|
||||
],
|
||||
"role": "model",
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
|
||||
},
|
||||
],
|
||||
"role": "user",
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
|
||||
},
|
||||
{
|
||||
"text": "Yield",
|
||||
},
|
||||
],
|
||||
"role": "model",
|
||||
},
|
||||
],
|
||||
"tokenTrajectory": [
|
||||
{
|
||||
"tokensAfterBackground": 130,
|
||||
"tokensBeforeBackground": 130,
|
||||
"turnIndex": 0,
|
||||
},
|
||||
{
|
||||
"tokensAfterBackground": 260,
|
||||
"tokensBeforeBackground": 260,
|
||||
"turnIndex": 1,
|
||||
},
|
||||
{
|
||||
"tokensAfterBackground": 390,
|
||||
"tokensBeforeBackground": 390,
|
||||
"turnIndex": 2,
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('System Lifecycle Golden Tests', () => {
|
||||
});
|
||||
|
||||
const getAggressiveConfig = (): SidecarConfig => ({
|
||||
budget: { maxTokens: 4000, retainedTokens: 2000 }, // Extremely tight limits
|
||||
budget: { maxTokens: 1000, retainedTokens: 500 }, // Extremely tight limits
|
||||
pipelines: [
|
||||
{
|
||||
name: 'Pressure Relief', // Emits from eventBus 'retained_exceeded'
|
||||
@@ -42,7 +42,7 @@ describe('System Lifecycle Golden Tests', () => {
|
||||
{
|
||||
processorId: 'ToolMaskingProcessor',
|
||||
options: { stringLengthThresholdTokens: 50 },
|
||||
}, // Mask any tool string > 200 chars
|
||||
}, // Mask any tool string > 50 chars
|
||||
{ processorId: 'StateSnapshotProcessor', options: {} }, // Squash old history
|
||||
],
|
||||
},
|
||||
@@ -54,6 +54,9 @@ describe('System Lifecycle Golden Tests', () => {
|
||||
],
|
||||
},
|
||||
],
|
||||
workers: [
|
||||
{ workerId: 'StateSnapshotWorker' }
|
||||
]
|
||||
});
|
||||
|
||||
const mockLlmClient = createMockLlmClient([
|
||||
@@ -138,4 +141,75 @@ describe('System Lifecycle Golden Tests', () => {
|
||||
|
||||
expect(goldenState).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('Scenario 2: Under Budget (No Modifications)', async () => {
|
||||
const generousConfig: SidecarConfig = {
|
||||
budget: { maxTokens: 100000, retainedTokens: 50000 },
|
||||
pipelines: [], // No triggers
|
||||
workers: []
|
||||
};
|
||||
|
||||
const harness = await SimulationHarness.create(
|
||||
generousConfig,
|
||||
mockLlmClient,
|
||||
);
|
||||
|
||||
// Turn 0: System Prompt
|
||||
await harness.simulateTurn([
|
||||
{ role: 'user', parts: [{ text: 'System Instructions' }] },
|
||||
{ role: 'model', parts: [{ text: 'Ack.' }] },
|
||||
]);
|
||||
|
||||
// Turn 1: Normal conversation
|
||||
await harness.simulateTurn([
|
||||
{ role: 'user', parts: [{ text: 'Hello!' }] },
|
||||
{ role: 'model', parts: [{ text: 'Hi, how can I help?' }] },
|
||||
]);
|
||||
|
||||
const goldenState = await harness.getGoldenState();
|
||||
|
||||
// Total tokens should cleanly match character count with no synthetic nodes
|
||||
expect(goldenState).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('Scenario 3: Worker-Driven Background GC', async () => {
|
||||
const gcConfig: SidecarConfig = {
|
||||
budget: { maxTokens: 200, retainedTokens: 100 },
|
||||
pipelines: [], // No standard pipelines
|
||||
workers: [
|
||||
{ workerId: 'StateSnapshotWorker' } // This should fire on chunk events
|
||||
]
|
||||
};
|
||||
|
||||
const harness = await SimulationHarness.create(
|
||||
gcConfig,
|
||||
mockLlmClient,
|
||||
);
|
||||
|
||||
// Turn 0
|
||||
await harness.simulateTurn([
|
||||
{ role: 'user', parts: [{ text: 'A'.repeat(50) }] },
|
||||
{ role: 'model', parts: [{ text: 'B'.repeat(50) }] },
|
||||
]);
|
||||
|
||||
// Turn 1 (Should trigger StateSnapshotWorker because we exceed 100 retainedTokens)
|
||||
await harness.simulateTurn([
|
||||
{ role: 'user', parts: [{ text: 'C'.repeat(50) }] },
|
||||
{ role: 'model', parts: [{ text: 'D'.repeat(50) }] },
|
||||
]);
|
||||
|
||||
// Give the background worker an extra beat to complete its async execution and emit variants
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
// Turn 2
|
||||
await harness.simulateTurn([
|
||||
{ role: 'user', parts: [{ text: 'E'.repeat(50) }] },
|
||||
{ role: 'model', parts: [{ text: 'F'.repeat(50) }] },
|
||||
]);
|
||||
|
||||
const goldenState = await harness.getGoldenState();
|
||||
|
||||
// We should see ROLLING_SUMMARY nodes injected into the graph, proving the worker ran in the background
|
||||
expect(goldenState).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user